mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Allow shard pruning with IN literal
This commit is contained in:
parent
78fca8f8fa
commit
fd336411ee
@ -224,24 +224,28 @@ namespace
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (const auto * tuple_literal = right->as<ASTLiteral>();
|
||||
tuple_literal && tuple_literal->value.getType() == Field::Types::Tuple)
|
||||
else if (const auto * tuple_literal = right->as<ASTLiteral>(); tuple_literal)
|
||||
{
|
||||
const auto & tuple = tuple_literal->value.get<const Tuple &>();
|
||||
for (const auto & child : tuple)
|
||||
if (tuple_literal->value.getType() == Field::Types::Tuple)
|
||||
{
|
||||
const auto dnf = analyzeEquals(identifier, child, expr);
|
||||
|
||||
if (dnf.empty())
|
||||
const auto & tuple = tuple_literal->value.get<const Tuple &>();
|
||||
for (const auto & child : tuple)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
const auto dnf = analyzeEquals(identifier, child, expr);
|
||||
|
||||
if (!add_dnf(dnf))
|
||||
{
|
||||
return {};
|
||||
if (dnf.empty())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!add_dnf(dnf))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
return analyzeEquals(identifier, tuple_literal, expr);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -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,)
|
||||
0 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
|
||||
others
|
||||
0
|
||||
|
@ -81,18 +81,18 @@ select query from system.query_log where
|
||||
type = 'QueryFinish'
|
||||
order by query;
|
||||
|
||||
-- not tuple
|
||||
select * from dist_01756 where dummy in (0);
|
||||
select * from dist_01756 where dummy in ('0');
|
||||
|
||||
--
|
||||
-- errors
|
||||
--
|
||||
select 'errors';
|
||||
|
||||
-- not tuple
|
||||
select * from dist_01756 where dummy in (0); -- { serverError 507 }
|
||||
-- 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 (toUInt8(0)); -- { serverError 507 }
|
||||
-- wrong type (tuple)
|
||||
select * from dist_01756 where dummy in ('0'); -- { serverError 507 }
|
||||
-- intHash64 does not accept string
|
||||
select * from dist_01756 where dummy in ('0', '2'); -- { serverError 43 }
|
||||
-- NOT IN does not supported
|
||||
|
@ -0,0 +1 @@
|
||||
1
|
15
tests/queries/0_stateless/01901_in_literal_shard_prune.sql
Normal file
15
tests/queries/0_stateless/01901_in_literal_shard_prune.sql
Normal 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;
|
Loading…
Reference in New Issue
Block a user