diff options
author | aidarsamer <aidarsamer@ydb.tech> | 2023-01-24 14:26:35 +0300 |
---|---|---|
committer | aidarsamer <aidarsamer@ydb.tech> | 2023-01-24 14:26:35 +0300 |
commit | f472affccc4bcf066a6b6adbaf896c74050ac6ea (patch) | |
tree | 01c32baa0d237c32c8c4ec5b0fe519c02436b1cf | |
parent | d8d5df1f1fe0d30fad1e8509f13ebf6e2cfde43c (diff) | |
download | ydb-f472affccc4bcf066a6b6adbaf896c74050ac6ea.tar.gz |
Fix filter pushdown when not all used fields in query are in SELECT clause
-rw-r--r-- | ydb/core/kqp/opt/physical/kqp_opt_phy_olap_filter.cpp | 42 | ||||
-rw-r--r-- | ydb/core/kqp/ut/olap/kqp_olap_ut.cpp | 13 |
2 files changed, 28 insertions, 27 deletions
diff --git a/ydb/core/kqp/opt/physical/kqp_opt_phy_olap_filter.cpp b/ydb/core/kqp/opt/physical/kqp_opt_phy_olap_filter.cpp index c28405ed7d..677b334f0f 100644 --- a/ydb/core/kqp/opt/physical/kqp_opt_phy_olap_filter.cpp +++ b/ydb/core/kqp/opt/physical/kqp_opt_phy_olap_filter.cpp @@ -50,40 +50,28 @@ bool ValidateIfArgument(const TCoOptionalIf& optionalIf, const TExprNode* rawLam return true; } - // Ok, maybe it is SELECT `field` ? + // Ok, maybe it is SELECT `field1`, `field2` ? auto maybeAsStruct = optionalIf.Value().Maybe<TCoAsStruct>(); - if (!maybeAsStruct) { return false; } - auto asStruct = maybeAsStruct.Cast(); - - // SELECT `field` has only one item - if (asStruct.ArgCount() > 1) { - return false; - } else if (asStruct.ArgCount() == 0) { - // In case of COUNT(*) we use empty AsStruct - return true; - } - - // Check that second tuple element is Member(lambda arg) - auto tuple = asStruct.Arg(0).Maybe<TExprList>().Cast(); - - if (tuple.Size() != 2) { - return false; - } - - auto maybeMember = tuple.Item(1).Maybe<TCoMember>(); - - if (!maybeMember) { - return false; - } + for (auto arg : maybeAsStruct.Cast()) { + // Check that second tuple element is Member(lambda arg) + auto tuple = arg.Maybe<TExprList>().Cast(); + if (tuple.Size() != 2) { + return false; + } - auto member = maybeMember.Cast(); + auto maybeMember = tuple.Item(1).Maybe<TCoMember>(); + if (!maybeMember) { + return false; + } - if (member.Struct().Raw() != rawLambdaArg) { - return false; + auto member = maybeMember.Cast(); + if (member.Struct().Raw() != rawLambdaArg) { + return false; + } } return true; diff --git a/ydb/core/kqp/ut/olap/kqp_olap_ut.cpp b/ydb/core/kqp/ut/olap/kqp_olap_ut.cpp index 2f01118c1d..657cbda1c8 100644 --- a/ydb/core/kqp/ut/olap/kqp_olap_ut.cpp +++ b/ydb/core/kqp/ut/olap/kqp_olap_ut.cpp @@ -1715,6 +1715,19 @@ Y_UNIT_TEST_SUITE(KqpOlap) { } } + Y_UNIT_TEST(Filter_NotAllUsedFieldsInSelectClause) { + TAggregationTestCase testCase; + testCase.SetQuery(R"( + SELECT id, resource_id FROM `/Root/tableWithNulls` + WHERE + level = 5; + )") + .SetExpectedReply("[[[5];#]]") + .AddExpectedPlanOptions("KqpOlapFilter"); + + TestTableWithNulls({ testCase }); + } + Y_UNIT_TEST(Aggregation_ResultDistinctCountRI_GroupByL) { TAggregationTestCase testCase; testCase.SetQuery(R"( |