Skip to content

[4.1.6-hotfix] fix(plan): deduplicate grouping NULL values in DISTINCT - #32802

Draft
ck89119 wants to merge 1 commit into
matrixorigin:4.1.6-hotfixfrom
ck89119:issue-32789-4.1.6-hotfix
Draft

ck89119 wants to merge 1 commit into
matrixorigin:4.1.6-hotfixfrom
ck89119:issue-32789-4.1.6-hotfix

Conversation

@ck89119

@ck89119 ck89119 commented Nov 16, 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:

Fixes #32789

What this PR does / why we need it:

Global DISTINCT over grouping-extension results can hash actual NULL and subtotal NULL as different values because transported columns still carry the internal grouping bitmap. This leaves duplicate visible NULL rows in ENUM/SET SELECT results and CTAS readback.

  • Materialize nullable selected column values at the final DISTINCT boundary using an explicit same-type CAST; use the existing single-argument COALESCE for types without an identity CAST, such as UUID.
  • Keep the original selected expressions for ORDER BY dependency resolution, and preserve upstream grouping provenance and explicitly selected GROUPING() values.
  • Add optimized-plan and expression/hash unit tests, plus ENUM/SET, wider-key, multi-column and CTAS regression cases. Generate and verify the expected results with mo-tester.

Validation on macOS arm64 with Go 1.26.4:

  • Confirmed the original SELECT/CTAS reproduction fails before the fix and passes afterward: ENUM row counts change from 4/2/2 to 3/2/1, and SET from 5/3/2 to 4/3/1 (total/non-NULL/NULL).
  • Grouping-focused unit tests and the complete pkg/sql/plan test package pass through the CGo test wrapper.
  • Incremental gofmt, vet and branch-matched golangci-lint v2.6.2 pass, including the newly added test file.
  • Changed-statement coverage blocks: 94.1%.
  • grouping_ctas.sql passes twice on the same isolated single-CN instance: 373/373 statements each time. Database/table teardown checks pass.

No protocol, catalog or persisted-format changes. Multi-CN and repository-wide SCA were not run.

This branch is being deployed

1 in progress deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants