Skip to content

fix(join): complete typed-key semantics for #26432 - #26738

Merged
XuPeng-SH merged 4 commits into
mainfrom
fix/join-key-semantics-26432
Aug 6, 2026
Merged

XuPeng-SH merged 4 commits into
mainfrom
fix/join-key-semantics-26432

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Aug 5, 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 #26432

What this PR does / why we need it:

Completes the three remaining typed-key equality semantics in #26432, consistently for resident maps and spill/re-spill rebuilds, without introducing a broad codec framework.

  • Canonicalizes exact JSON numeric forms (1, 1.0, 1e0) recursively and normalizes VECF32 signed-zero elements.
  • Makes FLOAT32/FLOAT64 NaNs non-matching only for join maps, preserves MARK join FALSE versus NULL semantics, and persists this key-domain policy through map serialization.
  • Adds HashJoin, DedupJoin, and RightDedupJoin coverage for resident, initial-spill, and re-spill modes, serialized maps, and repeated NaN probes.

Validation:

  • The newly enabled regressions fail on the pre-fix main baseline.
  • .agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/common/hashmap/keycodec ./pkg/common/hashmap ./pkg/sql/colexec/hashbuild ./pkg/sql/colexec/hashjoin ./pkg/sql/colexec/dedupjoin ./pkg/sql/colexec/rightdedupjoin -count=1
  • Built and vetted all six affected packages with the controlled CGo environment.
  • Repeated single-core HashBuild benchmarks: INT64, inline VARCHAR, and 128-byte VARCHAR median deltas were +0.9%, +0.8%, and +1.6%; allocations unchanged.

Self-review:

  • No new goroutines, locks, channels, waits, or lifecycle ownership changes; race-stress gate is not applicable.
  • Reviewed resident and serialized-map/rebuild closures, NULL/MARK behavior, key-size bounds, and common non-float/non-canonical hot paths.

Complete the remaining #26432 join-key semantics across resident and spill paths: normalize exact JSON numeric forms and VECF32 signed zero, and make FLOAT NaNs non-matching in join maps. Cover HashJoin, DedupJoin, RightDedupJoin, MARK joins, and serialized maps.
@XuPeng-SH
XuPeng-SH requested a review from aunjgr as a code owner August 5, 2026 18:52
@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

Copy link
Copy Markdown
Contributor Author

Self-review conclusion at ce47cd1: REQUEST CHANGES.\n\nGitHub does not allow the PR author to submit a formal REQUEST_CHANGES review on the same PR, so this comment records the decision and its blockers.\n\n1. JSON key equality is still not closed over the actual SQL numeric domain. Scalar comparison treats TpCodeDecimal as numeric and compares it exactly with INT64, UINT64, and FLOAT64, but canonicalByteJSONSize and appendCanonicalJSONNumeric only handle the latter three. CAST(decimal AS JSON) is a normal producer of TpCodeDecimal, so scalar equality can be TRUE while resident and spill keys differ. The same hole exists recursively in arrays and objects.\n\n2. VECF32 semantics remain representation-dependent. For inline short vectors, equalFn takes compareVarlenaEqual and compares raw bytes, so +0 and -0 yield FALSE; AppendCanonicalVecF32 canonicalizes every length, so the hash join matches them. A direct resident counterexample produced 129 matches where the scalar oracle expected none. The existing HashJoin oracle uses an 8-element vector, which forces the area path; the new short-vector DedupJoin and RightDedupJoin tests are not oracle-backed and therefore hide this mismatch.\n\n3. More fundamentally, current JSON INT/UINT versus FLOAT comparison uses a 1e-8 tolerance while FLOAT versus FLOAT is exact. Equality is non-transitive: 1 equals 1.000000001, and 1 equals 1.0, but 1.000000001 does not equal 1.0. No hash canonicalization can exactly represent a non-equivalence relation.\n\nPlease first define one transitive JSON numeric equality domain, use it in both scalar comparison and the typed-key codec including TpCodeDecimal recursively, and make inline/area VECF32 scalar comparison identical. Then add nested-loop differential cases for decimal root/nested JSON, near-integer JSON, and both inline and area VECF32.\n\nI pushed test-only commit ce47cd1. It covers JSON numeric boundaries, const/flat/null/start-offset/grouping shapes, resident canonical varlena keys, and spill partition hashing. Replaying the official coverage parser against the prior CI profiles plus these tests gives 199/226 changed blocks, 88.05%, above the 75% gate. This coverage improvement does not resolve the semantic blockers above.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Systematic fix is now pushed in f80f701. Self-review conclusion: APPROVE.

The previous blockers are closed at the equality-contract layer, not patched per operator:

  • JSON numeric equality is now a transitive exact order. INT/UINT/FLOAT keep allocation-free fast paths; DECIMAL uses a normalized sign/coefficient/arbitrary-precision exponent key, so values such as 1e2147483647 remain O(input length) instead of expanding by magnitude. The same representation drives scalar comparison and resident/spill keys recursively.
  • The audit found and fixed two additional JSON shapes: empty-array length comparison and legacy Base64 BLOB/BIT versus raw binary representations. Canonical keys now match every supported scalar-equality representation, including malformed-value fallbacks.
  • FLOAT32/FLOAT64/BF16/FLOAT16 arrays now use element equality independent of inline/area storage. Signed zero is canonicalized in resident and spill keys; arrays containing NaN use the existing non-matching join path because their equality is non-reflexive.
  • StrHashMap now backfills the varlena length after encoding, removing a redundant JSON canonicalization pass.

Validation:

  • Real scalar = oracle versus HashJoin in resident, initial-spill, and re-spill modes for root/nested DECIMAL JSON, near integers, binary JSON, array length, inline/area signed zero, and NaN across all floating array types.
  • Full tests passed for bytejson, keycodec, hashmap, function, hashbuild, hashjoin, dedupjoin, and rightdedupjoin.
  • Race tests passed for bytejson, keycodec, and hashmap; exact package list/build/vet passed.
  • Apple M4 microbenchmarks: common numeric compare 12.85 ns/op, 0 alloc; common canonical append 2.79 ns/op, 0 alloc. Extreme DECIMAL compare/encode remains about 0.2-0.3 us and bounded by input text size.

I did not wait for the restarted CI.

@aunjgr aunjgr 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 exact head f80f701. I checked the typed-key equality changes across resident maps, serialized spill/re-spill maps, JSON numeric canonicalization, signed-zero vector keys, NaN rejection, and NULL/MARK semantics. The key-size/encoding paths remain aligned and I found no blocking correctness or lifecycle issue. All required checks are green.

@mergify

mergify Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@XuPeng-SH
XuPeng-SH merged commit ffc1603 into main Aug 6, 2026
31 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/join-key-semantics-26432 branch August 6, 2026 05:29
XuPeng-SH added a commit that referenced this pull request Aug 11, 2026
## What changed

- accept non-empty constant vectors as logical broadcasts in spill and
re-spill row-shape validation
- project constant varlena recovery memory from logical row ranges
instead of physical vector length
- keep nil, empty constants with non-empty input, and ordinary short
vectors fail-closed
- add prepared-parameter initial-spill, re-spill materialization,
recovery-offset, and shape-control regressions

## Why

The typed-key work in #26738 made resident and spill hashing share one
codec. After #26836, resident hash maps also accept a
physical-length-one constant vector over an arbitrary logical row range,
while spill validation still required `vec.Length() == rows`. A prepared
parameter therefore worked in resident mode but failed initial spill or
re-spill with `ErrHashBuildBudgetInvalid`.

This change aligns the existing spill boundary with the vector broadcast
contract. It does not change typed-key encoding or add a new
abstraction.

## Validation

The new focused tests failed on the unfixed `main` with `invalid hash
build budget` and pass after the change.

- `go list`, `go build`, and `go vet` for `keycodec`, `hashbuild`, and
`spillutil`
- full tests for all three owning packages
- focused HashJoin, DedupJoin, and RightDedupJoin typed-key contract
suites across resident, initial spill, and re-spill modes

## Performance

The ordinary spill path adds one inlinable `IsConst` branch per vector
per batch. There are no new per-row operations, allocations, copies,
logs, locks, or retained state.

Closes #26432

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…xorigin#26738)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#26432

## What this PR does / why we need it:

Completes the three remaining typed-key equality semantics in matrixorigin#26432,
consistently for resident maps and spill/re-spill rebuilds, without
introducing a broad codec framework.

- Canonicalizes exact JSON numeric forms (`1`, `1.0`, `1e0`) recursively
and normalizes VECF32 signed-zero elements.
- Makes FLOAT32/FLOAT64 NaNs non-matching only for join maps, preserves
MARK join FALSE versus NULL semantics, and persists this key-domain
policy through map serialization.
- Adds HashJoin, DedupJoin, and RightDedupJoin coverage for resident,
initial-spill, and re-spill modes, serialized maps, and repeated NaN
probes.

Validation:

- [x] The newly enabled regressions fail on the pre-fix main baseline.
- [x] `.agents/skills/mo-dev/scripts/mo-cgo-test
./pkg/common/hashmap/keycodec ./pkg/common/hashmap
./pkg/sql/colexec/hashbuild ./pkg/sql/colexec/hashjoin
./pkg/sql/colexec/dedupjoin ./pkg/sql/colexec/rightdedupjoin -count=1`
- [x] Built and vetted all six affected packages with the controlled CGo
environment.
- [x] Repeated single-core HashBuild benchmarks: INT64, inline VARCHAR,
and 128-byte VARCHAR median deltas were +0.9%, +0.8%, and +1.6%;
allocations unchanged.

Self-review:

- No new goroutines, locks, channels, waits, or lifecycle ownership
changes; race-stress gate is not applicable.
- Reviewed resident and serialized-map/rebuild closures, NULL/MARK
behavior, key-size bounds, and common non-float/non-canonical hot paths.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…6938)

## What changed

- accept non-empty constant vectors as logical broadcasts in spill and
re-spill row-shape validation
- project constant varlena recovery memory from logical row ranges
instead of physical vector length
- keep nil, empty constants with non-empty input, and ordinary short
vectors fail-closed
- add prepared-parameter initial-spill, re-spill materialization,
recovery-offset, and shape-control regressions

## Why

The typed-key work in matrixorigin#26738 made resident and spill hashing share one
codec. After matrixorigin#26836, resident hash maps also accept a
physical-length-one constant vector over an arbitrary logical row range,
while spill validation still required `vec.Length() == rows`. A prepared
parameter therefore worked in resident mode but failed initial spill or
re-spill with `ErrHashBuildBudgetInvalid`.

This change aligns the existing spill boundary with the vector broadcast
contract. It does not change typed-key encoding or add a new
abstraction.

## Validation

The new focused tests failed on the unfixed `main` with `invalid hash
build budget` and pass after the change.

- `go list`, `go build`, and `go vet` for `keycodec`, `hashbuild`, and
`spillutil`
- full tests for all three owning packages
- focused HashJoin, DedupJoin, and RightDedupJoin typed-key contract
suites across resident, initial spill, and re-spill modes

## Performance

The ordinary spill path adds one inlinable `IsConst` branch per vector
per batch. There are no new per-row operations, allocations, copies,
logs, locks, or retained state.

Closes matrixorigin#26432

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…xorigin#26738)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#26432

## What this PR does / why we need it:

Completes the three remaining typed-key equality semantics in matrixorigin#26432,
consistently for resident maps and spill/re-spill rebuilds, without
introducing a broad codec framework.

- Canonicalizes exact JSON numeric forms (`1`, `1.0`, `1e0`) recursively
and normalizes VECF32 signed-zero elements.
- Makes FLOAT32/FLOAT64 NaNs non-matching only for join maps, preserves
MARK join FALSE versus NULL semantics, and persists this key-domain
policy through map serialization.
- Adds HashJoin, DedupJoin, and RightDedupJoin coverage for resident,
initial-spill, and re-spill modes, serialized maps, and repeated NaN
probes.

Validation:

- [x] The newly enabled regressions fail on the pre-fix main baseline.
- [x] `.agents/skills/mo-dev/scripts/mo-cgo-test
./pkg/common/hashmap/keycodec ./pkg/common/hashmap
./pkg/sql/colexec/hashbuild ./pkg/sql/colexec/hashjoin
./pkg/sql/colexec/dedupjoin ./pkg/sql/colexec/rightdedupjoin -count=1`
- [x] Built and vetted all six affected packages with the controlled CGo
environment.
- [x] Repeated single-core HashBuild benchmarks: INT64, inline VARCHAR,
and 128-byte VARCHAR median deltas were +0.9%, +0.8%, and +1.6%;
allocations unchanged.

Self-review:

- No new goroutines, locks, channels, waits, or lifecycle ownership
changes; race-stress gate is not applicable.
- Reviewed resident and serialized-map/rebuild closures, NULL/MARK
behavior, key-size bounds, and common non-float/non-canonical hot paths.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…6938)

## What changed

- accept non-empty constant vectors as logical broadcasts in spill and
re-spill row-shape validation
- project constant varlena recovery memory from logical row ranges
instead of physical vector length
- keep nil, empty constants with non-empty input, and ordinary short
vectors fail-closed
- add prepared-parameter initial-spill, re-spill materialization,
recovery-offset, and shape-control regressions

