Repository navigation
perf: enable right SINGLE filters for local queries without stats - #27626
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? |
aptend
left a comment
There was a problem hiding this comment.
Reviewed exact head eda360323d00cabf9f23fbe8644b49cca8db7f47. The unavailable-statistics path remains conservative for natural/forced multi-CN plans, and the accepted local path preserves the existing bounded exact-IN/PASS contract plus colocated scan placement. I also checked the right-SINGLE semantic/delivery guards, topology validation, composite-key path, forced execution hints, and the executable BVT shape. Relevant plan/compile tests, vet, and focused race tests pass. No blocking issues found.
|
Tick the box to add this pull request to the merge queue (same as
|
1ca11e0 to
03c0317
Compare
…trixorigin#27626) ## 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: `DefaultStats` means statistics are unavailable; it is not proof that a build has exactly 1,000 rows. Rejecting every such right-SINGLE filter is safe but makes a common newly-created tiny lookup table force a full scan of the probe table. This change bases the decision on the actual safety invariants: - If the query would already execute on one CN, right-SINGLE may use the existing exact runtime-filter protocol. Local delivery does not reduce scan placement in that case. - Naturally multi-CN queries, globally forced multi-CN scans, and `execType=3` diagnostics keep the no-filter fallback. A filter is never introduced by first downgrading a distributed scan. - HashBuild now enforces `RuntimeFilterSpec.UpperLimit` while collecting optional exact-filter keys. Once actual build cardinality exceeds the limit, it immediately releases those keys, continues building the complete mandatory JoinMap, and publishes `PASS`. Unknown statistics therefore cannot turn this optimization into unbounded duplicate key retention. - Membership-filter consumers retain their existing independent typed-key policy. - Existing key/type/primary-key/cardinality and delivery guards remain unchanged. The BVT change reuses the existing right-SINGLE fixture and adds only a zero-execution `EXPLAIN` assertion. It adds no data, setup, sleep, or duplicate semantic case; all existing semantic, duplicate-cardinality, DML, empty-input, and `LIMIT 0` cases remain. ### Validation on 10.222.1.55 The production files modified by this PR were copied checksum-for-checksum into the remote candidate worktree, compiled into a dedicated image, and run in an isolated fresh two-CN cluster. The image's `/mo-service` SHA256 was `da42201a0b627d4c4b3ceb41f3c1e69ce71b4d4ad322b4ee1eed9f792aedc95b`. Probe table: 1,000,000 rows. Lookup table: 3 rows. | mode | probe blocks | probe rows | read size | join input rows | result | | --- | ---: | ---: | ---: | ---: | --- | | RF enabled | 2 | 2 | 202.37 KiB | 5 | correct | | RF disabled | 128 | 1,000,000 | 8.19 MiB | 1,000,003 | identical | | forced multi-CN | full scan | 1,000,000 | 8.19 MiB | 1,000,003 | identical; completed without hang | The enabled plan is `AP QUERY PLAN ON ONE CN` and contains `Runtime Filter Build`, `Runtime Filter Probe`, and `ForceOneCN` on the already-local scans. Forced `execType=3` is `AP QUERY PLAN ON MULTICN`, contains no right-SINGLE runtime filter or `ForceOneCN`, and completes on the same two-CN cluster. Validation performed on the final code: - complete `./pkg/sql/colexec/hashbuild` tests: pass - complete `./pkg/sql/plan` tests: pass - focused planner/cardinality/fail-open regressions: pass - `go build -mod=readonly` and `go vet -mod=readonly` for both packages: pass - coverage: hashbuild 76.1%, plan 78.5%; new planner guard and limit-aware build entry are 100% covered - existing right-SINGLE BVT through CN1: 38/38, 100%, 5.869s - the same BVT through CN2 after reuse/cleanup: 38/38, 100%, 6.057s - cluster log audit: no panic, fatal, runtime-filter timeout, or topology error
…trixorigin#27626) ## 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: `DefaultStats` means statistics are unavailable; it is not proof that a build has exactly 1,000 rows. Rejecting every such right-SINGLE filter is safe but makes a common newly-created tiny lookup table force a full scan of the probe table. This change bases the decision on the actual safety invariants: - If the query would already execute on one CN, right-SINGLE may use the existing exact runtime-filter protocol. Local delivery does not reduce scan placement in that case. - Naturally multi-CN queries, globally forced multi-CN scans, and `execType=3` diagnostics keep the no-filter fallback. A filter is never introduced by first downgrading a distributed scan. - HashBuild now enforces `RuntimeFilterSpec.UpperLimit` while collecting optional exact-filter keys. Once actual build cardinality exceeds the limit, it immediately releases those keys, continues building the complete mandatory JoinMap, and publishes `PASS`. Unknown statistics therefore cannot turn this optimization into unbounded duplicate key retention. - Membership-filter consumers retain their existing independent typed-key policy. - Existing key/type/primary-key/cardinality and delivery guards remain unchanged. The BVT change reuses the existing right-SINGLE fixture and adds only a zero-execution `EXPLAIN` assertion. It adds no data, setup, sleep, or duplicate semantic case; all existing semantic, duplicate-cardinality, DML, empty-input, and `LIMIT 0` cases remain. ### Validation on 10.222.1.55 The production files modified by this PR were copied checksum-for-checksum into the remote candidate worktree, compiled into a dedicated image, and run in an isolated fresh two-CN cluster. The image's `/mo-service` SHA256 was `da42201a0b627d4c4b3ceb41f3c1e69ce71b4d4ad322b4ee1eed9f792aedc95b`. Probe table: 1,000,000 rows. Lookup table: 3 rows. | mode | probe blocks | probe rows | read size | join input rows | result | | --- | ---: | ---: | ---: | ---: | --- | | RF enabled | 2 | 2 | 202.37 KiB | 5 | correct | | RF disabled | 128 | 1,000,000 | 8.19 MiB | 1,000,003 | identical | | forced multi-CN | full scan | 1,000,000 | 8.19 MiB | 1,000,003 | identical; completed without hang | The enabled plan is `AP QUERY PLAN ON ONE CN` and contains `Runtime Filter Build`, `Runtime Filter Probe`, and `ForceOneCN` on the already-local scans. Forced `execType=3` is `AP QUERY PLAN ON MULTICN`, contains no right-SINGLE runtime filter or `ForceOneCN`, and completes on the same two-CN cluster. Validation performed on the final code: - complete `./pkg/sql/colexec/hashbuild` tests: pass - complete `./pkg/sql/plan` tests: pass - focused planner/cardinality/fail-open regressions: pass - `go build -mod=readonly` and `go vet -mod=readonly` for both packages: pass - coverage: hashbuild 76.1%, plan 78.5%; new planner guard and limit-aware build entry are 100% covered - existing right-SINGLE BVT through CN1: 38/38, 100%, 5.869s - the same BVT through CN2 after reuse/cleanup: 38/38, 100%, 6.057s - cluster log audit: no panic, fatal, runtime-filter timeout, or topology error
…trixorigin#27626) ## 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: `DefaultStats` means statistics are unavailable; it is not proof that a build has exactly 1,000 rows. Rejecting every such right-SINGLE filter is safe but makes a common newly-created tiny lookup table force a full scan of the probe table. This change bases the decision on the actual safety invariants: - If the query would already execute on one CN, right-SINGLE may use the existing exact runtime-filter protocol. Local delivery does not reduce scan placement in that case. - Naturally multi-CN queries, globally forced multi-CN scans, and `execType=3` diagnostics keep the no-filter fallback. A filter is never introduced by first downgrading a distributed scan. - HashBuild now enforces `RuntimeFilterSpec.UpperLimit` while collecting optional exact-filter keys. Once actual build cardinality exceeds the limit, it immediately releases those keys, continues building the complete mandatory JoinMap, and publishes `PASS`. Unknown statistics therefore cannot turn this optimization into unbounded duplicate key retention. - Membership-filter consumers retain their existing independent typed-key policy. - Existing key/type/primary-key/cardinality and delivery guards remain unchanged. The BVT change reuses the existing right-SINGLE fixture and adds only a zero-execution `EXPLAIN` assertion. It adds no data, setup, sleep, or duplicate semantic case; all existing semantic, duplicate-cardinality, DML, empty-input, and `LIMIT 0` cases remain. ### Validation on 10.222.1.55 The production files modified by this PR were copied checksum-for-checksum into the remote candidate worktree, compiled into a dedicated image, and run in an isolated fresh two-CN cluster. The image's `/mo-service` SHA256 was `da42201a0b627d4c4b3ceb41f3c1e69ce71b4d4ad322b4ee1eed9f792aedc95b`. Probe table: 1,000,000 rows. Lookup table: 3 rows. | mode | probe blocks | probe rows | read size | join input rows | result | | --- | ---: | ---: | ---: | ---: | --- | | RF enabled | 2 | 2 | 202.37 KiB | 5 | correct | | RF disabled | 128 | 1,000,000 | 8.19 MiB | 1,000,003 | identical | | forced multi-CN | full scan | 1,000,000 | 8.19 MiB | 1,000,003 | identical; completed without hang | The enabled plan is `AP QUERY PLAN ON ONE CN` and contains `Runtime Filter Build`, `Runtime Filter Probe`, and `ForceOneCN` on the already-local scans. Forced `execType=3` is `AP QUERY PLAN ON MULTICN`, contains no right-SINGLE runtime filter or `ForceOneCN`, and completes on the same two-CN cluster. Validation performed on the final code: - complete `./pkg/sql/colexec/hashbuild` tests: pass - complete `./pkg/sql/plan` tests: pass - focused planner/cardinality/fail-open regressions: pass - `go build -mod=readonly` and `go vet -mod=readonly` for both packages: pass - coverage: hashbuild 76.1%, plan 78.5%; new planner guard and limit-aware build entry are 100% covered - existing right-SINGLE BVT through CN1: 38/38, 100%, 5.869s - the same BVT through CN2 after reuse/cleanup: 38/38, 100%, 6.057s - cluster log audit: no panic, fatal, runtime-filter timeout, or topology error
What type of PR is this?
Which issue(s) this PR fixes:
issue #25862
What this PR does / why we need it:
DefaultStatsmeans statistics are unavailable; it is not proof that a build has exactly 1,000 rows. Rejecting every such right-SINGLE filter is safe but makes a common newly-created tiny lookup table force a full scan of the probe table.This change bases the decision on the actual safety invariants:
execType=3diagnostics keep the no-filter fallback. A filter is never introduced by first downgrading a distributed scan.RuntimeFilterSpec.UpperLimitwhile collecting optional exact-filter keys. Once actual build cardinality exceeds the limit, it immediately releases those keys, continues building the complete mandatory JoinMap, and publishesPASS. Unknown statistics therefore cannot turn this optimization into unbounded duplicate key retention.The BVT change reuses the existing right-SINGLE fixture and adds only a zero-execution
EXPLAINassertion. It adds no data, setup, sleep, or duplicate semantic case; all existing semantic, duplicate-cardinality, DML, empty-input, andLIMIT 0cases remain.Validation on 10.222.1.55
The production files modified by this PR were copied checksum-for-checksum into the remote candidate worktree, compiled into a dedicated image, and run in an isolated fresh two-CN cluster. The image's
/mo-serviceSHA256 wasda42201a0b627d4c4b3ceb41f3c1e69ce71b4d4ad322b4ee1eed9f792aedc95b.Probe table: 1,000,000 rows. Lookup table: 3 rows.
The enabled plan is
AP QUERY PLAN ON ONE CNand containsRuntime Filter Build,Runtime Filter Probe, andForceOneCNon the already-local scans. ForcedexecType=3isAP QUERY PLAN ON MULTICN, contains no right-SINGLE runtime filter orForceOneCN, and completes on the same two-CN cluster.Validation performed on the final code:
./pkg/sql/colexec/hashbuildtests: pass./pkg/sql/plantests: passgo build -mod=readonlyandgo vet -mod=readonlyfor both packages: pass