Skip to content

perf: enable right SINGLE filters for local queries without stats - #27626

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-25862-right-single-rf
Aug 26, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-25862-right-single-rf

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #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

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mergify

mergify Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@XuPeng-SH
XuPeng-SH merged commit 1891117 into matrixorigin:main Aug 26, 2026
16 of 19 checks passed
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants