Repository navigation
perf(sql): reduce redundant aggregation and preserve analytic parallelism - #32625
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? |
|
Queue requested — the merge queue status continues in this comment ↓. |
|
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: da5ebca8193d9c3f1d7e113fb0b0dfeaf12f2fce
Assessment: request_changes
The optimizations reasonably reuse existing execution and cleanup owners. However, grouped SUM pushdown has a reproducible regression: it can make a previously skipped fact predicate execute and turn an empty result into a CAST error.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
- P2
pkg/sql/plan/grouped_sum_pushdown.go:168: A total DECIMAL SUM reads a fact subtree containing a fallible predicate such as CAST(bf.s AS BIGINT)>0. The dimension filter matches no rows, but estimates admit pushdown and cause the partial fact aggregate to become the hash-build input.
Impact: The new blocking aggregate evaluates invalid fact rows that the original empty dimension build skipped. The query fails instead of returning an empty result. Checking only the SUM argument does not establish totality of the moved fact subtree.
Evidence: A native public-SQL probe with 50,000 fact rows, two fact keys and 5,000 dimension rows reproduces this using ordinary stale statistics after ANALYZE and UPDATE. With aggPushDown=1, the query returns no rows without error; the default plan raises Error 20203 for CAST('broken' AS BIGINT). EXPLAIN confirms the build-side transition. See sum-fact-predicate-build-flip-public.txt, review_sql_fact_build_flip_test.go and checks/1794486630936944738-3.json (exit 1). Prove the entire moved fact input total, or preserve its evaluation boundary, and add a regression covering this transition.
Validation:
-
Preflight and native CPU build passed; provenance audit verified 198 native inputs and eight artifacts.
-
Go 1.27.1: 122 focused tests across six owning packages passed. All 271 Window tests passed under race detection, plus 24 focused repetitions.
-
Corrected public-SQL probes passed fused-window NULL/order oracles, grouped SUM results and DECIMAL metadata, and the activated outer-domain overflow control.
-
The final SQL counterexample confirmed the regression. validation-audit.json correlates all 13 evidence checks with commands, source fingerprints, retained logs and terminal receipts.
-
All three discussion keys were assessed exactly once; source remains unchanged.
Limitations:
-
The historical 1TB benchmark was audited for source continuity but was not rerun at the final head.
-
Broader suite and static-analysis coverage relies on the supplied head-specific CI and author reports.
da5ebca to
bff833f
Compare
🚫 Left the queue · pull request dequeued23 min in the queue, with no time running CI. So far
Reason Pull request #32625 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
To get back in the queue
Tick the box to put this pull request back in the merge queue (same as
Times in UTC · dashboard · how the merge queue works |
What type of PR is this?
Which issue(s) this PR fixes:
Related to #26768.
What this PR does / why we need it:
Reduce repeated analytic work and avoid unnecessarily serial execution, using general relational and ownership proofs rather than query-specific rules:
No SQL text matching, query/table names, schema changes, ANALYZE requirement, new settings, increased resource limits or new wire/storage formats. Automatic-merge disabling is benchmark-only and is not included in this PR.
Measured performance
TPC-DS 1T, original 99-query corpus, 129, one CN / 64 logical CPUs, automatic DOP,
agg_spill_mem=4GiB,join_spill_mem=0(automatic),sort_spill_mem=512MiB, GOGC=200, service memory cap 192GiB / swap disabled; automatic merge off in both runs.The full-suite comparison is historical (
25d6a4746fversus the tested pre-rebase snapshot93e97fd571), not an isolated same-main A/B. All 21 changed production files were hash-verified against the native tested sources. The 12 patches were subsequently rebased unchanged ontob9c06b27b0, followed by the input-totality review fix below; the full-suite timing above is from before those updates.Independent original-SQL controls against each optimization's immediate parent support the individual improvements (incremental pairs; do not add their savings together):
Complete outputs match within each pair. Against the historical full99 outputs, 94 are byte-identical, four retain identical row multisets and ORDER BY key sequences with changes only within ties, and Q39 differs only in floating-point covariance results (maximum absolute difference 6.67e-16).
Versioned benchmark evidence includes all 99 timings, output checksums, settings, tested-source hashes and the post-rebase plan comparison.
Validation
-count=1: vector, hashjoin, window, compile, plan and explain, using.agents/skills/mo-dev/scripts/mo-cgo-test -p=2 -count=1 -timeout=6m.-count=1.35bd4d9a4055and golangci-lint2.14.0, repository configuration and tests included. The reverse-dependency selector reaches 351/509 packages and selects the full graph:molint check -mod=readonly ./...;golangci-lint run --allow-serial-runners --timeout=20m --concurrency=4 -c .golangci.yml --new-from-rev=b9c06b27b0d7384ca31ce67edd43f764152d56d2 ./.... The final error-code regression oracle was also rechecked with vet/molint/golangci over./pkg/sql/plan ./pkg/tests/sqlintegration.Reviewed design revisions and invariants are kept separately: versioned design bundle. Historical rejected alternatives in those notes are not part of the source diff. Raw benchmark records and fixture statistics remain outside this PR.
Review follow-up
Rebased onto
b9c06b27b0. Grouped SUM pushdown now requires both complete join inputs to be deterministic and total, reusing the existing safety proof. This covers nested predicates/projections and dimension block filters before a partial aggregate can change hash-build demand.The new public-SQL regression uses ordinary ANALYZE/UPDATE-stale estimates: the parent returns Error 20203 where
aggPushDown=1returns empty; the fixed default returns empty too, and still reportsmoerr.ErrInvalidArgwhen the dimension is nonempty and the CAST is demanded. The test passes twice in one process (4.73s first scenario, 0.21s reused scenario); three focused rejection cells are red on the parent and green after the fix. Owning planner tests pass (99.069s).Both 103-statement TPC-DS and 22-query TPC-H fixtures pass. Q4/Q11 retain their performance plans and all 22 TPC-H reachable trees are unchanged. Q5 conservatively loses three newly introduced partial aggregates whose complete inputs cannot be proved total; its earlier small timing difference was not an established improvement. No new full99 runtime is claimed for this review-fix head.