Merge pull request #67234 from ClickHouse/pr-lost-decimal-conversion

Fix: missing conversion in IN operator with parallel replicas
This commit is contained in:
Igor Nikonov 2024-08-15 20:51:13 +00:00 committed by GitHub
commit fc30b53dd0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 19 additions and 7 deletions

View File

@ -242,7 +242,8 @@ ASTPtr FunctionNode::toASTImpl(const ConvertToASTOptions & options) const
/// Avoid cast for `IN tuple(...)` expression.
/// Tuples could be quite big, and adding a type may significantly increase query size.
/// It should be safe because set type for `column IN tuple` is deduced from `column` type.
if (isNameOfInFunction(function_name) && argument_nodes.size() > 1 && argument_nodes[1]->getNodeType() == QueryTreeNodeType::CONSTANT)
if (isNameOfInFunction(function_name) && argument_nodes.size() > 1 && argument_nodes[1]->getNodeType() == QueryTreeNodeType::CONSTANT
&& !static_cast<const ConstantNode *>(argument_nodes[1].get())->hasSourceExpression())
new_options.add_cast_for_constants = false;
const auto & parameters = getParameters();

View File

@ -49,7 +49,7 @@ order by query;
tuple(2)
select 'optimize_skip_unused_shards_rewrite_in(2,)';
optimize_skip_unused_shards_rewrite_in(2,)
with (select currentDatabase()) as id_2 select *, ignore(id_2) from dist_01756 where dummy in (2,);
with (select currentDatabase()) as id_2 select *, ignore(id_2) from dist_01756 where dummy in (2);
system flush logs;
select splitByString('IN', query)[-1] from system.query_log where
event_date >= yesterday() and
@ -59,10 +59,10 @@ select splitByString('IN', query)[-1] from system.query_log where
query like concat('%', currentDatabase(), '%AS%id_2%') and
type = 'QueryFinish'
order by query;
tuple(2)
(2)
select 'optimize_skip_unused_shards_rewrite_in(0,)';
optimize_skip_unused_shards_rewrite_in(0,)
with (select currentDatabase()) as id_00 select *, ignore(id_00) from dist_01756 where dummy in (0,);
with (select currentDatabase()) as id_00 select *, ignore(id_00) from dist_01756 where dummy in (0);
0 0
system flush logs;
select splitByString('IN', query)[-1] from system.query_log where
@ -73,7 +73,7 @@ select splitByString('IN', query)[-1] from system.query_log where
query like concat('%', currentDatabase(), '%AS%id_00%') and
type = 'QueryFinish'
order by query;
tuple(0)
(0)
-- signed column
select 'signed column';
signed column

View File

@ -63,7 +63,7 @@ select splitByString('IN', query)[-1] from system.query_log where
order by query;
select 'optimize_skip_unused_shards_rewrite_in(2,)';
with (select currentDatabase()) as id_2 select *, ignore(id_2) from dist_01756 where dummy in (2,);
with (select currentDatabase()) as id_2 select *, ignore(id_2) from dist_01756 where dummy in (2);
system flush logs;
select splitByString('IN', query)[-1] from system.query_log where
event_date >= yesterday() and
@ -75,7 +75,7 @@ select splitByString('IN', query)[-1] from system.query_log where
order by query;
select 'optimize_skip_unused_shards_rewrite_in(0,)';
with (select currentDatabase()) as id_00 select *, ignore(id_00) from dist_01756 where dummy in (0,);
with (select currentDatabase()) as id_00 select *, ignore(id_00) from dist_01756 where dummy in (0);
system flush logs;
select splitByString('IN', query)[-1] from system.query_log where
event_date >= yesterday() and

View File

@ -0,0 +1,11 @@
DROP TABLE IF EXISTS t_03209 SYNC;
CREATE TABLE t_03209 ( `a` Decimal(18, 0), `b` Decimal(18, 1), `c` Decimal(36, 0) ) ENGINE = ReplicatedMergeTree('/clickhouse/{database}/test_03209', 'r1') ORDER BY tuple();
INSERT INTO t_03209 VALUES ('33', '44.4', '35');
SET max_parallel_replicas = 2, cluster_for_parallel_replicas='parallel_replicas';
SELECT * FROM t_03209 WHERE a IN toDecimal32('33.3000', 4) SETTINGS allow_experimental_parallel_reading_from_replicas=0;
SELECT * FROM t_03209 WHERE a IN toDecimal32('33.3000', 4) SETTINGS allow_experimental_parallel_reading_from_replicas=1;
DROP TABLE t_03209 SYNC;