Skip to content

Commit

Permalink
Dont consider prefix indices (#12315) (#12345)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssmike authored Dec 6, 2024
1 parent e6410e1 commit 21bf5e0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
15 changes: 15 additions & 0 deletions ydb/core/kqp/opt/logical/kqp_opt_log_ranges_predext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,21 @@ TExprBase KqpPushExtractedPredicateToReadTable(TExprBase node, TExprContext& ctx
for (auto& index : mainTableDesc.Metadata->Indexes) {
if (index.Type != TIndexDescription::EType::GlobalAsync && index.State == TIndexDescription::EIndexState::Ready) {
auto& tableDesc = kqpCtx.Tables->ExistingTable(kqpCtx.Cluster, mainTableDesc.Metadata->GetIndexMetadata(TString(index.Name)).first->Name);

bool uselessIndex = true;
for (size_t i = 0; i < mainTableDesc.Metadata->KeyColumnNames.size(); ++i) {
if (i >= tableDesc.Metadata->KeyColumnNames.size()) {
break;
}
if (mainTableDesc.Metadata->KeyColumnNames[i] != tableDesc.Metadata->KeyColumnNames[i]) {
uselessIndex = false;
break;
}
}
if (uselessIndex) {
continue;
}

auto buildResult = extractor->BuildComputeNode(tableDesc.Metadata->KeyColumnNames, ctx, typesCtx);
bool needsJoin = calcNeedsJoin(tableDesc.Metadata);

Expand Down
15 changes: 14 additions & 1 deletion ydb/core/kqp/ut/opt/kqp_ne_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4137,8 +4137,10 @@ Y_UNIT_TEST_SUITE(KqpNewEngine) {
Key Int32,
Fk Int32,
Value String,
Value2 String,
PRIMARY KEY (Key, Fk),
INDEX Index GLOBAL ON (Value)
INDEX Index GLOBAL ON (Value),
INDEX ByPk GLOBAL ON (Key)
);
)").GetValueSync());

Expand Down Expand Up @@ -4167,6 +4169,17 @@ Y_UNIT_TEST_SUITE(KqpNewEngine) {
)", TTxControl::BeginTx(TTxSettings::SerializableRW()), querySettings).GetValueSync();
AssertSuccessResult(result);
AssertTableReads(result, "/Root/ComplexKey", 2);

result = session.ExecuteDataQuery(R"(
--!syntax_v1
SELECT Key, Fk, Value FROM `/Root/ComplexKey`
WHERE Key = 2
ORDER BY Value DESC, Value2 DESC
LIMIT 1;
)", TTxControl::BeginTx(TTxSettings::SerializableRW()), querySettings).GetValueSync();
AssertSuccessResult(result);
AssertTableReads(result, "/Root/ComplexKey", 2);
AssertTableReads(result, "/Root/ComplexKey/ByPk/indexImplTable", 0);
}

Y_UNIT_TEST(MultipleBroadcastJoin) {
Expand Down

0 comments on commit 21bf5e0

Please sign in to comment.