Skip to content

Commit 315f35f

Browse files
author
pudge1000-7
committed
[CBO] Add Bytes hints
commit_hash:5b4543a711fae95d2b84490c37ff427fabae3e32
1 parent 55c54f1 commit 315f35f

File tree

3 files changed

+70
-8
lines changed

3 files changed

+70
-8
lines changed

yql/essentials/core/cbo/cbo_hints.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ class TOptimizerHintsParser {
2929
private:
3030
void Start() {
3131
while (Pos_ < Size_) {
32-
auto hintType = Keyword({"JoinOrder", "Leading", "JoinType", "Rows"});
32+
auto hintType = Keyword({"JoinOrder", "Leading", "JoinType", "Rows", "Bytes"});
3333
if (hintType == "JoinOrder" || hintType == "Leading") {
3434
JoinOrder(hintType == "Leading");
3535
} else if (hintType == "JoinType") {
3636
JoinType();
37-
} else if (hintType == "Rows"){
38-
Rows();
37+
} else if (hintType == "Rows") {
38+
CardinalityOrBytes(true);
39+
} else if (hintType == "Bytes") {
40+
CardinalityOrBytes(false);
3941
} else {
4042
ParseError(Sprintf("Undefined hints type: %s", hintType.c_str()), Pos_ - hintType.size());
4143
}
@@ -113,7 +115,7 @@ class TOptimizerHintsParser {
113115
Y_UNREACHABLE();
114116
}
115117

116-
void Rows() {
118+
void CardinalityOrBytes(bool isRows) {
117119
i32 beginPos = Pos_ + 1;
118120

119121
Keyword({"("});
@@ -134,7 +136,11 @@ class TOptimizerHintsParser {
134136
default: {ParseError(Sprintf("Unknown operation: '%c'", sign), Pos_ - 1); Y_UNREACHABLE();}
135137
}
136138

137-
Hints_.CardinalityHints->PushBack(std::move(labels), op, value, "Rows" + Text_.substr(beginPos, Pos_ - beginPos + 1));
139+
if (isRows) {
140+
Hints_.CardinalityHints->PushBack(std::move(labels), op, value, "Rows" + Text_.substr(beginPos, Pos_ - beginPos + 1));
141+
} else {
142+
Hints_.BytesHints->PushBack(std::move(labels), op, value, "Bytes" + Text_.substr(beginPos, Pos_ - beginPos + 1));
143+
}
138144
}
139145

140146
private:

yql/essentials/core/cbo/cbo_optimizer_new.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,28 @@ TOptimizerStatistics TBaseProviderContext::ComputeJoinStatsV1(
194194
return stats;
195195
}
196196

197+
TOptimizerStatistics TBaseProviderContext::ComputeJoinStatsV2(
198+
const TOptimizerStatistics& leftStats,
199+
const TOptimizerStatistics& rightStats,
200+
const TVector<NDq::TJoinColumn>& leftJoinKeys,
201+
const TVector<NDq::TJoinColumn>& rightJoinKeys,
202+
EJoinAlgoType joinAlgo,
203+
EJoinKind joinKind,
204+
TCardinalityHints::TCardinalityHint* maybeHint,
205+
bool shuffleLeftSide,
206+
bool shuffleRightSide,
207+
TCardinalityHints::TCardinalityHint* maybeBytesHint
208+
) const {
209+
210+
auto stats = ComputeJoinStatsV1(leftStats, rightStats, leftJoinKeys, rightJoinKeys, joinAlgo, joinKind, maybeHint, shuffleLeftSide, shuffleRightSide);
211+
212+
if (maybeBytesHint) {
213+
stats.ByteSize = maybeBytesHint->ApplyHint(stats.ByteSize);
214+
}
215+
216+
return stats;
217+
}
218+
197219
/**
198220
* Compute the cost and output cardinality of a join
199221
*
@@ -338,6 +360,12 @@ TVector<TString> TOptimizerHints::GetUnappliedString() {
338360
}
339361
}
340362

363+
for (const auto& hint: BytesHints->Hints) {
364+
if (!hint.Applied) {
365+
res.push_back(hint.StringRepr);
366+
}
367+
}
368+
341369
return res;
342370
}
343371

yql/essentials/core/cbo/cbo_optimizer_new.h

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,19 @@ struct TJoinOrderHints {
175175
};
176176

177177
struct TOptimizerHints {
178+
std::shared_ptr<TCardinalityHints> BytesHints = std::make_shared<TCardinalityHints>();
178179
std::shared_ptr<TCardinalityHints> CardinalityHints = std::make_shared<TCardinalityHints>();
179180
std::shared_ptr<TJoinAlgoHints> JoinAlgoHints = std::make_shared<TJoinAlgoHints>();
180181
std::shared_ptr<TJoinOrderHints> JoinOrderHints = std::make_shared<TJoinOrderHints>();
181182

182183
TVector<TString> GetUnappliedString();
183184

184185
/*
185-
* The function accepts string with three type of expressions: array of (JoinAlgo | Card | JoinOrder):
186+
* The function accepts string with four type of expressions: array of (JoinAlgo | Rows | Bytes | JoinOrder):
186187
* 1) JoinAlgo(t1 t2 ... tn Map | Grace | Lookup) to change join algo for join, where these labels take part
187-
* 2) Card(t1 t2 ... tn (*|/|+|-) Number) to change cardinality for join, where these labels take part or labels only
188-
* 3) JoinOrder( (t1 t2) (t3 (t4 ...)) ) - fixate this join subtree in the general join tree
188+
* 2) Rows(t1 t2 ... tn (*|/|+|-|#) Number) to change cardinality for join, where these labels take part or labels only
189+
* 3) Bytes(t1 t2 ... tn (*|/|+|-|#) Number) to change byte size for join, where these labels take part or labels only
190+
* 4) JoinOrder( (t1 t2) (t3 (t4 ...)) ) - fixate this join subtree in the general join tree
189191
*/
190192
static TOptimizerHints Parse(const TString&);
191193
};
@@ -228,6 +230,19 @@ struct IProviderContext {
228230
bool shuffleRightSide
229231
) const = 0;
230232

233+
virtual TOptimizerStatistics ComputeJoinStatsV2(
234+
const TOptimizerStatistics& leftStats,
235+
const TOptimizerStatistics& rightStats,
236+
const TVector<NDq::TJoinColumn>& leftJoinKeys,
237+
const TVector<NDq::TJoinColumn>& rightJoinKeys,
238+
EJoinAlgoType joinAlgo,
239+
EJoinKind joinKind,
240+
TCardinalityHints::TCardinalityHint* maybeHint,
241+
bool shuffleLeftSide,
242+
bool shuffleRightSide,
243+
TCardinalityHints::TCardinalityHint* maybeBytesHint
244+
) const = 0;
245+
231246
virtual bool IsJoinApplicable(const std::shared_ptr<IBaseOptimizerNode>& left,
232247
const std::shared_ptr<IBaseOptimizerNode>& right,
233248
const TVector<NDq::TJoinColumn>& leftJoinKeys,
@@ -283,6 +298,19 @@ struct TBaseProviderContext : public IProviderContext {
283298
bool shuffleRightSide
284299
) const override;
285300

301+
TOptimizerStatistics ComputeJoinStatsV2(
302+
const TOptimizerStatistics& leftStats,
303+
const TOptimizerStatistics& rightStats,
304+
const TVector<NDq::TJoinColumn>& leftJoinKeys,
305+
const TVector<NDq::TJoinColumn>& rightJoinKeys,
306+
EJoinAlgoType joinAlgo,
307+
EJoinKind joinKind,
308+
TCardinalityHints::TCardinalityHint* maybeHint,
309+
bool shuffleLeftSide,
310+
bool shuffleRightSide,
311+
TCardinalityHints::TCardinalityHint* maybeBytesHint
312+
) const override;
313+
286314
static const TBaseProviderContext& Instance();
287315
};
288316

0 commit comments

Comments
 (0)