mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 10:02:01 +00:00
Fix incorrect sharding key types for optimize_skip_unused_shards_rewrite_in
Before it always uses the first column from sample block, while it is not guaranteed. Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
This commit is contained in:
parent
5576cb7964
commit
32ed192434
@ -249,7 +249,6 @@ void executeQuery(
|
||||
{
|
||||
OptimizeShardingKeyRewriteInVisitor::Data visitor_data{
|
||||
sharding_key_expr,
|
||||
sharding_key_expr->getSampleBlock().getByPosition(0).type,
|
||||
sharding_key_column_name,
|
||||
shard_info,
|
||||
not_optimized_cluster->getSlotToShard(),
|
||||
@ -286,7 +285,6 @@ void executeQuery(
|
||||
{
|
||||
OptimizeShardingKeyRewriteInVisitor::Data visitor_data{
|
||||
sharding_key_expr,
|
||||
sharding_key_expr->getSampleBlock().getByPosition(0).type,
|
||||
sharding_key_column_name,
|
||||
shard_info,
|
||||
not_optimized_cluster->getSlotToShard(),
|
||||
|
@ -38,25 +38,27 @@ Field executeFunctionOnField(
|
||||
return (*ret.column)[0];
|
||||
}
|
||||
|
||||
/// @param sharding_column_value - one of values from IN
|
||||
/// @param column_value - one of values from IN
|
||||
/// @param sharding_column_name - name of that column
|
||||
/// @return true if shard may contain such value (or it is unknown), otherwise false.
|
||||
bool shardContains(
|
||||
Field sharding_column_value,
|
||||
Field column_value,
|
||||
const std::string & sharding_column_name,
|
||||
const OptimizeShardingKeyRewriteInMatcher::Data & data)
|
||||
{
|
||||
/// Type of column in storage (used for implicit conversion from i.e. String to Int)
|
||||
const DataTypePtr & column_type = data.sharding_key_expr->getSampleBlock().getByName(sharding_column_name).type;
|
||||
/// Implicit conversion.
|
||||
sharding_column_value = convertFieldToType(sharding_column_value, *data.sharding_key_type);
|
||||
column_value = convertFieldToType(column_value, *column_type);
|
||||
|
||||
/// NULL is not allowed in sharding key,
|
||||
/// so it should be safe to assume that shard cannot contain it.
|
||||
if (sharding_column_value.isNull())
|
||||
if (column_value.isNull())
|
||||
return false;
|
||||
|
||||
Field sharding_value = executeFunctionOnField(
|
||||
sharding_column_value, sharding_column_name,
|
||||
data.sharding_key_expr, data.sharding_key_type,
|
||||
column_value, sharding_column_name,
|
||||
data.sharding_key_expr, column_type,
|
||||
data.sharding_key_column_name);
|
||||
/// The value from IN can be non-numeric,
|
||||
/// but in this case it should be convertible to numeric type, let's try.
|
||||
|
@ -28,8 +28,6 @@ struct OptimizeShardingKeyRewriteInMatcher
|
||||
{
|
||||
/// Expression of sharding_key for the Distributed() table
|
||||
const ExpressionActionsPtr & sharding_key_expr;
|
||||
/// Type of sharding_key column.
|
||||
const DataTypePtr & sharding_key_type;
|
||||
/// Name of the column for sharding_expr
|
||||
const std::string & sharding_key_column_name;
|
||||
/// Info for the current shard (to compare shard_num with calculated)
|
||||
|
Loading…
Reference in New Issue
Block a user