mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-26 20:54:08 +00:00
* fix: align fulltext bloom tokens with matches_term and use them for LIKE The bloom fulltext index stored tokens that did not follow matches_term's word boundaries (`_`, ASCII next to Han, Han substrings), so pruning dropped rows matches_term accepts. Tokens and query probes now share the character classes of matches_term, Han runs are indexed as bigrams, and LIKE patterns use the same probes. The bloom blob is written under a new key; blobs from older versions are no longer probed. Tantivy no longer serves matches_term. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * chore: drop unused lazy_static from index and avoid typo-flagged test tokens Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * docs: link like_probes to tokenize instead of the downstream ScriptTokenizer Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * refactor: name probe extraction with verbs and document CharClass Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * feat: rebuild legacy fulltext bloom indexes and probe lower(col) The manifest records the fulltext bloom version per column, so ADMIN BUILD_INDEX now rebuilds SSTs whose bloom index predates the current tokens, and ssts_index_meta shows the version. Case-insensitive bloom indexes also store the tokens of the whole lowercased text for rows where it can differ (U+0130, U+212A, sigma), so matches_term(lower(col), ..) and lower(col) LIKE .. use the index. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test: cover legacy bloom index rewrite by compaction in the compat case Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * chore: log outdated fulltext bloom indexes in the consistency check Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * docs: explain the unrecorded fulltext bloom version Signed-off-by: Dennis Zhuang <killme2008@gmail.com> --------- Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
198 lines
6.8 KiB
Plaintext
198 lines
6.8 KiB
Plaintext
-- Only the SST written by the old binary.
|
|
SELECT ts, msg FROM t_fulltext_bloom_tokens WHERE msg @@ 'world' ORDER BY ts;
|
|
|
|
+-------------------------+-------------+
|
|
| ts | msg |
|
|
+-------------------------+-------------+
|
|
| 1970-01-01T00:00:00.001 | hello_world |
|
|
+-------------------------+-------------+
|
|
|
|
SELECT ts, msg FROM t_fulltext_bloom_tokens WHERE msg @@ 'error' ORDER BY ts;
|
|
|
|
+-------------------------+---------------+
|
|
| ts | msg |
|
|
+-------------------------+---------------+
|
|
| 1970-01-01T00:00:00.002 | 错误error日志 |
|
|
+-------------------------+---------------+
|
|
|
|
SELECT ts, msg FROM t_fulltext_bloom_tokens WHERE msg @@ '农业' ORDER BY ts;
|
|
|
|
+-------------------------+--------------+
|
|
| ts | msg |
|
|
+-------------------------+--------------+
|
|
| 1970-01-01T00:00:00.003 | 中国农业银行 |
|
|
+-------------------------+--------------+
|
|
|
|
SELECT ts, msg FROM t_fulltext_bloom_tokens WHERE msg LIKE 'hello\_%' ORDER BY ts;
|
|
|
|
+-------------------------+-------------+
|
|
| ts | msg |
|
|
+-------------------------+-------------+
|
|
| 1970-01-01T00:00:00.001 | hello_world |
|
|
+-------------------------+-------------+
|
|
|
|
INSERT INTO t_fulltext_bloom_tokens VALUES
|
|
(4, 'hello_world again'),
|
|
(5, '农业 error');
|
|
|
|
Affected Rows: 2
|
|
|
|
ADMIN FLUSH_TABLE('t_fulltext_bloom_tokens');
|
|
|
|
+----------------------------------------------+
|
|
| ADMIN FLUSH_TABLE('t_fulltext_bloom_tokens') |
|
|
+----------------------------------------------+
|
|
| 0 |
|
|
+----------------------------------------------+
|
|
|
|
-- Old and new SSTs: one bloom blob of each version.
|
|
SELECT meta_json LIKE '%"bloom_version":2%' AS is_v2, count(*) AS ssts
|
|
FROM information_schema.ssts_index_meta
|
|
WHERE table_id = (SELECT table_id FROM information_schema.tables WHERE table_name = 't_fulltext_bloom_tokens')
|
|
AND index_type = 'fulltext_bloom'
|
|
GROUP BY is_v2
|
|
ORDER BY is_v2;
|
|
|
|
+-------+------+
|
|
| is_v2 | ssts |
|
|
+-------+------+
|
|
| false | 1 |
|
|
| true | 1 |
|
|
+-------+------+
|
|
|
|
SELECT ts, msg FROM t_fulltext_bloom_tokens WHERE msg @@ 'world' ORDER BY ts;
|
|
|
|
+-------------------------+-------------------+
|
|
| ts | msg |
|
|
+-------------------------+-------------------+
|
|
| 1970-01-01T00:00:00.001 | hello_world |
|
|
| 1970-01-01T00:00:00.004 | hello_world again |
|
|
+-------------------------+-------------------+
|
|
|
|
SELECT ts, msg FROM t_fulltext_bloom_tokens WHERE msg @@ 'error' ORDER BY ts;
|
|
|
|
+-------------------------+---------------+
|
|
| ts | msg |
|
|
+-------------------------+---------------+
|
|
| 1970-01-01T00:00:00.002 | 错误error日志 |
|
|
| 1970-01-01T00:00:00.005 | 农业 error |
|
|
+-------------------------+---------------+
|
|
|
|
SELECT ts, msg FROM t_fulltext_bloom_tokens WHERE msg @@ '农业' ORDER BY ts;
|
|
|
|
+-------------------------+--------------+
|
|
| ts | msg |
|
|
+-------------------------+--------------+
|
|
| 1970-01-01T00:00:00.003 | 中国农业银行 |
|
|
| 1970-01-01T00:00:00.005 | 农业 error |
|
|
+-------------------------+--------------+
|
|
|
|
SELECT ts, msg FROM t_fulltext_bloom_tokens WHERE msg LIKE 'hello\_%' ORDER BY ts;
|
|
|
|
+-------------------------+-------------------+
|
|
| ts | msg |
|
|
+-------------------------+-------------------+
|
|
| 1970-01-01T00:00:00.001 | hello_world |
|
|
| 1970-01-01T00:00:00.004 | hello_world again |
|
|
+-------------------------+-------------------+
|
|
|
|
-- Rebuilds the old SST's index with the current bloom version.
|
|
ADMIN BUILD_INDEX('t_fulltext_bloom_tokens');
|
|
|
|
+----------------------------------------------+
|
|
| ADMIN BUILD_INDEX('t_fulltext_bloom_tokens') |
|
|
+----------------------------------------------+
|
|
| 0 |
|
|
+----------------------------------------------+
|
|
|
|
-- SQLNESS SLEEP 2s
|
|
SELECT meta_json LIKE '%"bloom_version":2%' AS is_v2, count(*) AS ssts
|
|
FROM information_schema.ssts_index_meta
|
|
WHERE table_id = (SELECT table_id FROM information_schema.tables WHERE table_name = 't_fulltext_bloom_tokens')
|
|
AND index_type = 'fulltext_bloom'
|
|
GROUP BY is_v2
|
|
ORDER BY is_v2;
|
|
|
|
+-------+------+
|
|
| is_v2 | ssts |
|
|
+-------+------+
|
|
| true | 2 |
|
|
+-------+------+
|
|
|
|
SELECT ts, msg FROM t_fulltext_bloom_tokens WHERE msg @@ 'world' ORDER BY ts;
|
|
|
|
+-------------------------+-------------------+
|
|
| ts | msg |
|
|
+-------------------------+-------------------+
|
|
| 1970-01-01T00:00:00.001 | hello_world |
|
|
| 1970-01-01T00:00:00.004 | hello_world again |
|
|
+-------------------------+-------------------+
|
|
|
|
DROP TABLE t_fulltext_bloom_tokens;
|
|
|
|
Affected Rows: 0
|
|
|
|
-- Two SSTs written by the old binary.
|
|
SELECT meta_json LIKE '%"bloom_version":2%' AS is_v2, count(*) AS ssts
|
|
FROM information_schema.ssts_index_meta
|
|
WHERE table_id = (SELECT table_id FROM information_schema.tables WHERE table_name = 't_fulltext_bloom_compact')
|
|
AND index_type = 'fulltext_bloom'
|
|
GROUP BY is_v2
|
|
ORDER BY is_v2;
|
|
|
|
+-------+------+
|
|
| is_v2 | ssts |
|
|
+-------+------+
|
|
| false | 2 |
|
|
+-------+------+
|
|
|
|
SELECT ts, msg FROM t_fulltext_bloom_compact WHERE msg @@ 'world' ORDER BY ts;
|
|
|
|
+-------------------------+-------------+
|
|
| ts | msg |
|
|
+-------------------------+-------------+
|
|
| 1970-01-01T00:00:00.001 | hello_world |
|
|
+-------------------------+-------------+
|
|
|
|
-- Merges both SSTs into one with a current bloom blob.
|
|
ADMIN COMPACT_TABLE('t_fulltext_bloom_compact', 'strict_window', 'window=3600');
|
|
|
|
+---------------------------------------------------------------------------------+
|
|
| ADMIN COMPACT_TABLE('t_fulltext_bloom_compact', 'strict_window', 'window=3600') |
|
|
+---------------------------------------------------------------------------------+
|
|
| 0 |
|
|
+---------------------------------------------------------------------------------+
|
|
|
|
SELECT meta_json LIKE '%"bloom_version":2%' AS is_v2, count(*) AS ssts
|
|
FROM information_schema.ssts_index_meta
|
|
WHERE table_id = (SELECT table_id FROM information_schema.tables WHERE table_name = 't_fulltext_bloom_compact')
|
|
AND index_type = 'fulltext_bloom'
|
|
GROUP BY is_v2
|
|
ORDER BY is_v2;
|
|
|
|
+-------+------+
|
|
| is_v2 | ssts |
|
|
+-------+------+
|
|
| true | 1 |
|
|
+-------+------+
|
|
|
|
SELECT ts, msg FROM t_fulltext_bloom_compact WHERE msg @@ 'world' ORDER BY ts;
|
|
|
|
+-------------------------+-------------+
|
|
| ts | msg |
|
|
+-------------------------+-------------+
|
|
| 1970-01-01T00:00:00.001 | hello_world |
|
|
+-------------------------+-------------+
|
|
|
|
SELECT ts, msg FROM t_fulltext_bloom_compact WHERE msg @@ '农业' ORDER BY ts;
|
|
|
|
+-------------------------+--------------+
|
|
| ts | msg |
|
|
+-------------------------+--------------+
|
|
| 1970-01-01T00:00:00.003 | 中国农业银行 |
|
|
+-------------------------+--------------+
|
|
|
|
DROP TABLE t_fulltext_bloom_compact;
|
|
|
|
Affected Rows: 0
|