Check left join strictness in tryInitDictJoin

This commit is contained in:
vdimir 2021-09-14 15:04:45 +03:00
parent 6847610ed3
commit 32e8c11cab
No known key found for this signature in database
GPG Key ID: F57B3E10A21DBB31
3 changed files with 17 additions and 1 deletions

View File

@ -339,8 +339,16 @@ static std::optional<String> 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();

View File

@ -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

View File

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