Repository navigation
fix(sql): preserve MIN/MAX DISTINCT input values - #32372
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? |
|
mo-bot review · Commit: Review linked issue or PR description changed before publication; a fresh contextual review is queued. |
|
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: d2f2a658bed6df3c9f6cf378dccd598021c165a1
Assessment: approve
The guard makes argument normalization follow the existing retained DISTINCT flag, restoring ordinary MIN/MAX value semantics while preserving true DISTINCT paths. It reuses existing behavior without adding mechanisms; no actionable findings remain.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
Validation:
-
Reviewed all four changed files, affected owners and consumers, SQL value and evaluation-count oracles, both linked issues and all three discussion items.
-
Isolation preflight passed: checks/1794151892343461269-3.json and preflight.log.
-
Static audit passed: frozen head, clean source, patch content, git diff --check, gofmt, 36 SQL/result statement echoes and complete discussion coverage; checks/1794152121964531005-3.json and static-audit-final.log.
-
Author reports planner normal/race tests and repeated 1CN/2CN SQL validation; these are reported evidence, not independent local passes.
Limitations:
-
Focused Go tests could not start: installed Go 1.26.6 cannot satisfy required Go 1.27.1. Automatic toolchain recovery timed out after 60 seconds; receipts and logs are retained in validation-ledger.json.
-
No local SQL cluster execution; author execution logs were not supplied and CI remains partly pending.
## What type of PR is this? - [x] Test and CI ## Which issue(s) this PR fixes: Refs #32373, #32369, #32372 and #32368. ## What this PR does / why we need it: Add 4.2 regression coverage for the aggregate input contracts addressed by the two main-branch PRs. Their production patches do not apply to the current 4.2 implementation: - MIN/MAX discard DISTINCT without adding the main branch's DISTINCT-only PAD SPACE normalization. The SQL case checks exact returned bytes, NULL/empty inputs, and prepared execution; a planner test checks that DISTINCT preserves the bound input. - Group evaluates a batch once and returns build/evaluation errors; it spills after a complete batch rather than retrying a partially processed batch. Tests inject capacity errors during evaluation and after one completed hash chunk, and exercise ordinary spill/reload with exact results and evaluation counts. The errors are synthetic; this branch does not have the upstream capacity-recovery path. There are no production-code or query hot-path changes. Validation on 4.2-dev base `0351bc89d7478ccd908fbc7b084ff0dd71a0ee80` (Go 1.26.4, Linux/amd64): - Full normal tests for `pkg/sql/plan` and `pkg/sql/colexec/group`; focused new tests in normal and race modes passed. - Local single-CN SQL: exact trailing-space bytes and session-mode restoration verified. The 19-statement BVT passed in normal comparison and with CI flags on the same instance; database teardown was checked after each run. - Incremental gofmt, go vet, and golangci-lint v2.6.2 passed for the two changed Go packages. Pinned molint emitted three pre-existing `checkrecover` diagnostics, identical on a clean copy of the base; it reported no new diagnostics. - The BVT took approximately 0.07 seconds per local comparison run. CI remains pending.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #32373
Discovered while investigating #32060; this PR addresses a separate correctness defect.
What this PR does / why we need it:
The binder already discards
DISTINCTforMINandMAX, because duplicate elimination cannot change their result. It nevertheless applies DISTINCT-only PAD SPACE normalization to the argument. Forc CHAR(8) = NULLandv VARCHAR(8) = 'a ',HEX(MAX(COALESCE(c, v)))returns6120, butHEX(MAX(DISTINCT COALESCE(c, v)))returns61.Only apply that DISTINCT-only normalization when the bound aggregate actually retains the DISTINCT flag. The existing ordinary MIN/MAX input and comparison path is then shared by their DISTINCT forms; aggregates that still retain DISTINCT keep their existing normalization.
Validation:
pkg/sql/plannormal and race tests passed. After a test-local preallocation adjustment, the changed tests passed normal and race again. Incremental gofmt, vet, molint, and golangci-lint passed forpkg/sql/planandpkg/sql/compile.The performance report in #32060 and other PAD SPACE grouping and DISTINCT-aggregate equality defects found during that investigation remain outside the scope of this change. CI is pending.