Repository navigation
fix(plan): retain bounded REPLACE primary-key runtime filters (cherry-pick #32401) - #32432
Conversation
…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)
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? |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
What type of PR is this?
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) to4.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
4.2-dev's existingHashmapSizeand singleton admission logic; do not import main's point-filter/tree refactoring.pkg/tests/issues/isolated, using an owned single-CN cluster and explicit cleanup instead of importing main's SQL-integration harness.multi_insert.resultexpectation 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:
-count=2). Exact rows, cardinality, duplicate-input semantics, and transaction-local conflicts are checked separately from read work.pkg/sql/plantests pass: 76.0% statement coverage; changed production statements are fully covered.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.