From 3266bbb54cb0f8d0604511e8cae36e8c5df6de74 Mon Sep 17 00:00:00 2001 From: vdimir Date: Tue, 20 Apr 2021 12:52:52 +0300 Subject: [PATCH] TableJoin: forceHashJoin for dictionary_reader, add tests --- src/Interpreters/HashJoin.cpp | 2 +- src/Interpreters/TableJoin.h | 6 +++- .../01115_join_with_dictionary.reference | 29 +++++++++++++++++++ .../01115_join_with_dictionary.sql | 18 +++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/Interpreters/HashJoin.cpp b/src/Interpreters/HashJoin.cpp index 7912c06b3d4..fcd89aed84d 100644 --- a/src/Interpreters/HashJoin.cpp +++ b/src/Interpreters/HashJoin.cpp @@ -571,7 +571,7 @@ namespace 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). - 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) { saved_block_sample = right_table_keys.cloneEmpty(); diff --git a/src/Interpreters/TableJoin.h b/src/Interpreters/TableJoin.h index 71a27849297..b75ef848f13 100644 --- a/src/Interpreters/TableJoin.h +++ b/src/Interpreters/TableJoin.h @@ -128,7 +128,11 @@ public: bool allowDictJoin(const String & dict_key, const Block & sample_block, Names &, NamesAndTypesList &) const; bool preferMergeJoin() const { return join_algorithm == JoinAlgorithm::PREFER_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 forceNullableLeft() const { return join_use_nulls && isRightOrFull(table_join.kind); } diff --git a/tests/queries/0_stateless/01115_join_with_dictionary.reference b/tests/queries/0_stateless/01115_join_with_dictionary.reference index 772b581bd37..77f7ba193c0 100644 --- a/tests/queries/0_stateless/01115_join_with_dictionary.reference +++ b/tests/queries/0_stateless/01115_join_with_dictionary.reference @@ -102,8 +102,37 @@ not optimized (smoke) 2 2 2 2 3 3 3 3 issue 23002 +- 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 +- +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 diff --git a/tests/queries/0_stateless/01115_join_with_dictionary.sql b/tests/queries/0_stateless/01115_join_with_dictionary.sql index 740c1b71dcf..d2c42bb6f75 100644 --- a/tests/queries/0_stateless/01115_join_with_dictionary.sql +++ b/tests/queries/0_stateless/01115_join_with_dictionary.sql @@ -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; SET join_use_nulls = 0; -SET join_algorithm = 'auto'; + 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 '-'; +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_hashed;