Skip to content

fix(sql): match MySQL empty-input ROLLUP results - #30169

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/30148-empty-rollup
Oct 15, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/30148-empty-rollup

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Please leave the issue open for the reporter to verify after merge.

What this PR does / why we need it:

Empty input currently produces an extra all-rolled row from GROUP BY ... WITH ROLLUP. Match MySQL's zero-row result for both ROLLUP spellings, including window, CTE, HAVING, UNION and write consumers. Explicit GROUPING SETS/CUBE and ordinary scalar aggregates retain their empty-input identities; a real NULL input row still contributes detail and total groups.

Add a hidden COUNT(*) > 0 HAVING guard to generated aggregate ROLLUP branches. Keep aggregate binding symmetric and preserve the guard through shared aggregation and the direct split path. SAMPLE already emits no rows on empty input, so its current SELECT block keeps the sampling path without an injected ordinary aggregate. Nested SAMPLE does not disable an outer ROLLUP guard, and explicit SAMPLE mixed with ordinary aggregates remains invalid.

Preserve primary-key detail aggregate elimination after shared-plan selection: a direct scan with a complete SQL-compatible unique key and all active grouping keys can project its sole canonical COUNT(*) as one. Remove only the proven constant count guard, allowing normal projection cleanup to discard an unused hidden count. Inactive subtotal branches, additional HAVING/aggregates, unsafe expressions and invalid metadata retain their aggregate and guard. LIMIT does not cross the grouping-set UNION.

Validation on macOS/arm64, Go 1.27.1:

  • Pre-fix public SQL reproduces the extra empty-input row, both SAMPLE spellings' error 1149, and the primary-key detail hash aggregate regression.
  • Full planner and DML packages pass on the final business patch before rebase. Counterexamples cover query-block SAMPLE scope, explicit mixed-aggregate errors, typed count/comparison identities, malformed grouping flags, extra HAVING, missing uniqueness and unsafe expressions. The rebase preserves every PR file blob and all four patches unchanged.
  • Formatting, scoped go vet and repository-pinned golangci-lint 2.14.0 incremental checks pass with 0 issues.
  • The changed function BVT passes normal comparison twice (34/34 each). The window BVT passes twice (230/230 each), including after rebase onto official main. Test database residue is zero after each run. SAMPLE row/percent, empty/nonempty and user HAVING controls pass through the real service.
  • With 1024 integer primary keys and shared computation disabled, one warm-up plus three measured EXPLAIN PHYPLAN ANALYZE rounds all report 16384B OperatorMemorySum, versus 152600B before this repair. The 131096B detail hash aggregate is eliminated; only the inactive total branch retains aggregation. This matches the review's baseline memory value, without imposing platform-specific byte assertions in BVT.
  • A fresh service build and focused string-IN ownership, allocation, collation and NULL tests validate the new official-main dependency after rebase.

Design and overall review use gpt-6-astra with reasoning effort medium. The pre-repair head's required CI is green; the updated head will receive fresh CI after push.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added kind/bug Something isn't working kind/test-ci labels Oct 14, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Oct 14, 2026
@iamlinjunhong
iamlinjunhong force-pushed the fix/30148-empty-rollup branch from ba00ed8 to a2c0d8e Compare October 14, 2026 18:07
@XuPeng-SH

XuPeng-SH commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 3754080ae6874a3a577008c1aebfe59662422ba7

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 3754080ae6874a3a577008c1aebfe59662422ba7

Assessment: approve

Reviewed the complete eleven-file delta and affected callers. Planner-owned COUNT guards distinguish empty ROLLUP input from real NULL rows while preserving SAMPLE and explicit grouping-set behavior. Shared/direct/split paths retain the guard, and established uniqueness proofs safely remove singleton detail aggregation. Both previous findings are closed; no actionable defect remains.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

Validation:

  • Full planner package passed: 15,445 named passes and two preexisting skips. All changed planner-test roots were selected.

  • Public SQL checks passed twice: 40 named passes covering empty input, SAMPLE, HAVING, windows, prepared reuse, CTAS/INSERT and forced remote grouping. Shared-fixture teardown completed.

  • Controlled merge-base production overlays passed the same SAMPLE and plan-cost probes twice. With 1,024 primary keys, candidate and base both reported 16,384B operator memory for ROLLUP and 8,232B for ordinary GROUP BY.

  • Preflight, native provenance verification (192 inputs and 62 artifacts), formatting, whitespace and clean-source checks passed. Tests used assigned caches and the supplied executor.

  • Frozen current-head statuses report successful required CI, Ubuntu UT, SCA, coverage and both BVT groups. Local commands, receipts, logs and overlay hashes are reconciled in /home/xupeng/.local/state/mo-bot/jobs/d7cef1a815eddf85d12b718e/attempt-1/evidence-audit.json; detailed analysis is in review-report.md.

Limitations:

  • Raw CI logs, author validation artifacts and the full linked issue body were not supplied. CI statuses were distinguished from independently audited local execution.

  • No fresh local full BVT, full DML package or race suite was run. Production changes introduce no new concurrency mechanism.

  • Performance comparison covers operator memory for the reported workload, not throughput or process peak memory. Additional HAVING/aggregates and unsafe expressions intentionally retain conservative aggregation.

@mergify mergify Bot added the queued label Oct 15, 2026
@mergify

mergify Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-15 12:29 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-15 13:54 UTC · at 8933d8c9c5aabf15b3ad0f3be6933f7254517f8c

This pull request spent 1 hour 24 minutes 21 seconds in the queue, with no time running CI.

Reason

Pull request #30169 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.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch had an error being deployed

1 failed deployment
ci — 8933d8c9 Deployed Oct 15, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants