@@ -38,6 +38,74 @@ bool IsStreamLookup(const TCoEquiJoinTuple& joinTuple) {
38
38
39
39
}
40
40
41
+ /* *
42
+ * DQ Specific cost function and join applicability cost function
43
+ */
44
+ struct TDqCBOProviderContext : public NYql ::TBaseProviderContext {
45
+ TDqCBOProviderContext (TTypeAnnotationContext& typeCtx, const TDqConfiguration::TPtr& config)
46
+ : NYql::TBaseProviderContext()
47
+ , Config(config)
48
+ , TypesCtx(typeCtx) {}
49
+
50
+ virtual bool IsJoinApplicable (const std::shared_ptr<NYql::IBaseOptimizerNode>& left,
51
+ const std::shared_ptr<NYql::IBaseOptimizerNode>& right,
52
+ const std::set<std::pair<NYql::NDq::TJoinColumn, NYql::NDq::TJoinColumn>>& joinConditions,
53
+ const TVector<TString>& leftJoinKeys, const TVector<TString>& rightJoinKeys,
54
+ NYql::EJoinAlgoType joinAlgo, NYql::EJoinKind joinKind) override ;
55
+
56
+ virtual double ComputeJoinCost (const NYql::TOptimizerStatistics& leftStats, const NYql::TOptimizerStatistics& rightStats, const double outputRows, const double outputByteSize, NYql::EJoinAlgoType joinAlgo) const override ;
57
+
58
+ TDqConfiguration::TPtr Config;
59
+ TTypeAnnotationContext& TypesCtx;
60
+ };
61
+
62
+
63
+ bool TDqCBOProviderContext::IsJoinApplicable (const std::shared_ptr<NYql::IBaseOptimizerNode>& left,
64
+ const std::shared_ptr<NYql::IBaseOptimizerNode>& right,
65
+ const std::set<std::pair<NYql::NDq::TJoinColumn, NYql::NDq::TJoinColumn>>& joinConditions,
66
+ const TVector<TString>& leftJoinKeys, const TVector<TString>& rightJoinKeys,
67
+ NYql::EJoinAlgoType joinAlgo, NYql::EJoinKind joinKind) {
68
+ Y_UNUSED (left);
69
+ Y_UNUSED (right);
70
+ Y_UNUSED (joinConditions);
71
+ Y_UNUSED (leftJoinKeys);
72
+ Y_UNUSED (rightJoinKeys);
73
+
74
+ switch (joinAlgo) {
75
+
76
+ case EJoinAlgoType::MapJoin:
77
+ if (joinKind == EJoinKind::OuterJoin || joinKind == EJoinKind::Exclusion)
78
+ return false ;
79
+ if (auto hashJoinMode = Config->HashJoinMode .Get ().GetOrElse (EHashJoinMode::Off);
80
+ hashJoinMode == EHashJoinMode::Off || hashJoinMode == EHashJoinMode::Map)
81
+ return true ;
82
+ break ;
83
+
84
+ case EJoinAlgoType::GraceJoin:
85
+ return true ;
86
+
87
+ default :
88
+ break ;
89
+ }
90
+ return false ;
91
+ }
92
+
93
+
94
+ double TDqCBOProviderContext::ComputeJoinCost (const TOptimizerStatistics& leftStats, const TOptimizerStatistics& rightStats, const double outputRows, const double outputByteSize, EJoinAlgoType joinAlgo) const {
95
+ Y_UNUSED (outputByteSize);
96
+
97
+ switch (joinAlgo) {
98
+ case EJoinAlgoType::MapJoin:
99
+ return 1.5 * (leftStats.Nrows + 1.8 * rightStats.Nrows + outputRows);
100
+ case EJoinAlgoType::GraceJoin:
101
+ return 1.5 * (leftStats.Nrows + 2.0 * rightStats.Nrows + outputRows);
102
+ default :
103
+ Y_ENSURE (false , " Illegal join type encountered" );
104
+ return 0 ;
105
+ }
106
+ }
107
+
108
+
41
109
class TDqsLogicalOptProposalTransformer : public TOptimizeTransformerBase {
42
110
public:
43
111
TDqsLogicalOptProposalTransformer (TTypeAnnotationContext* typeCtx, const TDqConfiguration::TPtr& config)
@@ -206,7 +274,7 @@ class TDqsLogicalOptProposalTransformer : public TOptimizeTransformerBase {
206
274
};
207
275
208
276
std::unique_ptr<IOptimizerNew> opt;
209
- TBaseProviderContext pctx;
277
+ TDqCBOProviderContext pctx (TypesCtx, Config) ;
210
278
211
279
switch (TypesCtx.CostBasedOptimizer ) {
212
280
case ECostBasedOptimizerType::Native:
0 commit comments