Repository navigation
perf(compile): omit redundant key preaggregation on one CN - #30982
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? |
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
|
mo-bot review · Commit: "interrupted" |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Review verdict: APPROVE — no blocking findings.
Reviewed all hunks in 9cb07ef against the declared stacked base 0e5f091. No subagents were used in this review.
Design and implementation:
- The existing physical compiler owns this choice. The logical candidate remains intact; no parallel planner policy, runtime state machine, storage, protocol, compatibility branch or memory-budget ledger is added.
- For the admitted pure key pair, final deduplication preserves the result when local deduplication is omitted. The copied projection preserves the raw key's output slot and expression ownership. Actual immediate source/target placement, normal shuffle and DOP guards keep the optimization within one CN.
- The local Group fallback remains necessary for remote transfer, semantic key production, partial results and ineligible estimates. Local filter/projection/sort order is preserved there. The unused temporary Group and duplicate admitted-path projection have been removed.
- The previously identified parent-coordinator relocation issue is closed by the parent semantic guards and its physical-placement test. Projection, shuffle and final Group continue to own Prepare/Call/Reset/Free, cancellation and bounded buffering.
Tests, evidence and independent QA:
- Production +89/-9 lines and tests +257/-23 lines were reviewed separately. The tests reuse lightweight fixtures and cover placement, boundaries, nonzero source-column mapping, NULLs, plan immutability and SQL-planner reachability. No large-data fixture is added to ordinary UT. There are no repository documentation changes; the PR description accurately limits its claims.
- Reused matching final-source evidence after independently checking source/diff/binary hashes: compiler package UT/vet (11.285s), affected race tests (2.627s), incremental SCA (0 issues), native exact-result/prepared/forced-spill tests, and the final ABBA performance evidence.
- Added an independent 10,005,480-row / 3,000,001-key control with approximately 70% hotspot, using both VARCHAR and unsigned BIGINT keys. Exact results pass; both versions retain local preaggregation. Ten measured samples/version give 0.2811→0.2888s and 0.1496→0.1556s, respectively, with overlapping sample ranges; these are fallback controls, not a speedup claim.
- Added execution-phase cancellation: observed active Group and shuffle stacks on the optimized 100M query with a 32MiB spill setting, then KILL QUERY. It returned error 1317 in about 9ms; SELECT 1 and an exact 5M-key count succeeded in the same session. This proves execution cancellation/recovery, not cancellation specifically during spill I/O. Task-created table was dropped and owned services stopped.
Comments and remaining scope:
- At submission there are no inline review threads or actionable reviewer findings on this PR. Qodo is paused; the separate mo-bot review is still marked in progress, so its pending result is not represented as resolved.
- The 2M/25% cost thresholds remain empirical. The recorded 50M/100M gains are scoped to the measured synthetic single-CN workload, not a universal no-regression or original ClickBench-issue closure claim.
- This review is against the stacked dependency #30976. It does not assert that all required CI checks or main-branch integration are complete.
Submission limitation: GitHub rejected the APPROVE event with HTTP 422 ("Can not approve your own pull request") because the authenticated account XuPeng-SH is also the author. This COMMENT records the completed review and its APPROVE recommendation; it does not supply a formal independent GitHub approval.
9cb07ef to
d9171f2
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: d9171f22fa5281edd47c49e2ab40ddd4027218c1
Assessment: request_changes
The compiler-owned design is coherent and preserves existing execution and cleanup owners. Complete source review found no demonstrated implementation defect, and local tests passed. Approval remains blocked by missing traceable SQL execution and performance evidence for the optimization.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1
- P2
pkg/sql/compile/compile.go:8303: An eligible single-CN DISTINCT plan omits local aggregation, sending raw rows into shuffle and final Group.
Impact: Validation requirement: recover the reported native SQL and baseline/candidate benchmark artifacts before approval. Evidence should demonstrate actual branch selection, exact results, prepared reuse, forced spill, and affected/control workload measurements. Existing artifacts may suffice after source compatibility is established; rerun only missing or stale checks.
Evidence: evidence.json.local_validation is empty, and the frozen native SQL/ABBA reports provide summaries without accessible command/source/exit receipts or raw logs. Added tests verify selection, topology and projection output, but do not execute the complete selected SQL pipeline or measure its performance tradeoff. Fresh compiler and spill unit tests pass, but do not close those distinct claims.
Validation:
-
Reviewed all changes: compile.go +89/-9 and compile_test.go +257/-23, including planner callers, placement, projection, shuffle, final Group, allocation ownership and cleanup.
-
Isolation preflight and Go 1.27.1 bootstrap passed. Native prerequisites were built through make cgo in the diagnostic copy; provenance and frozen-source identity passed.
-
Focused compiler/shuffle/preaggregation and streaming-spill tests passed: 25 root tests, no failures or skips.
-
Full pkg/sql/compile tests passed with default vet checks: 1,553 root tests, no failures or skips, 11.255 seconds.
-
Formatting, patch whitespace and source-cleanliness checks passed. Compiler/test and native build inputs match the historical optimization head.
-
Commands, source fingerprints, terminal exits and retained logs were reconciled in /home/xupeng/.local/state/mo-bot/jobs/a4ef4f750db621860dee2096/attempt-1/validation-audit.json; review coverage is recorded in review-map.md.
Limitations:
-
No fresh SQL execution, race run or performance benchmark was performed. Frozen build/UT/SCA CI statuses were still in progress.
-
Historical synthetic single-CN speedups are author-reported measurements, not independently verified results here. Removing duplicate hash state increases raw-row shuffle work; the empirical thresholds do not establish universal regression avoidance.
-
Source review is complete; public execution and performance evidence reconciliation remains open. The related ClickBench issues are not claimed resolved.
d9171f2 to
296b188
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: 296b188a88f49229ac8fe7df772c1890ad6e637a
Assessment: approve
Complete review found no actionable defects. The compiler appropriately owns the placement-dependent optimization: key projection preserves the input contract, final Group retains deduplication, and existing shuffle, spill and cleanup owners remain authoritative. Reconciled execution and performance evidence closes the earlier validation-only finding.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
Validation:
-
Reviewed all four changed files, planner/compiler callers, conservative fallback guards, projection ownership, cancellation, prepared reuse, compatibility and test quality.
-
Verified that the tested revision db0a75e differs from this head only in the two evidence documents. Reconciled 22 artifact hashes and 11 command/source/exit receipts with retained logs. Native provenance passed using the recorded compiler environment.
-
Reused verified passing evidence: 1,553 compiler tests; race runs covering 1,553 compiler, 46 shuffle and 6 projection root tests. No failures, skips or race reports.
-
Verified frontend SQL evidence demonstrates actual omission, retained final aggregation, exact integer and nullable VARCHAR results, fallback controls, prepared parameters [3000000, 0, 1, 3000000], final-Group spill/reload, cancellation and same-session recovery.
-
Recomputed sequential ABBA measurements: eligible integer median improved from 0.422883s to 0.180913s, or 2.337x. Small and duplicate-heavy controls retained local aggregation; their timing ranges overlapped.
-
Verified ordinary vet passed, configured golangci-lint reported zero issues, and all nine molint diagnostics concern files byte-identical to the base. Formatting, whitespace and source-cleanliness checks passed.
-
Fresh checks audited evidence and native provenance without repeating product tests. Receipts and logs are reconciled in /home/xupeng/.local/state/mo-bot/jobs/161fa734bc38fb909824720e/attempt-1/validation-audit.json; complete review coverage is recorded in review-map.json.
Limitations:
-
The frozen CI snapshot still contains pending checks; this assessment does not claim CI completion.
-
Measurements cover synthetic single-CN workloads with four threads. Increased raw-row shuffle work remains a tradeoff; empirical thresholds do not guarantee universal speedups or close the related ClickBench issues.
-
Cancellation evidence covers active Group/shuffle execution, not specifically cancellation during spill I/O.
What type of PR is this?
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:
pkg/sql/compileUT: 1553 roots passed.go vetpasses. 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.EXPLAIN PHYPLAN VERBOSEproves producergroup(idx:1)is replaced by its key projection beforeshuffle(idx:2)for eligible integer/VARCHAR queries; final deduplication and outer count remain. Both versions retain the producer Group in the three controls.agg_spill_mem=33554432, the final key Group reports positiveGroupSpillSerializedBytesand reload activity; exact results and subsequent normal execution pass. This is a per-operator spill threshold, not a 32MiB statement cap.KILL QUERYreturns 1317 in 5.238ms; the same connection then returns the exact 3M count. This does not claim cancellation specifically during spill I/O.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.
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 and raw evidence record 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-solwithxhighreasoning; final accepted revision is296b188a88f49229ac8fe7df772c1890ad6e637a. Previous-head required CI, UT, SCA and multi-CN lanes passed; new-head remote CI is pending.