mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-10-15 16:32:34 +00:00
test: add inverted index compatibility case (#9519)
* test: add inverted index compatibility case (#5188) Signed-off-by: NightG1owZ <316247938+NightG1owZ@users.noreply.github.com> * test(compat): assert the newly indexed column stays queryable (#9535) Signed-off-by: NightG1owZ <316247938+NightG1owZ@users.noreply.github.com> * test(compat): narrow to_range to versions carrying #9545 The filtered read added in the previous commit only returns rows once #9545 is present. That fix is on main only (no backport-* labels), so it ships in the v1.4.0 line. Narrow to_range to >=v1.4.0-alpha.0 so the documented downgrade invocation (--to-version v1.1.4) is not broken. Also add the missing trailing newline to the three case files. Signed-off-by: NightG1owZ <316247938+NightG1owZ@users.noreply.github.com> --------- Signed-off-by: NightG1owZ <316247938+NightG1owZ@users.noreply.github.com> Co-authored-by: NightG1owZ <316247938+NightG1owZ@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
name = "inverted_index_survival"
|
||||
reason = "Verify column-level INVERTED INDEX written by old binaries stays readable, writable and alterable after upgrade, and that a column indexed after the fact stays queryable."
|
||||
introduced_by = "#5188; regression guard for #9535"
|
||||
topologies = ["distributed", "standalone"]
|
||||
from_range = ["*"]
|
||||
to_range = [">=v1.4.0-alpha.0"]
|
||||
features = ["table", "index", "inverted_index", "metadata", "alter", "read", "write"]
|
||||
owner = "storage"
|
||||
@@ -0,0 +1,14 @@
|
||||
CREATE TABLE t_inverted_index_survival (
|
||||
host STRING INVERTED INDEX,
|
||||
msg STRING INVERTED INDEX,
|
||||
msg2 STRING,
|
||||
ts TIMESTAMP TIME INDEX,
|
||||
cpu DOUBLE,
|
||||
PRIMARY KEY(host)
|
||||
) ENGINE=mito;
|
||||
|
||||
INSERT INTO t_inverted_index_survival VALUES
|
||||
('h1', 'first event', 'first note', '2026-07-07 00:00:00+0000', 1.0),
|
||||
('h2', 'second event', 'second note', '2026-07-07 00:01:00+0000', 2.0);
|
||||
|
||||
ADMIN FLUSH_TABLE('t_inverted_index_survival');
|
||||
@@ -0,0 +1,145 @@
|
||||
-- 1. Index metadata written by the old binary must survive.
|
||||
SHOW CREATE TABLE t_inverted_index_survival;
|
||||
|
||||
+---------------------------+----------------------------------------------------------+
|
||||
| Table | Create Table |
|
||||
+---------------------------+----------------------------------------------------------+
|
||||
| t_inverted_index_survival | CREATE TABLE IF NOT EXISTS "t_inverted_index_survival" ( |
|
||||
| | "host" STRING NULL INVERTED INDEX, |
|
||||
| | "msg" STRING NULL INVERTED INDEX, |
|
||||
| | "msg2" STRING NULL, |
|
||||
| | "ts" TIMESTAMP(3) NOT NULL, |
|
||||
| | "cpu" DOUBLE NULL, |
|
||||
| | TIME INDEX ("ts"), |
|
||||
| | PRIMARY KEY ("host") |
|
||||
| | ) |
|
||||
| | |
|
||||
| | ENGINE=mito |
|
||||
| | |
|
||||
+---------------------------+----------------------------------------------------------+
|
||||
|
||||
-- 2. Rows written by the old binary must still be readable.
|
||||
SELECT host, msg, cpu
|
||||
FROM t_inverted_index_survival
|
||||
ORDER BY host, ts;
|
||||
|
||||
+------+--------------+-----+
|
||||
| host | msg | cpu |
|
||||
+------+--------------+-----+
|
||||
| h1 | first event | 1.0 |
|
||||
| h2 | second event | 2.0 |
|
||||
+------+--------------+-----+
|
||||
|
||||
-- 3. Filtered read on the column indexed by the old binary.
|
||||
SELECT host, msg
|
||||
FROM t_inverted_index_survival
|
||||
WHERE msg = 'first event'
|
||||
ORDER BY host, ts;
|
||||
|
||||
+------+-------------+
|
||||
| host | msg |
|
||||
+------+-------------+
|
||||
| h1 | first event |
|
||||
+------+-------------+
|
||||
|
||||
-- 4. The new binary must still be able to write into the old table.
|
||||
INSERT INTO t_inverted_index_survival VALUES
|
||||
('h3', 'third event', 'third note', '2026-07-07 00:02:00+0000', 3.0);
|
||||
|
||||
Affected Rows: 1
|
||||
|
||||
SELECT host, msg, cpu
|
||||
FROM t_inverted_index_survival
|
||||
ORDER BY host, ts;
|
||||
|
||||
+------+--------------+-----+
|
||||
| host | msg | cpu |
|
||||
+------+--------------+-----+
|
||||
| h1 | first event | 1.0 |
|
||||
| h2 | second event | 2.0 |
|
||||
| h3 | third event | 3.0 |
|
||||
+------+--------------+-----+
|
||||
|
||||
-- 5. Enabling an index on an existing column must keep SSTs written before the
|
||||
-- index existed readable (regression guard for #9535). 'first note' and
|
||||
-- 'second note' live in the SST written by the old binary, which carries
|
||||
-- inverted indexes for host/msg but not for msg2.
|
||||
ALTER TABLE t_inverted_index_survival MODIFY COLUMN msg2 SET INVERTED INDEX;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
SHOW CREATE TABLE t_inverted_index_survival;
|
||||
|
||||
+---------------------------+----------------------------------------------------------+
|
||||
| Table | Create Table |
|
||||
+---------------------------+----------------------------------------------------------+
|
||||
| t_inverted_index_survival | CREATE TABLE IF NOT EXISTS "t_inverted_index_survival" ( |
|
||||
| | "host" STRING NULL INVERTED INDEX, |
|
||||
| | "msg" STRING NULL INVERTED INDEX, |
|
||||
| | "msg2" STRING NULL INVERTED INDEX, |
|
||||
| | "ts" TIMESTAMP(3) NOT NULL, |
|
||||
| | "cpu" DOUBLE NULL, |
|
||||
| | TIME INDEX ("ts"), |
|
||||
| | PRIMARY KEY ("host") |
|
||||
| | ) |
|
||||
| | |
|
||||
| | ENGINE=mito |
|
||||
| | |
|
||||
+---------------------------+----------------------------------------------------------+
|
||||
|
||||
SELECT host, msg2
|
||||
FROM t_inverted_index_survival
|
||||
WHERE msg2 = 'first note'
|
||||
ORDER BY host, ts;
|
||||
|
||||
+------+------------+
|
||||
| host | msg2 |
|
||||
+------+------------+
|
||||
| h1 | first note |
|
||||
+------+------------+
|
||||
|
||||
SELECT host, msg2
|
||||
FROM t_inverted_index_survival
|
||||
WHERE msg2 = 'second note'
|
||||
ORDER BY host, ts;
|
||||
|
||||
+------+-------------+
|
||||
| host | msg2 |
|
||||
+------+-------------+
|
||||
| h2 | second note |
|
||||
+------+-------------+
|
||||
|
||||
-- A non-matching predicate must still return nothing.
|
||||
SELECT host, msg2
|
||||
FROM t_inverted_index_survival
|
||||
WHERE msg2 = 'no such note'
|
||||
ORDER BY host, ts;
|
||||
|
||||
+------+------+
|
||||
| host | msg2 |
|
||||
+------+------+
|
||||
+------+------+
|
||||
|
||||
-- 6. The index can still be removed afterwards.
|
||||
ALTER TABLE t_inverted_index_survival MODIFY COLUMN msg2 UNSET INVERTED INDEX;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
SHOW CREATE TABLE t_inverted_index_survival;
|
||||
|
||||
+---------------------------+----------------------------------------------------------+
|
||||
| Table | Create Table |
|
||||
+---------------------------+----------------------------------------------------------+
|
||||
| t_inverted_index_survival | CREATE TABLE IF NOT EXISTS "t_inverted_index_survival" ( |
|
||||
| | "host" STRING NULL INVERTED INDEX, |
|
||||
| | "msg" STRING NULL INVERTED INDEX, |
|
||||
| | "msg2" STRING NULL, |
|
||||
| | "ts" TIMESTAMP(3) NOT NULL, |
|
||||
| | "cpu" DOUBLE NULL, |
|
||||
| | TIME INDEX ("ts"), |
|
||||
| | PRIMARY KEY ("host") |
|
||||
| | ) |
|
||||
| | |
|
||||
| | ENGINE=mito |
|
||||
| | |
|
||||
+---------------------------+----------------------------------------------------------+
|
||||
@@ -0,0 +1,50 @@
|
||||
-- 1. Index metadata written by the old binary must survive.
|
||||
SHOW CREATE TABLE t_inverted_index_survival;
|
||||
|
||||
-- 2. Rows written by the old binary must still be readable.
|
||||
SELECT host, msg, cpu
|
||||
FROM t_inverted_index_survival
|
||||
ORDER BY host, ts;
|
||||
|
||||
-- 3. Filtered read on the column indexed by the old binary.
|
||||
SELECT host, msg
|
||||
FROM t_inverted_index_survival
|
||||
WHERE msg = 'first event'
|
||||
ORDER BY host, ts;
|
||||
|
||||
-- 4. The new binary must still be able to write into the old table.
|
||||
INSERT INTO t_inverted_index_survival VALUES
|
||||
('h3', 'third event', 'third note', '2026-07-07 00:02:00+0000', 3.0);
|
||||
|
||||
SELECT host, msg, cpu
|
||||
FROM t_inverted_index_survival
|
||||
ORDER BY host, ts;
|
||||
|
||||
-- 5. Enabling an index on an existing column must keep SSTs written before the
|
||||
-- index existed readable (regression guard for #9535). 'first note' and
|
||||
-- 'second note' live in the SST written by the old binary, which carries
|
||||
-- inverted indexes for host/msg but not for msg2.
|
||||
ALTER TABLE t_inverted_index_survival MODIFY COLUMN msg2 SET INVERTED INDEX;
|
||||
|
||||
SHOW CREATE TABLE t_inverted_index_survival;
|
||||
|
||||
SELECT host, msg2
|
||||
FROM t_inverted_index_survival
|
||||
WHERE msg2 = 'first note'
|
||||
ORDER BY host, ts;
|
||||
|
||||
SELECT host, msg2
|
||||
FROM t_inverted_index_survival
|
||||
WHERE msg2 = 'second note'
|
||||
ORDER BY host, ts;
|
||||
|
||||
-- A non-matching predicate must still return nothing.
|
||||
SELECT host, msg2
|
||||
FROM t_inverted_index_survival
|
||||
WHERE msg2 = 'no such note'
|
||||
ORDER BY host, ts;
|
||||
|
||||
-- 6. The index can still be removed afterwards.
|
||||
ALTER TABLE t_inverted_index_survival MODIFY COLUMN msg2 UNSET INVERTED INDEX;
|
||||
|
||||
SHOW CREATE TABLE t_inverted_index_survival;
|
||||
Reference in New Issue
Block a user