Skip to content

fix(join): canonicalize DOUBLE signed zero across spill modes - #26450

Merged
XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
XuPeng-SH:agent/issue-26432-join-key-contract
Jul 30, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
XuPeng-SH:agent/issue-26432-join-key-contract

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Jul 30, 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:

Related to #26432. This is an incremental contract fix; it intentionally does not close the whole issue.

What this PR does / why we need it

Spill is not a separate equality domain. A join key that is equal under SQL must remain equivalent in every physical phase: resident hashmap lookup, initial spill partitioning, probe partitioning, and recursive re-spill.

This PR fixes one concrete violation of that invariant: SQL DOUBLE +0 = -0 was true in the scalar evaluator, while raw IEEE-754 bytes sent the two values to different hashmap keys or spill partitions.

The implementation defines signed-zero canonicalization once in keycodec and uses the same typed contract in all CN-local phases:

  • resident IntHashMap keys;
  • resident composite StrHashMap keys;
  • initial build-side spill partitioning;
  • probe-side partitioning and recursive re-spill.

Resident hashmaps dispatch once per vector and retain specialized row loops. Initial spill and re-spill call the same vector-level partition-hash implementation. Common non-DOUBLE loops are unchanged; there is no per-row interface dispatch or allocation.

Only the ephemeral hashmap/partition key is canonicalized. Input vectors, result values, and serialized spill batches retain their original values and format, so this introduces no spill-file or wire-format change.

Contract status

Each pending case first executes the real scalar = evaluator as the SQL oracle, then skips before asserting the known-incomplete physical behavior. The PR does not bless a current mismatch as expected output.

Type / values Scalar SQL = Resident Initial spill Re-spill Status
DOUBLE +0 / -0 TRUE match match match fixed and active
scaled FLOAT32(scale=2) 1.234 / 1.23 TRUE pending pending pending skipped with #26432 reason
JSON 1 / 1.0 TRUE pending pending pending skipped with #26432 reason
VECF32 +0 / -0 TRUE pending pending pending skipped with #26432 reason
same-payload DOUBLE NaN / NaN FALSE pending pending pending skipped with #26432 reason
DOUBLE NULL / NULL NULL no match no match no match active and correct

FLOAT64 is not currently eligible for the planner's remote-shuffle key path. This PR establishes the local resident/spill/re-spill invariant; remote typed-key equivalence and the remaining types stay tracked by #26432.

Regression design

These are deterministic operator-level tests, not large-data BVTs or embedded-cluster SQL. A low spill threshold selects the physical mode with 257 build rows plus one probe row, so runtime and memory remain small while the same batches traverse real join operators and spill files.

Operator Exact oracle checked in resident, initial-spill, and re-spill modes
HashJoin One -0 probe must return exactly the 129 distinct payloads belonging to the skewed +0/-0 build equivalence class—no loss, duplicate, wrong build row, or NULL payload.
DedupJoin The exact 257-row build multiset is preserved; only the signed-zero row receives probe capture 42, with exact capture NULL states.
RightDedupJoin The signed-zero pair returns ErrDuplicateEntry for contract_key, with zero output before and at the error.

The fixtures also prove that:

  • the signed-zero target starts in the second hashmap chunk (start > 0);
  • resident mode does not spill;
  • initial-spill mode increments depth 1 but not depth 2;
  • re-spill mode increments both depths, and the target bucket itself meets the re-spill threshold;
  • operator cleanup returns memory-budget usage, spill-disk usage, open spill FDs, and mpool bytes to zero.

A public hashmap-iterator contract matrix covers both IntHashMap and composite StrHashMap: flat vectors with a non-zero start, nullable vectors with and without actual NULLs, NULL filtering, NULL-as-key, constants, and constant NULLs. It asserts zValues, live group IDs, and GroupCount across insert and find operations.

Scope and performance

Microbenchmark setup: latest main versus this branch, identical harness, GOMAXPROCS=1, five samples/median, 8192 spill rows and 256 resident hashmap rows.

