mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-24 18:50:49 +00:00
Fix Distributed engine with virtual columns of the underlying table in WHERE
Before storage has not been passed to the SyntaxAnalyzer and hence it cannot check if there is such column and throw for virtual columns like _part (MergeTree) and others. Follow-up-for: #8846
This commit is contained in:
parent
dcf4d5198f
commit
5039b6ab73
@ -227,16 +227,16 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void replaceConstantExpressions(ASTPtr & node, const Context & context, const NamesAndTypesList & columns)
|
||||
void replaceConstantExpressions(ASTPtr & node, const Context & context, const NamesAndTypesList & columns, ConstStoragePtr storage)
|
||||
{
|
||||
auto syntax_result = SyntaxAnalyzer(context).analyze(node, columns);
|
||||
auto syntax_result = SyntaxAnalyzer(context).analyze(node, columns, storage);
|
||||
Block block_with_constants = KeyCondition::getBlockWithConstants(node, syntax_result, context);
|
||||
|
||||
InDepthNodeVisitor<ReplacingConstantExpressionsMatcher, true> visitor(block_with_constants);
|
||||
visitor.visit(node);
|
||||
}
|
||||
|
||||
}
|
||||
} // \anonymous
|
||||
|
||||
|
||||
/// For destruction of std::unique_ptr of type that is incomplete in class definition.
|
||||
@ -662,7 +662,7 @@ ClusterPtr StorageDistributed::skipUnusedShards(ClusterPtr cluster, const Select
|
||||
condition_ast = select.prewhere() ? select.prewhere()->clone() : select.where()->clone();
|
||||
}
|
||||
|
||||
replaceConstantExpressions(condition_ast, context, getColumns().getAllPhysical() /** TODO: sharding_key_column_name */);
|
||||
replaceConstantExpressions(condition_ast, context, getColumns().getAll(), shared_from_this());
|
||||
const auto blocks = evaluateExpressionOverConstantCondition(condition_ast, sharding_key_expr);
|
||||
|
||||
// Can't get definite answer if we can skip any shards
|
||||
|
@ -45,5 +45,12 @@ select * from dist_01072 where key=toInt32(value); -- { serverError 507; }
|
||||
select * from dist_01072 where key=value settings force_optimize_skip_unused_shards=0;
|
||||
select * from dist_01072 where key=toInt32(value) settings force_optimize_skip_unused_shards=0;
|
||||
|
||||
-- check virtual columns
|
||||
drop table data_01072;
|
||||
drop table dist_01072;
|
||||
create table data_01072 (key Int) Engine=MergeTree() ORDER BY key;
|
||||
create table dist_01072 (key Int) Engine=Distributed(test_cluster_two_shards, currentDatabase(), data_01072, key);
|
||||
select * from dist_01072 where key=0 and _part='0' settings force_optimize_skip_unused_shards=2;
|
||||
|
||||
drop table data_01072;
|
||||
drop table dist_01072;
|
||||
|
Loading…
Reference in New Issue
Block a user