diff options
author | ssmike <ssmike@ydb.tech> | 2023-05-16 16:02:57 +0300 |
---|---|---|
committer | ssmike <ssmike@ydb.tech> | 2023-05-16 16:02:57 +0300 |
commit | 795c2e84c391ffc80b4e79935f114604e76421ee (patch) | |
tree | 9ca30d50f515f8aff2b8b896379d28b83d2bada9 | |
parent | d30ab3560c33768daaadea9752ec15dc11490dd5 (diff) | |
download | ydb-795c2e84c391ffc80b4e79935f114604e76421ee.tar.gz |
fix plans with empty keys
3 files changed, 80 insertions, 4 deletions
diff --git a/ydb/core/kqp/opt/kqp_query_plan.cpp b/ydb/core/kqp/opt/kqp_query_plan.cpp index ef3638024f..8e75bbd911 100644 --- a/ydb/core/kqp/opt/kqp_query_plan.cpp +++ b/ydb/core/kqp/opt/kqp_query_plan.cpp @@ -580,6 +580,20 @@ private: } } + TString DescribeValue(const NKikimr::NClient::TValue& value) { + auto str = value.GetDataText(); + switch (value.GetType().GetData().GetScheme()) { + case NScheme::NTypeIds::Utf8: + case NScheme::NTypeIds::Json: + case NScheme::NTypeIds::String: + case NScheme::NTypeIds::String4k: + case NScheme::NTypeIds::String2m: + return "«" + str + "»"; + default: + return str; + } + } + void Visit(const TKqpReadRangesSourceSettings& sourceSettings, TQueryPlanNode& planNode) { if (sourceSettings.RangesExpr().Maybe<TKqlKeyRange>()) { auto table = TString(sourceSettings.Table().Path()); @@ -599,7 +613,7 @@ private: if (auto result = GetResult(txId, resId)) { auto index = FromString<ui32>(key.Cast<TCoNth>().Index()); Y_ENSURE(index < result->Size()); - return (*result)[index].GetDataText(); + return DescribeValue((*result)[index]); } } } @@ -1301,7 +1315,7 @@ private: if (auto result = GetResult(txId, resId)) { auto index = FromString<ui32>(key.Cast<TCoNth>().Index()); Y_ENSURE(index < result->Size()); - return (*result)[index].GetDataText(); + return DescribeValue((*result)[index]); } } } diff --git a/ydb/core/kqp/ut/query/kqp_explain_ut.cpp b/ydb/core/kqp/ut/query/kqp_explain_ut.cpp index a669187a79..3b74b0e4ca 100644 --- a/ydb/core/kqp/ut/query/kqp_explain_ut.cpp +++ b/ydb/core/kqp/ut/query/kqp_explain_ut.cpp @@ -39,6 +39,25 @@ void CreateSampleTables(TKikimrRunner& kikimr) { UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString()); + AssertSuccessResult(session.ExecuteSchemeQuery(R"( + --!syntax_v1 + + CREATE TABLE `/Root/test_table_idx_idx` ( + str_field String, + complex_field Uint64, + id Uint64, + PRIMARY KEY (str_field, complex_field) + ); + + CREATE TABLE `/Root/test_table_idx` ( + id Uint64, + complex_field Uint64, + str_field String, + Value String, + PRIMARY KEY (id) + ); + )").GetValueSync()); + session.Close(); } @@ -281,7 +300,7 @@ Y_UNIT_TEST_SUITE(KqpExplain) { auto& lookup = operators[lookupMember].GetMapSafe(); UNIT_ASSERT(lookup.at("Name") == "TablePointLookup"); - UNIT_ASSERT(lookup.at("ReadRange").GetArraySafe()[0] == "App (new_app_1)"); + UNIT_ASSERT_VALUES_EQUAL(lookup.at("ReadRange").GetArraySafe()[0], "App («new_app_1»)"); } Y_UNIT_TEST(SortStage) { @@ -845,6 +864,49 @@ Y_UNIT_TEST_SUITE(KqpExplain) { } } } + + Y_UNIT_TEST_TWIN(IdxFullscan, Source) { + TKikimrSettings settings; + NKikimrConfig::TAppConfig appConfig; + appConfig.MutableTableServiceConfig()->SetEnableKqpDataQuerySourceRead(Source); + settings.SetDomainRoot(KikimrDefaultUtDomainRoot); + settings.SetAppConfig(appConfig); + + TKikimrRunner kikimr(settings); + CreateSampleTables(kikimr); + + auto db = kikimr.GetTableClient(); + auto session = db.CreateSession().GetValueSync().GetSession(); + + auto res = session.ExplainDataQuery(R"( + PRAGMA kikimr.OptEnablePredicateExtract = 'true'; + SELECT t.* + FROM + (SELECT * FROM `/Root/test_table_idx_idx` + WHERE `str_field` is NULL + ) as idx + INNER JOIN + `/Root/test_table_idx` AS t + USING (`id`) + )").GetValueSync(); + + UNIT_ASSERT_C(res.IsSuccess(), res.GetIssues().ToString()); + auto strPlan = res.GetPlan(); + UNIT_ASSERT(strPlan); + + Cerr << strPlan << Endl; + + NJson::TJsonValue plan; + NJson::ReadJsonTree(strPlan, &plan, true); + UNIT_ASSERT(ValidatePlanNodeIds(plan)); + + auto fullscan = FindPlanNodeByKv( + plan, + "Name", + "TableFullScan" + ); + UNIT_ASSERT(!fullscan.IsDefined()); + } } } // namespace NKqp diff --git a/ydb/tests/functional/canonical/canondata/test_sql.TestCanonicalFolder1.test_case_pk_predicate_pk_predicate_null.sql-plan_/pk_predicate_pk_predicate_null.sql.plan b/ydb/tests/functional/canonical/canondata/test_sql.TestCanonicalFolder1.test_case_pk_predicate_pk_predicate_null.sql-plan_/pk_predicate_pk_predicate_null.sql.plan index c37cc68559..498cef25f8 100644 --- a/ydb/tests/functional/canonical/canondata/test_sql.TestCanonicalFolder1.test_case_pk_predicate_pk_predicate_null.sql-plan_/pk_predicate_pk_predicate_null.sql.plan +++ b/ydb/tests/functional/canonical/canondata/test_sql.TestCanonicalFolder1.test_case_pk_predicate_pk_predicate_null.sql-plan_/pk_predicate_pk_predicate_null.sql.plan @@ -19,7 +19,7 @@ "Group (0)" ], "scan_by": [ - "Name (-\u221e, Name2)" + "Name (-\u221e, \u00abName2\u00bb)" ], "type": "Lookup" } |