mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Merge pull request #69719 from ClickHouse/backport/24.6/69684
Backport #69684 to 24.6: Prohibit `ALTER TABLE ... ADD INDEX ... TYPE` inverted if setting = 0
This commit is contained in:
commit
49fc7936d2
@ -1142,6 +1142,16 @@ bool AlterCommands::hasFullTextIndex(const StorageInMemoryMetadata & metadata)
|
|||||||
return false;
|
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
|
void AlterCommands::apply(StorageInMemoryMetadata & metadata, ContextPtr context) const
|
||||||
{
|
{
|
||||||
if (!prepared)
|
if (!prepared)
|
||||||
|
@ -235,8 +235,10 @@ public:
|
|||||||
/// additional mutation command (MATERIALIZE_TTL) will be returned.
|
/// additional mutation command (MATERIALIZE_TTL) will be returned.
|
||||||
MutationCommands getMutationCommands(StorageInMemoryMetadata metadata, bool materialize_ttl, ContextPtr context, bool with_alters=false) const;
|
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 hasFullTextIndex(const StorageInMemoryMetadata & metadata);
|
||||||
|
static bool hasLegacyInvertedIndex(const StorageInMemoryMetadata & metadata);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3212,6 +3212,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::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())
|
for (const auto & disk : getDisks())
|
||||||
if (!disk->supportsHardLinks() && !commands.isSettingsAlter() && !commands.isCommentAlter())
|
if (!disk->supportsHardLinks() && !commands.isSettingsAlter() && !commands.isCommentAlter())
|
||||||
throw Exception(
|
throw Exception(
|
||||||
|
@ -1,16 +1,60 @@
|
|||||||
-- Tests that the inverted index can only be supported when allow_experimental_full_text_index = 1.
|
-- Tests that CREATE TABLE and ADD INDEX respect settings 'allow_experimental_full_text_index' and `allow_experimental_inverted_index`
|
||||||
|
|
||||||
SET allow_experimental_full_text_index = 0;
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS tab;
|
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;
|
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