cwida / duckpgq-extension

DuckDB extension that adds support for SQL/PGQ
https://duckpgq.notion.site/b8ac652667964f958bfada1c3e53f1bb?v=3b47a8d44bdf4e0c8b503bf23f1b76f2
MIT License
86 stars 7 forks source link

Move shortest path function to CTE #133

Closed Dtenwolde closed 3 months ago

Dtenwolde commented 3 months ago

Fixes #131 This PR moves the shortest path function to a materialized CTE as described in the issue above. A quick benchmark:

FROM GRAPH_TABLE (snb
        MATCH o = ANY SHORTEST (p:Person where p.firstName = 'John')-[k:knows]-> *(p2:Person) 
        COLUMNS(element_id(o), path_length(o), vertices(o), edges(o)));

main -- a4cd66bcbd957705c565ab354a2346bee9ac4fbe: Run Time (s): real 547.356 user 518.047915 sys 24.484855

This PR -- 944ac096aa7c14c8f1564b98577d7ed3f28ab145 Run Time (s): real 111.225 user 104.965922 sys 4.298592

This is the best case possible where all four functions are called. In the old way, the shortest path function was executed four times. Now it will only be called once and the results are materialized.

Performance will be the same if the query only calls the function once.