mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 00:22:29 +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>();
|
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
|
||||||
{
|
{
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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