Skip to content

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

Merged
XuPeng-SH merged 2 commits into
matrixorigin:4.1.6-hotfixfrom
ck89119:issue-32789-4.1.6-hotfix
Nov 16, 2026
Merged

XuPeng-SH merged 2 commits 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 columns at the final DISTINCT boundary through the existing generic VALUES scalar. Copy the stored values, exact types and NULL bits, and clear only the result's grouping bitmap without mutating the input.
  • Use the existing batch-copy path without allocating an identity selection array. Do not use CAST or COALESCE for materialization: even a same-type CAST can round or revalidate already-stored values.
  • Keep the original selected expressions for ORDER BY dependency resolution, and preserve upstream grouping provenance and explicitly selected GROUPING() values.
  • Add optimized-plan, expression/hash and vector-ownership unit tests, plus ENUM/SET, wider-key, multi-column, FLOAT and GEOMETRY SELECT/CTAS regressions. Generate and verify expected results with mo-tester.

Validation on macOS arm64 with Go 1.26.4:

  • Confirmed the original ENUM/SET 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).
  • Reproduced the review counterexamples against the original PR head: FLOAT(8,2) stores the rounded value 1000000 but the added CAST rejects it; lowering max_points_in_geometry rejects stored four-point geometries during DISTINCT/CTAS. Both now succeed without revalidation. Execution tests also cover GEOMETRY32.
  • Grouping/VALUES-focused tests and the complete pkg/sql/plan and pkg/sql/plan/function test packages pass through the CGo test wrapper.
  • Incremental gofmt, vet and branch-matched golangci-lint v2.6.2 pass. Changed-statement coverage blocks for the review fix are 100% in the planner and 85.7% in the copy function.
  • grouping_ctas.sql passes twice on the same isolated single-CN instance: 391/391 statements each time. Database/table teardown and geometry-session-setting restoration checks pass.
  • Existing func_geometry.test: 763/763 pass. Existing on_duplicate_key.sql: 139 pass, 8 existing skips, no failures.

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

@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 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@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.

Approved after reviewing b51540a against 4.1.6-hotfix on 10.222.1.57.

The final DISTINCT boundary materializes nullable selected columns without mutating upstream grouping provenance or converting stored values. I checked the shared VALUES caller, vector reuse and NULL/grouping ownership, ORDER BY resolution, and the FLOAT and GEOMETRY revalidation counterexamples. On 57, the focused planner and function tests passed, including the typed keys, constant/NULL/empty vectors, repeated evaluation, and existing VALUES tests. The public SQL/CTAS coverage and the author's two normal BVT runs provide complementary evidence. There were no unresolved human review comments at review time.

This adds a vector copy for nullable selected keys at this boundary; no production-scale performance claim is made. CI currently reports failed UT/SCA jobs with incomplete step records; this approval does not assert those checks passed or identify their cause.

This branch was previously deployed

1 inactive deployment
ci — b51540a8 Deployed Nov 16, 2026 by ck89119
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.

3 participants