summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvvvv <[email protected]>2025-06-16 19:45:49 +0300
committervvvv <[email protected]>2025-06-16 20:23:32 +0300
commit8de8ac27d1347542272117ba36a37762f57c467a (patch)
tree45560879678d56372b130ca2b687f669d55dd44a
parentbcbebc88fecedccc6267457436865fc7c082a433 (diff)
YQL-20079 drop optimizer
commit_hash:c94ae2e1918d822a6a01192bc2e42d668cf16b4d
-rw-r--r--yql/essentials/core/peephole_opt/yql_opt_peephole_physical.cpp74
-rw-r--r--yql/essentials/tests/sql/minirun/part0/canondata/result.json14
-rw-r--r--yql/essentials/tests/sql/sql2yql/canondata/result.json12
-rw-r--r--yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_optimizers-YQL-20079_/formatted.sql8
-rw-r--r--yql/essentials/tests/sql/suites/optimizers/YQL-20079.sql4
5 files changed, 38 insertions, 74 deletions
diff --git a/yql/essentials/core/peephole_opt/yql_opt_peephole_physical.cpp b/yql/essentials/core/peephole_opt/yql_opt_peephole_physical.cpp
index 78a084422c7..eff04076764 100644
--- a/yql/essentials/core/peephole_opt/yql_opt_peephole_physical.cpp
+++ b/yql/essentials/core/peephole_opt/yql_opt_peephole_physical.cpp
@@ -3612,78 +3612,6 @@ TExprNode::TPtr ExpandAsSet(const TExprNode::TPtr& node, TExprContext& ctx) {
.Build();
}
-ui32 GetCommonPartWidth(const TExprNode& lhs, const TExprNode& rhs) {
- ui32 c = 0U;
- while (c < lhs.ChildrenSize() && c < rhs.ChildrenSize() && lhs.Child(c) == rhs.Child(c)) {
- ++c;
- }
- return c;
-}
-
-template<bool AndOr>
-TExprNode::TPtr OptimizeLogicalDups(const TExprNode::TPtr& node, TExprContext& ctx) {
- auto children = node->ChildrenList();
- const auto opposite = AndOr ? "Or" : "And";
- for (auto curr = children.begin(); children.cend() != curr;) {
- if (const auto next = curr + 1U; children.cend() != next) {
- if ((*curr)->IsCallable(opposite) && (*next)->IsCallable(opposite)) {
- if (const auto common = GetCommonPartWidth(**curr, **next)) {
- if ((*next)->ChildrenSize() == common) {
- curr = children.erase(curr);
- } else if ((*curr)->ChildrenSize() == common) {
- children.erase(next);
- } else {
- auto childrenOne = (*curr)->ChildrenList();
- auto childrenTwo = (*next)->ChildrenList();
-
- TExprNode::TListType newChildren(common + 1U);
- std::move(childrenOne.begin(), childrenOne.begin() + common, newChildren.begin());
-
- childrenOne.erase(childrenOne.cbegin(), childrenOne.cbegin() + common);
- childrenTwo.erase(childrenTwo.cbegin(), childrenTwo.cbegin() + common);
-
- auto one = 1U == childrenOne.size() ? std::move(childrenOne.front()) : ctx.ChangeChildren(**curr, std::move(childrenOne));
- auto two = 1U == childrenTwo.size() ? std::move(childrenTwo.front()) : ctx.ChangeChildren(**next, std::move(childrenTwo));
-
- newChildren.back() = ctx.ChangeChildren(*node, {std::move(one), std::move(two)});
- *curr = ctx.ChangeChildren(**curr, std::move(newChildren));
- children.erase(next);
- }
- continue;
- }
- } else if ((*curr)->IsCallable(opposite) && &(*curr)->Head() == next->Get()) {
- curr = children.erase(curr);
- continue;
- } else if ((*next)->IsCallable(opposite) && &(*next)->Head() == curr->Get()) {
- children.erase(next);
- continue;
- } else if ((*curr)->IsCallable() && (*next)->IsCallable() && (*curr)->Content() == (*next)->Content()
- && ((*next)->Content().ends_with("Map") || ((*curr)->IsCallable("IfPresent") && &(*curr)->Tail() == &(*next)->Tail()))
- && &(*curr)->Head() == &(*next)->Head()) {
- auto lambda = ctx.Builder(node->Pos())
- .Lambda()
- .Param("arg")
- .Callable(node->Content())
- .Apply(0, *(*curr)->Child(1U)).With(0, "arg").Seal()
- .Apply(1, *(*next)->Child(1U)).With(0, "arg").Seal()
- .Seal()
- .Seal().Build();
- *curr = ctx.ChangeChild(**curr, 1U, std::move(lambda));
- children.erase(next);
- continue;
- }
- }
- ++curr;
- }
-
- if (children.size() < node->ChildrenSize()) {
- YQL_CLOG(DEBUG, CorePeepHole) << "Dedup " << node->ChildrenSize() - children.size() << " common parts of " << opposite << "'s under " << node->Content();
- return 1U == children.size() ? children.front() : ctx.ChangeChildren(*node, std::move(children));
- }
-
- return node;
-}
-
TExprNode::TPtr ExpandCombineByKey(const TExprNode::TPtr& node, TExprContext& ctx) {
const bool isStreamOrFlow = node->GetTypeAnn()->GetKind() == ETypeAnnotationKind::Stream ||
node->GetTypeAnn()->GetKind() == ETypeAnnotationKind::Flow;
@@ -9025,8 +8953,6 @@ struct TPeepHoleRules {
{"AggrMax", &ExpandAggrMinMax<false>},
{"Min", &ExpandMinMax},
{"Max", &ExpandMinMax},
- {"And", &OptimizeLogicalDups<true>},
- {"Or", &OptimizeLogicalDups<false>},
{"CombineByKey", &ExpandCombineByKey},
{"FinalizeByKey", &ExpandFinalizeByKey},
{"SkipNullMembers", &ExpandSkipNullFields},
diff --git a/yql/essentials/tests/sql/minirun/part0/canondata/result.json b/yql/essentials/tests/sql/minirun/part0/canondata/result.json
index 52d9fa7481b..faa30df1fe6 100644
--- a/yql/essentials/tests/sql/minirun/part0/canondata/result.json
+++ b/yql/essentials/tests/sql/minirun/part0/canondata/result.json
@@ -820,6 +820,20 @@
"uri": "https://{canondata_backend}/1942100/6ea7bdc94febc162c165c9eafba66d971745efa9/resource.tar.gz#test.test_match_recognize-test_type-default.txt-Results_/results.txt"
}
],
+ "test.test[optimizers-YQL-20079-default.txt-Debug]": [
+ {
+ "checksum": "2ca6dbe9b3b3d8fb0758f4466476a534",
+ "size": 473,
+ "uri": "https://{canondata_backend}/1925842/088a4fd339648a5b7675bfce9241140c058f3615/resource.tar.gz#test.test_optimizers-YQL-20079-default.txt-Debug_/opt.yql"
+ }
+ ],
+ "test.test[optimizers-YQL-20079-default.txt-Results]": [
+ {
+ "checksum": "56de73c873cafff267843da0d2621330",
+ "size": 889,
+ "uri": "https://{canondata_backend}/1925842/088a4fd339648a5b7675bfce9241140c058f3615/resource.tar.gz#test.test_optimizers-YQL-20079-default.txt-Results_/results.txt"
+ }
+ ],
"test.test[optimizers-or_absorption--Debug]": [
{
"checksum": "634f82b790060e433dfd0d9004cb899d",
diff --git a/yql/essentials/tests/sql/sql2yql/canondata/result.json b/yql/essentials/tests/sql/sql2yql/canondata/result.json
index a7a91b348f2..029d804ed93 100644
--- a/yql/essentials/tests/sql/sql2yql/canondata/result.json
+++ b/yql/essentials/tests/sql/sql2yql/canondata/result.json
@@ -4479,6 +4479,13 @@
"uri": "https://{canondata_backend}/937458/48f7c08aeea2b81122c2d3efab2783a2c7764b0a/resource.tar.gz#test_sql2yql.test_match_recognize-test_type_predicate_/sql.yql"
}
],
+ "test_sql2yql.test[optimizers-YQL-20079]": [
+ {
+ "checksum": "8c025af66ed8641331d4183d44f1066a",
+ "size": 1783,
+ "uri": "https://{canondata_backend}/1946324/f43579d53a31be3a89dd101f779698a4a507e4eb/resource.tar.gz#test_sql2yql.test_optimizers-YQL-20079_/sql.yql"
+ }
+ ],
"test_sql2yql.test[optimizers-and_absorption]": [
{
"checksum": "342629f3c35c2da10e66658b50f1bdbd",
@@ -10731,6 +10738,11 @@
"uri": "file://test_sql_format.test_match_recognize-test_type_predicate_/formatted.sql"
}
],
+ "test_sql_format.test[optimizers-YQL-20079]": [
+ {
+ "uri": "file://test_sql_format.test_optimizers-YQL-20079_/formatted.sql"
+ }
+ ],
"test_sql_format.test[optimizers-and_absorption]": [
{
"uri": "file://test_sql_format.test_optimizers-and_absorption_/formatted.sql"
diff --git a/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_optimizers-YQL-20079_/formatted.sql b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_optimizers-YQL-20079_/formatted.sql
new file mode 100644
index 00000000000..2d636deeb86
--- /dev/null
+++ b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_optimizers-YQL-20079_/formatted.sql
@@ -0,0 +1,8 @@
+SELECT
+ x IS NOT NULL
+ OR (x IS NOT NULL AND y)
+FROM (
+ SELECT
+ Opaque(just(1)) AS x,
+ Opaque(just(TRUE)) AS y
+);
diff --git a/yql/essentials/tests/sql/suites/optimizers/YQL-20079.sql b/yql/essentials/tests/sql/suites/optimizers/YQL-20079.sql
new file mode 100644
index 00000000000..b16c6ce3d83
--- /dev/null
+++ b/yql/essentials/tests/sql/suites/optimizers/YQL-20079.sql
@@ -0,0 +1,4 @@
+select x is not null or
+(x is not null and y)
+from (select Opaque(just(1)) as x, Opaque(just(true)) as y)
+