Skip to content

Add tests for compareTrackAt in partial_merge join - #110646

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:groeneai/test-partial-merge-join-track
Jul 16, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:groeneai/test-partial-merge-join-track

Conversation

@groeneai

@groeneai groeneai commented Jul 16, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Description

Test-only. Adds compareTrackAt coverage for the partial_merge join algorithm (the devirtualized IColumn::compareAt used for merge-sorted joins, PR #99013). Reopens #99706, renumbered to 04546/04547.

  • 04546: Float64 / +-Inf / NaN keys. Exercises float compareTrackAt multi-row skipping around +-inf. The NaN case is composite (NaN first key on both sides, mismatching second key) so compareTrackAt compares NaN vs NaN while the (k1, k2) join yields no NaN match. partial_merge compares float keys bitwise; this is independent of the hash / full_sorting_merge / direct NaN != NaN equi-join change in Treat float NaN keys as NULL on JOIN ON #106540, which explicitly leaves partial_merge unchanged.
  • 04547: multi-key sort. compareTrackAt skips multiple rows on the first key, then falls back to compareAt for the secondary key on first-key ties.

Covers compareTrackAt (devirtualized IColumn::compareAt for merge-sorted
join, PR ClickHouse#99013) which the existing partial_merge tests do not exercise:
- 04546: Float64/NaN/Inf keys (CompareHelper NaN handling, NaN=NaN match).
  NaN rows pinned last via isNaN() so ORDER BY is deterministic under
  randomized nan_direction_hint.
- 04547: multi-key sort, first-key multi-row track skipping interacting
  with secondary-key matching.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @vdimir — could you review this test-only PR? It reopens #99706 (closed as stale, renumbered to 04546/04547) adding compareTrackAt coverage for partial_merge join (Float/NaN keys and multi-key track skipping).

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0049e26]

Summary: ✅


AI Review

Summary

This PR adds two stateless tests for partial_merge joins: one around Float64 keys with +-inf / NaN, and one around multi-key first-column skipping. I did not find a remaining correctness or coverage issue in the current head after rechecking the merge-join path, the prior discussion, and the current CI report.

Final Verdict

✅ No new findings on the current patch.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 16, 2026
partial_merge currently matches NaN to NaN (bitwise compareAt returns 0),
which diverges from equi-join semantics (NaN != NaN, as hash join follows).
Freezing that into a regression test would block the correct semantic fix.
Rework 04546 so the right table has no NaN key: the test still exercises
Float compareTrackAt multi-row skipping and asserts +inf matches while NaN
never matches, matching equi-join semantics.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

You are right: partial_merge currently matches NaN=NaN (bitwise `compareAt` returns 0), which diverges from equi-join semantics (hash join returns NaN != NaN). Freezing the NaN match would block the correct fix. Reworked so the right table has no NaN key: the test still exercises Float `compareTrackAt` multi-row skipping, asserts +inf matches, and asserts a NaN key never matches (equi-join semantics). Verified locally (5/5).

@vdimir

vdimir commented Jul 16, 2026

Copy link
Copy Markdown
Member

hash join returns NaN != NaN

But this PR attempts to fix this case #106540

…rge NaN semantics

Make the NaN case composite (NaN first key on both sides, mismatching second
key) so compareTrackAt actually compares NaN vs NaN, while the join still
yields no NaN match. Correct the comment: partial_merge compares float keys
bitwise, and PR ClickHouse#106540 leaves that unchanged, so the test is independent of
the hash / full_sorting_merge NaN!=NaN equi-join fix.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Good catch, and my earlier phrasing was misleading. On master today both hash and partial_merge match NaN=NaN bitwise; #106540 changes only hash / parallel_hash / grace_hash / full_sorting_merge / direct to NaN != NaN and its description explicitly leaves partial_merge comparing float keys bitwise. So partial_merge does NOT follow equi-join NaN semantics, and #106540 will not change that.

I reworked 04546 accordingly (8f03785):

  • Fixed the stale comment: it now states partial_merge compares float keys bitwise and that this is independent of Treat float NaN keys as NULL on JOIN ON #106540.
  • The NaN case is now composite (NaN as the first key on both sides, mismatching second key), so compareTrackAt actually compares NaN vs NaN, while the (k1,k2) join still yields no NaN match. This also closes the coverage gap the AI review flagged (previously the right side had no NaN, so the merge cursor hit right-EOF before ever comparing NaN).

Net: 04546/04547 stay correct after #106540 lands, since neither depends on hash-side NaN semantics.

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog and removed pr-ci labels Jul 16, 2026
Functional CI randomizes max_block_size. A small value splits the sorted
left input into 1-2 row blocks, so MergeJoinCursor::compareTrackAt never
returns |track| > 1 over the 7,8,9 < 10 run (04546) or the key1 runs
(04547). The join result is unchanged, so the test still passes while
silently losing the multi-row-skip coverage this PR adds. Pin
max_block_size to keep the whole left input in one block.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pinned max_block_size = 65505 in both tests (0049e26). Confirmed the concern locally: with the default randomized max_block_size the join result is identical whether the block is 1 row or 65505 rows, so a small value silently voided the multi-row skip. A query-level SET overrides the runner injection, so compareTrackAt now sees the full 7,8,9 < 10 run (04546) / key1 runs (04547) in one block and returns |track| > 1. References unchanged (results do not depend on block size, which is the point).

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 0049e26

CI fully finished (Finish Workflow + Mergeable Check + CH Inc sync all pass). No test failures on this head. Ready for review.

Session id: cron:our-pr-ci-monitor:20260716-163000

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 16, 2026
Merged via the queue into ClickHouse:master with commit 6103d99 Jul 16, 2026
178 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 16, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ial-merge-join-track

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

Labels

can be tested Allows running workflows for external contributors pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants