Repository navigation
fix(sql): enable leading-key pruning for distributed Top-K scans - #32242
Conversation
Preserve multi-key Top-K semantics while enabling leading-key block filtering and restoring remote Top/scan metadata. Implement private remote block ordering and preserve remote InputBlocks statistics. Related to matrixorigin#32219.
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. |
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed the full change at e956471, including planner eligibility, Top/remote codecs, reader-local block ordering, threshold application and scan-counter serialization. Leading-key pruning retains equal-key candidates and the full Top-K comparator, does not install a multi-key static row limit, and falls back for nullable or ambiguous mappings. Reader ordering does not mutate shared RelData; cancellation/error publication and reset paths are covered. No blocking findings.
Reused exact-head successful CI and assessed the focused component/race and one-/two-CN SQL evidence. These results support the optimization, not a claim that the original production timeout was uniquely reproduced or resolved.
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: e956471de326eae0f1a813e6f99b65fa8b952a1f
Assessment: request_changes
The existing Top/reader design is coherent, but the P2 metadata-retention defect remains. The new approval confirms correctness and cleanup without addressing the whole-object buffers pinned by the remote permutation.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
- P2
pkg/vm/engine/readutil/datasource.go:301: A remote ordered Top-K scan spans many wide objects, even when LIMIT is small or only a few blocks per object survive range filtering.
Impact: The permutation retains every object's complete uncompressed metadata until reader close, defeating metadata-cache eviction and causing a potentially multi-GB heap increase before the first block is returned.
Evidence: GetBlockMeta (objectio/meta.go:66), GetColumnMeta (objectio/column.go:40), and ZoneMap (column.go:93) all return views into the same allocation. Storing these views in orderedBlocks pins metadata for all columns and blocks; writer.go:417 builds that metadata in one buffer. For example, 1,000 objects with 128 blocks and 100 metadata columns retain at least 1.59 GB, although one selected zonemap per object needs only 64 KB. The previous remote path retained no such list. Clone/detach each zonemap before storing it, using the existing ZoneMap.Clone capability as SetFilterZM already does.
Validation:
-
Recovered the complete 15-file review and successful static/descriptor/17-query reference checks from attempt 1, matching retained commands, source hashes, exits and logs.
-
Recovery audit passed (checks/1793935844639769841-2.json; recovery-check-final.log). Frozen source, patch, PR body, linked issue and successful CI are unchanged.
-
Assessed all three discussion items, including approval 5790146917, against the retained source evidence.
Limitations:
-
No local Go, MatrixOne or memory-profile execution; CI and author reports lack supplied raw execution logs.
-
Metadata amplification is established by source ownership and layout, not an observed OOM. The original incident timeout remains unverified.
Clone retained zonemaps so remote block ordering cannot prevent full object metadata from being reclaimed after cache eviction. Add a regression using the existing persisted-block fixture to verify equal values and independent fixed-size backing storage. Addresses the metadata-retention review in matrixorigin#32242. Related to matrixorigin#32219.
|
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: 92bde96fb753adfb2a345ac9a0036e26131d17f6
Assessment: request_changes
The design reuses existing Top and reader mechanisms, and both prior metadata-retention findings are resolved. Newly eligible GEOMETRY leading keys still expose an unsupported-type panic.
Model: gpt-6.1-sol / max
Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0
- P2
pkg/sql/plan/message.go:79: A query such as SELECT id FROM t ORDER BY g DESC, id DESC LIMIT 1 uses a GEOMETRY NOT NULL column, and an ordered reader receives at least two persisted blocks with initialized g zonemaps.
Impact: The previously supported multi-key query reaches an unsupported-type panic instead of completing.
Evidence: GEOMETRY passes encodedOrderMatchesSQLOrder, which only rejects floats. Its persisted zonemaps are initialized. Remote block sorting at readutil/datasource.go:317/319 and local sorting call ZM.CompareMax/CompareMin, reaching compute.Compare, which lacks GEOMETRY support and panics at pkg/vm/engine/tae/compute/compare.go:140. Baseline rejects multi-key message installation, while ordinary Top supports GEOMETRY. Keep unsupported comparison types on the full-scan fallback or implement matching comparator support, and add a persisted multi-key regression with an optimization-disabled control. Source proof is retained in geometry-source-trace.json.
Validation:
-
Reviewed all 17 changed files, affected consumers, all 9 discussion entries and linked issue context; saved review-plan.md and discussion-assessment.json.
-
Source audit passed: clean frozen head, diff whitespace, gofmt on 14 Go files, and generated protobuf descriptor/codec consistency.
-
Independent SQLite reference matched all 17 expected row sets.
-
Static GEOMETRY call-path and baseline assertions passed; no runtime reproduction is claimed.
-
Private /tmp and loopback preflight passed. All five check receipts, including the superseded probe error, match terminal exits, source fingerprints and retained logs in validation-review.json.
-
Reused frozen current-head successful build, UT, SCA, coverage and proxy/multi-CN BVT statuses.
Limitations:
-
No local Go tests or MatrixOne SQL execution; the finding is established by source reasoning.
-
CI and author execution evidence was supplied as summaries without raw logs. The prior approval body names another head and was not treated as current-head local execution proof.
-
The original production timeout remains unreproduced; scoped pruning evidence does not establish its root cause.
Reject geometry and geometry32 in the shared encoded-order eligibility check because storage zonemap comparators do not support spatial types. Retain the full logical Top comparator and full-scan fallback instead of installing dynamic messages or ordered reader limits. Add planner family regressions and persisted GEOMETRY TP/AP SQL controls with the optimization enabled and disabled. Related to matrixorigin#32219. Addresses the spatial-key review in matrixorigin#32242.
|
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: 6810d5f04e27b91d808fc0be0c96dcb928b44b39
Assessment: approve
Leading-key pruning preserves full Top-K ordering and conservative fallbacks. Reader-owned permutations and detached zonemaps fit existing lifecycle owners; prior metadata-retention and spatial-panic findings are resolved.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
Validation:
-
Reviewed all 18 changed files, affected consumers, linked issue context and all 11 discussion entries; saved complete discussion dispositions.
-
Source/descriptor audit passed: frozen patch, clean source, whitespace, gofmt on 15 Go files and protobuf field/codec consistency. Receipt: checks/1794034649670401398-3.json; source-descriptor-audit.log.
-
All 25 expected SQL row sets matched an independent relational reference. Receipt: checks/1794034649369237908-3.json; sql-reference-audit.log.
-
Isolation preflight passed. Receipt: checks/1794034507655361414-3.json; preflight.log.
-
Reused frozen-head successful CI statuses and attributed focused, race and distributed BVT reports at their supplied scope.
Limitations:
-
Native testing stopped before compilation because cgo/libmo.so was missing. Receipt: checks/1794034517265568015-3.json; native-readutil.log. No fresh linked Go/race or MatrixOne execution is claimed.
-
External CI and author results were supplied as summaries without raw logs.
-
The original stability timeout remains unreproduced; scoped pruning evidence establishes no production latency guarantee.
What type of PR is this?
Which issue(s) this PR fixes:
Related to #32219.
What this PR does / why we need it:
Multi-column
ORDER BY ... LIMITskipped Top-to-scan dynamic filtering, and remote execution lost the Top message tag and runtime scan ordering. Consequently, a small result limit did not bound scan work.InputBlocksthrough remote statistics serialization.Validation (Go 1.26.4, Darwin/arm64):
The original 30-second stability timeout was not reproduced. These measurements validate the scan optimization, not a unique production root cause or a guaranteed resolution of the incident.