Skip to content

Commit 460c850

Browse files
authored
[25-3-1] Ignore new prefixes during prefixed vector index update (#28134)
2 parents f75c208 + b095972 commit 460c850

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

ydb/core/kqp/opt/physical/effects/kqp_opt_phy_vector_index.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,20 @@ TExprBase BuildVectorIndexPrefixRows(const TKikimrTableDescription& table, const
263263

264264
auto mapLambda = Build<TCoLambda>(ctx, pos)
265265
.Args({lookupArg})
266-
.Body<TCoAsStruct>()
267-
.Add(MakeColumnGetters(leftRow, postingColumns, pos, ctx))
268-
.Add<TCoNameValueTuple>()
269-
.Name().Build(NTableIndex::NKMeans::ParentColumn)
270-
.template Value<TCoMember>()
271-
.Struct<TCoUnwrap>().Optional(rightRow).Build()
272-
.Name().Build(NTableIndex::NKMeans::IdColumn)
266+
.Body<TCoFlatOptionalIf>()
267+
.Predicate<TCoExists>()
268+
.Optional(rightRow)
269+
.Build()
270+
.Value<TCoJust>()
271+
.Input<TCoAsStruct>()
272+
.Add(MakeColumnGetters(leftRow, postingColumns, pos, ctx))
273+
.Add<TCoNameValueTuple>()
274+
.Name().Build(NTableIndex::NKMeans::ParentColumn)
275+
.template Value<TCoMember>()
276+
.Struct<TCoUnwrap>().Optional(rightRow).Build()
277+
.Name().Build(NTableIndex::NKMeans::IdColumn)
278+
.Build()
279+
.Build()
273280
.Build()
274281
.Build()
275282
.Build()
@@ -282,7 +289,7 @@ TExprBase BuildVectorIndexPrefixRows(const TKikimrTableDescription& table, const
282289
.Program()
283290
.Args({"rows"})
284291
.Body<TCoToStream>()
285-
.Input<TCoMap>()
292+
.Input<TCoFlatMap>()
286293
.Input("rows")
287294
.Lambda(mapLambda)
288295
.Build()

ydb/core/kqp/ut/indexes/kqp_indexes_prefixed_vector_ut.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,45 @@ Y_UNIT_TEST_SUITE(KqpPrefixedVectorIndexes) {
763763
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);
764764
}
765765

766+
Y_UNIT_TEST(PrefixedVectorIndexIgnoreNewPrefix) {
767+
NKikimrConfig::TFeatureFlags featureFlags;
768+
featureFlags.SetEnableVectorIndex(true);
769+
auto setting = NKikimrKqp::TKqpSetting();
770+
auto serverSettings = TKikimrSettings()
771+
.SetFeatureFlags(featureFlags)
772+
.SetKqpSettings({setting});
773+
774+
TKikimrRunner kikimr(serverSettings);
775+
kikimr.GetTestServer().GetRuntime()->SetLogPriority(NKikimrServices::BUILD_INDEX, NActors::NLog::PRI_TRACE);
776+
kikimr.GetTestServer().GetRuntime()->SetLogPriority(NKikimrServices::FLAT_TX_SCHEMESHARD, NActors::NLog::PRI_TRACE);
777+
778+
auto db = kikimr.GetTableClient();
779+
780+
auto session = DoCreateTableForPrefixedVectorIndex(db, false);
781+
DoCreatePrefixedVectorIndex(session, false, "", 2);
782+
783+
const TString originalPostingTable = ReadTablePartToYson(session, "/Root/TestTable/index/indexImplPostingTable");
784+
const TString originalPrefixTable = ReadTablePartToYson(session, "/Root/TestTable/index/indexImplPrefixTable");
785+
786+
// Insert to the table with index should succeed
787+
{
788+
TString query1(Q_(R"(
789+
INSERT INTO `/Root/TestTable` (pk, user, emb, data) VALUES
790+
(101, "user_d", "\x03\x29\x03", "101")
791+
)"));
792+
793+
auto result = session.ExecuteDataQuery(query1, TTxControl::BeginTx(TTxSettings::SerializableRW()).CommitTx())
794+
.ExtractValueSync();
795+
UNIT_ASSERT(result.IsSuccess());
796+
}
797+
798+
// Index is not updated
799+
const TString postingTable1_ins = ReadTablePartToYson(session, "/Root/TestTable/index/indexImplPostingTable");
800+
UNIT_ASSERT_STRINGS_EQUAL(originalPostingTable, postingTable1_ins);
801+
const TString prefixTable1_ins = ReadTablePartToYson(session, "/Root/TestTable/index/indexImplPrefixTable");
802+
UNIT_ASSERT_STRINGS_EQUAL(originalPrefixTable, prefixTable1_ins);
803+
}
804+
766805
}
767806

768807
}

0 commit comments

Comments
 (0)