DataJunction / dj

A metrics platform.
http://datajunction.io
MIT License
35 stars 15 forks source link

Make sure that we detect cycles in the dimensions traversal queries #1189

Closed shangyian closed 1 month ago

shangyian commented 1 month ago

Summary

This change adds cycle detection to the recursive queries used to traverse the dimensions graph. We do so by adding CYCLE node_revision_id SET is_cycle USING path to the recursive CTE, which is recommended in the Postgres docs.

We also add a depth parameter to the API call, so that clients can make less expensive queries if they only need a few levels and not the entire graph. The default depth is set to 30, which is reasonable for the vast majority of cases. Note that if we actually have circular loops, keeping the cycle detection from above will make it significantly faster for the query to return, since it will stop traversing immediately after detecting a cycle.

Test Plan

Deployment Plan

netlify[bot] commented 1 month ago

Deploy Preview for thriving-cassata-78ae72 canceled.

Name Link
Latest commit 4014e954b7813e1da72846f198120a7f8ccbd5d0
Latest deploy log https://app.netlify.com/sites/thriving-cassata-78ae72/deploys/66fe1e3b5994f80008a3ccbe