Repository navigation
fix(group): drain streaming partial spills and preserve DISTINCT keys - #30976
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed current head 0e5f0916f57d7883ae30150959ceec70ec1b1399 (this is my PR, so leaving a COMMENT review).
The state-machine change drains queued generic spill buckets for streaming partial Group output, loading the next bucket only after the consumer returns the previous batch. The regression exercises both key-only grouping and grouped COUNT, verifies all 768 expected keys and duplicate counts, and checks account/spill-disk/spill-FD cleanup. I found no new issue in this static review.
Validation boundary: the PR description reports group package tests, focused race tests, and Q06 workloads, but I did not execute those here. This workspace has no MatrixOne checkout or Go runtime; the exact-head combined status is empty.
|
mo-bot review · Commit: "interrupted" |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed the one-commit update from 0e5f091 to e12b022.
The changed partial-Group state machine now keeps Eval active while generic spill buckets remain, loads each next bucket only after the previously returned batch has been consumed, and defers exact-DISTINCT leaves until generic reload is exhausted and input has reached EOF. Restricting grouped DISTINCT cardinality preparation to NeedEval preserves exact key identities in partial output for downstream MergeGroup deduplication. The new regressions exercise deterministic capacity rejection, all 768 expected keys and COUNT values, mixed generic/exact DISTINCT spill with COUNT/SUM, resumed input, cancellation/reset/reuse, and account/disk/fd cleanup.
I found no new blocking issue in this static review. The reported package normal/race, vet/lint, SQL, and Q06 results are from the PR description; I did not execute them here. This workspace has no MatrixOne checkout or Go toolchain, and the exact-head combined status is empty (the workflow API exposes only Iceberg Connector E2E success). The separate Q06 performance issue #27670 remains open; this review does not mark it resolved.
|
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: eb356f0d4d5bc7aa4a39c9e308d7334eb98318bf
Assessment: approve
Complete delta and owner/caller review found no actionable defects. The fix preserves every partial contribution and DISTINCT identity through existing spill loaders and serialization, with correct batch lifetime, cancellation, and reset behavior. Added branches are confined to output boundaries.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
Validation:
-
Private-runtime preflight passed. Built native prerequisites at the frozen commit through the repository build owner and verified provenance.
-
Both new regression tests passed, covering five subcases.
-
All 216 Group test roots passed without skips: normal mode in 14.161s and race mode in 24.376s, using count=1 and the supplied test-exec.
-
Negative control reverting only production exec2.go reproduced the original failures: 1 instead of 768 keys and undrained mixed-DISTINCT buckets.
-
Independent one-CN SQL control passed twice on the same instance at agg_spill_mem=2 and 67108864, checking COUNT, SUM, DISTINCT, NULL, empty input, and teardown.
-
Commands, source fingerprints, exit receipts, and retained logs reconciled in /home/xupeng/.local/state/mo-bot/jobs/3d1b3fe7fbd1e56f5062f5dd/attempt-1/evidence-audit.json. Assigned source remained unchanged.
Limitations:
-
SQL controls exercise public integration; deterministic operator regressions establish hard-capacity recovery.
-
Broader CI UT, static analysis, and multi-CN BVT remained pending and were not counted as passing evidence.
-
No large Q06 throughput benchmark was repeated. Historical wrong-result timings are not a valid performance baseline; issue #27670 remains separate.
## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [x] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Related to #27670 and #27720. This is a bounded single-CN follow-up; it does not close the original ClickBench issue or implement the full adaptive DISTINCT proposal. #30976 is merged into main and is not carried as a dependency commit. ## What this PR does / why we need it: ### Design and scope Large single-key DISTINCT plans can build a local deduplication table immediately before a shuffled Group builds the complete key set again. When local reduction is small, overlapping hash state adds CPU, memory pressure and spill. Keep the logical candidate and omit local hash aggregation only during physical compilation when the actual shuffle target and every immediate source identify the same CN, DOP > 1, and the adjacent Groups have a pure direct-key contract. A copied projection preserves the local Group output schema and expression ownership. Existing shuffle, final Group, allocation and spill implementations remain the owners. Keep local aggregation for remote/unknown placement, partial results, small or duplicate-heavy estimates, shuffle reuse, canonical/computed keys, coordinator consumers and semantic transformations. The empirical guards require estimated key cardinality >=2M and key/input ratio >=25%; they are not a worker-skew model or a universal speedup guarantee. Rebased onto main `f039b89fa923821fa0fa9219fe567e54a9d0f2ed`. The optimization patch is equivalent to the original head. No production logic changes were needed after review; the follow-up closes the missing execution/performance evidence with portable artifacts. ### Current validation Linux amd64 / Go 1.27.1, matching source and native-library fingerprints: - Full `pkg/sql/compile` UT: **1553 roots passed**. - Full owning compiler race: **1553 roots passed**, plus shuffle **46** and projection **6** roots; no race reports. - `go vet` passes. Pinned molint exits successfully with nine existing diagnostics in files verified byte-identical to the base; configured incremental golangci-lint reports **0 issues**, with no new SCA finding. Formatting and patch whitespace checks pass. - Native frontend SQL: exact integer and nullable/empty VARCHAR counts, small/duplicate-heavy/CHAR-padding controls, and repeated execution of one prepared handle including empty input. - Actual `EXPLAIN PHYPLAN VERBOSE` proves producer `group(idx:1)` is replaced by its key projection before `shuffle(idx:2)` for eligible integer/VARCHAR queries; final deduplication and outer count remain. Both versions retain the producer Group in the three controls. - At `agg_spill_mem=33554432`, the final key Group reports positive `GroupSpillSerializedBytes` and reload activity; exact results and subsequent normal execution pass. This is a per-operator spill threshold, not a 32MiB statement cap. - After observing active Group and shuffle calls, `KILL QUERY` returns 1317 in **5.238ms**; the same connection then returns the exact 3M count. This does not claim cancellation specifically during spill I/O. - Owned task databases were dropped and absence verified; embedded services were closed. ### Sequential baseline/candidate ABBA One CN, four threads, natural statistics and identical diagnostic configuration. One warmup and three measured executions per workload per phase give six samples/version. Loading, ANALYZE, EXPLAIN and startup are excluded; every result is consumed and checked. | Synthetic workload | Baseline median | Candidate median | Observation | | --- | ---: | ---: | --- | | 6M rows / 3M integer keys | 0.422883s | 0.180913s | 2.34x; sample ranges do not overlap | | 1M rows / 500K keys | 0.052015s | 0.047817s | fallback; sample ranges overlap | | 6M rows / 10K keys | 0.052821s | 0.045323s | fallback; sample ranges overlap | The two binaries share the target dependency tree, native library, diagnostic harness and fixture overlays; BASE replaces only the compiler implementation. Both use 512MiB CN memory/disk caches, a 512MiB TN memory cache, the existing 1GiB TN disk cache, and a 1GiB fixture spill allowance. The canonical feature-test fixture's 32MiB caches caused eviction-dominated diagnostic timings, which are excluded. No production configuration or runtime policy was changed. Portable [validation report](https://github.com/matrixorigin/matrixone/blob/296b188a88f49229ac8fe7df772c1890ad6e637a/docs/design/single-cn-key-preaggregation-validation.md) and [raw evidence record](https://github.com/matrixorigin/matrixone/blob/296b188a88f49229ac8fe7df772c1890ad6e637a/docs/design/single-cn-key-preaggregation-evidence.json) retain SQL, phase samples/ranges, plans, Group spill statistics, source/native/binary hashes and command/exit receipts. Full runtime logs and diagnostics are retained at the hashed external paths in the record. Historical Apple M4 timing reports were not recovered and are not presented as current evidence. These Linux synthetic measurements do not reproduce ClickBench, compare DuckDB, claim distributed gains or prove universal regression avoidance. Design and final overall review **passed**, using explicitly selected `gpt-6.1-sol` with `xhigh` reasoning; final accepted revision is `296b188a88f49229ac8fe7df772c1890ad6e637a`. Previous-head required CI, UT, SCA and multi-CN lanes passed; new-head remote CI is pending.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #30975
What this PR does / why we need it:
Hard-capacity recovery can spill a streaming partial Group. Ending or resetting after its first reloaded bucket silently drops remaining keys and aggregate contributions. When generic group spill and exact COUNT(DISTINCT) spill coexist, choosing the exact-key path first also skips queued generic buckets; reducing exact keys to final cardinalities in a partial loses the identities required for downstream deduplication.
Keep the existing Group output owner and readers. Drain generic buckets before exact-key leaves, retain exact keys across input flushes, and emit those leaves after input EOF. Only final evaluation prepares DISTINCT count contributions. Load the next bucket on the following Call so the consumer retains the previously returned batch. Remove the duplicate pre-spill exact drain already performed by spillDataToDisk. This also avoids final-only DISTINCT contribution work in partial producers, without new buffers, state, configuration, or wire formats.
The original deterministic regression checks all 768 keys and COUNT contributions through a real MergeGroup after one capacity rejection. A shared mixed-spill fixture adds two serialized partial producers with COUNT, SUM and COUNT(DISTINCT), overlapping/disjoint argument sets, repeated values across producers, NULL-only groups, resumed input, and cancellation/reset/reuse. It verifies exact per-key results and terminal account, spill-disk and spill-FD cleanup. The new regression fails on the original PR head with 31 generic buckets remaining.
Validation on the follow-up candidate:
Earlier author evidence for the original key-only/COUNT fix:
The separate Q06 performance issue #27670 remains open. Local validation above does not claim that CI for the newly pushed revision has passed.