2021-03-07 15:51:01 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Interpreters/InDepthNodeVisitor.h>
|
|
|
|
#include <Interpreters/Cluster.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class ExpressionActions;
|
|
|
|
using ExpressionActionsPtr = std::shared_ptr<ExpressionActions>;
|
|
|
|
|
|
|
|
class ASTFunction;
|
|
|
|
|
|
|
|
/// Rewrite `sharding_key IN (...)` for specific shard,
|
|
|
|
/// so that it will contain only values that belong to this specific shard.
|
|
|
|
///
|
|
|
|
/// See also:
|
|
|
|
/// - evaluateExpressionOverConstantCondition()
|
|
|
|
/// - StorageDistributed::createSelector()
|
|
|
|
/// - createBlockSelector()
|
|
|
|
struct OptimizeShardingKeyRewriteInMatcher
|
|
|
|
{
|
|
|
|
/// Cluster::SlotToShard
|
|
|
|
using SlotToShard = std::vector<UInt64>;
|
|
|
|
|
|
|
|
struct Data
|
|
|
|
{
|
2021-06-28 18:55:30 +00:00
|
|
|
/// Expression of sharding_key for the Distributed() table
|
2021-03-07 15:51:01 +00:00
|
|
|
const ExpressionActionsPtr & sharding_key_expr;
|
2021-06-28 18:55:30 +00:00
|
|
|
/// Type of sharding_key column.
|
|
|
|
const DataTypePtr & sharding_key_type;
|
|
|
|
/// Name of the column for sharding_expr
|
2021-03-07 15:51:01 +00:00
|
|
|
const std::string & sharding_key_column_name;
|
2021-06-28 18:55:30 +00:00
|
|
|
/// Info for the current shard (to compare shard_num with calculated)
|
2021-03-07 15:51:01 +00:00
|
|
|
const Cluster::ShardInfo & shard_info;
|
2021-06-28 18:55:30 +00:00
|
|
|
/// weight -> shard mapping
|
2021-03-07 15:51:01 +00:00
|
|
|
const Cluster::SlotToShard & slots;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool needChildVisit(ASTPtr & /*node*/, const ASTPtr & /*child*/);
|
|
|
|
static void visit(ASTPtr & node, Data & data);
|
|
|
|
static void visit(ASTFunction & function, Data & data);
|
|
|
|
};
|
|
|
|
|
|
|
|
using OptimizeShardingKeyRewriteInVisitor = InDepthNodeVisitor<OptimizeShardingKeyRewriteInMatcher, true>;
|
|
|
|
|
|
|
|
}
|