2024-06-05 13:27:07 +00:00
|
|
|
-- Index type 'inverted' was renamed to 'full_text' in April 2024.
|
|
|
|
-- Such indexes are experimental. Test what happens when ClickHouse encounters tables with the old index type.
|
|
|
|
|
2024-05-30 20:20:15 +00:00
|
|
|
DROP TABLE IF EXISTS tab;
|
|
|
|
|
2024-06-05 13:27:07 +00:00
|
|
|
-- It must be possible to load old tables with 'inverted'-type indexes
|
|
|
|
-- In stateless tests, we cannot use old persistences. Emulate "loading an old index" by creating it (internally, similar code executes).
|
2024-05-30 20:20:15 +00:00
|
|
|
|
2024-06-05 13:27:07 +00:00
|
|
|
-- Creation only works with the (old) setting enabled.
|
2024-05-30 20:20:15 +00:00
|
|
|
SET allow_experimental_inverted_index = 0;
|
2024-06-05 13:27:07 +00:00
|
|
|
CREATE TABLE tab(k UInt64, s String, INDEX idx(s) TYPE inverted(2)) ENGINE = MergeTree() ORDER BY k; -- { serverError ILLEGAL_INDEX }
|
|
|
|
|
|
|
|
SET allow_experimental_inverted_index = 1;
|
2024-05-30 20:20:15 +00:00
|
|
|
CREATE TABLE tab(k UInt64, s String, INDEX idx(s) TYPE inverted(2)) ENGINE = MergeTree() ORDER BY k;
|
|
|
|
INSERT INTO tab VALUES (1, 'ab') (2, 'bc');
|
|
|
|
|
|
|
|
-- Detach and attach should work.
|
|
|
|
DETACH TABLE tab;
|
|
|
|
ATTACH TABLE tab;
|
|
|
|
|
2024-06-05 13:27:07 +00:00
|
|
|
-- To encourage users to migrate to the new index type, we now throw an exception when the index is used by queries.
|
2024-05-30 20:20:15 +00:00
|
|
|
SELECT * from tab WHERE s = 'bc'; -- { serverError ILLEGAL_INDEX }
|
|
|
|
|
|
|
|
-- The exception recommends to drop the index and create a 'full_text' index instead. Let's try.
|
|
|
|
ALTER TABLE tab DROP INDEX idx;
|
2024-06-05 13:27:07 +00:00
|
|
|
SET allow_experimental_full_text_index = 1; -- the new setting
|
2024-05-30 20:20:15 +00:00
|
|
|
ALTER TABLE tab ADD INDEX idx(s) TYPE full_text(2);
|
|
|
|
|
|
|
|
SELECT * from tab WHERE s = 'bc';
|
|
|
|
|
|
|
|
DROP TABLE tab;
|