Disable alter table add vector similarity index if setting does not enabled

This commit is contained in:
flynn 2024-08-29 10:56:26 +00:00
parent 589a63a256
commit d88aa3952d
5 changed files with 36 additions and 0 deletions

View File

@ -1142,6 +1142,16 @@ bool AlterCommands::hasFullTextIndex(const StorageInMemoryMetadata & metadata)
return false;
}
bool AlterCommands::hasVectorSimilarityIndex(const StorageInMemoryMetadata & metadata)
{
for (const auto & index : metadata.secondary_indices)
{
if (index.type == "vector_similarity")
return true;
}
return false;
}
void AlterCommands::apply(StorageInMemoryMetadata & metadata, ContextPtr context) const
{
if (!prepared)

View File

@ -237,6 +237,8 @@ public:
/// Check if commands have any full-text index
static bool hasFullTextIndex(const StorageInMemoryMetadata & metadata);
static bool hasVectorSimilarityIndex(const StorageInMemoryMetadata & metadata);
};
}

View File

@ -3230,6 +3230,11 @@ void MergeTreeData::checkAlterIsPossible(const AlterCommands & commands, Context
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED,
"Experimental full-text index feature is not enabled (turn on setting 'allow_experimental_full_text_index')");
if (AlterCommands::hasVectorSimilarityIndex(new_metadata) && !settings.allow_experimental_vector_similarity_index)
throw Exception(
ErrorCodes::SUPPORT_IS_DISABLED,
"Experimental vector_similarity index feature is not enabled (turn on setting 'allow_experimental_vector_similarity_index')");
for (const auto & disk : getDisks())
if (!disk->supportsHardLinks() && !commands.isSettingsAlter() && !commands.isCommentAlter())
throw Exception(

View File

@ -0,0 +1,19 @@
DROP TABLE IF EXISTS test_embedding;
CREATE TABLE test_embedding
(
id UInt32,
embedding Array(Float32),
)
ENGINE = MergeTree
ORDER BY tuple();
SET allow_experimental_vector_similarity_index = 0;
alter table test_embedding add INDEX idx embedding TYPE vector_similarity('hnsw', 'cosineDistance'); -- { serverError SUPPORT_IS_DISABLED }
SET allow_experimental_vector_similarity_index = 1;
alter table test_embedding add INDEX idx embedding TYPE vector_similarity('hnsw', 'cosineDistance');
DROP TABLE test_embedding;