Allow shard pruning with IN literal

This commit is contained in:
Amos Bird 2021-06-04 21:16:15 +08:00
parent 78fca8f8fa
commit fd336411ee
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
5 changed files with 38 additions and 16 deletions

View File

@ -224,24 +224,28 @@ namespace
} }
} }
} }
else if (const auto * tuple_literal = right->as<ASTLiteral>(); else if (const auto * tuple_literal = right->as<ASTLiteral>(); tuple_literal)
tuple_literal && tuple_literal->value.getType() == Field::Types::Tuple)
{ {
const auto & tuple = tuple_literal->value.get<const Tuple &>(); if (tuple_literal->value.getType() == Field::Types::Tuple)
for (const auto & child : tuple)
{ {
const auto dnf = analyzeEquals(identifier, child, expr); const auto & tuple = tuple_literal->value.get<const Tuple &>();
for (const auto & child : tuple)
if (dnf.empty())
{ {
return {}; const auto dnf = analyzeEquals(identifier, child, expr);
}
if (!add_dnf(dnf)) if (dnf.empty())
{ {
return {}; return {};
}
if (!add_dnf(dnf))
{
return {};
}
} }
} }
else
return analyzeEquals(identifier, tuple_literal, expr);
} }
else else
{ {

View File

@ -12,6 +12,8 @@ WITH CAST(\'default\', \'String\') AS id_2 SELECT one.dummy, ignore(id_2) FROM s
optimize_skip_unused_shards_rewrite_in(0,) optimize_skip_unused_shards_rewrite_in(0,)
0 0 0 0
WITH CAST(\'default\', \'String\') AS id_0 SELECT one.dummy, ignore(id_0) FROM system.one WHERE dummy IN tuple(0) WITH CAST(\'default\', \'String\') AS id_0 SELECT one.dummy, ignore(id_0) FROM system.one WHERE dummy IN tuple(0)
0
0
errors errors
others others
0 0

View File

@ -81,18 +81,18 @@ select query from system.query_log where
type = 'QueryFinish' type = 'QueryFinish'
order by query; order by query;
-- not tuple
select * from dist_01756 where dummy in (0);
select * from dist_01756 where dummy in ('0');
-- --
-- errors -- errors
-- --
select 'errors'; select 'errors';
-- not tuple
select * from dist_01756 where dummy in (0); -- { serverError 507 }
-- optimize_skip_unused_shards does not support non-constants -- optimize_skip_unused_shards does not support non-constants
select * from dist_01756 where dummy in (select * from system.one); -- { serverError 507 } select * from dist_01756 where dummy in (select * from system.one); -- { serverError 507 }
select * from dist_01756 where dummy in (toUInt8(0)); -- { serverError 507 } select * from dist_01756 where dummy in (toUInt8(0)); -- { serverError 507 }
-- wrong type (tuple)
select * from dist_01756 where dummy in ('0'); -- { serverError 507 }
-- intHash64 does not accept string -- intHash64 does not accept string
select * from dist_01756 where dummy in ('0', '2'); -- { serverError 43 } select * from dist_01756 where dummy in ('0', '2'); -- { serverError 43 }
-- NOT IN does not supported -- NOT IN does not supported

View File

@ -0,0 +1,15 @@
set optimize_skip_unused_shards=1;
set force_optimize_skip_unused_shards=1;
drop table if exists d;
drop table if exists dp;
create table d (i UInt8) Engine=Memory;
create table dp as d Engine=Distributed(test_cluster_two_shards, currentDatabase(), d, i);
insert into d values (1), (2);
select * from dp where i in (1);
drop table if exists d;
drop table if exists dp;