From 32e8c11cab7ec5c222073a767d65cceffbd0d3b4 Mon Sep 17 00:00:00 2001 From: vdimir Date: Tue, 14 Sep 2021 15:04:45 +0300 Subject: [PATCH] Check left join strictness in tryInitDictJoin --- src/Interpreters/TableJoin.cpp | 10 +++++++++- .../0_stateless/01115_join_with_dictionary.reference | 6 ++++++ .../queries/0_stateless/01115_join_with_dictionary.sql | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Interpreters/TableJoin.cpp b/src/Interpreters/TableJoin.cpp index 9194de3073a..b0c89adee45 100644 --- a/src/Interpreters/TableJoin.cpp +++ b/src/Interpreters/TableJoin.cpp @@ -339,8 +339,16 @@ static std::optional getDictKeyName(const String & dict_name , ContextPt bool TableJoin::tryInitDictJoin(const Block & sample_block, ContextPtr context) { + using Strictness = ASTTableJoin::Strictness; + + bool allowed_inner = isInner(kind()) && strictness() == Strictness::All; + bool allowed_left = isLeft(kind()) && (strictness() == Strictness::Any || + strictness() == Strictness::All || + strictness() == Strictness::Semi || + strictness() == Strictness::Anti); + /// Support ALL INNER, [ANY | ALL | SEMI | ANTI] LEFT - if (!isLeft(kind()) && !(isInner(kind()) && strictness() == ASTTableJoin::Strictness::All)) + if (!allowed_inner && !allowed_left) return false; const Names & right_keys = keyNamesRight(); diff --git a/tests/queries/0_stateless/01115_join_with_dictionary.reference b/tests/queries/0_stateless/01115_join_with_dictionary.reference index 77f7ba193c0..76337bdfc0b 100644 --- a/tests/queries/0_stateless/01115_join_with_dictionary.reference +++ b/tests/queries/0_stateless/01115_join_with_dictionary.reference @@ -16,6 +16,12 @@ flat: any left 2 2 2 2 3 3 3 3 4 0 0 +flat: any left + any_join_distinct_right_table_keys +0 0 0 0 +1 1 1 1 +2 2 2 2 +3 3 3 3 +4 0 0 flat: semi left 0 0 0 0 1 1 1 1 diff --git a/tests/queries/0_stateless/01115_join_with_dictionary.sql b/tests/queries/0_stateless/01115_join_with_dictionary.sql index 0c84d372f6d..8d8589d6085 100644 --- a/tests/queries/0_stateless/01115_join_with_dictionary.sql +++ b/tests/queries/0_stateless/01115_join_with_dictionary.sql @@ -33,6 +33,8 @@ SELECT 'flat: left'; SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 LEFT JOIN dict_flat d USING(key) ORDER BY key; SELECT 'flat: any left'; SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 ANY LEFT JOIN dict_flat d USING(key) ORDER BY key; +SELECT 'flat: any left + any_join_distinct_right_table_keys'; -- falls back to regular join +SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 ANY LEFT JOIN dict_flat d USING(key) ORDER BY key SETTINGS any_join_distinct_right_table_keys = '1'; SELECT 'flat: semi left'; SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 SEMI JOIN dict_flat d USING(key) ORDER BY key; SELECT 'flat: anti left';