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.
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 defaultdepth
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
make check
passesmake test
shows 100% unit test coverageDeployment Plan