mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-19 16:20:50 +00:00
Merge pull request #69720 from ClickHouse/backport/24.7/69684
Backport #69684 to 24.7: Prohibit `ALTER TABLE ... ADD INDEX ... TYPE` inverted if setting = 0
This commit is contained in:
commit
c936b3e1dc
@ -1143,6 +1143,16 @@ bool AlterCommands::hasFullTextIndex(const StorageInMemoryMetadata & metadata)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AlterCommands::hasLegacyInvertedIndex(const StorageInMemoryMetadata & metadata)
|
||||
{
|
||||
for (const auto & index : metadata.secondary_indices)
|
||||
{
|
||||
if (index.type == INVERTED_INDEX_NAME)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void AlterCommands::apply(StorageInMemoryMetadata & metadata, ContextPtr context) const
|
||||
{
|
||||
if (!prepared)
|
||||
|
@ -235,8 +235,9 @@ public:
|
||||
/// additional mutation command (MATERIALIZE_TTL) will be returned.
|
||||
MutationCommands getMutationCommands(StorageInMemoryMetadata metadata, bool materialize_ttl, ContextPtr context, bool with_alters=false) const;
|
||||
|
||||
/// Check if commands have any full-text index
|
||||
/// Check if commands have any full-text index or a (legacy) inverted index
|
||||
static bool hasFullTextIndex(const StorageInMemoryMetadata & metadata);
|
||||
static bool hasLegacyInvertedIndex(const StorageInMemoryMetadata & metadata);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -3217,6 +3217,10 @@ 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::hasLegacyInvertedIndex(new_metadata) && !settings.allow_experimental_inverted_index)
|
||||
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED,
|
||||
"Experimental inverted index feature is not enabled (turn on setting 'allow_experimental_inverted_index')");
|
||||
|
||||
for (const auto & disk : getDisks())
|
||||
if (!disk->supportsHardLinks() && !commands.isSettingsAlter() && !commands.isCommentAlter())
|
||||
throw Exception(
|
||||
|
@ -1,16 +1,60 @@
|
||||
-- Tests that the inverted index can only be supported when allow_experimental_full_text_index = 1.
|
||||
|
||||
SET allow_experimental_full_text_index = 0;
|
||||
-- Tests that CREATE TABLE and ADD INDEX respect settings 'allow_experimental_full_text_index' and `allow_experimental_inverted_index`
|
||||
|
||||
DROP TABLE IF EXISTS tab;
|
||||
CREATE TABLE tab
|
||||
(
|
||||
`key` UInt64,
|
||||
`str` String
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
ORDER BY key;
|
||||
|
||||
ALTER TABLE tab ADD INDEX inv_idx(str) TYPE full_text(0); -- { serverError SUPPORT_IS_DISABLED }
|
||||
-- Test CREATE TABLE + full_text index setting
|
||||
|
||||
SET allow_experimental_full_text_index = 0;
|
||||
CREATE TABLE tab (id UInt32, str String, INDEX idx str TYPE full_text(0)) ENGINE = MergeTree ORDER BY tuple(); -- { serverError SUPPORT_IS_DISABLED }
|
||||
CREATE TABLE tab (id UInt32, str String, INDEX idx str TYPE inverted(0)) ENGINE = MergeTree ORDER BY tuple(); -- { serverError ILLEGAL_INDEX }
|
||||
|
||||
SET allow_experimental_full_text_index = 1;
|
||||
CREATE TABLE tab (id UInt32, str String, INDEX idx str TYPE full_text(0)) ENGINE = MergeTree ORDER BY tuple();
|
||||
CREATE TABLE tab (id UInt32, str String, INDEX idx str TYPE inverted(0)) ENGINE = MergeTree ORDER BY tuple(); -- { serverError ILLEGAL_INDEX }
|
||||
DROP TABLE tab;
|
||||
|
||||
SET allow_experimental_full_text_index = 0; -- reset to default
|
||||
|
||||
-- Test CREATE TABLE + inverted index setting
|
||||
|
||||
SET allow_experimental_inverted_index = 0;
|
||||
CREATE TABLE tab (id UInt32, str String, INDEX idx str TYPE full_text(0)) ENGINE = MergeTree ORDER BY tuple(); -- { serverError SUPPORT_IS_DISABLED }
|
||||
CREATE TABLE tab (id UInt32, str String, INDEX idx str TYPE inverted(0)) ENGINE = MergeTree ORDER BY tuple(); -- { serverError ILLEGAL_INDEX }
|
||||
|
||||
SET allow_experimental_inverted_index = 1;
|
||||
CREATE TABLE tab (id UInt32, str String, INDEX idx str TYPE full_text(0)) ENGINE = MergeTree ORDER BY tuple(); -- { serverError SUPPORT_IS_DISABLED }
|
||||
CREATE TABLE tab (id UInt32, str String, INDEX idx str TYPE inverted(0)) ENGINE = MergeTree ORDER BY tuple();
|
||||
DROP TABLE tab;
|
||||
|
||||
SET allow_experimental_inverted_index = 0; -- reset to default
|
||||
|
||||
-- Test ADD INDEX + full_text index setting
|
||||
|
||||
SET allow_experimental_full_text_index = 0;
|
||||
CREATE TABLE tab (id UInt32, str String) ENGINE = MergeTree ORDER BY tuple();
|
||||
ALTER TABLE tab ADD INDEX idx1 str TYPE full_text(0); -- { serverError SUPPORT_IS_DISABLED }
|
||||
ALTER TABLE tab ADD INDEX idx2 str TYPE inverted(0); -- { serverError SUPPORT_IS_DISABLED }
|
||||
DROP TABLE tab;
|
||||
|
||||
SET allow_experimental_full_text_index = 1;
|
||||
CREATE TABLE tab (id UInt32, str String) ENGINE = MergeTree ORDER BY tuple();
|
||||
ALTER TABLE tab ADD INDEX idx1 str TYPE full_text(0);
|
||||
ALTER TABLE tab ADD INDEX idx2 str TYPE inverted(0); -- { serverError SUPPORT_IS_DISABLED }
|
||||
DROP TABLE tab;
|
||||
SET allow_experimental_full_text_index = 0; -- reset to default
|
||||
|
||||
|
||||
-- Test ADD INDEX + inverted index setting
|
||||
|
||||
SET allow_experimental_inverted_index = 0;
|
||||
CREATE TABLE tab (id UInt32, str String) ENGINE = MergeTree ORDER BY tuple();
|
||||
ALTER TABLE tab ADD INDEX idx1 str TYPE full_text(0); -- { serverError SUPPORT_IS_DISABLED }
|
||||
ALTER TABLE tab ADD INDEX idx2 str TYPE inverted(0); -- { serverError SUPPORT_IS_DISABLED }
|
||||
DROP TABLE tab;
|
||||
|
||||
SET allow_experimental_inverted_index = 1;
|
||||
CREATE TABLE tab (id UInt32, str String) ENGINE = MergeTree ORDER BY tuple();
|
||||
ALTER TABLE tab ADD INDEX idx1 str TYPE full_text(0); -- { serverError SUPPORT_IS_DISABLED }
|
||||
ALTER TABLE tab ADD INDEX idx2 str TYPE inverted(0);
|
||||
DROP TABLE tab;
|
||||
SET allow_experimental_inverted_index = 0; -- reset to default
|
||||
|
Loading…
Reference in New Issue
Block a user