Merge pull request #17887 from sundy-li/trivial_count-fix

disable optimize_trivial_count in query with array join
This commit is contained in:
alexey-milovidov 2020-12-12 02:44:07 +03:00 committed by GitHub
commit 0d6fe7121d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -562,7 +562,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.
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();
if (partition_desc.expression)

View File

@ -2,7 +2,7 @@ drop table if exists test1;
drop table if exists test_tuple;
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);
set max_rows_to_read = 1;
@ -22,7 +22,7 @@ select count() from test1 where toDate(p) > '2020-09-01';
-- non-optimized
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);
@ -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;
-- optimized
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);