Skip to content

Commit a27ab2e

Browse files
authored
[yt provider] Bypass YtCopy before YtLength (#11436)
1 parent a7178b2 commit a27ab2e

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

ydb/library/yql/providers/yt/provider/yql_yt_physical_finalizing.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class TYtPhysicalFinalizingTransformer : public TSyncTransformerBase {
182182
}
183183

184184
if (!disableOptimizers.contains("BypassMergeBeforeLength")) {
185-
status = BypassMergeBeforeLength(input, output, opDeps, lefts, ctx);
185+
status = BypassMergeOrCopyBeforeLength(input, output, opDeps, lefts, ctx);
186186
if (status.Level != TStatus::Ok) {
187187
return status;
188188
}
@@ -1610,33 +1610,35 @@ class TYtPhysicalFinalizingTransformer : public TSyncTransformerBase {
16101610
return lambda;
16111611
}
16121612

1613-
TStatus BypassMergeBeforeLength(TExprNode::TPtr input, TExprNode::TPtr& output, const TOpDeps& opDeps, const TNodeSet& lefts, TExprContext& ctx) {
1613+
TStatus BypassMergeOrCopyBeforeLength(TExprNode::TPtr input, TExprNode::TPtr& output, const TOpDeps& opDeps, const TNodeSet& lefts, TExprContext& ctx) {
16141614
TNodeOnNodeOwnedMap replaces;
16151615
for (auto& x: opDeps) {
1616-
if (TYtMerge::Match(x.first) && x.second.size() > 0 && AllOf(x.second, [](const auto& item) { return TYtLength::Match(std::get<0>(item)); } )) {
1617-
auto merge = TYtMerge(x.first);
1618-
if (merge.Ref().HasResult()) {
1616+
if ((TYtMerge::Match(x.first) || TYtCopy::Match(x.first)) && x.second.size() > 0 && AllOf(x.second, [](const auto& item) { return TYtLength::Match(std::get<0>(item)); } )) {
1617+
auto op = TYtTransientOpBase(x.first);
1618+
if (op.Ref().HasResult()) {
16191619
continue;
16201620
}
16211621

1622-
if (NYql::HasSetting(merge.Settings().Ref(), EYtSettingType::Limit)) {
1623-
continue;
1624-
}
1622+
auto section = op.Input().Item(0);
1623+
if (op.Maybe<TYtMerge>()) {
1624+
if (NYql::HasSetting(op.Settings().Ref(), EYtSettingType::Limit)) {
1625+
continue;
1626+
}
16251627

1626-
auto section = merge.Input().Item(0);
1627-
if (NYql::HasAnySetting(section.Settings().Ref(), EYtSettingType::Take | EYtSettingType::Skip | EYtSettingType::Sample)) {
1628-
continue;
1629-
}
1630-
if (NYql::HasNonEmptyKeyFilter(section)) {
1631-
continue;
1632-
}
1628+
if (NYql::HasAnySetting(section.Settings().Ref(), EYtSettingType::Take | EYtSettingType::Skip | EYtSettingType::Sample)) {
1629+
continue;
1630+
}
1631+
if (NYql::HasNonEmptyKeyFilter(section)) {
1632+
continue;
1633+
}
16331634

1634-
if (AnyOf(section.Paths(), [](const TYtPath& path) { return !path.Ranges().Maybe<TCoVoid>() || TYtTableBaseInfo::GetMeta(path.Table())->IsDynamic; })) {
1635-
continue;
1636-
}
1637-
// Dependency on more than 1 operation
1638-
if (1 < Accumulate(section.Paths(), 0ull, [](ui64 val, const TYtPath& path) { return val + path.Table().Maybe<TYtOutput>().IsValid(); })) {
1639-
continue;
1635+
if (AnyOf(section.Paths(), [](const TYtPath& path) { return !path.Ranges().Maybe<TCoVoid>() || TYtTableBaseInfo::GetMeta(path.Table())->IsDynamic; })) {
1636+
continue;
1637+
}
1638+
// Dependency on more than 1 operation
1639+
if (1 < Accumulate(section.Paths(), 0ull, [](ui64 val, const TYtPath& path) { return val + path.Table().Maybe<TYtOutput>().IsValid(); })) {
1640+
continue;
1641+
}
16401642
}
16411643

16421644
TSyncMap syncList;
@@ -1645,10 +1647,10 @@ class TYtPhysicalFinalizingTransformer : public TSyncTransformerBase {
16451647
syncList.emplace(GetOutputOp(out.Cast()).Ptr(), syncList.size());
16461648
}
16471649
}
1648-
auto newWorld = ApplySyncListToWorld(merge.World().Ptr(), syncList, ctx);
1650+
auto newWorld = ApplySyncListToWorld(op.World().Ptr(), syncList, ctx);
16491651
for (auto node: lefts) {
16501652
TCoLeft left(node);
1651-
if (left.Input().Raw() == merge.Raw()) {
1653+
if (left.Input().Raw() == op.Raw()) {
16521654
replaces[node] = newWorld;
16531655
}
16541656
}
@@ -1695,7 +1697,7 @@ class TYtPhysicalFinalizingTransformer : public TSyncTransformerBase {
16951697
}
16961698

16971699
if (!replaces.empty()) {
1698-
YQL_CLOG(INFO, ProviderYt) << "PhysicalFinalizing-BypassMergeBeforeLength";
1700+
YQL_CLOG(INFO, ProviderYt) << "PhysicalFinalizing-BypassMergeOrCopyBeforeLength";
16991701
return RemapExpr(input, output, replaces, ctx, TOptimizeExprSettings(State_->Types));
17001702
}
17011703

0 commit comments

Comments
 (0)