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';