Path latest main ns/row this PR ns/row delta
spill INT64 4.824 4.861 +0.8%
spill DOUBLE 4.788 2.660 -44.4%
resident IntHashMap INT64 2.879 2.882 +0.1%
resident IntHashMap DOUBLE 2.941 2.814 -4.3%
resident StrHashMap composite INT64 7.869 7.942 +0.9%
resident StrHashMap composite DOUBLE 7.887 6.903 -12.5%

The common integer paths show no material regression. The DOUBLE specializations are faster than the previous raw-byte path while implementing SQL-equivalent hashing.

Test plan

All commands use the repository's deterministic CGo/libmo wrapper and were rerun after rebasing onto origin/main at 38ce3a774a.

Focused race stress, all pass with -race -count=100:

  • TestHashJoinKeyEqualityContract
  • TestDedupJoinDoubleSignedZeroContract
  • TestRightDedupJoinDoubleSignedZeroContract
  • TestHashMapsFloat64SignedZeroContract

Complete non-race and -race -count=1 suites both pass for all owning packages:

  • pkg/common/hashmap
  • pkg/sql/colexec/hashbuild
  • pkg/sql/colexec/spillutil
  • pkg/sql/colexec/hashjoin
  • pkg/sql/colexec/dedupjoin
  • pkg/sql/colexec/rightdedupjoin

go vet and go build -mod=readonly pass for the same six packages. The new hashmap state matrix directly exercises the FLOAT64 const, nullable, NULL, non-zero-start, and composite-key branches that the prior CI coverage review identified.

@XuPeng-SH
XuPeng-SH requested a review from aunjgr as a code owner July 30, 2026 07:58
@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 →

@XuPeng-SH
XuPeng-SH requested a review from VioletQwQ-0 July 30, 2026 07:58
@mergify mergify Bot added the kind/test-ci label Jul 30, 2026
@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Jul 30, 2026
@XuPeng-SH
XuPeng-SH requested a review from aptend July 30, 2026 08:00
@XuPeng-SH
XuPeng-SH marked this pull request as draft July 30, 2026 08:06
@XuPeng-SH XuPeng-SH changed the title test(join): characterize key equality across spill modes fix(join): canonicalize DOUBLE signed zero across spill modes Jul 30, 2026
@XuPeng-SH
XuPeng-SH marked this pull request as ready for review July 30, 2026 08:47
@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 →

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

Reviewed the signed-zero canonicalization across resident, initial-spill, and re-spill paths. Focused contract tests passed with -race -count=100, and all six owning packages passed with -race -count=1.

@VioletQwQ-0 VioletQwQ-0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed the current exact head d234f5a from multiple angles. I did not find a production-correctness blocker in the DOUBLE signed-zero canonicalization across resident, initial-spill, and re-spill paths.

The only remaining validation blocker is the required Matrixone Utils CI / Coverage check: PR coverage is 61.48%, below the 75% threshold. Please add focused coverage for the new FLOAT64 specialized branches, especially const, const-null, nullable/mixed-NULL, non-zero start, and const/short-vector hashing with a non-zero seed, then re-request review after the check is green.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Deep review of exact head 73a335ae27d590f0b7a0820f2877273593cf4a03: no blocking findings.

Signed-zero canonicalization is defined once in the typed key codec and is consistently consumed by resident IntHashMap/composite StrHashMap, initial spill partitioning, and recursive re-spill. It preserves NULL behavior, non-zero starts, const vectors, original payload values, and spill-file format. The intentionally incomplete equality cases remain explicitly skipped and tracked by #26432 rather than being blessed as expected behavior.

Fresh local evidence: hashmap, HashJoin, DedupJoin, and RightDedupJoin signed-zero contracts all pass under -race -count=3 across resident/initial-spill/re-spill modes, including cleanup counters; go build and go vet pass for all six affected packages. Final diff is clean, latest CI is green, and the PR remains MERGEABLE.

This branch was previously deployed

1 inactive 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 kind/refactor Code refactor kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants