Skip to content

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

Description

@XuPeng-SH

Context

Follow-up from #26408 and #26412. The ownership/lifecycle fixes in #26412 intentionally do not redesign join-key encoding.

Problem

Resident hash joins, initial spill partitioning, and re-spill must use one SQL-equality canonicalization contract. Today the paths can consistently disagree with SQL equality or with a nested-loop oracle for values such as:

  • DOUBLE +0 versus -0;
  • NaN values;
  • JSON numeric forms such as 1 versus 1.0;
  • scaled floating-point values;
  • long VECF32 values containing +0/-0.

Fixing isolated hash functions per type is insufficient: encoding, hashing, equality, partitioning, and rebuild must share the same typed-key contract.

Proposed direction

  • Define one typed-key codec/canonicalization interface used by resident build/probe, initial spill, re-spill, and remote execution.
  • Specify NULL, NaN, signed-zero, JSON numeric, vector, decimal/scale, and collation behavior explicitly.
  • Version any persisted spill representation affected by the codec.
  • Use nested-loop execution as the semantic oracle rather than comparing two hash implementations.

Acceptance criteria

  • Resident, initial-spill, and re-spill joins return identical rows for the same inputs.
  • Differential tests compare hash join variants against a nested-loop oracle for all supported key types and the edge cases above.
  • Tests cover HashJoin, DedupJoin, and RightDedupJoin, including multi-column and NULL-containing keys.
  • Remote/local execution and mixed spill rounds use the same codec version.
  • Benchmarks show no material regression for common integer/string join keys.

Related: #26408, #26412.

Activity

  1. added
    kind/bug
    on Jul 30, 2026
  2. XuPeng-SH commented on Aug 1, 2026

    @XuPeng-SH
    ContributorAuthor

    Roadmap classification: #26563. Keep this as an independent typed-key correctness change. It must prove identical canonical equality across resident and spill paths, but must not be bundled with planner key selection (#26556), threshold units (#26434), or spill-storage redesign.

  3. Ariznawlll commented on Aug 10, 2026

    @Ariznawlll
    Collaborator

    最新 main 补充探索(resident path)

    • commit:00cb7ef3169a6c61f358774ac5c690a405ac162d
    • 部署:本地 standalone,单 CN/TN/log service
    • 日期:2026-08-11

    本轮只验证 resident 小数据路径,不作为该 issue 的最终 QA 结论,也不覆盖 spill/re-spill、remote 或多 CN。

    DOUBLE 特殊键

    表内包含 NULL、-Inf、-1、-0、+0、1、+Inf、两个 NaN。

    • a.f=b.f hash join:8 对。
    • 非等值 oracle a.f<=b.f AND a.f>=b.f:同样 8 对,明细完全一致。
    • 两条路径均让 -0/+0 形成 4 个组合,并排除 NaN。
    • <=> hash join:9 对;在 oracle 中显式加入双 NULL 后也是 9 对。

    JSON 特殊键

    覆盖 JSON 数字 1/1.0/1.00、对象 {"a":1,"b":2}/{"b":2,"a":1}、数组和 NULL。

    • equality hash join:14 对。
    • <= AND >= oracle:14 对,明细完全一致。
    • 三种数字形式互相匹配,对象键顺序不同也互相匹配。

    VECF32 特殊键

    覆盖 [0,-0,1,2] 与 [-0,0,1,2]、不同尾元素、不同首元素和 NULL。

    • equality hash join:6 对。
    • <= AND >= oracle:6 对,明细完全一致。
    • 两个 signed-zero 向量形成 4 个组合。

    另外在 Sort/Top 路径发现了独立的 NaN 非严格序问题,已单独提交 #26941;它不替代本 issue 的 join typed-key 验收。后续这里仍需按 acceptance criteria 补 resident/spill/re-spill、Hash/Dedup/RightDedup、multi-column、remote/multi-CN 的同一数据集差分。

  4. added a commit that references this issue on Aug 11, 2026
    d01c859
  5. Ariznawlll commented on Aug 11, 2026

    @Ariznawlll
    Collaborator

    最新 main 补充探索:双 CN Remote Hash Join

    • commit:b84a6627060539173f9ee243e8523792a3ad2200
    • 拓扑:官方 etc/launch-multi-cn/,单 TN/LogService、双 CN(127.0.0.1:16001 / :16002)
    • 范围:普通非分区表;分别通过 CN1 写入、CN1/CN2 查询

    SHOW BACKEND SERVERS 显示两个 CN 都为 Working。两类语句的 EXPLAIN PHYPLAN 都是 Magic: Remote 的 probe Scope + Remote hash-build PreScope,实际走 Hash Join,不是 nested-loop 对照路径。

    DOUBLE:signed-zero / NaN / infinity

    两侧各 4,096 行:-0/+0 各 512,NaN 512,另外 -1/1/+Inf/-Inf/42 各 512。

    • CN1:COUNT(*) = 2,359,296
    • CN2:COUNT(*) = 2,359,296
    • 结果等于 (512+512)^2 + 5*512^2,即 -0/+0 交叉匹配、5 个普通或无穷值桶分别匹配,NaN 不匹配。

    JSON:数值表示 / 对象键序 / 数组 / NULL

    两侧各 4,096 行,包含 1/1.0/1.00,{"a":1,"b":2}/{"b":2,"a":1},两个不同数组和 NULL。

    • CN1、CN2 均为 COUNT(*) = 3,932,160、SUM(probe.id) = 8,052,539,392
    • 数字三种表示与对象两种键序均按 SQL 相等性合并;两个数组仅分别自匹配;NULL 不匹配。

    VECF32:signed-zero 与 NaN

    • [0,0,1] 与 [-0,0,1]:两侧各 2,048 行的 Join 在 CN1/CN2 都为 1,310,720,等于 (512+512)^2 + 512^2。
    • 加入 [1,NaN,3] 和 NULL 后:两侧各 1,024 行的 Join 在 CN1/CN2 都为 262,144 = (256+256)^2;NaN 和 NULL 均没有形成匹配。

    spill/re-spill 证据

    本轮黑盒 SQL 即使设置 join_spill_mem=1,EXPLAIN ANALYZE 仍未输出 SpillRows/SpillSize;因此不把该 SQL 标记为实际 spill/re-spill 覆盖。

    但 latest main 的定向合同测试已在本机通过:

    go test ./pkg/sql/colexec/hashjoin ./pkg/sql/colexec/dedupjoin ./pkg/sql/colexec/rightdedupjoin \\
      -run 'Test(HashJoinKeyEqualityContract|DedupJoin(DoubleSignedZeroContract|RemainingKeyContracts)|RightDedupJoin(DoubleSignedZeroContract|RemainingKeyContracts))$' -count=1
    
    ok hashjoin
    ok dedupjoin
    ok rightdedupjoin
    

    该组测试强制 resident、initial-spill、re-spill 三模式,覆盖 HashJoin、DedupJoin、RightDedupJoin 的 JSON numeric、VECF32 signed-zero/NaN、DOUBLE signed-zero/NaN 等 typed-key 合同。

    当前结论

    双 CN Remote Hash Join 的上述特殊键黑盒结果正确;resident/spill/re-spill 的三种 join 算子合同测试也通过。仍缺“黑盒 SQL 明确观测到 SpillRows/SpillSize 的特殊键数据集”这一项,故本 comment 不是对本 issue acceptance criteria 的最终 QA 关闭结论。

  6. 4 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions