Skip to content

fix: add composite primary key runtime filters (cherry-pick #27501) - #32400

Merged
XuPeng-SH merged 6 commits into
matrixorigin:4.2-devfrom
ck89119:issue-22653-4.2-dev
Nov 9, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:4.2-devfrom
ck89119:issue-22653-4.2-dev

Conversation

@ck89119

@ck89119 ck89119 commented Nov 9, 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:

Related to #22653 (backport of #27501 to 4.2-dev).

What this PR does / why we need it:

Cherry-pick #27501 (ae12701a888fac102e9641cc7cbb8706527366d8) to 4.2-dev.

Generate exact serialized runtime filters when broadcast join keys fully cover a composite primary key. Preserve primary-key component order and safely narrow same-signed integer join keys into the probe domain. Out-of-range optional filter values fall back to PASS without changing JOIN semantics.

The backport uses the corresponding 4.2-dev HashBuild budget constructor and fixture helper; no other main-branch changes are imported. A review follow-up moves the existing runtime-filter hint check to the common broadcast-join entry, so both single-column and composite-key optional filters honor runtimeFilter=1, while preserving the mandatory INDEX/DEDUP exceptions.

Validation on Go 1.26.4 / macOS arm64:

  • Focused regression tests and full runtimefilter, hashbuild, and plan package tests passed through the CGo test wrapper.
  • Changed-line coverage: 225/279 instrumented lines (80.65%).
  • Changed-package go vet and incremental golangci-lint v2.6.2 passed; formatting and whitespace checks passed.
  • Native dependencies and mo-service built successfully.
  • An isolated SQL instance passed two rounds of seven result checks: full composite keys, reordered join conditions, integer narrowing/overflow, mixed valid/out-of-range keys, duplicate build keys, partial key coverage, and empty build input.
  • On a flushed 100,000-row composite-PK table joined with three inline keys, EXPLAIN ANALYZE reported 3 input blocks / 3 input rows / 3 output rows, with the serialized build filter probing __mo_cpkey_col.

This is the ordinary composite-PK JOIN fix only. It does not claim to resolve the remaining REPLACE read-amplification problem in #27403. Full BVT, multi-CN, and CI validation were not run locally.

Review follow-up validation (4ba2addf0b):

  • Merged the updated mo/4.2-dev base (a860d63a97) without conflicts.
  • Added 18 typed-plan scenarios across single/composite keys, default/enabled/disabled hints, and INNER/INDEX/DEDUP joins. Before the fix only the disabled composite INNER case failed; all 18 now pass.
  • Full planner package tests, changed-package vet and incremental lint passed on Go 1.26.4. The moved production guard is fully covered.
  • Two rounds of isolated SQL checks on 20-row single/composite-PK tables verified identical two-row results with the default, disabled, and restored hint settings. Disabling removes both build/probe filters and scans 20 rows; restoring the setting reinstates the filter and scans 2 rows.

CI follow-up (d0a9003743):

  • Merged the latest mo/4.2-dev base (fa6bc2bcd9).
  • The ordinary race UT lane reached the historical-owner authorization test and rejected CREATE DATABASE immediately after a grant committed on another CN. Added the existing commit-visibility fence before both affected cross-CN DDL statements. No authorization implementation or success/denial assertions were changed.
  • All 10 scenarios of the full authorization parent test passed locally with Go 1.26.4, -short -tags matrixone_test -race -count=1; changed-package vet, incremental lint, formatting, and whitespace checks passed.
  • An additional normal-mode run was blocked during cluster startup by another worktree using port 10060; it did not reach the assertions and is not reported as a pass.
  • Prior UT Coverage and merged Coverage passed at 4ba2addf0b. New-head full CI remains unverified. Iceberg job logs still report an ONNX Runtime download HTTP 504; no product code or test gate was changed to bypass provisioning failures.

Generate exact serialized runtime filters when broadcast join keys fully cover a composite primary key. The build side serializes hash-key slots in primary-key order, while the probe side filters the hidden composite primary-key column.

The runtime-filter contract now supports safe same-signedness integer narrowing for join keys promoted by comparison binding (for example, an `INT` table column compared with a `BIGINT` inline `VALUES` column). Out-of-range build values fail open with a PASS filter, preserving join semantics.

Validation:
- `make build`
- package tests for `pkg/sql/plan`, `pkg/sql/colexec/runtimefilter`, and `pkg/sql/colexec/hashbuild`
- `go vet` for the affected packages
- the original 10-million-row reproduction: the table scan is reduced from 10,000,000 rows to 3 rows and returns the expected result
- an out-of-range inline key control returns zero matches without changing query error semantics

Approved by: @XuPeng-SH, @aptend, @aunjgr

(cherry picked from commit ae12701)
@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 →

@XuPeng-SH

XuPeng-SH commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: d0a9003743bafe4401322a1120cd71457cbd478b

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH 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.

mo-bot review · mo-bot-local · review

Commit: d0a9003743bafe4401322a1120cd71457cbd478b

Assessment: approve

The backport coherently reuses existing exact-filter, cast and budget owners. Composite-key ordering, narrowing fallback and hint handling are covered; no actionable defects remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Full runtimefilter, hashbuild and plan suites passed with vet and the supplied isolated executor; three planner skips were recorded.

  • Full runtimefilter/hashbuild race suites passed. Each of the two new HashBuild regression tests also passed 100 exact-name race repetitions.

  • Preflight, native build/provenance, formatting, source integrity and discussion/receipt audits passed. Frozen-head CI reports successful UT, SCA, coverage and enabled BVT checks.

Limitations:

  • Public SQL/pruning and authorization-parent executions are author-reported; raw author/CI logs were unavailable. No fresh local BVT or multi-CN campaign was run.

  • REPLACE read-amplification and long-soak acceptance in #27403 remain outside this JOIN backport.

@XuPeng-SH
XuPeng-SH merged commit ba2a0ca into matrixorigin:4.2-dev Nov 9, 2026
@ck89119
ck89119 deleted the issue-22653-4.2-dev branch November 9, 2026 15:03
XuPeng-SH added a commit that referenced this pull request Nov 9, 2026
…-pick #32401) (#32432)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to #27403 (backport of #32401 to `4.2-dev`).

## What this PR does / why we need it:

Cherry-pick #32401 (`da867c90dfaf1c5102ace1a192b358fcc5adbb9c`) to
`4.2-dev`.

Keep a bounded DEDUP lookup on the leading, complete physical primary
key from losing its runtime filter at the NDV ratio gate. This includes
REPLACE's already-serialized composite primary key. Preserve the
exact-IN budget, encoding checks, join-direction restrictions, scan
limits, large-build guards, and runtime PASS fallback.

This backport is independent of #32400: it uses the existing single-key
DEDUP path, not the new multi-column JOIN filter construction.

### Backport adaptations

- Use `4.2-dev`'s existing `HashmapSize` and singleton admission logic;
do not import main's point-filter/tree refactoring.
- Adapt all 13 planner scenarios to the target branch's builder and
scoped configuration APIs.
- Preserve all 14 REPLACE regression scenarios in
`pkg/tests/issues/isolated`, using an owned single-CN cluster and
explicit cleanup instead of importing main's SQL-integration harness.
- Omit only the four `multi_insert.result` expectation lines: the target
branch has neither that fixture nor the multi-table INSERT feature. No
unrelated feature or dependency PR is imported.

### Validation

Go 1.26.4, macOS arm64, worktree-built native libraries, repository CGo
test wrapper:

- Before the fix, the five positive planner cases fail, while the eight
rejection controls pass. The SQL regression also fails for the intended
missing-filter condition.
- After the fix, all 13 planner cases pass; all 14 SQL scenarios pass in
each of two runs (`-count=2`). Exact rows, cardinality, duplicate-input
semantics, and transaction-local conflicts are checked separately from
read work.
- With 16 new keys, persisted reads change from **8 blocks / 512 rows**
and **16 blocks / 1,024 rows** to **0 blocks / 0 rows / 0 bytes** for
both layouts.
- Full `pkg/sql/plan` tests pass: 76.0% statement coverage; changed
production statements are fully covered.
- Changed-package `go vet`, incremental golangci-lint 2.6.2, Go 1.26.4
formatting, and whitespace checks pass.

Full BVT, the full isolated integration-test package, multi-CN, and CI
validation were not run locally. This is a local mechanism backport, not
a claim that the long-running deployment workload in #27403 has been
validated.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: XuPeng-SH <[email protected]>
XuPeng-SH added a commit that referenced this pull request Nov 10, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [x] Code Refactoring

## Which issue(s) this PR fixes:

Related to #30125. Backport of #32191.

## What this PR does / why we need it:

Bound HashBuild runtime-filter key collection to aligned chunks of at
most 8,192 rows, with earlier splits for component-vector byte limits.
This avoids growing one key vector across the entire build. The ordinary
path collects newly inserted hash groups; HashOnPK retains the existing
primary-key uniqueness assumption. Account for chunk metadata, roll back
failed multi-column appends, and reject invalid checkpoints without
publishing partial keys.

Keep the ordinary IN encoding and single-chunk fast path. Numeric runs
are copied and sorted in the final admitted buffer; other sorted runs
are merged without a whole-build vector. Inline runs whose key ranges
are already ordered can use the same admitted buffer and bulk-copy path.
Integrate the 4.2-dev composite-primary-key filter from #32400: convert
components in probe-key order for each chunk, use the converted vectors
for bounds and encoding, and turn an out-of-range optional filter into
whole-filter PASS. A cancellation already observed at that fallback
remains an error.

Publish membership keys as one immutable, reference-counted payload and
adapt the existing 4.2-dev IVF/fulltext consumers to visit all chunks.
IVF may use a complete exact SQL predicate or a tagged reader filter,
according to the existing key-type contract. Required non-integer IVF
membership retains the 8 MiB global literal-list limit and fails rather
than becoming partial or approximate. The release keeps its existing TVF
architecture and native filter ABI.

The rebase also adapts the #32243 optional-collection failure tests to
the chunked owner, preserving PASS, complete JoinMap, wide-key lookup,
and accounting checks. It retains the author's concurrent merge fixes
and fixture cleanup.

## Validation of the rebased production tree

- Normal and race suites for the 12 changed/affected CPU packages;
HashBuild, runtimefilter and the planner were rerun after the last
production change. The exact two-CN role-grant fixture was also run
under `-race -short`.
- Four focused lifecycle tests each passed 100 `-race` repetitions:
ordered-run cancellation and cleanup, composite narrowing, next-chunk
admission failure, and cross-chunk rollback. HashBuild also passed
`-short -covermode=set` (74.7% of that package's statements; this is not
changed-code coverage).
- An embedded SQL differential test verified an actual
`serial(cast(...), ...)` composite-PK runtime-filter plan with 9,000
build keys; enabled, disabled, out-of-range and NULL controls returned
the same 9,000 matches. The input exceeded one chunk, but the SQL
experiment did not instrument per-operator chunk count; white-box tests
explicitly construct and validate multiple chunks.
- The repository's IVF membership BVT ran twice in normal comparison
mode on one isolated CN after SQL and ISCP readiness: 44/44 statements
each time, zero ignored, with both test databases verified absent after
each run.
- Incremental `gofmt`, `molint`, and golangci-lint 2.6.2 passed over the
changed package closure. The additional planner scan reports three
`checkrecover` items at identical lines on the unmodified 4.2-dev
baseline. Tests used Go 1.26.6 and CPU native libraries; a rebuild from
the same tracked native sources produced an identical libmo
executable-code section.

## Performance and limits

In a local pinned-CPU microbenchmark comparing the rebased code
immediately before and after the ordered-inline optimization,
three-sample medians for ordered composite keys changed from 1.156/1.190
ms to 0.880/0.907 ms at 8,193 rows and from 10.341/10.101 ms to
7.537/7.755 ms at 65,536 rows (direct/cast respectively). Single-chunk
controls also varied 4–8%, so these are local measurements, not a
general speedup claim. Randomly interleaved 65,536-row cases changed by
+2.4%/+1.4% in another three-sample comparison. Chunking still increases
Go allocations: the 65,536-row cast fixture used about 111 allocations
on the 4.2-dev baseline and 359 here. Go allocation figures exclude
MPool/native memory.

CUDA, mixed-version rollout, multi-gigabyte workloads, peak MPool/native
memory and end-to-end OLAP performance were not independently validated
in this run. The author previously reported full-repository SCA and
additional 100-run ownership stress on the earlier PR revision; those
reports are historical evidence, not new-head CI results.

Design: [bounded HashBuild key collection and 4.2-dev
integration](https://github.com/aunjgr/matrixone/blob/91c9bbf26c012fab1cc8a4a4e7bb2f73373d7977/docs/design/hashbuild-key-batches.md).

---------

Co-authored-by: XuPeng-SH <[email protected]>

This branch was successfully deployed

No deployments
ci — 51cdd0b2 Deployed Nov 9, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants