diff --git a/ydb/core/kqp/opt/physical/effects/kqp_opt_phy_vector_index.cpp b/ydb/core/kqp/opt/physical/effects/kqp_opt_phy_vector_index.cpp index 748198e630f9..97d544bf4a8e 100644 --- a/ydb/core/kqp/opt/physical/effects/kqp_opt_phy_vector_index.cpp +++ b/ydb/core/kqp/opt/physical/effects/kqp_opt_phy_vector_index.cpp @@ -263,13 +263,20 @@ TExprBase BuildVectorIndexPrefixRows(const TKikimrTableDescription& table, const auto mapLambda = Build(ctx, pos) .Args({lookupArg}) - .Body() - .Add(MakeColumnGetters(leftRow, postingColumns, pos, ctx)) - .Add() - .Name().Build(NTableIndex::NKMeans::ParentColumn) - .template Value() - .Struct().Optional(rightRow).Build() - .Name().Build(NTableIndex::NKMeans::IdColumn) + .Body() + .Predicate() + .Optional(rightRow) + .Build() + .Value() + .Input() + .Add(MakeColumnGetters(leftRow, postingColumns, pos, ctx)) + .Add() + .Name().Build(NTableIndex::NKMeans::ParentColumn) + .template Value() + .Struct().Optional(rightRow).Build() + .Name().Build(NTableIndex::NKMeans::IdColumn) + .Build() + .Build() .Build() .Build() .Build() @@ -282,7 +289,7 @@ TExprBase BuildVectorIndexPrefixRows(const TKikimrTableDescription& table, const .Program() .Args({"rows"}) .Body() - .Input() + .Input() .Input("rows") .Lambda(mapLambda) .Build() diff --git a/ydb/core/kqp/ut/indexes/kqp_indexes_prefixed_vector_ut.cpp b/ydb/core/kqp/ut/indexes/kqp_indexes_prefixed_vector_ut.cpp index 6d3d035482a0..7a572bd7957d 100644 --- a/ydb/core/kqp/ut/indexes/kqp_indexes_prefixed_vector_ut.cpp +++ b/ydb/core/kqp/ut/indexes/kqp_indexes_prefixed_vector_ut.cpp @@ -763,6 +763,45 @@ Y_UNIT_TEST_SUITE(KqpPrefixedVectorIndexes) { DoTestPrefixedVectorIndexUpdateClusterChange(Q_(R"(UPSERT INTO `/Root/TestTable` (`pk`, `user`, `emb`, `data`) VALUES (91, "user_a", "\x03\x31\x03", "19") RETURNING `data`, `emb`, `user`, `pk`;)"), true, Covered); } + Y_UNIT_TEST(PrefixedVectorIndexIgnoreNewPrefix) { + NKikimrConfig::TFeatureFlags featureFlags; + featureFlags.SetEnableVectorIndex(true); + auto setting = NKikimrKqp::TKqpSetting(); + auto serverSettings = TKikimrSettings() + .SetFeatureFlags(featureFlags) + .SetKqpSettings({setting}); + + TKikimrRunner kikimr(serverSettings); + kikimr.GetTestServer().GetRuntime()->SetLogPriority(NKikimrServices::BUILD_INDEX, NActors::NLog::PRI_TRACE); + kikimr.GetTestServer().GetRuntime()->SetLogPriority(NKikimrServices::FLAT_TX_SCHEMESHARD, NActors::NLog::PRI_TRACE); + + auto db = kikimr.GetTableClient(); + + auto session = DoCreateTableForPrefixedVectorIndex(db, false); + DoCreatePrefixedVectorIndex(session, false, "", 2); + + const TString originalPostingTable = ReadTablePartToYson(session, "/Root/TestTable/index/indexImplPostingTable"); + const TString originalPrefixTable = ReadTablePartToYson(session, "/Root/TestTable/index/indexImplPrefixTable"); + + // Insert to the table with index should succeed + { + TString query1(Q_(R"( + INSERT INTO `/Root/TestTable` (pk, user, emb, data) VALUES + (101, "user_d", "\x03\x29\x03", "101") + )")); + + auto result = session.ExecuteDataQuery(query1, TTxControl::BeginTx(TTxSettings::SerializableRW()).CommitTx()) + .ExtractValueSync(); + UNIT_ASSERT(result.IsSuccess()); + } + + // Index is not updated + const TString postingTable1_ins = ReadTablePartToYson(session, "/Root/TestTable/index/indexImplPostingTable"); + UNIT_ASSERT_STRINGS_EQUAL(originalPostingTable, postingTable1_ins); + const TString prefixTable1_ins = ReadTablePartToYson(session, "/Root/TestTable/index/indexImplPrefixTable"); + UNIT_ASSERT_STRINGS_EQUAL(originalPrefixTable, prefixTable1_ins); + } + } }