Repository navigation
fix: canonicalize signed zero for distinct aggregates - #27434
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep-reviewed exact head f2aab03b9b79eb1575f1e16f1e3397954e4072c7 against base 344d852ac3288e391a3ae6be3e3c7108caf2b75d. The signed-zero equivalence is applied consistently to single-column, multi-column, preflight, merge, and serialized saved-argument keys, but the implementation introduces a blocking hot-path allocation defect.
[P1] Keep signed-zero DISTINCT key construction allocation-free and inside the aggregate allocation contract. canonicalDistinctArgumentBytes returns a slice of a local [4]byte or [8]byte. The function is not inlineable, and escape analysis reports both local zero arrays escaping to the Go heap. A deterministic testing.AllocsPerRun probe measured exactly 1,000 allocations for 1,000 calls.
This helper is called from preflightArgumentRowsEqual (twice per candidate comparison), preflight key construction, and the real batchFillArgs path. A signed-zero-heavy DISTINCT batch can therefore create a large number of row-frequency Go objects outside mpool, outside the allocation account, and after capacity preflight was supposed to make mutation safe. That reopens GC/OOM behavior the preflight/accounting work is designed to prevent.
Please write the canonical zero directly into the existing accounted key scratch, or reuse an immutable/non-escaping representation without exposing mutable shared bytes. Add an allocation regression that exercises both PreflightBatchFill and BatchFill, not only result correctness. The current signed-zero result regression passes, but it cannot detect this resource-bound violation.
The temporary allocation probe was removed afterward. git diff --check is clean and all current GitHub checks are complete with allowed conclusions.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep re-reviewed exact head db88a4b09c089bac387a73febdfed2c2f704f894 after my requested changes on f2aab03b9b79eb1575f1e16f1e3397954e4072c7. The hot-path allocation blocker is closed: signed zero is canonicalized directly in the existing mpool-accounted scratch key, while preflight duplicate comparison avoids temporary byte slices. The single-column and multi-column key layouts remain consistent across preflight, fill, merge, and serialized saved-argument paths; non-zero payloads and NULL behavior are unchanged.
Validation on the exact head: focused signed-zero/preflight tests at -count=10, focused race tests at -race -count=3, the full pkg/sql/colexec/aggexec package, and git diff --check all pass. The new allocation regression covers FLOAT32, FLOAT64, and multi-column keys in both PreflightBatchFill and BatchFill. No remaining blocking issue found.
Merge Queue Status
This pull request spent 51 minutes 43 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonThe merge conditions cannot be satisfied due to failing checks Failing checks:
HintYou may have to fix your CI before adding the pull request to the queue again. Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #27425
What this PR does / why we need it:
Fixes incorrect
COUNT(DISTINCT FLOAT/DOUBLE)results when signed zero values are combined with another aggregate.Before this change, the saved-argument DISTINCT path compared raw IEEE-754 bytes. As a result,
-0.0and+0.0were treated as different values when an ordinary aggregate was present, even though MatrixOne SQL equality and GROUP BY already treat them as equal.This change:
Validated locally with:
go test -mod=readonly -vet=off -count=1 -short -tags matrixone_test -p 1 ./pkg/sql/colexec/aggexecgo test -mod=readonly -vet=off -count=1 -short -race -tags matrixone_test -p 1 ./pkg/sql/colexec/aggexecgo vet -mod=readonly ./pkg/sql/colexec/aggexecgit diff --checkmake buildExpected result for the issue reproducer: