Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions ydb/core/kqp/opt/physical/effects/kqp_opt_phy_vector_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,20 @@ TExprBase BuildVectorIndexPrefixRows(const TKikimrTableDescription& table, const

auto mapLambda = Build<TCoLambda>(ctx, pos)
.Args({lookupArg})
.Body<TCoAsStruct>()
.Add(MakeColumnGetters(leftRow, postingColumns, pos, ctx))
.Add<TCoNameValueTuple>()
.Name().Build(NTableIndex::NKMeans::ParentColumn)
.template Value<TCoMember>()
.Struct<TCoUnwrap>().Optional(rightRow).Build()
.Name().Build(NTableIndex::NKMeans::IdColumn)
.Body<TCoFlatOptionalIf>()
.Predicate<TCoExists>()
.Optional(rightRow)
.Build()
.Value<TCoJust>()
.Input<TCoAsStruct>()
.Add(MakeColumnGetters(leftRow, postingColumns, pos, ctx))
.Add<TCoNameValueTuple>()
.Name().Build(NTableIndex::NKMeans::ParentColumn)
.template Value<TCoMember>()
.Struct<TCoUnwrap>().Optional(rightRow).Build()
.Name().Build(NTableIndex::NKMeans::IdColumn)
.Build()
.Build()
.Build()
.Build()
.Build()
Expand All @@ -282,7 +289,7 @@ TExprBase BuildVectorIndexPrefixRows(const TKikimrTableDescription& table, const
.Program()
.Args({"rows"})
.Body<TCoToStream>()
.Input<TCoMap>()
.Input<TCoFlatMap>()
.Input("rows")
.Lambda(mapLambda)
.Build()
Expand Down
39 changes: 39 additions & 0 deletions ydb/core/kqp/ut/indexes/kqp_indexes_prefixed_vector_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

}
Expand Down
Loading