From caefcfd01244107b6aa4e106529af7b9f2f57c04 Mon Sep 17 00:00:00 2001 From: NightG1owZ <3112428897@qq.com> Date: Wed, 14 Oct 2026 02:00:39 +0000 Subject: [PATCH] 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> --- .../cases/inverted_index_survival/case.toml | 8 + .../cases/inverted_index_survival/setup.sql | 14 ++ .../inverted_index_survival/verify.result | 145 ++++++++++++++++++ .../cases/inverted_index_survival/verify.sql | 50 ++++++ 4 files changed, 217 insertions(+) create mode 100644 tests/compatibility/cases/inverted_index_survival/case.toml create mode 100644 tests/compatibility/cases/inverted_index_survival/setup.sql create mode 100644 tests/compatibility/cases/inverted_index_survival/verify.result create mode 100644 tests/compatibility/cases/inverted_index_survival/verify.sql diff --git a/tests/compatibility/cases/inverted_index_survival/case.toml b/tests/compatibility/cases/inverted_index_survival/case.toml new file mode 100644 index 00000000000..e5ce3f93788 --- /dev/null +++ b/tests/compatibility/cases/inverted_index_survival/case.toml @@ -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" diff --git a/tests/compatibility/cases/inverted_index_survival/setup.sql b/tests/compatibility/cases/inverted_index_survival/setup.sql new file mode 100644 index 00000000000..ca11fa0c353 --- /dev/null +++ b/tests/compatibility/cases/inverted_index_survival/setup.sql @@ -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'); diff --git a/tests/compatibility/cases/inverted_index_survival/verify.result b/tests/compatibility/cases/inverted_index_survival/verify.result new file mode 100644 index 00000000000..1678f07a72f --- /dev/null +++ b/tests/compatibility/cases/inverted_index_survival/verify.result @@ -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 | +| | | ++---------------------------+----------------------------------------------------------+ diff --git a/tests/compatibility/cases/inverted_index_survival/verify.sql b/tests/compatibility/cases/inverted_index_survival/verify.sql new file mode 100644 index 00000000000..1cd5f396852 --- /dev/null +++ b/tests/compatibility/cases/inverted_index_survival/verify.sql @@ -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;