diff options
author | vpolka <vpolka@yandex-team.com> | 2023-07-11 15:32:01 +0300 |
---|---|---|
committer | vpolka <vpolka@yandex-team.com> | 2023-07-11 15:32:01 +0300 |
commit | 765740530ffb3fc45a4621fea927d01f233811ac (patch) | |
tree | 52d55e21171f24fcdceb519ede9b10831bd70142 | |
parent | 64294550656395357c20ecd69f1a7f1855958914 (diff) | |
download | ydb-765740530ffb3fc45a4621fea927d01f233811ac.tar.gz |
Fix full scan in scan query with LIKE. (KIKIMR-18592)
-rw-r--r-- | ydb/core/kqp/opt/logical/kqp_opt_log_ranges_predext.cpp | 1 | ||||
-rw-r--r-- | ydb/core/kqp/ut/scan/kqp_scan_ut.cpp | 51 |
2 files changed, 52 insertions, 0 deletions
diff --git a/ydb/core/kqp/opt/logical/kqp_opt_log_ranges_predext.cpp b/ydb/core/kqp/opt/logical/kqp_opt_log_ranges_predext.cpp index a50e4881ded..fc9cc2c70f6 100644 --- a/ydb/core/kqp/opt/logical/kqp_opt_log_ranges_predext.cpp +++ b/ydb/core/kqp/opt/logical/kqp_opt_log_ranges_predext.cpp @@ -215,6 +215,7 @@ TExprBase KqpPushExtractedPredicateToReadTable(TExprBase node, TExprContext& ctx THashSet<TString> possibleKeys; TPredicateExtractorSettings settings; settings.MergeAdjacentPointRanges = true; + settings.HaveNextValueCallable = true; auto extractor = MakePredicateRangeExtractor(settings); YQL_ENSURE(tableDesc.SchemeNode); diff --git a/ydb/core/kqp/ut/scan/kqp_scan_ut.cpp b/ydb/core/kqp/ut/scan/kqp_scan_ut.cpp index 98a25b8114f..52b8ec45bb7 100644 --- a/ydb/core/kqp/ut/scan/kqp_scan_ut.cpp +++ b/ydb/core/kqp/ut/scan/kqp_scan_ut.cpp @@ -2415,6 +2415,57 @@ Y_UNIT_TEST_SUITE(KqpScan) { auto limit = FindPlanNodeByKv(indexRead, "Limit", "2"); UNIT_ASSERT(limit.IsDefined()); } + + Y_UNIT_TEST(Like) { + TKikimrRunner kikimr; + auto db = kikimr.GetTableClient(); + auto session = db.CreateSession().GetValueSync().GetSession(); + NYdb::NScripting::TScriptingClient client(kikimr.GetDriver()); + + { + auto result = session.ExecuteSchemeQuery(R"( + CREATE TABLE `/Root/TestTable` ( + Key Utf8, + Value Utf8, + PRIMARY KEY (Key) + ); + )").GetValueSync(); + UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString()); + + result = session.ExecuteDataQuery(R"( + REPLACE INTO `/Root/TestTable` (Key, Value) VALUES + ('SomeString1', '100'), + ('SomeString2', '200'), + ('SomeString3', '300'), + ('SomeString4', '400'), + ('SomeString5', '500'), + ('SomeString6', '600'), + ('SomeString7', '700'), + ('SomeString8', '800'); + )", TTxControl::BeginTx().CommitTx()).GetValueSync(); + UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString()); + } + + TStreamExecScanQuerySettings querySettings; + querySettings.Explain(true); + auto it = db.StreamExecuteScanQuery(R"( + SELECT * FROM `/Root/TestTable` WHERE Key like "SomeString%"; + )", querySettings).GetValueSync(); + UNIT_ASSERT_C(it.IsSuccess(), it.GetIssues().ToString()); + + auto res = CollectStreamResult(it); + UNIT_ASSERT(res.PlanJson); + NJson::TJsonValue plan; + NJson::ReadJsonTree(*res.PlanJson, &plan, true); + + UNIT_ASSERT_VALUES_EQUAL(plan["tables"].GetArray().size(), 1); + UNIT_ASSERT_VALUES_EQUAL(plan["tables"][0]["name"], "/Root/TestTable"); + UNIT_ASSERT_VALUES_EQUAL(plan["tables"][0]["reads"].GetArray().size(), 1); + auto& read = plan["tables"][0]["reads"][0]; + UNIT_ASSERT_VALUES_EQUAL(read["type"], "Scan"); + UNIT_ASSERT_VALUES_EQUAL(read["scan_by"].GetArray().size(), 1); + UNIT_ASSERT_VALUES_EQUAL(read["scan_by"][0], "Key [SomeString, SomeStrinh)"); + } } } // namespace NKqp |