Skip to content

fix(plan): retain bounded REPLACE primary-key runtime filters (cherry-pick #32401) - #32432

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

XuPeng-SH merged 2 commits into
matrixorigin:4.2-devfrom
ck89119:issue-27403-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 #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.

…origin#32401)

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

Related to matrixorigin#27403.

REPLACE conflict lookup already compares the serialized composite
primary key as a single key. Unlike the multi-column JOIN path addressed
by matrixorigin#27501, it can still lose its runtime filter at the generic NDV
selectivity gate.

In a current-main reproduction, a session retained `NDV=64` and
`TableCnt=64` while flushed L0 objects accumulated. A batch of 16 new
keys therefore exceeded the 10% admission threshold, and the DEDUP
target scan read every historical block despite there being no
conflicts.

Allow a bounded DEDUP lookup on the leading, complete physical primary
key to bypass that NDV ratio gate. Retain the existing exact-IN budget,
encoding checks, join-direction restrictions, scan limits, and
large-build guards. Actual over-budget builds still fall back to PASS.
Ordinary joins, partial composite keys, and nonleading keys retain their
existing cost gates; no reader, storage-format, or protocol changes are
introduced.

The independent single-CN SQL fixture disables table auto-merge,
verifies the L0 object layout, and waits for logtail application rather
than sleeping. With a fixed 16-key input:

| Persisted layout | Before: scan blocks / input rows | After: scan
blocks / input rows | After: scan ReadSize |
| --- | --- | --- | --- |
| 8 objects / 512 rows | 8 / 512 | 0 / 0 | 0 bytes |
| 16 objects / 1,024 rows | 16 / 1,024 | 0 / 0 | 0 bytes |

The regression also checks exact result rows and table cardinality for
existing keys, mixed keys, two matching objects, different run IDs,
duplicate input with last-value semantics, and transaction-local
conflicts. Workspace batches are counted separately from persisted
reads. Planner tests cover stale/unknown NDV, single and serialized PKs,
budget boundaries, and the nearest rejected candidates. The new positive
planner cases and the original read-work regression fail without the
fix.

Local validation used Go 1.27.1 with matching worktree-native libraries
and the repository CGo test wrapper:

- Focused planner regressions and existing REPLACE planning controls:
passed.
- `TestReplaceCompositeKeyPrunesFlushedObjects`, `-count=2`: all 14
scenarios passed in each run.
- Full `pkg/sql/plan`, `pkg/sql/colexec/hashbuild`, and
`pkg/sql/colexec/runtimefilter` packages: passed.
- Changed production statements: 100% coverage; planner package: 86.0%.
- Changed-package `go vet`, incremental golangci-lint 2.14.0, gofmt, and
`git diff --check`: passed.
- Built a separate local mo-service and ran the existing
`test/distributed/cases/dml/replace` suite through mo-tester: **783/783
SQL statements passed**, with no failures, skips, or abnormal results.

This is a local mechanism fix on main, not a claim that the MNL2
deployment or long-running workload has been validated. It does not
promise constant-time object metadata work and does not include a
4.2-dev backport.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit da867c9)
@mergify
mergify Bot requested a review from XuPeng-SH November 9, 2026 14:11
@mergify mergify Bot added the kind/bug Something isn't working label Nov 9, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Nov 9, 2026
@XuPeng-SH
XuPeng-SH marked this pull request as ready for review November 9, 2026 14:44
@XuPeng-SH
XuPeng-SH requested a review from aunjgr as a code owner November 9, 2026 14:44
@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: b02085e755d5b3d5e3b7371b7d883afed47af6df

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: b02085e755d5b3d5e3b7371b7d883afed47af6df

Assessment: approve

The bounded complete-primary-key DEDUP exception is a narrow correction in the existing admission owner. It reuses the exact-IN budget, encoding and delivery checks, and runtime PASS fallback without adding state or a parallel filtering path. Planner and SQL controls confirm stale-NDV admission and reduced reads while preserving conflict, duplicate-input and transaction-local semantics. No actionable defects remain in this backport.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Read the complete three-file delta, affected planner/REPLACE/hashbuild/scan consumers, both discussion entries, and linked issue 27403 with all six comments; discussion-assessment.json covers every index key.

  • Isolation preflight and current-source CPU native build passed; Go 1.26.6 linux/amd64, task-local caches, repository-expanded CGo flags and supplied test-exec. See preflight.log, build-native.log, native-inputs.json and native-artifacts.json; receipts 1794241008391511310-4 and 1794241066312952738-4.

  • Focused TestDedupPrimaryKeyRuntimeFilterWithStaleStats passed all 13 cases; full pkg/sql/plan passed 1,711 top-level tests, no skips (planner-focused.log/planner-package.log; receipts 1794241266545323858-3/1794241291256611757-3).

  • Focused TestReplaceCompositeKeyPrunesFlushedObjects passed all 14 scenarios; the full five-test pkg/tests/issues/isolated package also passed, repeating all 14 scenarios. New keys at both 8/16 objects read 0 blocks/0 rows/0 bytes (replace-focused.log/isolated-package.log; receipts 1794241373835881904-3/1794241557269394461-3).

  • Unfixed production-file overlay retained candidate tests/native inputs: five positive planner cases failed and eight rejection controls passed; new-key SQL failed for missing runtime filter and read 8 blocks/512 rows. These are expected failing controls, not candidate failures (planner-baseline-control.log/replace-baseline-control.log; receipts 1794241322299538332-3/1794241488215052148-3).

  • git diff --check passed, source remained clean at the frozen head, and every claimed local execution was matched to command/source/exit receipt and retained terminal events in validation-audit.json. Supplied CI snapshot reports successful build, Ubuntu UT/coverage, arm64 SCA and compose BVT; no CI was rerun.

Limitations:

  • Local execution was CPU, single-CN and normal mode; full distributed BVT, multi-CN and managed deployment tests were not rerun locally.

  • The original 72-hour throughput/latency, larger object history, object-metadata cost, cancellation/reconnect and final continuity acceptance in issue 27403 remain QA work. This scoped backport does not claim those outcomes or constant-time metadata enumeration.

@XuPeng-SH
XuPeng-SH merged commit 55e875b into matrixorigin:4.2-dev Nov 9, 2026
@ck89119
ck89119 deleted the issue-27403-4.2-dev branch November 10, 2026 02:55
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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants