Fix 02382_join_and_filtering_set

Copy missing corresponding code from Interpreter, adjust test (removed
with cube)
This commit is contained in:
vdimir 2023-06-01 10:52:04 +00:00
parent 16eeec69bf
commit 84e838d038
No known key found for this signature in database
GPG Key ID: 6EE4CE2BEDC51862
4 changed files with 23 additions and 8 deletions

View File

@ -1248,7 +1248,26 @@ JoinTreeQueryPlan buildQueryPlanForJoinNode(const QueryTreeNodePtr & join_table_
const auto & join_clause = table_join->getOnlyClause(); const auto & join_clause = table_join->getOnlyClause();
bool kind_allows_filtering = isInner(join_kind) || isLeft(join_kind) || isRight(join_kind); bool kind_allows_filtering = isInner(join_kind) || isLeft(join_kind) || isRight(join_kind);
if (settings.max_rows_in_set_to_optimize_join > 0 && kind_allows_filtering)
auto has_non_const = [](const Block & block, const auto & keys)
{
for (const auto & key : keys)
{
const auto & column = block.getByName(key).column;
if (column && !isColumnConst(*column))
return true;
}
return false;
};
/// This optimization relies on the sorting that should buffer the whole stream before emitting any rows.
/// It doesn't hold such a guarantee for streams with const keys.
/// Note: it's also doesn't work with the read-in-order optimization.
/// No checks here because read in order is not applied if we have `CreateSetAndFilterOnTheFlyStep` in the pipeline between the reading and sorting steps.
bool has_non_const_keys = has_non_const(left_plan.getCurrentDataStream().header, join_clause.key_names_left)
&& has_non_const(right_plan.getCurrentDataStream().header, join_clause.key_names_right);
if (settings.max_rows_in_set_to_optimize_join > 0 && kind_allows_filtering && has_non_const_keys)
{ {
auto * left_set = add_create_set(left_plan, join_clause.key_names_left, JoinTableSide::Left); auto * left_set = add_create_set(left_plan, join_clause.key_names_left, JoinTableSide::Left);
auto * right_set = add_create_set(right_plan, join_clause.key_names_right, JoinTableSide::Right); auto * right_set = add_create_set(right_plan, join_clause.key_names_right, JoinTableSide::Right);

View File

@ -82,7 +82,6 @@
02354_annoy 02354_annoy
02366_union_decimal_conversion 02366_union_decimal_conversion
02375_rocksdb_with_filters 02375_rocksdb_with_filters
02382_join_and_filtering_set
02402_merge_engine_with_view 02402_merge_engine_with_view
02404_memory_bound_merging 02404_memory_bound_merging
02426_orc_bug 02426_orc_bug

View File

@ -7,8 +7,5 @@
10 10
bug with constant columns in join keys bug with constant columns in join keys
a a a a
a a
a a
a a
1 1
1 1

View File

@ -22,20 +22,20 @@ SELECT count() FROM t1 JOIN t2 ON t1.x = t2.x WHERE t1.x % 2 == 0 AND t2.x % 2 =
SELECT 'bug with constant columns in join keys'; SELECT 'bug with constant columns in join keys';
SELECT * FROM ( SELECT 'a' AS key ) AS t1 SELECT * FROM ( SELECT 'a' AS key ) AS t1
INNER JOIN ( SELECT 'a' AS key GROUP BY ignore(1), ignore(2) WITH CUBE ) AS t2 INNER JOIN ( SELECT 'a' AS key ) AS t2
ON t1.key = t2.key ON t1.key = t2.key
; ;
SELECT count() > 1 FROM (EXPLAIN PIPELINE SELECT count() > 1 FROM (EXPLAIN PIPELINE
SELECT * FROM ( SELECT materialize('a') AS key ) AS t1 SELECT * FROM ( SELECT materialize('a') AS key ) AS t1
INNER JOIN ( SELECT materialize('a') AS key GROUP BY ignore(1), ignore(2) WITH CUBE ) AS t2 INNER JOIN ( SELECT materialize('a') AS key ) AS t2
ON t1.key = t2.key ON t1.key = t2.key
) WHERE explain ilike '%FilterBySetOnTheFlyTransform%' ) WHERE explain ilike '%FilterBySetOnTheFlyTransform%'
; ;
SELECT count() == 0 FROM (EXPLAIN PIPELINE SELECT count() == 0 FROM (EXPLAIN PIPELINE
SELECT * FROM ( SELECT 'a' AS key ) AS t1 SELECT * FROM ( SELECT 'a' AS key ) AS t1
INNER JOIN ( SELECT 'a' AS key GROUP BY ignore(1), ignore(2) WITH CUBE ) AS t2 INNER JOIN ( SELECT 'a' AS key ) AS t2
ON t1.key = t2.key ON t1.key = t2.key
) WHERE explain ilike '%FilterBySetOnTheFlyTransform%' ) WHERE explain ilike '%FilterBySetOnTheFlyTransform%'
; ;