Repository navigation
Conversation
|
Workflow [PR], commit [bfa5eed] Summary: ✅
AI ReviewSummaryThis PR changes Findings
Tests
Final VerdictStatus: ❌ Block Minimum required actions: fix cross-left-block duplicate suppression for |
|
It's probably not a full fix. If there could be blocks' splits with same key on a split border there could be duplicates too. |
vdimir
left a comment
There was a problem hiding this comment.
Since, as you mentioned, the change does not cover the case with block split, I'm not sure it's worth going with a partial fix and having non-deterministic results based on block size. We can think about forbidding ANY INNER for partial merge (as we do for ANY RIGHT, probably for the same reason that we cannot deduplicate the left side?). But that would be backward-incompatible and would require a setting, so I'm also not sure if it's worth doing.
Even worse. As soon as left table is not fully sorted there would be duplicates between left table portions we are joining.
We could. But only if we make key-visit map of the right table (or maybe for each right table block separately). Like it was in HashJoin (I'm not sure about its current state). In fact currently |
To keep queries compatible with older behavior, we probably will need to introduce a compatibility setting something along the lines of |
I'm not sure I fully understand which behaviour we should to keep. Both variants are works not in sync with other Would it better if I mark the PR as DRAFT and you continue it with your vision? |
|
This was fixed by #105146. Let's update the branch. |
# Conflicts: # src/Interpreters/MergeJoin.cpp
# Conflicts: # tests/queries/0_stateless/01881_join_on_conditions_hash.sql.j2
The previous fix set range.left_length = 1 for ANY INNER, which also limited how far the left cursor advanced. As a result, when the right rows of a single key were split across several right blocks (e.g. with partial_merge_join_rows_in_right_blocks = 1), the same left key could be emitted once per right block, producing block-size-dependent duplicates. Now semiLeftJoin still emits only the first left row of the equal range for ANY INNER, but advances the left cursor past the whole range. Because left keys are contiguous and sorted, a matched key is never reconsidered in later right blocks, so the result is one row per matched left key regardless of the right block size, matching the hash join. Add test 05017_any_inner_join_partial_merge_block_split. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@vdimir I addressed the block-split concern in 46a57db instead of going with a partial fix. The issue was that New test |
|
|
||
| right_cursor.nextN(range.right_length); | ||
| left_cursor.nextN(range.left_length); | ||
| left_cursor.nextN(left_length); |
There was a problem hiding this comment.
ANY INNER with the default any_join_distinct_right_table_keys = 0 promises one row per key from both sides, but this only skips duplicates within the current left block. joinBlock sorts each incoming left block independently and partial_merge_join_left_table_buffer_bytes is disabled, so if the same left key arrives in two left blocks this code emits it once per block. For example, left block 1 contains id = 1, left block 2 also contains id = 1, and the right side contains id = 1: hash can suppress the second row via its used flags, but this path has no cross-left-block state and returns two rows. Please either keep emitted-key state for ANY INNER across left blocks, or make partial_merge fall back/reject this strictness, and add a regression that splits duplicate left keys across blocks (for example with max_block_size = 1).
The new test was numbered 05017, far above the current maximum stateless test number (04336), which `check_gaps_in_tests_numbers` flags as `Gap (4336, 5017) > 100`. Renumber it to 04340 to close the gap. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104621&sha=46a57dba53f66101699abd40746a9e8133cc5247&name_0=PR&name_1=Style%20check Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 9/9 (100.00%) | Lost baseline coverage: none · Uncovered code |
I believe issue with inter-block keys remains, tested with script: #!/usr/bin/env -S ${HOME}/clickhouse client --queries-file
DROP TABLE IF EXISTS t1;
CREATE TABLE IF NOT EXISTS t1 ( `id` UInt64, `name` String, ) ENGINE = MergeTree ORDER BY id;
DROP TABLE IF EXISTS t2;
CREATE TABLE IF NOT EXISTS t2 ( `id` UInt64, `name` String, ) ENGINE = MergeTree ORDER BY id;
SYSTEM STOP MERGES t1;
SYSTEM STOP MERGES t2;
INSERT INTO t1 VALUES (1, 'A'), (2, 'B'), (3, 'C');
INSERT INTO t1 VALUES (1, 'D'), (2, 'E'), (4, 'F');
INSERT INTO t2 VALUES (1, 'a'), (2, 'b'), (3, 'c');
INSERT INTO t2 VALUES (1, 'd'), (2, 'e'), (4, 'f');
SELECT * FROM t1
ANY INNER JOIN t2 USING id
SETTINGS join_algorithm = 'partial_merge';
SYSTEM START MERGES t1;
SYSTEM START MERGES t2;
OPTIMIZE TABLE t1 FINAL;
OPTIMIZE TABLE t2 FINAL;
SELECT '--';
SELECT * FROM t1
ANY INNER JOIN t2 USING id
SETTINGS join_algorithm = 'partial_merge';
SELECT * FROM system.build_options
WHERE name = 'GIT_COMMIT_SUBJECT'
FORMAT PrettyCompact; |
|
Proper implementation would require some kind of tracking keys, e.g. storing them in hash table, with will add signification overhead, and in that case it's better to use hash join |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
fix wrong
ANY INNER JOINresult used withpartial_mergealgo