Repository navigation
perf(plan): prune right SINGLE probe scans with runtime filters - #25865
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? |
LeftHandCold
left a comment
There was a problem hiding this comment.
Deep review found one reproducible compile-time regression in the new topology validation. The right-SINGLE semantics, physical side swap, exact-IN bounds, message delivery/cancellation, and resource lifecycle otherwise look consistent. Local full package tests, focused race tests, build, vet, and diff checks passed.
aptend
left a comment
There was a problem hiding this comment.
I confirmed the compile-time regression identified in the existing review. rightSingleLocalRuntimeFilterTags scans every node in the flat query, while compilePlanScope prunes literal LIMIT 0 subtrees before producing scopes. A right-SINGLE scalar subquery below a branch-level LIMIT 0 in UNION ALL therefore leaves a planned RF tag with no compiled consumer, and topology validation rejects the otherwise valid query with tag ... has no scan consumer.
Please derive the validated tags from subtrees that were actually compiled (or explicitly track compiled node IDs), while retaining missing/duplicate-producer validation for reachable subtrees. Add a regression covering branch-level LIMIT 0 + UNION ALL + right-SINGLE.
LeftHandCold
left a comment
There was a problem hiding this comment.
Re-reviewed head 70a366a with a focus on data correctness and normal-query regressions. The parallel build scan remains parallel below a single Merge and therefore has exactly one HashBuild runtime-filter producer; topology validation also fails closed if that physical invariant changes. DefaultStats is no longer accepted as a hard build-size bound, compile-pruned LIMIT 0 branches remain excluded, and each received IN payload now retains its originating spec across preceding PASS messages. Right-SINGLE preserved-side stats, exact-IN eligibility, cancellation/reset termination, and existing join/runtime-filter policies remain consistent. Full plan and compile package tests, focused race tests, dependent hashbuild/hashjoin/message tests, build, vet, diff checks, and current CI all pass. No remaining blocker found.
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
No concrete regressions found in the reviewed diff.
aptend
left a comment
There was a problem hiding this comment.
Re-reviewed current head ea10dc4. The parallel build scan is merged before the single HashBuild runtime-filter producer; the DefaultStats fallback and PASS/IN spec association are fixed. Relevant package tests, focused race tests, go vet, and go build all pass. No blocking issues found.
…ixorigin#25865) ## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#25862 ## What this PR does / why we need it: Right SINGLE joins produced by correlated scalar-subquery flattening preserve the build side, but previously could scan the entire discardable probe table because SINGLE joins could not build runtime filters. This PR adds a conservative, exact-IN runtime-filter path for eligible physical right SINGLE joins. - Centralizes runtime-filter eligibility so planning, one-CN placement, statistics, and compile-time validation use the same policy. - Restricts the optimization to direct table scans, supported key types, a leading primary/cluster-key prefix, no probe LIMIT/OFFSET, and build/probe cardinalities that fit the exact-IN limit. - Colocates the producer and all consumers on one CN instead of extending the current-CN runtime-filter protocol across CNs. - Validates the final physical topology before pipelines start: exactly one producer, every consumer colocated, and no ambiguous partial metadata. - Records right-SINGLE nodes actually visited by `compilePlanScope`, so logically retained but physically pruned subtrees (for example branch-level `LIMIT 0`) are excluded without weakening validation for reachable subtrees. - Sends DROP for empty or aborted builds and preserves query-context cancellation while consumers wait. - Corrects right SINGLE cardinality after physical child swapping and propagates the corrected estimate to parent nodes. - Preserves the existing fallback for ineligible, expensive, non-leading-key, or uncertain shapes. - Keeps `disableRightSingleRF=1` as a diagnostic rollback switch. ### Correctness and unhappy-path coverage - Match, miss, NULL, empty build, residual predicates, duplicate scalar results, no-PK fallback, composite-key full/prefix cases, and UPDATE/INSERT/DELETE consumers. - Missing/duplicate producers, fully missing reachable topology, physically pruned topology, remote consumers, ambiguous metadata, standalone execution, shared scope graphs, and cancellation while waiting. - Branch-level `LIMIT 0` + `UNION ALL` + right-SINGLE regression from review. - Single-CN and 2-CN BVT execution without assuming a fixed deployment topology. - Race testing covers plan, compile, hashbuild, hashjoin, and runtime-filter message packages. ### Performance evidence For an eligible 100,000-row probe table, `EXPLAIN ANALYZE` showed: | mode | probe rows | probe blocks | | --- | ---: | ---: | | right SINGLE runtime filter enabled | 5,000 | 1 | | disabled fallback | 100,000 | 13 | The compile-time no-filter topology path remains allocation-free at approximately 2.26 ns/op. Queries without a right-SINGLE join allocate no compiled-node tracking state. ### Phase boundary and follow-up Phase 1 intentionally keeps the cardinality correction in a post-swap-only pass. Under the current frozen physical orientation, a right SINGLE uses physical child 1 as the semantic preserved side; the downstream-join regression proves that consumers see the preserved cardinality instead of the discardable probe cardinality. This positional rule is a tested bridge, not the long-term optimizer model. A follow-up should introduce an explicit semantic join descriptor with stable preserved/discardable relation identities, keep physical probe/build orientation separate, migrate stats/RF/compile/explain consumers, and then remove the `IsRightJoin + child index` inference. ### Validation - Full tests: `pkg/sql/plan`, `pkg/sql/compile`, `pkg/sql/colexec/hashbuild`, `pkg/sql/colexec/hashjoin`, and `pkg/vm/message` - The same package set with `-race -p=1` - `go vet` for the same package set and a full `make -j8 build` - 34/34 semantic BVT statements from both CN entry points in a 2-CN deployment, then 34/34 again after membership converged to single-CN - Shuffled compile/plan package tests, 3 repetitions - 31,000 repeated standalone BVT statements - 50,000 successful 2-CN stress executions - 50 cancellation cycles while a consumer waited for its runtime filter; no stuck waiters or goroutine growth - Heap-profile review after stress found no runtime-filter-specific retained ownership chain
…ixorigin#25865) ## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#25862 ## What this PR does / why we need it: Right SINGLE joins produced by correlated scalar-subquery flattening preserve the build side, but previously could scan the entire discardable probe table because SINGLE joins could not build runtime filters. This PR adds a conservative, exact-IN runtime-filter path for eligible physical right SINGLE joins. - Centralizes runtime-filter eligibility so planning, one-CN placement, statistics, and compile-time validation use the same policy. - Restricts the optimization to direct table scans, supported key types, a leading primary/cluster-key prefix, no probe LIMIT/OFFSET, and build/probe cardinalities that fit the exact-IN limit. - Colocates the producer and all consumers on one CN instead of extending the current-CN runtime-filter protocol across CNs. - Validates the final physical topology before pipelines start: exactly one producer, every consumer colocated, and no ambiguous partial metadata. - Records right-SINGLE nodes actually visited by `compilePlanScope`, so logically retained but physically pruned subtrees (for example branch-level `LIMIT 0`) are excluded without weakening validation for reachable subtrees. - Sends DROP for empty or aborted builds and preserves query-context cancellation while consumers wait. - Corrects right SINGLE cardinality after physical child swapping and propagates the corrected estimate to parent nodes. - Preserves the existing fallback for ineligible, expensive, non-leading-key, or uncertain shapes. - Keeps `disableRightSingleRF=1` as a diagnostic rollback switch. ### Correctness and unhappy-path coverage - Match, miss, NULL, empty build, residual predicates, duplicate scalar results, no-PK fallback, composite-key full/prefix cases, and UPDATE/INSERT/DELETE consumers. - Missing/duplicate producers, fully missing reachable topology, physically pruned topology, remote consumers, ambiguous metadata, standalone execution, shared scope graphs, and cancellation while waiting. - Branch-level `LIMIT 0` + `UNION ALL` + right-SINGLE regression from review. - Single-CN and 2-CN BVT execution without assuming a fixed deployment topology. - Race testing covers plan, compile, hashbuild, hashjoin, and runtime-filter message packages. ### Performance evidence For an eligible 100,000-row probe table, `EXPLAIN ANALYZE` showed: | mode | probe rows | probe blocks | | --- | ---: | ---: | | right SINGLE runtime filter enabled | 5,000 | 1 | | disabled fallback | 100,000 | 13 | The compile-time no-filter topology path remains allocation-free at approximately 2.26 ns/op. Queries without a right-SINGLE join allocate no compiled-node tracking state. ### Phase boundary and follow-up Phase 1 intentionally keeps the cardinality correction in a post-swap-only pass. Under the current frozen physical orientation, a right SINGLE uses physical child 1 as the semantic preserved side; the downstream-join regression proves that consumers see the preserved cardinality instead of the discardable probe cardinality. This positional rule is a tested bridge, not the long-term optimizer model. A follow-up should introduce an explicit semantic join descriptor with stable preserved/discardable relation identities, keep physical probe/build orientation separate, migrate stats/RF/compile/explain consumers, and then remove the `IsRightJoin + child index` inference. ### Validation - Full tests: `pkg/sql/plan`, `pkg/sql/compile`, `pkg/sql/colexec/hashbuild`, `pkg/sql/colexec/hashjoin`, and `pkg/vm/message` - The same package set with `-race -p=1` - `go vet` for the same package set and a full `make -j8 build` - 34/34 semantic BVT statements from both CN entry points in a 2-CN deployment, then 34/34 again after membership converged to single-CN - Shuffled compile/plan package tests, 3 repetitions - 31,000 repeated standalone BVT statements - 50,000 successful 2-CN stress executions - 50 cancellation cycles while a consumer waited for its runtime filter; no stuck waiters or goroutine growth - Heap-profile review after stress found no runtime-filter-specific retained ownership chain
…ixorigin#25865) ## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#25862 ## What this PR does / why we need it: Right SINGLE joins produced by correlated scalar-subquery flattening preserve the build side, but previously could scan the entire discardable probe table because SINGLE joins could not build runtime filters. This PR adds a conservative, exact-IN runtime-filter path for eligible physical right SINGLE joins. - Centralizes runtime-filter eligibility so planning, one-CN placement, statistics, and compile-time validation use the same policy. - Restricts the optimization to direct table scans, supported key types, a leading primary/cluster-key prefix, no probe LIMIT/OFFSET, and build/probe cardinalities that fit the exact-IN limit. - Colocates the producer and all consumers on one CN instead of extending the current-CN runtime-filter protocol across CNs. - Validates the final physical topology before pipelines start: exactly one producer, every consumer colocated, and no ambiguous partial metadata. - Records right-SINGLE nodes actually visited by `compilePlanScope`, so logically retained but physically pruned subtrees (for example branch-level `LIMIT 0`) are excluded without weakening validation for reachable subtrees. - Sends DROP for empty or aborted builds and preserves query-context cancellation while consumers wait. - Corrects right SINGLE cardinality after physical child swapping and propagates the corrected estimate to parent nodes. - Preserves the existing fallback for ineligible, expensive, non-leading-key, or uncertain shapes. - Keeps `disableRightSingleRF=1` as a diagnostic rollback switch. ### Correctness and unhappy-path coverage - Match, miss, NULL, empty build, residual predicates, duplicate scalar results, no-PK fallback, composite-key full/prefix cases, and UPDATE/INSERT/DELETE consumers. - Missing/duplicate producers, fully missing reachable topology, physically pruned topology, remote consumers, ambiguous metadata, standalone execution, shared scope graphs, and cancellation while waiting. - Branch-level `LIMIT 0` + `UNION ALL` + right-SINGLE regression from review. - Single-CN and 2-CN BVT execution without assuming a fixed deployment topology. - Race testing covers plan, compile, hashbuild, hashjoin, and runtime-filter message packages. ### Performance evidence For an eligible 100,000-row probe table, `EXPLAIN ANALYZE` showed: | mode | probe rows | probe blocks | | --- | ---: | ---: | | right SINGLE runtime filter enabled | 5,000 | 1 | | disabled fallback | 100,000 | 13 | The compile-time no-filter topology path remains allocation-free at approximately 2.26 ns/op. Queries without a right-SINGLE join allocate no compiled-node tracking state. ### Phase boundary and follow-up Phase 1 intentionally keeps the cardinality correction in a post-swap-only pass. Under the current frozen physical orientation, a right SINGLE uses physical child 1 as the semantic preserved side; the downstream-join regression proves that consumers see the preserved cardinality instead of the discardable probe cardinality. This positional rule is a tested bridge, not the long-term optimizer model. A follow-up should introduce an explicit semantic join descriptor with stable preserved/discardable relation identities, keep physical probe/build orientation separate, migrate stats/RF/compile/explain consumers, and then remove the `IsRightJoin + child index` inference. ### Validation - Full tests: `pkg/sql/plan`, `pkg/sql/compile`, `pkg/sql/colexec/hashbuild`, `pkg/sql/colexec/hashjoin`, and `pkg/vm/message` - The same package set with `-race -p=1` - `go vet` for the same package set and a full `make -j8 build` - 34/34 semantic BVT statements from both CN entry points in a 2-CN deployment, then 34/34 again after membership converged to single-CN - Shuffled compile/plan package tests, 3 repetitions - 31,000 repeated standalone BVT statements - 50,000 successful 2-CN stress executions - 50 cancellation cycles while a consumer waited for its runtime filter; no stuck waiters or goroutine growth - Heap-profile review after stress found no runtime-filter-specific retained ownership chain
What type of PR is this?
Which issue(s) this PR fixes:
issue #25862
What this PR does / why we need it:
Right SINGLE joins produced by correlated scalar-subquery flattening preserve the build side, but previously could scan the entire discardable probe table because SINGLE joins could not build runtime filters.
This PR adds a conservative, exact-IN runtime-filter path for eligible physical right SINGLE joins.
compilePlanScope, so logically retained but physically pruned subtrees (for example branch-levelLIMIT 0) are excluded without weakening validation for reachable subtrees.disableRightSingleRF=1as a diagnostic rollback switch.Correctness and unhappy-path coverage
LIMIT 0+UNION ALL+ right-SINGLE regression from review.Performance evidence
For an eligible 100,000-row probe table,
EXPLAIN ANALYZEshowed:The compile-time no-filter topology path remains allocation-free at approximately 2.26 ns/op. Queries without a right-SINGLE join allocate no compiled-node tracking state.
Phase boundary and follow-up
Phase 1 intentionally keeps the cardinality correction in a post-swap-only pass. Under the current frozen physical orientation, a right SINGLE uses physical child 1 as the semantic preserved side; the downstream-join regression proves that consumers see the preserved cardinality instead of the discardable probe cardinality.
This positional rule is a tested bridge, not the long-term optimizer model. A follow-up should introduce an explicit semantic join descriptor with stable preserved/discardable relation identities, keep physical probe/build orientation separate, migrate stats/RF/compile/explain consumers, and then remove the
IsRightJoin + child indexinference.Validation
pkg/sql/plan,pkg/sql/compile,pkg/sql/colexec/hashbuild,pkg/sql/colexec/hashjoin, andpkg/vm/message-race -p=1go vetfor the same package set and a fullmake -j8 build