mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
Merge pull request #69065 from ucasfl/vector-index
Disable alter table add vector similarity index if setting does not enabled
This commit is contained in:
commit
d9d83fd56b
@ -781,14 +781,14 @@ InterpreterCreateQuery::TableProperties InterpreterCreateQuery::getTableProperti
|
|||||||
|
|
||||||
const auto & settings = getContext()->getSettingsRef();
|
const auto & settings = getContext()->getSettingsRef();
|
||||||
if (index_desc.type == FULL_TEXT_INDEX_NAME && !settings.allow_experimental_full_text_index)
|
if (index_desc.type == FULL_TEXT_INDEX_NAME && !settings.allow_experimental_full_text_index)
|
||||||
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, "Experimental full-text index feature is not enabled (the setting 'allow_experimental_full_text_index')");
|
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, "Experimental full-text index feature is disabled. Turn on setting 'allow_experimental_full_text_index'");
|
||||||
/// ----
|
/// ----
|
||||||
/// Temporary check during a transition period. Please remove at the end of 2024.
|
/// Temporary check during a transition period. Please remove at the end of 2024.
|
||||||
if (index_desc.type == INVERTED_INDEX_NAME && !settings.allow_experimental_inverted_index)
|
if (index_desc.type == INVERTED_INDEX_NAME && !settings.allow_experimental_inverted_index)
|
||||||
throw Exception(ErrorCodes::ILLEGAL_INDEX, "Please use index type 'full_text' instead of 'inverted'");
|
throw Exception(ErrorCodes::ILLEGAL_INDEX, "Please use index type 'full_text' instead of 'inverted'");
|
||||||
/// ----
|
/// ----
|
||||||
if (index_desc.type == "vector_similarity" && !settings.allow_experimental_vector_similarity_index)
|
if (index_desc.type == "vector_similarity" && !settings.allow_experimental_vector_similarity_index)
|
||||||
throw Exception(ErrorCodes::INCORRECT_QUERY, "Vector similarity index is disabled. Turn on allow_experimental_vector_similarity_index");
|
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, "Experimental vector similarity index is disabled. Turn on setting 'allow_experimental_vector_similarity_index'");
|
||||||
|
|
||||||
properties.indices.push_back(index_desc);
|
properties.indices.push_back(index_desc);
|
||||||
}
|
}
|
||||||
|
@ -1142,6 +1142,16 @@ bool AlterCommands::hasFullTextIndex(const StorageInMemoryMetadata & metadata)
|
|||||||
return false;
|
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
|
void AlterCommands::apply(StorageInMemoryMetadata & metadata, ContextPtr context) const
|
||||||
{
|
{
|
||||||
if (!prepared)
|
if (!prepared)
|
||||||
|
@ -237,6 +237,9 @@ public:
|
|||||||
|
|
||||||
/// Check if commands have any full-text index
|
/// Check if commands have any full-text index
|
||||||
static bool hasFullTextIndex(const StorageInMemoryMetadata & metadata);
|
static bool hasFullTextIndex(const StorageInMemoryMetadata & metadata);
|
||||||
|
|
||||||
|
/// Check if commands have any vector similarity index
|
||||||
|
static bool hasVectorSimilarityIndex(const StorageInMemoryMetadata & metadata);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3230,6 +3230,10 @@ void MergeTreeData::checkAlterIsPossible(const AlterCommands & commands, Context
|
|||||||
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED,
|
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED,
|
||||||
"Experimental full-text index feature is not enabled (turn on setting 'allow_experimental_full_text_index')");
|
"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 is disabled (turn on setting 'allow_experimental_vector_similarity_index')");
|
||||||
|
|
||||||
for (const auto & disk : getDisks())
|
for (const auto & disk : getDisks())
|
||||||
if (!disk->supportsHardLinks() && !commands.isSettingsAlter() && !commands.isCommentAlter())
|
if (!disk->supportsHardLinks() && !commands.isSettingsAlter() && !commands.isCommentAlter())
|
||||||
throw Exception(
|
throw Exception(
|
||||||
|
@ -195,7 +195,7 @@ void MergeTreeIndexGranuleVectorSimilarity::serializeBinary(WriteBuffer & ostr)
|
|||||||
LOG_TRACE(logger, "Start writing vector similarity index");
|
LOG_TRACE(logger, "Start writing vector similarity index");
|
||||||
|
|
||||||
if (empty())
|
if (empty())
|
||||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Attempt to write empty minmax index {}", backQuote(index_name));
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Attempt to write empty vector similarity index {}", backQuote(index_name));
|
||||||
|
|
||||||
writeIntBinary(FILE_FORMAT_VERSION, ostr);
|
writeIntBinary(FILE_FORMAT_VERSION, ostr);
|
||||||
|
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
-- Tags: no-fasttest, no-ordinary-database
|
||||||
|
|
||||||
|
-- Tests that CREATE TABLE and ADD INDEX respect setting 'allow_experimental_vector_similarity_index'.
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS tab;
|
||||||
|
|
||||||
|
-- Test CREATE TABLE
|
||||||
|
|
||||||
|
SET allow_experimental_vector_similarity_index = 0;
|
||||||
|
CREATE TABLE tab (id UInt32, vec Array(Float32), INDEX idx vec TYPE vector_similarity('hnsw', 'L2Distance')) ENGINE = MergeTree ORDER BY tuple(); -- { serverError SUPPORT_IS_DISABLED }
|
||||||
|
|
||||||
|
SET allow_experimental_vector_similarity_index = 1;
|
||||||
|
CREATE TABLE tab (id UInt32, vec Array(Float32), INDEX idx vec TYPE vector_similarity('hnsw', 'L2Distance')) ENGINE = MergeTree ORDER BY tuple();
|
||||||
|
DROP TABLE tab;
|
||||||
|
|
||||||
|
-- Test ADD INDEX
|
||||||
|
|
||||||
|
CREATE TABLE tab (id UInt32, vec Array(Float32)) ENGINE = MergeTree ORDER BY tuple();
|
||||||
|
|
||||||
|
SET allow_experimental_vector_similarity_index = 0;
|
||||||
|
ALTER TABLE tab ADD INDEX idx vec TYPE vector_similarity('hnsw', 'L2Distance'); -- { serverError SUPPORT_IS_DISABLED }
|
||||||
|
|
||||||
|
SET allow_experimental_vector_similarity_index = 1;
|
||||||
|
ALTER TABLE tab ADD INDEX idx vec TYPE vector_similarity('hnsw', 'L2Distance');
|
||||||
|
|
||||||
|
-- Other index DDL must work regardless of the setting
|
||||||
|
SET allow_experimental_vector_similarity_index = 0;
|
||||||
|
ALTER TABLE tab MATERIALIZE INDEX idx;
|
||||||
|
-- ALTER TABLE tab CLEAR INDEX idx; -- <-- Should work but doesn't w/o enabled setting. Unexpected but not terrible.
|
||||||
|
ALTER TABLE tab DROP INDEX idx;
|
||||||
|
|
||||||
|
DROP TABLE tab;
|
Loading…
Reference in New Issue
Block a user