From a445d9702742b1b7dcb9ddeed0ed69acbbd63292 Mon Sep 17 00:00:00 2001 From: Andrey Neporada Date: Sat, 2 Nov 2024 12:33:31 +0300 Subject: [PATCH] Backport #11203 (#11210) --- .../provider/phy_opt/yql_yt_phy_opt_merge.cpp | 6 +++++- .../tests/sql/sql2yql/canondata/result.json | 14 +++++++++++++ .../sql/suites/key_filter/no_bypass_merge.cfg | 3 +++ .../sql/suites/key_filter/no_bypass_merge.sql | 8 +++++++ .../part17/canondata/result.json | 21 +++++++++++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 ydb/library/yql/tests/sql/suites/key_filter/no_bypass_merge.cfg create mode 100644 ydb/library/yql/tests/sql/suites/key_filter/no_bypass_merge.sql diff --git a/ydb/library/yql/providers/yt/provider/phy_opt/yql_yt_phy_opt_merge.cpp b/ydb/library/yql/providers/yt/provider/phy_opt/yql_yt_phy_opt_merge.cpp index 77d65d129337..184bf55baffc 100644 --- a/ydb/library/yql/providers/yt/provider/phy_opt/yql_yt_phy_opt_merge.cpp +++ b/ydb/library/yql/providers/yt/provider/phy_opt/yql_yt_phy_opt_merge.cpp @@ -60,6 +60,7 @@ TMaybeNode TYtPhysicalOptProposalTransformer::BypassMerge(TExprBase n for (auto path: section.Paths()) { updatedPaths.push_back(path); + bool hasRanges = false; if (!path.Ranges().Maybe()) { bool pathLimits = false; for (auto range: path.Ranges().Cast()) { @@ -67,6 +68,9 @@ TMaybeNode TYtPhysicalOptProposalTransformer::BypassMerge(TExprBase n pathLimits = true; break; } + if (range.Maybe()) { + hasRanges = true; + } } if (pathLimits) { continue; @@ -118,7 +122,7 @@ TMaybeNode TYtPhysicalOptProposalTransformer::BypassMerge(TExprBase n if (hasTakeSkip && sortedMerge && NYql::HasSetting(innerMerge.Settings().Ref(), EYtSettingType::KeepSorted)) { continue; } - if (hasTakeSkip && AnyOf(innerMergeSection.Paths(), [](const auto& path) { return !path.Ranges().template Maybe(); })) { + if ((hasTakeSkip || hasRanges) && AnyOf(innerMergeSection.Paths(), [](const auto& path) { return !path.Ranges().template Maybe(); })) { continue; } diff --git a/ydb/library/yql/tests/sql/sql2yql/canondata/result.json b/ydb/library/yql/tests/sql/sql2yql/canondata/result.json index 3b6ea98244f8..fb5692299e4d 100644 --- a/ydb/library/yql/tests/sql/sql2yql/canondata/result.json +++ b/ydb/library/yql/tests/sql/sql2yql/canondata/result.json @@ -10142,6 +10142,13 @@ "uri": "https://{canondata_backend}/1936947/659b615f15086142a8960946dabd06b519d43335/resource.tar.gz#test_sql2yql.test_key_filter-nile_pred_/sql.yql" } ], + "test_sql2yql.test[key_filter-no_bypass_merge]": [ + { + "checksum": "8f1e1bfb745fc93ab99799dd4bee37d2", + "size": 3234, + "uri": "https://{canondata_backend}/937458/29a3c1b9b216969a2d55da5642f70db3cb889590/resource.tar.gz#test_sql2yql.test_key_filter-no_bypass_merge_/sql.yql" + } + ], "test_sql2yql.test[key_filter-part_key_over_dynamic]": [ { "checksum": "ed0c681c0b57fd43338fa44f79dfcda3", @@ -29693,6 +29700,13 @@ "uri": "https://{canondata_backend}/1880306/64654158d6bfb1289c66c626a8162239289559d0/resource.tar.gz#test_sql_format.test_key_filter-nile_pred_/formatted.sql" } ], + "test_sql_format.test[key_filter-no_bypass_merge]": [ + { + "checksum": "c11c4aac4740bc96f1f16fc34273b3b5", + "size": 338, + "uri": "https://{canondata_backend}/1946324/60ea49a653935bd647f75184f5571f43eaea2f1e/resource.tar.gz#test_sql_format.test_key_filter-no_bypass_merge_/formatted.sql" + } + ], "test_sql_format.test[key_filter-part_key_over_dynamic]": [ { "checksum": "d0780baa61449d404c28577d330972b1", diff --git a/ydb/library/yql/tests/sql/suites/key_filter/no_bypass_merge.cfg b/ydb/library/yql/tests/sql/suites/key_filter/no_bypass_merge.cfg new file mode 100644 index 000000000000..18d60334088f --- /dev/null +++ b/ydb/library/yql/tests/sql/suites/key_filter/no_bypass_merge.cfg @@ -0,0 +1,3 @@ +in Input sorted2.txt +res result.txt +providers yt diff --git a/ydb/library/yql/tests/sql/suites/key_filter/no_bypass_merge.sql b/ydb/library/yql/tests/sql/suites/key_filter/no_bypass_merge.sql new file mode 100644 index 000000000000..431fbd30141a --- /dev/null +++ b/ydb/library/yql/tests/sql/suites/key_filter/no_bypass_merge.sql @@ -0,0 +1,8 @@ +/* ignore runonopt plan diff - extra LogicalOptimizer-PushdownOpColumns */ +pragma yt.PruneKeyFilterLambda = 'true'; + +USE plato; + +$src = select * from Input where key == "1" || "5" || "0"; +select key, subkey from $src; +select key, value from $src where key >= "000" and key < "999" and len(value) > 0; diff --git a/ydb/library/yql/tests/sql/yt_native_file/part17/canondata/result.json b/ydb/library/yql/tests/sql/yt_native_file/part17/canondata/result.json index e0639d2c0f66..d71adf5aa34a 100644 --- a/ydb/library/yql/tests/sql/yt_native_file/part17/canondata/result.json +++ b/ydb/library/yql/tests/sql/yt_native_file/part17/canondata/result.json @@ -1358,6 +1358,27 @@ "uri": "https://{canondata_backend}/1942415/9dc26178536314feaac77333a6a0e27c8703d1e2/resource.tar.gz#test.test_key_filter-multiusage--Results_/results.txt" } ], + "test.test[key_filter-no_bypass_merge--Debug]": [ + { + "checksum": "9efb0ce10102840559dccf5f29a12682", + "size": 2615, + "uri": "https://{canondata_backend}/1920236/8c593c8466092b61944efd67353210491ded1ec3/resource.tar.gz#test.test_key_filter-no_bypass_merge--Debug_/opt.yql" + } + ], + "test.test[key_filter-no_bypass_merge--Plan]": [ + { + "checksum": "00bc4300b735e6c0e3643be6c50db81d", + "size": 7695, + "uri": "https://{canondata_backend}/1920236/8c593c8466092b61944efd67353210491ded1ec3/resource.tar.gz#test.test_key_filter-no_bypass_merge--Plan_/plan.txt" + } + ], + "test.test[key_filter-no_bypass_merge--Results]": [ + { + "checksum": "d0d822f1bcf2596880c7df78329d0916", + "size": 2393, + "uri": "https://{canondata_backend}/1920236/8c593c8466092b61944efd67353210491ded1ec3/resource.tar.gz#test.test_key_filter-no_bypass_merge--Results_/results.txt" + } + ], "test.test[key_filter-string_with_legacy--Debug]": [ { "checksum": "c4cc2c1f00131d237cc8e804250ef355",