未验证 提交 7006b1bb 编写于 作者: A alexey-milovidov 提交者: GitHub

Merge pull request #18021 from ClickHouse/backport/20.12/17887

Backport #17887 to 20.12: disable optimize_trivial_count in query with array join
...@@ -513,7 +513,7 @@ void TreeRewriterResult::collectUsedColumns(const ASTPtr & query, bool is_select ...@@ -513,7 +513,7 @@ void TreeRewriterResult::collectUsedColumns(const ASTPtr & query, bool is_select
/// If we have no information about columns sizes, choose a column of minimum size of its data type. /// If we have no information about columns sizes, choose a column of minimum size of its data type.
required.insert(ExpressionActions::getSmallestColumn(source_columns)); required.insert(ExpressionActions::getSmallestColumn(source_columns));
} }
else if (is_select && metadata_snapshot) else if (is_select && metadata_snapshot && !columns_context.has_array_join)
{ {
const auto & partition_desc = metadata_snapshot->getPartitionKey(); const auto & partition_desc = metadata_snapshot->getPartitionKey();
if (partition_desc.expression) if (partition_desc.expression)
......
...@@ -2,7 +2,7 @@ drop table if exists test1; ...@@ -2,7 +2,7 @@ drop table if exists test1;
drop table if exists test_tuple; drop table if exists test_tuple;
drop table if exists test_two_args; drop table if exists test_two_args;
create table test1(p DateTime, k int) engine MergeTree partition by toDate(p) order by k; create table test1(p DateTime, k int) engine MergeTree partition by toDate(p) order by k settings index_granularity = 1;
insert into test1 values ('2020-09-01 00:01:02', 1), ('2020-09-01 20:01:03', 2), ('2020-09-02 00:01:03', 3); insert into test1 values ('2020-09-01 00:01:02', 1), ('2020-09-01 20:01:03', 2), ('2020-09-02 00:01:03', 3);
set max_rows_to_read = 1; set max_rows_to_read = 1;
...@@ -22,7 +22,7 @@ select count() from test1 where toDate(p) > '2020-09-01'; ...@@ -22,7 +22,7 @@ select count() from test1 where toDate(p) > '2020-09-01';
-- non-optimized -- non-optimized
select count() from test1 where toDate(p) >= '2020-09-01' and p <= '2020-09-01 00:00:00'; select count() from test1 where toDate(p) >= '2020-09-01' and p <= '2020-09-01 00:00:00';
create table test_tuple(p DateTime, i int, j int) engine MergeTree partition by (toDate(p), i) order by j; create table test_tuple(p DateTime, i int, j int) engine MergeTree partition by (toDate(p), i) order by j settings index_granularity = 1;
insert into test_tuple values ('2020-09-01 00:01:02', 1, 2), ('2020-09-01 00:01:03', 2, 3), ('2020-09-02 00:01:03', 3, 4); insert into test_tuple values ('2020-09-01 00:01:02', 1, 2), ('2020-09-01 00:01:03', 2, 3), ('2020-09-02 00:01:03', 3, 4);
...@@ -34,8 +34,14 @@ select count() from test_tuple where toDate(p) > '2020-09-01' and i = 1; ...@@ -34,8 +34,14 @@ select count() from test_tuple where toDate(p) > '2020-09-01' and i = 1;
select count() from test_tuple where i > 1; select count() from test_tuple where i > 1;
-- optimized -- optimized
select count() from test_tuple where i < 1; select count() from test_tuple where i < 1;
-- non-optimized
select count() from test_tuple array join [p,p] as c where toDate(p) = '2020-09-01'; -- { serverError 158; }
select count() from test_tuple array join [1,2] as c where toDate(p) = '2020-09-01' settings max_rows_to_read = 4;
-- non-optimized
select count() from test_tuple array join [1,2,3] as c where toDate(p) = '2020-09-01'; -- { serverError 158; }
select count() from test_tuple array join [1,2,3] as c where toDate(p) = '2020-09-01' settings max_rows_to_read = 6;
create table test_two_args(i int, j int, k int) engine MergeTree partition by i + j order by k; create table test_two_args(i int, j int, k int) engine MergeTree partition by i + j order by k settings index_granularity = 1;
insert into test_two_args values (1, 2, 3), (2, 1, 3), (0, 3, 4); insert into test_two_args values (1, 2, 3), (2, 1, 3), (0, 3, 4);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册