## Why

The typed-key work in matrixorigin#26738 made resident and spill hashing share one
codec. After matrixorigin#26836, resident hash maps also accept a
physical-length-one constant vector over an arbitrary logical row range,
while spill validation still required `vec.Length() == rows`. A prepared
parameter therefore worked in resident mode but failed initial spill or
re-spill with `ErrHashBuildBudgetInvalid`.

This change aligns the existing spill boundary with the vector broadcast
contract. It does not change typed-key encoding or add a new
abstraction.

## Validation

The new focused tests failed on the unfixed `main` with `invalid hash
build budget` and pass after the change.

- `go list`, `go build`, and `go vet` for `keycodec`, `hashbuild`, and
`spillutil`
- full tests for all three owning packages
- focused HashJoin, DedupJoin, and RightDedupJoin typed-key contract
suites across resident, initial spill, and re-spill modes

## Performance

The ordinary spill path adds one inlinable `IsConst` branch per vector
per batch. There are no new per-row operations, allocations, copies,
logs, locks, or retained state.

Closes matrixorigin#26432

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…xorigin#26738)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#26432

## What this PR does / why we need it:

Completes the three remaining typed-key equality semantics in matrixorigin#26432,
consistently for resident maps and spill/re-spill rebuilds, without
introducing a broad codec framework.

- Canonicalizes exact JSON numeric forms (`1`, `1.0`, `1e0`) recursively
and normalizes VECF32 signed-zero elements.
- Makes FLOAT32/FLOAT64 NaNs non-matching only for join maps, preserves
MARK join FALSE versus NULL semantics, and persists this key-domain
policy through map serialization.
- Adds HashJoin, DedupJoin, and RightDedupJoin coverage for resident,
initial-spill, and re-spill modes, serialized maps, and repeated NaN
probes.

Validation:

- [x] The newly enabled regressions fail on the pre-fix main baseline.
- [x] `.agents/skills/mo-dev/scripts/mo-cgo-test
./pkg/common/hashmap/keycodec ./pkg/common/hashmap
./pkg/sql/colexec/hashbuild ./pkg/sql/colexec/hashjoin
./pkg/sql/colexec/dedupjoin ./pkg/sql/colexec/rightdedupjoin -count=1`
- [x] Built and vetted all six affected packages with the controlled CGo
environment.
- [x] Repeated single-core HashBuild benchmarks: INT64, inline VARCHAR,
and 128-byte VARCHAR median deltas were +0.9%, +0.8%, and +1.6%;
allocations unchanged.

Self-review:

- No new goroutines, locks, channels, waits, or lifecycle ownership
changes; race-stress gate is not applicable.
- Reviewed resident and serialized-map/rebuild closures, NULL/MARK
behavior, key-size bounds, and common non-float/non-canonical hot paths.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…6938)

## What changed

- accept non-empty constant vectors as logical broadcasts in spill and
re-spill row-shape validation
- project constant varlena recovery memory from logical row ranges
instead of physical vector length
- keep nil, empty constants with non-empty input, and ordinary short
vectors fail-closed
- add prepared-parameter initial-spill, re-spill materialization,
recovery-offset, and shape-control regressions

## Why

The typed-key work in matrixorigin#26738 made resident and spill hashing share one
codec. After matrixorigin#26836, resident hash maps also accept a
physical-length-one constant vector over an arbitrary logical row range,
while spill validation still required `vec.Length() == rows`. A prepared
parameter therefore worked in resident mode but failed initial spill or
re-spill with `ErrHashBuildBudgetInvalid`.

This change aligns the existing spill boundary with the vector broadcast
contract. It does not change typed-key encoding or add a new
abstraction.

## Validation

The new focused tests failed on the unfixed `main` with `invalid hash
build budget` and pass after the change.

- `go list`, `go build`, and `go vet` for `keycodec`, `hashbuild`, and
`spillutil`
- full tests for all three owning packages
- focused HashJoin, DedupJoin, and RightDedupJoin typed-key contract
suites across resident, initial spill, and re-spill modes

## Performance

The ordinary spill path adds one inlinable `IsConst` branch per vector
per batch. There are no new per-row operations, allocations, copies,
logs, locks, or retained state.

Closes matrixorigin#26432

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

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/test-ci size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: unify join typed-key canonicalization across resident and spill paths

3 participants