TableJoin: forceHashJoin for dictionary_reader, add tests

This commit is contained in:
vdimir 2021-04-20 12:52:52 +03:00
parent a95c4dcfff
commit 3266bbb54c
No known key found for this signature in database
GPG Key ID: F57B3E10A21DBB31
4 changed files with 52 additions and 3 deletions

View File

@ -571,7 +571,7 @@ namespace
void HashJoin::initRightBlockStructure(Block & saved_block_sample) void HashJoin::initRightBlockStructure(Block & saved_block_sample)
{ {
/// We could remove key columns for LEFT | INNER HashJoin but we should keep them for JoinSwitcher (if any). /// We could remove key columns for LEFT | INNER HashJoin but we should keep them for JoinSwitcher (if any).
bool save_key_columns = !(table_join->forceHashJoin() || table_join->dictionary_reader) || isRightOrFull(kind); bool save_key_columns = !table_join->forceHashJoin() || isRightOrFull(kind);
if (save_key_columns) if (save_key_columns)
{ {
saved_block_sample = right_table_keys.cloneEmpty(); saved_block_sample = right_table_keys.cloneEmpty();

View File

@ -128,7 +128,11 @@ public:
bool allowDictJoin(const String & dict_key, const Block & sample_block, Names &, NamesAndTypesList &) const; bool allowDictJoin(const String & dict_key, const Block & sample_block, Names &, NamesAndTypesList &) const;
bool preferMergeJoin() const { return join_algorithm == JoinAlgorithm::PREFER_PARTIAL_MERGE; } bool preferMergeJoin() const { return join_algorithm == JoinAlgorithm::PREFER_PARTIAL_MERGE; }
bool forceMergeJoin() const { return join_algorithm == JoinAlgorithm::PARTIAL_MERGE; } bool forceMergeJoin() const { return join_algorithm == JoinAlgorithm::PARTIAL_MERGE; }
bool forceHashJoin() const { return join_algorithm == JoinAlgorithm::HASH; } bool forceHashJoin() const
{
/// HashJoin always used for DictJoin
return dictionary_reader || join_algorithm == JoinAlgorithm::HASH;
}
bool forceNullableRight() const { return join_use_nulls && isLeftOrFull(table_join.kind); } bool forceNullableRight() const { return join_use_nulls && isLeftOrFull(table_join.kind); }
bool forceNullableLeft() const { return join_use_nulls && isRightOrFull(table_join.kind); } bool forceNullableLeft() const { return join_use_nulls && isRightOrFull(table_join.kind); }

View File

@ -102,8 +102,37 @@ not optimized (smoke)
2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3
issue 23002 issue 23002
-
0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3
4 0 0 0 4 0 0 0
-
0 0 0 0
1 1 1 1
2 2 2 2
3 3 3 3
4 0 0
-
0 0 0 0 0
1 1 1 1 1
0 2 2 2 2
0 3 3 3 3
-
0 0 0 0 0
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 0 0 0
-
0 0 0 0
1 1 1 1
2 2 2 2
3 3 3 3
4 0 0
-
0 0 0 0 0
1 1 1 1 1
0 2 2 2 2
0 3 3 3 3

View File

@ -83,9 +83,25 @@ SELECT '-';
SELECT * FROM (SELECT number AS key FROM numbers(2)) s1 ANTI RIGHT JOIN dict_flat d USING(key) ORDER BY s1.key; SELECT * FROM (SELECT number AS key FROM numbers(2)) s1 ANTI RIGHT JOIN dict_flat d USING(key) ORDER BY s1.key;
SET join_use_nulls = 0; SET join_use_nulls = 0;
SET join_algorithm = 'auto';
SELECT 'issue 23002'; SELECT 'issue 23002';
SET join_algorithm = 'auto';
SELECT '-';
SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 LEFT JOIN dict_flat d ON s1.key = d.key ORDER BY s1.key; SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 LEFT JOIN dict_flat d ON s1.key = d.key ORDER BY s1.key;
SELECT '-';
SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 ANY LEFT JOIN dict_flat d USING(key) ORDER BY key;
SELECT '-';
SELECT * FROM (SELECT number AS key FROM numbers(2)) s1 RIGHT JOIN dict_flat d ON s1.key = d.key ORDER BY d.key;
SET join_algorithm = 'partial_merge';
SELECT '-';
SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 LEFT JOIN dict_flat d ON s1.key = d.key ORDER BY s1.key;
SELECT '-';
SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 ANY LEFT JOIN dict_flat d USING(key) ORDER BY key;
SELECT '-';
SELECT * FROM (SELECT number AS key FROM numbers(2)) s1 RIGHT JOIN dict_flat d ON s1.key = d.key ORDER BY d.key;
DROP DICTIONARY dict_flat; DROP DICTIONARY dict_flat;
DROP DICTIONARY dict_hashed; DROP DICTIONARY dict_hashed;