blob: d546db40df7407b48b1b660ee7caabe186fcab23 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#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
{
/// 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)
const Cluster::ShardInfo & shard_info;
/// weight -> shard mapping
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>;
}
|