Repository navigation
fix(plan): reject nested recursive CTE references - #27326
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed exact head 8492495. The earlier nested-recursive stack-overflow path is closed by resolving the exact active CTE state across the BindContext parent chain instead of consulting only the replaceable current state. SELECT query-block identity is established at bindSelect, structural FROM and JOIN contexts inherit it, and nested query blocks are rejected before recursive expansion. Tests cover EXISTS, scalar, and nested-recursive failures plus legal JOIN, correlation-only, and independent nested-recursion controls, with a public SQL service-health regression. No blocking findings.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of exact head 8492495770e2dc02353f6a02c69be70ee11fdfc9: APPROVED.
The previous nested-recursive stack-overflow blocker is closed. Recursive scan reuse now resolves the exact active CTE state across the BindContext parent chain, so replacing the current state with a nested recursive CTE cannot hide an still-active outer owner. SELECT query-block identity changes at nested SELECT boundaries while structural FROM and JOIN contexts inherit it, which rejects nested recursive sources before expansion without rejecting legal top-level joins or correlation-only subqueries.
The deterministic nested-WITH reproducer now returns the normal recursive-table validation error, and the controls cover legal nested recursion and recursive scan counts. Focused controlled-CGo TestRecursiveCTEQueryBlockReferenceScope passes on this exact head. I found no blocking issue in the complete PR diff.
aptend
left a comment
There was a problem hiding this comment.
Deep re-review completed against exact head 8492495. The previous nested-recursive stack-overflow blocker is closed: active recursive ownership is resolved by CTERef identity through the BindContext parent chain, while queryBlockOwner changes at nested SELECT boundaries and is inherited by structural FROM/JOIN contexts. I also exercised additional IN-subquery, nested non-recursive CTE, three-level recursive nesting, parenthesized JOIN, and shadowing controls; invalid recursive sources were rejected and valid same-block/shadowing cases planned successfully. Full pkg/sql/plan tests, the focused race test, go vet, and diff check passed with the required CGO/thirdparties setup. No blocking findings.
Merge Queue Status
This pull request spent 6 hours 20 minutes 52 seconds in the queue, including 44 minutes 34 seconds running CI. Required conditions to merge
|
Recursive CTE references inside nested query blocks reused the recursive member's scan node without validating query-block ownership. As a result, unsupported recursive references in EXISTS or scalar subqueries could pass planning and later panic or hang during execution. This change tracks the SELECT query block that owns the recursive scan and rejects recursive table sources from nested SELECT blocks with the existing parse error. Structural FROM contexts, such as JOIN operands, continue to inherit the owning query block, and correlated subqueries that do not introduce another recursive source remain valid. Regression coverage includes planner unit tests for EXISTS and scalar subqueries, legal JOIN and correlated-subquery controls, and a distributed SQL case that verifies stable errors and service availability after each rejection. Validation: - `make build` - `make static-check` - CGo-configured `go build` and `go vet` for `./pkg/sql/plan` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/sql/plan` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=1 -timeout=240s -run '^TestRecursiveCTEQueryBlockReferenceScope$' ./pkg/sql/plan` - mo-tester regression: 5/5 statements passed Approved by: @XuPeng-SH, @aptend, @aunjgr
Recursive CTE references inside nested query blocks reused the recursive member's scan node without validating query-block ownership. As a result, unsupported recursive references in EXISTS or scalar subqueries could pass planning and later panic or hang during execution. This change tracks the SELECT query block that owns the recursive scan and rejects recursive table sources from nested SELECT blocks with the existing parse error. Structural FROM contexts, such as JOIN operands, continue to inherit the owning query block, and correlated subqueries that do not introduce another recursive source remain valid. Regression coverage includes planner unit tests for EXISTS and scalar subqueries, legal JOIN and correlated-subquery controls, and a distributed SQL case that verifies stable errors and service availability after each rejection. Validation: - `make build` - `make static-check` - CGo-configured `go build` and `go vet` for `./pkg/sql/plan` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/sql/plan` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=1 -timeout=240s -run '^TestRecursiveCTEQueryBlockReferenceScope$' ./pkg/sql/plan` - mo-tester regression: 5/5 statements passed Approved by: @XuPeng-SH, @aptend, @aunjgr
Recursive CTE references inside nested query blocks reused the recursive member's scan node without validating query-block ownership. As a result, unsupported recursive references in EXISTS or scalar subqueries could pass planning and later panic or hang during execution. This change tracks the SELECT query block that owns the recursive scan and rejects recursive table sources from nested SELECT blocks with the existing parse error. Structural FROM contexts, such as JOIN operands, continue to inherit the owning query block, and correlated subqueries that do not introduce another recursive source remain valid. Regression coverage includes planner unit tests for EXISTS and scalar subqueries, legal JOIN and correlated-subquery controls, and a distributed SQL case that verifies stable errors and service availability after each rejection. Validation: - `make build` - `make static-check` - CGo-configured `go build` and `go vet` for `./pkg/sql/plan` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/sql/plan` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=1 -timeout=240s -run '^TestRecursiveCTEQueryBlockReferenceScope$' ./pkg/sql/plan` - mo-tester regression: 5/5 statements passed Approved by: @XuPeng-SH, @aptend, @aunjgr
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #25958
What this PR does / why we need it:
Recursive CTE references inside nested query blocks reused the recursive member's scan node without validating query-block ownership. As a result, unsupported recursive references in EXISTS or scalar subqueries could pass planning and later panic or hang during execution.
This change tracks the SELECT query block that owns the recursive scan and rejects recursive table sources from nested SELECT blocks with the existing parse error. Structural FROM contexts, such as JOIN operands, continue to inherit the owning query block, and correlated subqueries that do not introduce another recursive source remain valid.
Regression coverage includes planner unit tests for EXISTS and scalar subqueries, legal JOIN and correlated-subquery controls, and a distributed SQL case that verifies stable errors and service availability after each rejection.
Validation:
make buildmake static-checkgo buildandgo vetfor./pkg/sql/plan.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/sql/plan.agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=1 -timeout=240s -run '^TestRecursiveCTEQueryBlockReferenceScope$' ./pkg/sql/plan