ClickHouse/tests/queries/0_stateless/02346_fulltext_index_match_predicate.sql
Julia Kartseva 94a8c7edb1
Merge pull request #64720 from korowa/fix-split-tokenized-indices
fix: function filters with token-based text indexes
2024-06-06 09:02:23 +00:00

108 lines
2.2 KiB
SQL

-- Tests that match() utilizes the inverted index
SET allow_experimental_full_text_index = true;
DROP TABLE IF EXISTS tab;
CREATE TABLE tab
(
id UInt32,
str String,
INDEX inv_idx(str) TYPE full_text(0) GRANULARITY 1
)
ENGINE = MergeTree
ORDER BY id
SETTINGS index_granularity = 1;
INSERT INTO tab VALUES (1, 'Well, Hello ClickHouse !'), (2, 'Well, Hello World !'), (3, 'Good Weather !'), (4, 'Say Hello !'), (5, 'Its An OLAP Database'), (6, 'True World Champion');
SELECT * FROM tab WHERE match(str, ' Hello (ClickHouse|World) ') ORDER BY id;
-- Read 2/6 granules
-- Required string: ' Hello '
-- Alternatives: ' Hello ClickHouse ', ' Hello World '
SELECT *
FROM
(
EXPLAIN PLAN indexes=1
SELECT * FROM tab WHERE match(str, ' Hello (ClickHouse|World) ') ORDER BY id
)
WHERE
explain LIKE '%Granules: %'
SETTINGS
allow_experimental_analyzer = 0;
SELECT *
FROM
(
EXPLAIN PLAN indexes=1
SELECT * FROM tab WHERE match(str, ' Hello (ClickHouse|World) ') ORDER BY id
)
WHERE
explain LIKE '%Granules: %'
SETTINGS
allow_experimental_analyzer = 1;
SELECT '---';
SELECT * FROM tab WHERE match(str, '.* (ClickHouse|World) ') ORDER BY id;
-- Read 3/6 granules
-- Required string: -
-- Alternatives: ' ClickHouse ', ' World '
SELECT *
FROM
(
EXPLAIN PLAN indexes = 1
SELECT * FROM tab WHERE match(str, '.* (ClickHouse|World) ') ORDER BY id
)
WHERE
explain LIKE '%Granules: %'
SETTINGS
allow_experimental_analyzer = 0;
SELECT *
FROM
(
EXPLAIN PLAN indexes = 1
SELECT * FROM tab WHERE match(str, '.* (ClickHouse|World) ') ORDER BY id
)
WHERE
explain LIKE '%Granules: %'
SETTINGS
allow_experimental_analyzer = 1;
SELECT '---';
SELECT * FROM tab WHERE match(str, ' OLAP .*') ORDER BY id;
-- Read 1/6 granules
-- Required string: ' OLAP '
-- Alternatives: -
SELECT *
FROM
(
EXPLAIN PLAN indexes = 1
SELECT * FROM tab WHERE match(str, ' OLAP (.*?)*') ORDER BY id
)
WHERE
explain LIKE '%Granules: %'
SETTINGS
allow_experimental_analyzer = 0;
SELECT *
FROM
(
EXPLAIN PLAN indexes = 1
SELECT * FROM tab WHERE match(str, ' OLAP (.*?)*') ORDER BY id
)
WHERE
explain LIKE '%Granules: %'
SETTINGS
allow_experimental_analyzer = 1;
DROP TABLE tab;