Skip to content

Commit a7a5bcf

Browse files
committed
Do not perform FuseEquiJoins opt when called from peephole
commit_hash:9909fd2bda625151a5763f049f0fdf99e9246b8d
1 parent a07e3cc commit a7a5bcf

File tree

7 files changed

+27
-20
lines changed

7 files changed

+27
-20
lines changed

yql/essentials/core/common_opt/yql_co.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace NYql {
1010
struct TOptimizeContext {
1111
TTypeAnnotationContext* Types = nullptr;
1212
TParentsMap* ParentsMap = nullptr;
13+
bool ForPeephole = false;
1314

1415
const TExprNode* GetParentIfSingle(const TExprNode& node) const {
1516
YQL_ENSURE(ParentsMap);

yql/essentials/core/common_opt/yql_co_flow2.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,15 +2000,18 @@ void RegisterCoFlowCallables2(TCallableOptimizerMap& map) {
20002000
};
20012001

20022002
map["EquiJoin"] = [](const TExprNode::TPtr& node, TExprContext& ctx, TOptimizeContext& optCtx) {
2003-
ui32 inputsCount = node->ChildrenSize() - 2;
2004-
for (ui32 i = 0; i < inputsCount; ++i) {
2005-
if (node->Child(i)->Child(0)->IsCallable("EquiJoin") &&
2006-
optCtx.IsSingleUsage(*node->Child(i)) &&
2007-
optCtx.IsSingleUsage(*node->Child(i)->Child(0))) {
2008-
auto ret = FuseEquiJoins(node, i, ctx);
2009-
if (ret != node) {
2010-
YQL_CLOG(DEBUG, Core) << "FuseEquiJoins";
2011-
return ret;
2003+
if (!optCtx.ForPeephole) {
2004+
// Peephole splits EquiJoin to pairs, so we don't perform FuseEquiJoin here
2005+
ui32 inputsCount = node->ChildrenSize() - 2;
2006+
for (ui32 i = 0; i < inputsCount; ++i) {
2007+
if (node->Child(i)->Child(0)->IsCallable("EquiJoin") &&
2008+
optCtx.IsSingleUsage(*node->Child(i)) &&
2009+
optCtx.IsSingleUsage(*node->Child(i)->Child(0))) {
2010+
auto ret = FuseEquiJoins(node, i, ctx);
2011+
if (ret != node) {
2012+
YQL_CLOG(DEBUG, Core) << "FuseEquiJoins";
2013+
return ret;
2014+
}
20122015
}
20132016
}
20142017
}

yql/essentials/core/common_opt/yql_co_transformer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ namespace {
2222

2323
class TCommonOptTransformer final : public TSyncTransformerBase {
2424
public:
25-
TCommonOptTransformer(TTypeAnnotationContext* typeCtx, bool final)
25+
TCommonOptTransformer(TTypeAnnotationContext* typeCtx, bool final, bool forPeephole)
2626
: TypeCtx(typeCtx)
2727
, Final(final)
28+
, ForPeephole(forPeephole)
2829
{}
2930

3031
IGraphTransformer::TStatus DoTransform(TExprNode::TPtr input, TExprNode::TPtr& output, TExprContext& ctx) final;
@@ -47,17 +48,18 @@ class TCommonOptTransformer final : public TSyncTransformerBase {
4748
THashSet<TIssue> AddedErrors;
4849
TTypeAnnotationContext* TypeCtx;
4950
const bool Final;
51+
const bool ForPeephole;
5052
bool CheckMissingWorld = false;
5153
};
5254

5355
}
5456

55-
TAutoPtr<IGraphTransformer> CreateCommonOptTransformer(TTypeAnnotationContext* typeCtx) {
56-
return new TCommonOptTransformer(typeCtx, false);
57+
TAutoPtr<IGraphTransformer> CreateCommonOptTransformer(bool forPeephole, TTypeAnnotationContext* typeCtx) {
58+
return new TCommonOptTransformer(typeCtx, false, forPeephole);
5759
}
5860

5961
TAutoPtr<IGraphTransformer> CreateCommonOptFinalTransformer(TTypeAnnotationContext* typeCtx) {
60-
return new TCommonOptTransformer(typeCtx, true);
62+
return new TCommonOptTransformer(typeCtx, true, false);
6163
}
6264

6365
IGraphTransformer::TStatus TCommonOptTransformer::DoTransform(TExprNode::TPtr input, TExprNode::TPtr& output, TExprContext& ctx) {
@@ -148,6 +150,7 @@ IGraphTransformer::TStatus TCommonOptTransformer::DoTransform(
148150
TParentsMap parentsMap;
149151
TOptimizeContext optCtx;
150152
optCtx.Types = TypeCtx;
153+
optCtx.ForPeephole = ForPeephole;
151154
if (withParents) {
152155
GatherParents(*input, parentsMap);
153156
optCtx.ParentsMap = &parentsMap;

yql/essentials/core/common_opt/yql_co_transformer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace NYql {
1010

11-
TAutoPtr<IGraphTransformer> CreateCommonOptTransformer(TTypeAnnotationContext* typeCtx);
11+
TAutoPtr<IGraphTransformer> CreateCommonOptTransformer(bool forPeephole, TTypeAnnotationContext* typeCtx);
1212
TAutoPtr<IGraphTransformer> CreateCommonOptFinalTransformer(TTypeAnnotationContext* typeCtx);
1313

1414
}

yql/essentials/core/peephole_opt/yql_opt_peephole_physical.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9108,7 +9108,7 @@ THolder<IGraphTransformer> CreatePeepHoleCommonStageTransformer(TTypeAnnotationC
91089108

91099109
auto issueCode = TIssuesIds::CORE_EXEC;
91109110

9111-
pipeline.AddCommonOptimization(issueCode);
9111+
pipeline.AddCommonOptimization(true, issueCode);
91129112
pipeline.Add(CreateFunctorTransformer(
91139113
[&types](const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) {
91149114
return PeepHoleCommonStage(input, output, ctx, types,

yql/essentials/core/services/yql_transform_pipeline.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ TTransformationPipeline& TTransformationPipeline::AddPostTypeAnnotation(bool for
137137
return *this;
138138
}
139139

140-
TTransformationPipeline& TTransformationPipeline::AddCommonOptimization(EYqlIssueCode issueCode) {
140+
TTransformationPipeline& TTransformationPipeline::AddCommonOptimization(bool forPeephole, EYqlIssueCode issueCode) {
141141
// auto instantCallableTransformer =
142142
// CreateExtCallableTypeAnnotationTransformer(*TypeAnnotationContext_, true);
143143
// TypeAnnotationContext_->CustomInstantTypeTransformer =
144144
// CreateTypeAnnotationTransformer(instantCallableTransformer, *TypeAnnotationContext_);
145145
Transformers_.push_back(TTransformStage(
146-
CreateCommonOptTransformer(TypeAnnotationContext_.Get()),
146+
CreateCommonOptTransformer(forPeephole, TypeAnnotationContext_.Get()),
147147
"CommonOptimization",
148148
issueCode));
149149
return *this;
@@ -158,7 +158,7 @@ TTransformationPipeline& TTransformationPipeline::AddFinalCommonOptimization(EYq
158158
}
159159

160160
TTransformationPipeline& TTransformationPipeline::AddOptimization(bool checkWorld, bool withFinalOptimization, EYqlIssueCode issueCode) {
161-
AddCommonOptimization(issueCode);
161+
AddCommonOptimization(false, issueCode);
162162
Transformers_.push_back(TTransformStage(
163163
CreateChoiceGraphTransformer(
164164
[&typesCtx = std::as_const(*TypeAnnotationContext_)](const TExprNode::TPtr&, TExprContext&) {
@@ -199,7 +199,7 @@ TTransformationPipeline& TTransformationPipeline::AddOptimization(bool checkWorl
199199
}
200200

201201
TTransformationPipeline& TTransformationPipeline::AddLineageOptimization(TMaybe<TString>& lineageOut, EYqlIssueCode issueCode) {
202-
AddCommonOptimization(issueCode);
202+
AddCommonOptimization(false, issueCode);
203203
Transformers_.push_back(TTransformStage(
204204
CreateFunctorTransformer(
205205
[typeCtx = TypeAnnotationContext_, &lineageOut](const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) {

yql/essentials/core/services/yql_transform_pipeline.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class TTransformationPipeline
3232
TTransformationPipeline& AddIOAnnotation(bool withEpochsTransformer = true, EYqlIssueCode issueCode = TIssuesIds::CORE_PRE_TYPE_ANN);
3333
TTransformationPipeline& AddTypeAnnotation(EYqlIssueCode issueCode = TIssuesIds::CORE_TYPE_ANN, bool twoStages = false);
3434
TTransformationPipeline& AddPostTypeAnnotation(bool forSubGraph = false, bool disableConstraintCheck = false, EYqlIssueCode issueCode = TIssuesIds::CORE_POST_TYPE_ANN);
35-
TTransformationPipeline& AddCommonOptimization(EYqlIssueCode issueCode = TIssuesIds::CORE_OPTIMIZATION);
35+
TTransformationPipeline& AddCommonOptimization(bool forPeephole = false, EYqlIssueCode issueCode = TIssuesIds::CORE_OPTIMIZATION);
3636
TTransformationPipeline& AddFinalCommonOptimization(EYqlIssueCode issueCode = TIssuesIds::CORE_OPTIMIZATION);
3737
TTransformationPipeline& AddOptimization(bool checkWorld = true, bool withFinalOptimization = true, EYqlIssueCode issueCode = TIssuesIds::CORE_OPTIMIZATION);
3838
TTransformationPipeline& AddLineageOptimization(TMaybe<TString>& lineageOut, EYqlIssueCode issueCode = TIssuesIds::CORE_OPTIMIZATION);

0 commit comments

Comments
 (0)