diff options
author | udovichenko-r <udovichenko-r@yandex-team.ru> | 2022-02-16 02:26:19 +0300 |
---|---|---|
committer | udovichenko-r <udovichenko-r@yandex-team.ru> | 2022-02-16 02:26:19 +0300 |
commit | 414d86e47571a9a5e9ef80cfc28f2a7facc32623 (patch) | |
tree | cf87a1ef85b6a05b67760b86567469b02e447b79 | |
parent | 1de3c666314929ac9afa4646b07acd822fcd8baf (diff) | |
download | ydb-414d86e47571a9a5e9ef80cfc28f2a7facc32623.tar.gz |
[yql] Core optimizers to remove sort in SqlIn/ToOptional
YQL-14369
ref:70a02a8e8042d22181f14297633c8ca1bf15f55d
-rw-r--r-- | ydb/library/yql/core/common_opt/yql_co_simple1.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/ydb/library/yql/core/common_opt/yql_co_simple1.cpp b/ydb/library/yql/core/common_opt/yql_co_simple1.cpp index a32a6c3dab..7a7fe75545 100644 --- a/ydb/library/yql/core/common_opt/yql_co_simple1.cpp +++ b/ydb/library/yql/core/common_opt/yql_co_simple1.cpp @@ -1178,7 +1178,7 @@ TExprNode::TPtr OptimizeFlatContainerIf(const TExprNode::TPtr& node, TExprContex return node; } -template <bool HeadOrTail> +template <bool HeadOrTail, bool OrderAware = true> TExprNode::TPtr OptimizeToOptional(const TExprNode::TPtr& node, TExprContext& ctx) { if (node->Head().IsCallable("ToList")) { YQL_CLOG(DEBUG, Core) << node->Content() << " over " << node->Head().Content(); @@ -1196,6 +1196,13 @@ TExprNode::TPtr OptimizeToOptional(const TExprNode::TPtr& node, TExprContext& ct return ctx.NewCallable(node->Head().Pos(), "Nothing", {ExpandType(node->Pos(), *node->GetTypeAnn(), ctx)}); } + if constexpr (!OrderAware) { + if (node->Head().GetConstraint<TSortedConstraintNode>()) { + YQL_CLOG(DEBUG, Core) << node->Content() << " over sorted collection"; + return ctx.ChangeChild(*node, 0, ctx.NewCallable(node->Head().Pos(), "Unordered", {node->HeadPtr()})); + } + } + return node; } @@ -3706,6 +3713,11 @@ void RegisterCoSimpleCallables1(TCallableOptimizerMap& map) { } } + if (collectionKind == ETypeAnnotationKind::List && collection->GetConstraint<TSortedConstraintNode>()) { + YQL_CLOG(DEBUG, Core) << "IN over sorted collection"; + return ctx.ChangeChild(*node, 0, ctx.NewCallable(collection->Pos(), "Unordered", {collection})); + } + return node; }; @@ -4304,7 +4316,7 @@ void RegisterCoSimpleCallables1(TCallableOptimizerMap& map) { return node; }; - map["ToOptional"] = std::bind(OptimizeToOptional<true>, _1, _2); + map["ToOptional"] = std::bind(OptimizeToOptional<true, false>, _1, _2); map["Head"] = std::bind(OptimizeToOptional<true>, _1, _2); map["Last"] = std::bind(OptimizeToOptional<false>, _1, _2); |