Skip to content

Commit 3745d96

Browse files
authored
Table with vector index is updatable but vector index is unchanged (#17358)
1 parent 0fbe2c4 commit 3745d96

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

ydb/core/kqp/provider/yql_kikimr_gateway.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ struct TIndexDescription {
203203
case EType::GlobalAsync:
204204
return false;
205205
case EType::GlobalSyncVectorKMeansTree:
206-
return true;
206+
return false;
207207
}
208208
}
209209

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,6 +3238,77 @@ Y_UNIT_TEST_SUITE(KqpIndexes) {
32383238
DoPositiveQueriesPrefixedVectorIndexOrderByCosine(session);
32393239
}
32403240

3241+
Y_UNIT_TEST(VectorIndexIsNotUpdatable) {
3242+
NKikimrConfig::TFeatureFlags featureFlags;
3243+
featureFlags.SetEnableVectorIndex(true);
3244+
auto setting = NKikimrKqp::TKqpSetting();
3245+
auto serverSettings = TKikimrSettings()
3246+
.SetFeatureFlags(featureFlags)
3247+
.SetKqpSettings({setting});
3248+
3249+
TKikimrRunner kikimr(serverSettings);
3250+
kikimr.GetTestServer().GetRuntime()->SetLogPriority(NKikimrServices::BUILD_INDEX, NActors::NLog::PRI_TRACE);
3251+
3252+
auto db = kikimr.GetTableClient();
3253+
auto session = DoCreateTableForVectorIndex(db, true);
3254+
3255+
// Add first index
3256+
{
3257+
const TString createIndex(Q_(R"(
3258+
ALTER TABLE `/Root/TestTable`
3259+
ADD INDEX index1
3260+
GLOBAL USING vector_kmeans_tree
3261+
ON (emb)
3262+
WITH (similarity=cosine, vector_type="uint8", vector_dimension=2, levels=2, clusters=2);
3263+
)"));
3264+
3265+
auto result = session.ExecuteSchemeQuery(createIndex).ExtractValueSync();
3266+
3267+
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
3268+
}
3269+
3270+
const TString originalPostingTable = ReadTablePartToYson(session, "/Root/TestTable/index1/indexImplPostingTable");
3271+
3272+
// Upsert to the table with index should succeed
3273+
{
3274+
const TString query1(Q_(R"(
3275+
UPSERT INTO `/Root/TestTable` (pk, emb, data) VALUES)"
3276+
"(10, \"\x76\x76\x03\", \"10\");"
3277+
));
3278+
3279+
auto result = session.ExecuteDataQuery(
3280+
query1,
3281+
TTxControl::BeginTx(TTxSettings::SerializableRW()).CommitTx())
3282+
.ExtractValueSync();
3283+
UNIT_ASSERT(result.IsSuccess());
3284+
}
3285+
3286+
const TString postingTable1 = ReadTablePartToYson(session, "/Root/TestTable/index1/indexImplPostingTable");
3287+
3288+
// First index is not updated
3289+
UNIT_ASSERT_STRINGS_EQUAL(originalPostingTable, postingTable1);
3290+
3291+
// Add second index
3292+
{
3293+
const TString createIndex(Q_(R"(
3294+
ALTER TABLE `/Root/TestTable`
3295+
ADD INDEX index2
3296+
GLOBAL USING vector_kmeans_tree
3297+
ON (emb)
3298+
WITH (similarity=cosine, vector_type="uint8", vector_dimension=2, levels=2, clusters=2);
3299+
)"));
3300+
3301+
auto result = session.ExecuteSchemeQuery(createIndex).ExtractValueSync();
3302+
3303+
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
3304+
}
3305+
3306+
const TString postingTable2 = ReadTablePartToYson(session, "/Root/TestTable/index2/indexImplPostingTable");
3307+
3308+
// Second index is different
3309+
UNIT_ASSERT_STRINGS_UNEQUAL(originalPostingTable, postingTable2);
3310+
}
3311+
32413312
Y_UNIT_TEST(ExplainCollectFullDiagnostics) {
32423313
auto setting = NKikimrKqp::TKqpSetting();
32433314
auto serverSettings = TKikimrSettings()

0 commit comments

Comments
 (0)