Repository navigation
[4.2-dev] fix(plan): safely admit simple ZoneMap filters - #32419
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? |
8e75926 to
7d585d3
Compare
|
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: 7d585d3855d8a0128198042f888c13404e130047
Assessment: approve
The change coherently reuses existing planner, reader, ZoneMap and partition owners. Conservative unknown/NaN handling preserves query semantics, and the prior prepared NULL-bound defect is resolved. No actionable findings.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
Validation:
-
Reviewed all 25 changed files, affected consumers, complete discussion and linked-issue context.
-
Source, gofmt and expected-result audit passed: checks/1794279938335352591-3.json. Existing SQL row/DML expectations remain unchanged; source remains clean.
-
Frozen exact-head CI reports successful build, UT, SCA, coverage, Proxy and pessimistic multi-CN BVT. Author reports passing owning-package normal/race and public SQL controls.
Limitations:
-
No fresh local Go, race or SQL execution; reported execution evidence retains its attribution. Optimistic BVT and upgrade checks were skipped.
-
Customer-scale latency and original-tenant acceptance remain unverified. Legacy NaN coverage uses persisted-summary fixtures.
## 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 matrixorigin/matrixflow#20285 ## What this PR does / why we need it: Port the scalar NaN-ZoneMap safety fix identified during review of #32419 to `4.1.6-hotfix`. The defect also exists on this branch independently of the new planner admission policy: its current writer can persist an initialized `[NaN, NaN]` summary for a block containing `[NaN, 7]`. Scalar pruning then incorrectly rejects ordinary value `7`. Unlike `4.2-dev`, this branch also lacks the existing conservative `>=`/`<=` guards. - Add the FLOAT/DOUBLE NaN-bound check at the `index.ZM` ownership boundary. - Fail open for scalar equality, `<`, `<=`, `>`, `>=`, and `Between`; `InRange` inherits the safe comparisons for all open/closed bounds. - Preserve finite/infinite ordinary-summary pruning and existing uninitialized-summary behavior. - Cover both the actual writer-produced metadata and injected historical single-/double-ended NaN summaries through object/block filtering, sorted summaries, seek, and early-stop checks. - Add a two-row public SQL regression with default, explicitly enabled, and disabled block-filter modes. The session hint is used only to deterministically exercise the existing consumer, not as evidence of a new default admission policy or performance improvement. This is a minimal scalar-pruning fix. It does **not** backport the #32012 planner-admission change, change the writer/storage format or row-level NaN semantics, or redesign runtime-IN pruning. Validation on base `ef9256eca2` (macOS/arm64, Go 1.26.4, CPU CGo): - Native dependencies rebuilt from this branch. Focused regressions fail on the original implementation and pass after the fix. - Complete `pkg/vm/engine/tae/index`, `pkg/vm/engine/readutil`, `pkg/sql/plan`, and `pkg/container/types` tests pass using the repository CGo wrapper borrowed into the worktree (the older branch does not contain it). - gofmt, incremental go vet, and golangci-lint 2.6.2 built with Go 1.26.4 pass (0 issues). - Original and patched binaries built with the same Makefile/toolchain/native libraries. The original binary uses a Go overlay restoring the sole production change, `zm.go`, to HEAD; no working-tree rollback or 4.2 native artifacts are involved. - Original SQL execution loses `7` in eight forced-block-filter cases across FLOAT/DOUBLE equality, `>`, `>=`, and `BETWEEN`; disabled controls return it. The small fixture's default mode does not reproduce the failure, so no default-mode reproduction claim is made. - The patched binary passes all 36 independent result assertions across default/enabled/disabled modes. - `optimizer/legacy_nan_zonemap.sql` expectations generated and reviewed, then normal mo-tester comparison passes twice on the same instance: **31/31, 31/31**, with database teardown verified between runs. - Production changed-line-intersecting coverage blocks/statements: **18/18 (100%)**; this is not branch coverage. Linux/multi-CN, full CI, and real business-data acceptance are not claimed as validated. No IDC cluster was upgraded, restarted, or modified. ### CI follow-up: error propagation and bounded embedded race execution Related to #32433. The failed rerun exposed an independently reproducible panic: INSERT binding asserted every error as `*moerr.Error`, so a standard `context.DeadlineExceeded` triggered a second panic. Use the existing `moerr.IsMoErrCode` guard and preserve the original error. Regression controls retain both permitted legacy fallback cases and reject fallback for other errors/upserts. The release-branch runner previously admitted all packages through one `go test -p8 -race` command. Run ordinary race packages first at the requested parallelism, then execute embedded-cluster packages serially with no overlap. This includes `pkg/embed`, `pkg/tests/*`, and the existing `pkg/util/test` embedded owner. Preserve race/short/tags/timeouts, the complete package inventory, concatenated JSON reports and nonzero exit status; do not retry, skip tests, weaken assertions, or increase timeouts. The non-race path is not split into stages. Follow-up validation (Go 1.26.4, macOS/arm64): - Original error-propagation regression reproduces the exact interface-conversion panic; fixed regression passes for deadline, cancellation, ordinary errors, MO errors, and legacy-fallback boundaries. - Full planner/optools packages and focused race regressions pass; incremental vet/lint (golangci-lint 2.6.2), gofmt and Bash 3.2 syntax checks pass. - Dispatcher and real-entry contract tests check package boundaries/order, caller tags, failure/report propagation, cancellation status, empty stages and invalid inputs. The actual filtered `go list` inventory contains 421 packages: a mock-command execution through the real dispatcher proves each appears exactly once (408 ordinary, 13 embedded). This inventory check is not a full UT run. - The five CI-failed cluster cases pass with `-race -short -tags matrixone_test -count=1 -p1`: `TestPitrCases`, `TestDeleteAndSelect`, `TestClientDisconnectCancelsQueryAndRollsBack`, `TestAffectedRows`, and `TestPartitionBasedShardCanBeCreated`. The cascade failure `TestDataBranchDiffAsFile` also passes in a separate race run. Selected package execution took approximately 17–22 seconds each; the latter test took 33.81 seconds, excluding compilation. These changes fix the demonstrated error-type panic and enforce a bounded resource-admission contract. They do not prove the underlying runner CPU/I/O/HAKeeper stall cause, full Linux CI success, or full-lane timing acceptance. The original RPC incident remains tracked in #32433. The previous rerun passed Proxy BVT and coverage; CI for the new commits is pending.
…32550) ## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Related to matrixorigin/matrixflow#21333 ## What this PR does / why we need it: Adapt two complementary optimizations to `4.1.6-hotfix`: reduce repeated scalar CTE computation, and admit safe ZoneMap pruning independently of estimated block selectivity. This is **a target-branch adaptation, not a pure cherry-pick**. The branch lacks the CTE-sharing prerequisite used by #32522. This PR supplies a deliberately restricted prerequisite and adapts its non-truncating LIMIT proof, rather than importing main's general CTE materialization/spill subsystem. The ZoneMap portion adapts the admission work from #32012/#32419, preserves the existing #32431 protections, and does not import partition behavior changes. ### Two separate commits 1. **Safe ZoneMap admission and reader protections** (`ce71f6e3bf`) - Admit stable direct-column comparisons/ranges even with unhelpful or missing statistics; preserve residual predicates and `blockFilter=2` disabling. - Normalize constant-on-left comparisons without mutating shared expressions. Fail open for missing summaries and avoid unsafe floating-key seek, early-stop, and raw-byte filtering paths. - Retain the previous admission policy for partition tables. 2. **Bounded scalar CTE sharing and LIMIT proof** (`9f19e6fb7c`) - Match the same CTE declaration and actual bound source, including snapshots, types, and column mappings. Require deterministic, data-error-free producers with structurally at most one fixed-width row. - Bound each query to one shared producer, 64 readers, 256 output columns, and 64 KiB of fixed-width output. Unsupported, correlated/recursive, volatile, early-stop, or otherwise unsafe shapes remain inline. - Admit a positive literal LIMIT only when it covers a structural scalar/UNION ALL row bound. Statistics, OFFSET, and LIMIT itself do not tighten that bound. - Gather the final scalar result on the coordinator, project the compact published schema, and remap each reader after pruning. Give each reader a private copy through existing connector/spool machinery before evaluating expressions: decimal casts can mutate input vector metadata. - Preserve CTAS `HaveDDL=true` and same-transaction visibility. Do not force CTAS onto multiple CNs, change terminal protocols, or add a materialized source, spill store, or cross-query cache. ### Validation Local validation used **Go 1.26.4**, worktree-built native libraries, the CGo test wrapper, and golangci-lint 2.14.0 built with Go 1.26.4. - Both complete incident queries, with their original schema and **12 synthetic rows**: base-table scans changed from **8/4 to 1/1**. Actual CTAS produced 8/4 rows; business values and `SHOW CREATE TABLE` matched the optimization-disabled controls. Unordered row-number assignments were not used as an equality oracle. - Two independent local CN processes: both complete source SELECTs returned matching results from either coordinator. Actual remote contribution was verified by zero local scan rows on one coordinator, nonempty producer merge input, and matching business results—not merely an `AP_MULTICN` label or a remote placeholder in EXPLAIN. - ZoneMap fixture: clustered ranges read **1 block / 2 rows**, versus **3 blocks / 6 rows** with filtering disabled. Interleaved ranges correctly retained all three blocks. Commuted comparisons preserved results. - New BVT results were generated with mo-tester and verified twice: **41/41** for scalar CTEs and **60/60** for ZoneMaps. Adjacent ordinary/recursive CTE, recursive INSERT, and legacy NaN cases also passed (**54 + 124 + 31 checks**, including the new CTE case in the first group; none ignored). - Planner tests cover 2/4/8-branch LIMIT boundaries, structural unknown/overflow/cycle controls, source identity, pruning, and unsafe-inline cases. Compiler/operator tests cover local/remote-shaped producers, reader vector isolation, success/error/cancellation, partial preparation/publication, and zero residual mpool usage. Targeted race checks passed. - `go vet`, incremental lint, gofmt, and diff checks passed. Changed-line coverage mapped through Go coverage blocks is **519/616 = 84.25%**; affected-block statement coverage is **434/505 = 85.94%**. **Known baseline test failures:** the initial related-package run hit these three Parquet tests. The same failures were reproduced on a clean `54feca6423` worktree with matching Go/native inputs. The subsequent related-package run passed while explicitly excluding only these tests; no test was disabled or weakened in the committed code: - `TestCompileExternScanParquetLoadUsesRowGroupFanoutWithEmptyFiles` - `TestCompileExternScanParquetRowGroupFanoutValidatesEmptyFileColumnCount` - `TestCompileExternScanParquetLoadUsesFileFanoutMainPath` The package selection covered planner, compiler, readutil, TAE index, dispatch, merge, connector, pSpool, and process. This is not a claim that the unfiltered full suite or CI is green. ### Limits of the evidence No production deployment, production CTAS/DML, or production-scale latency/throughput/memory acceptance was performed. The small local fixtures establish plan, result, metadata, and lifecycle behavior; they do not establish a production wall-clock speedup. Customer SQL, local evidence, credentials, and build/data artifacts are not included in this PR. ### P2 review follow-up: concurrent copying of a broadcast batch Addressed in [`c8e4f588b7`](c8e4f58), after merging latest target `bf18d10904` (nullability inference). - Confirmed the review finding: `GetCopiedBatch` moved `ExtraBuf` out of its source, so multiple reader connectors copying a broadcast batch raced even with nil metadata. Both a minimal spool regression and the real compiler/connector path failed under `-race -count=1`. This proves a data race, not an observed wrong SQL result or crash. - Fix the common copy owner with `slices.Clone(src.ExtraBuf)`. Source metadata is read-only; destinations own independent backing. No reader serialization, if-nil workaround, or terminal-protocol change. Nonempty metadata copying costs O(metadata bytes); the scalar fixed-width output bound is not a general bound on serialized metadata. - Regressions now run the **copy phase concurrently** rather than only modifying completed copies concurrently. Cover nil/empty/nonempty metadata, source preservation, non-aliasing, cache reuse, 4/8 real readers, error/cancellation/partial preparation/publication, and zero residual mpool usage. Each exact concurrency test passed **100 race repetitions**. - Spool/compiler owning normal/race checks passed with the same three previously disclosed unrelated Parquet failures explicitly excluded from compiler selection. Unfiltered runs retain those failures; no repository test was disabled or weakened. Connector/dispatch/process race, merged plan/function/group normal tests, vet and incremental lint passed. Changed-production line coverage against the latest base is **520/617 = 84.28%**; the copy fix is **1/1 = 100%**. - On a fresh local service, complete scalar CTE, ZoneMap and CTAS fixtures passed twice: **41**, **60**, and **1,284** successful checks respectively per round, with **30 pre-existing CTAS ignores** and zero failures. An initial CTAS run with an inappropriate private default database was excluded; the final runs used no JDBC default database, preserving privilege/no-database assertions without changing SQL/results. - Rebuilt and revalidated both complete incident queries on the merged base: one base scan each, actual CTAS 8/4 rows, matching business values and table metadata versus disabled-optimization controls, plus two-CN remote contribution/result checks. No production access or production-scale performance acceptance. Post-push CI and maintainer design approval are not claimed. ### Versioned design and approval status - **Repository design document:** [v3-public.3 — scalar CTE sharing and safe ZoneMap admission](https://github.com/matrixorigin/matrixone/blob/c8e4f588b798984c2068802a1d20c2f682972e1e/docs/design/CLAUDE_32550_scalar_cte_zonemap_design.md) (`docs/design/CLAUDE_32550_scalar_cte_zonemap_design.md`). This commit-pinned repository file is the authoritative design; the earlier v3-public.1 PR comment is historical, not the formal document location. - The document binds base `54feca6423`, implementation `9f19e6fb7c`, and expectation-only fix `35edb87c48`. Revision v3-public.2 moved the document into the repository; v3-public.3 adds the source-immutable metadata-copy contract, review regression, and merged-base validation in section 10. - Approval provenance: the requester approved local v3 with “go ahead” before implementation and authorized delivery with “go on”. These are private-session scope/implementation authorizations, **not a maintainer design approval**; no public link to that private exchange is claimed. - **Maintainer design approval: pending.** XuPeng-SH is requested as reviewer. Please review **v3-public.3 at the pinned repository revision** and record approval/requested changes on GitHub. Publishing the document does not itself close the design-gate blocker. - Review item 1 (EXPLAIN expectations) was addressed in `35edb87c48`: the 10 affected cases passed twice locally, each with 999 successes, zero failures, and eight unchanged pre-existing decimal ignores.
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes #32720 ## What this PR does / why we need it: Port only the BOOL correctness closure from main #29527 (`f6eb974d5a`), without its unrelated Cartesian DML or statistics changes. - Calculate the BOOL maximum with OR, not AND, in both nullable and non-nullable vector summaries. Mixed false/true input must not be summarized as false/false. - Protect historical persisted BOOL summaries at column, ZoneMap-area and object-sort-key read boundaries. Legacy false/false bounds may hide true values, so expose a conservative private view without mutating shared metadata or expression/constant ZoneMaps. - Preserve exact raw writer serialization, including genuinely all-false new blocks. No disk-format or protocol change is introduced. - Add vector, metadata, physical write/read and real readutil consumer regressions. Extend the existing six-row persisted SQL fixture to check independent left/right counts and matched/left-only/right-only FULL OUTER JOIN output with default and disabled block filters. Validation on `4.2-dev@1d90e51`, macOS/arm64, Go 1.26.4, CPU mode: - Exact-baseline overlays fail the new vector/legacy-metadata and readutil regressions. A real six-row SQL probe reproduces the unfixed failure after flush: both filtered inputs are empty and FULL OUTER JOIN returns no rows; disabling block filters restores two rows per input and all three expected join rows. The fixed binary returns correct results in both modes. - Complete vector, objectio, objectio/ioutil, tae/index and readutil owning/consumer packages pass. Focused race validation, 100 repetitions of the metadata-view regression and the complete objectio race suite pass. - Service builds, scoped go vet and golangci-lint 2.6.2 pass (0 lint issues). - mo-tester generated the updated expectations; reviewed output contains only the new BOOL results. Two normal runs of `optimizer/non_primary_zonemap.sql` pass **92/92** each, with independent database-teardown checks between runs. - Changed-production-line-intersecting coverage is **24/24 statements (100%)**, not whole-package or branch coverage. Compatibility tradeoff: historical mixed and genuinely all-false BOOL bounds are indistinguishable without writer provenance. Conservative reads may scan additional all-false blocks rather than lose true rows. Only the ambiguous BOOL view is copied; other metadata paths remain unchanged. Limits: the original 100M/three-CN workload, Linux CI and customer-scale performance have not been rerun. The minimal reproduction proves the current-branch failure mechanism, not that #32419 is the original incident's uniquely bisected introducing commit. Approved-by: XuPeng-SH <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
Related to https://github.com/matrixorigin/matrixflow/issues/20285
What this PR does / why we need it:
Adapt the simple ZoneMap-filter admission fix from #32012 to
4.2-dev, including the reader compatibility fixes needed to preserve query results on this branch.100 < kwhere[150, 200, 201]was expected; this PR includes the consumer fix rather than shipping that unsafe backport.Additional correctness fixes after rebase:
Validation on rebased
4.2-dev(c6606110e8):pkg/partitionprune,pkg/sql/plan,pkg/vm/engine/readutilandpkg/vm/engine/tae/indextests passed in normal and-racemodes on Linux/amd64 with Go 1.26.6 and the repository CGo wrapper.pkg/vm/engine/disttaeandpkg/sql/compile(0 lint issues).11 → NULL → 11with default and disabled block filters. The normaloptimizer/non_primary_zonemap.sqlBVT passed twice (77/77 each), with database teardown checked between runs.The float safeguard may examine every block summary in a sorted float object and leaves scalar float primary-key filtering to the residual predicate. It does not claim to resolve separate pre-existing float upsert-probe behavior. Real customer-scale performance and the new remote CI run remain unverified.
Historical author validation on earlier revisions:
4.2-devbasefa6bc2bcd9: completepkg/sql/planandpkg/vm/engine/readutiltests pass with Go 1.26.4 and the repository CGo wrapper; gofmt, incremental go vet, and golangci-lint 2.6.2 built with Go 1.26.4 pass (0 issues).10d204b876.optimizer/non_primary_zonemap.sqlpassed normal mo-tester comparison twice (60/60 each); generated expectations were checked against independent expected rows before comparison. Cleanup was verified between runs.blockFilter=1was used.Evidence reuse: the only change between previously validated
a860d63a97and current basefa6bc2bcd9is the repeated Top/mergeTop ordering-key fix (#32402). It does not change the planner/readutil implementation or this BVT fixture; current-base package/static checks were rerun, while deployment-baseline SQL/BVT evidence is retained with its original revision attribution.Limitations: local validation was macOS/arm64, single-node CPU mode. Real 96-million-row latency, Linux/multi-CN, original-tenant permission integration, the full BVT/EXPLAIN baseline suite, and full CI are not claimed as validated. IDC Dev was not upgraded, restarted, or modified. Real-data acceptance still requires a suitable environment.
Review follow-up validation: the new legacy-NaN regressions failed before the fix and pass afterward. Complete
pkg/vm/engine/tae/index,pkg/vm/engine/readutil, andpkg/sql/plantests pass with Go 1.26.4; incremental vet/lint pass. New production changed-line-intersecting coverage blocks are 8/8 (100%). The compatibility fixture injects historical summary bytes into a valid object metadata layout: the current writer no longer emits this legacy state, so no new-write SQL test is presented as a reproduction. Existing integer BVT evidence is reused; it is not a NaN SQL acceptance claim.CI follow-up (run 42600602130): the BVT failures comprised stale EXPLAIN expectations and a range-partition pruning consumer that passed materialized Fold constants directly to the general expression executor. Normalize the already-copied partition expressions using the existing hash/list conversion helper; preserve original filters and partition metadata. The new UT fails with the original executor error before the fix. Refresh only generated EXPLAIN checkpoints for the new block filters; all SQL row results and UPDATE/DELETE expectations remain unchanged.
After merging
mo/4.2-devate4f70a7268, the four complete owning packages (partitionprune,plan,readutil,tae/index), incremental vet/lint, and two local normal mo-tester runs of all 11 failed files passed (1187/1187 each), with database teardown checked between runs. Changed-line-intersecting statement-weighted coverage is 116/118 (98.31%). The earlier CI coverage job was blocked by failed BVT prerequisites and did not compute a verdict. These local checks do not claim the next remote multi-CN run is green.CI and rebase follow-up:
5dc6dec013. Restore the existing index-table ZoneMap admission rule when optimizer statistics are unavailable, still requiring a zonemappable expression and honoringblockFilter=2. Default costs and residual row filters remain unchanged. This removes the missing-prefix-filter plan differences seen in run 42726120209; unavailable statistics is a source-supported explanation, though that run did not log its stats state.prefix_eq/prefix_inblock filters. Both focused tests reproduce the missing-filter behavior before the change.plan,partitionprune,readutil, andtae/indexowning packages passed normal and race tests. Final planner tests were rerun after the test additions. Incremental gofmt, vet and configured golangci-lint passed for these packages plusdisttaeandsql/compile.309a0ca650against a private three-CN embedded cluster through one CN, the four affected BVT files passed: decimal 625/625, index 134/134, index-cast 73/73 and non-primary ZoneMap 77/77. A persisted secondary-index SQL probe also verified equality and unordered preparedINwith NULL, with block pruning enabled and disabled. These local runs do not replace the remote Proxy and multi-CN BVT jobs.