Skip to content

fix(join): hash and compare LIST key cells by value - #1376

Merged
singaraiona merged 4 commits into
devfrom
fix/1373-join-list-keys
Nov 22, 2026
Merged

singaraiona merged 4 commits into
devfrom
fix/1373-join-list-keys

Conversation

@singaraiona

@singaraiona singaraiona commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

A join on a LIST key column matched the wrong rows (#1373):

(set A (table [K v] (list (list [7 7] [-0.0] [1] [0.0]) [10 20 30 40])))
(set B (table [K w] (list (list [7 7] [0.0] [2]) [100 200 300])))
(inner-join [K] A B)   ;; dev: K [[1] [1]], v [30 30], w [300 100]

A's [1] met B's [2] and [7 7], and [7 7] met nothing.

Cause. hash_row_keys and join_keys_eq (src/ops/join.c) read every key type other than STR, GUID and F64 through read_col_i64. For a LIST column that is the cell's pointer, so rows hashed and compared by address.

Fix.

  • Hash: a LIST key cell hashes with ray_key_hash. Its span bits come from ray_key_spans over both sides' LIST key columns, computed once per join (join_key_flags) and carried beside the nullfree proof in the key flags every hash and compare already receives. A TIMESPAN-free LIST join hashes exactly; one holding a TIMESPAN cell uses the bits atom_eq needs.
  • Compare: it compares with atom_eq, the equality group, distinct and in use. A LIST key meets only a LIST key, as STR meets only STR.

Every hash-join route goes through these two functions, so inner, left, anti and semi joins all follow, on the parallel radix path too. [7 7] meets [7 7], [0.5] meets [0.5], a TIMESPAN cell meets an equal I64/F64 cell, and atoms, nested lists and numeric cells meet by value. Full, asof and window joins already refuse LIST keys (domain/nyi), so they never compared pointers.

Timing. 20k-row joins on table, dict and fractional-float LIST cells take 3–8 ms; hashing with every span bit took 10–25 s. 1M × 500k rows of [i 5] cells: 115 ms at -c 1, 30 ms at -c 8. Ordinary I64/SYM/STR key joins are unchanged (cachegrind: under 0.1%).

Limit. One TIMESPAN cell anywhere in either key column coarsens the hash for every row, as it does for group and distinct, which share the hash: about 18 s for 20k table cells plus one span. Answers stay right.

Tests. rfl/join/list_key_join.rfl (@also-unfused) pins:

  • the issue's case, a left join, anti-join and semi-mask;
  • TIMESPAN cells (atom, vector, in a dict) against equal I64/F64 cells, with the span side on the left and on the right;
  • mixed atom/vector/nested/string cells;
  • timed 20k table and dict joins;
  • inner and left joins over I64-vector cells against the same joins on the cells' printed text, at 2k and 140k rows.

It passes at 2 and 8 cores and under ASan+UBSan, and fails with dev's join.c. Dropping the span bits on either side fails it. An independent review compared a pairwise atom_eq oracle over 106 cell kinds: inner both ways, left, anti, semi and anti-mask, single and multi-key, up to 70k × 70k at -c 1 and -c 8, with and without TIMESPAN cells. All match. Full suite: 5529/5533 passed, 4 skipped, 0 failed.

Fixes #1373

@singaraiona

Copy link
Copy Markdown
Collaborator Author

Pushed eb92fff after the independent review:

  • Quadratic hash (high): hashing every LIST key with all span bits sent table, dict and fractional-float cells to one bucket. 20k-row joins took 17.7 s (table cells) and 25 s (dict cells). The span bits now come from ray_key_spans over both sides' LIST key columns, computed once per join and carried in the join key flags beside the nullfree proof (join_key_flags). TIMESPAN-free LIST joins hash exactly: those cases now take 3.9 ms and 5.0 ms.
  • Test: it adds TIMESPAN cells against equal I64/F64 cells (atom, vector, inside a dict), which fail if the spans are dropped; anti-join and semi-mask; and timed table and dict joins. It drops the -0.0 cells, so it doesn't depend on fix(collection): LIST distinct keeps first-occurrence order; -0.0 equals 0.0 in float vector cells #1372.

Full suite: 5529/5533, 0 failed; the test passes at 2 and 8 cores and under ASan+UBSan.

@singaraiona
singaraiona merged commit fef9327 into dev Nov 22, 2026
11 checks passed
@singaraiona
singaraiona deleted the fix/1373-join-list-keys branch November 22, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(join): a join on a LIST key column hashes and compares cell pointers, matching the wrong rows

1 participant