Repository navigation
Description
Is there an existing issue for this?
- I searched existing issues and pull requests.
- Related but distinct: [Bug]: Prepared SELECT returns a different column after RENAME COLUMN #25622 covers stale base-table column positions after
RENAME COLUMN. This issue is specific to FULLTEXT/IVF_FLAT/HNSW hidden index state after index DDL. - [Bug]: MATCH() AGAINST(? ...) with a bound parameter rejected by parser — breaks Prisma fullTextSearch (v3.0.11 & 4.0-dev) #24735 covers parser rejection of
MATCH ... AGAINST(?); it does not cover stale prepared plans after index DDL.
Branch / Commit
- Branch:
test/issues-24122-21685-4.0-dev - Commit:
7f7de555c49acc3a64995b078025f5526afc9c34
Environment
- Local
launch-with-proxydeployment with two CNs - Reproduced through Proxy
6001and directly across CN16001/ CN16002 - macOS arm64
Summary
Prepared statements that use special indexes retain stale hidden-index state after index DDL instead of being invalidated and rebuilt.
| Index / prepared operation | DDL | Old prepared result | Fresh result |
|---|---|---|---|
| FULLTEXT SELECT | DROP + CREATE, same session | empty set | correct rows |
| FULLTEXT SELECT | prepared on CN1, DROP + CREATE on CN2 | empty set | correct rows, including a row inserted on CN2 |
| FULLTEXT UPDATE | prepared on CN1, DROP + CREATE on CN2 | success, 0 rows affected | fresh prepared UPDATE affects 2 rows |
| FULLTEXT DELETE | same cross-CN setup | correct in the tested case | correct |
| IVF_FLAT SELECT | DROP + CREATE | error referencing deleted old hidden table | correct nearest rows |
| IVF_FLAT SELECT | ALTER REINDEX, lists=2 to lists=3 |
index-out-of-range panic | plan must be rebuilt |
| HNSW SELECT | DROP + CREATE, then converged DML | reads the pre-DDL HNSW snapshot | fresh statement sees converged UPDATE/DELETE/INSERT |
Controls:
- Ordinary secondary-index prepared SELECT/UPDATE/DELETE remain correct across same-session and cross-CN DROP + CREATE.
- A HNSW statement prepared after the index DDL observes later UPDATE/INSERT after the async index converges. This isolates the HNSW failure to the pre-DDL prepared plan, not normal async CDC delay.
FULLTEXT SELECT Reproduction
DROP DATABASE IF EXISTS prepared_special_index_ddl;
CREATE DATABASE prepared_special_index_ddl;
USE prepared_special_index_ddl;
CREATE TABLE ft(id INT PRIMARY KEY, title VARCHAR(200));
INSERT INTO ft VALUES (1,'matrixone alpha'),(2,'other');
CREATE FULLTEXT INDEX idx_ft ON ft(title);
PREPARE pf FROM
"SELECT id FROM ft
WHERE MATCH(title) AGAINST('matrixone' IN NATURAL LANGUAGE MODE)
ORDER BY id";
EXECUTE pf; -- 1
DROP INDEX idx_ft ON ft;
CREATE FULLTEXT INDEX idx_ft ON ft(title);
EXECUTE pf; -- actual: empty; expected: 1
SELECT id FROM ft
WHERE MATCH(title) AGAINST('matrixone' IN NATURAL LANGUAGE MODE)
ORDER BY id; -- correct: 1The same failure occurs when pf is prepared and executed on CN1 while CN2 performs DROP/CREATE and inserts a new matching row. The old CN1 statement returns empty; fresh CN1 SQL returns all old and new matches.
FULLTEXT Prepared UPDATE Variant
CREATE TABLE ftdml(
id INT PRIMARY KEY,
title VARCHAR(200),
mark INT DEFAULT 0
);
INSERT INTO ftdml VALUES
(1,'update_token alpha',0),
(2,'other',0),
(4,'update_token beta',0);
CREATE FULLTEXT INDEX idx_ftdml ON ftdml(title);
PREPARE pupd FROM
"UPDATE ftdml SET mark=mark+1
WHERE MATCH(title) AGAINST('update_token' IN NATURAL LANGUAGE MODE)";
EXECUTE pupd; -- 2 rows; reset mark to 0 after this control execution
UPDATE ftdml SET mark=0;
-- Run on another CN:
DROP INDEX idx_ftdml ON ftdml;
CREATE FULLTEXT INDEX idx_ftdml ON ftdml(title);
-- Back on the original CN:
EXECUTE pupd; -- actual: success, 0 rows affected
SELECT id FROM ftdml
WHERE MATCH(title) AGAINST('update_token' IN NATURAL LANGUAGE MODE);
-- fresh query correctly returns 1,4
PREPARE pupd2 FROM
"UPDATE ftdml SET mark=mark+1
WHERE MATCH(title) AGAINST('update_token' IN NATURAL LANGUAGE MODE)";
EXECUTE pupd2; -- correct: 2 rows affectedIVF_FLAT DROP / CREATE Reproduction
CREATE TABLE vec(id INT PRIMARY KEY, emb vecf32(3));
INSERT INTO vec VALUES
(1,'[0,0,0]'),(2,'[1,0,0]'),(3,'[2,0,0]'),
(4,'[3,0,0]'),(5,'[4,0,0]'),(6,'[5,0,0]');
CREATE INDEX idx_vec USING ivfflat ON vec(emb)
lists=2 op_type 'vector_l2_ops';
PREPARE pv FROM
"SELECT id FROM vec
ORDER BY l2_distance(emb,'[0,0,0]')
LIMIT 2 by rank with option 'mode=pre'";
EXECUTE pv; -- 1,2
DROP INDEX idx_vec ON vec;
CREATE INDEX idx_vec USING ivfflat ON vec(emb)
lists=2 op_type 'vector_l2_ops';
EXECUTE pv;
-- actual: table "__mo_index_secondary_<old UUID>" does not exist
SELECT id FROM vec
ORDER BY l2_distance(emb,'[0,0,0]')
LIMIT 2 by rank with option 'mode=pre'; -- correct: 1,2IVF_FLAT ALTER REINDEX Panic
-- Starting from vec + idx_vec above
PREPARE pvr FROM
"SELECT id FROM vec
ORDER BY l2_distance(emb,'[0,0,0]')
LIMIT 2 by rank with option 'mode=pre'";
EXECUTE pvr; -- 1,2
ALTER TABLE vec ALTER REINDEX idx_vec IVFFLAT lists=3 force_sync;
EXECUTE pvr;Observed stack:
internal error: panic runtime error: index out of range [2] with length 2
github.com/matrixorigin/matrixone/pkg/vectorindex/ivfflat.(*IvfflatSearchIndex[...]).LoadCentroids
pkg/vectorindex/ivfflat/search.go:228
github.com/matrixorigin/matrixone/pkg/vectorindex/ivfflat.(*IvfflatSearchIndex[...]).Load
HNSW Isolation
- Prepare and execute an HNSW nearest-neighbor SELECT:
1,2. - DROP and recreate the HNSW index with the same name.
- UPDATE
id=1from[0,0,0]to[9,0,0], DELETEid=2, and INSERTid=7as[0.1,0,0]. - Wait 8 seconds for async HNSW CDC convergence.
The pre-DDL prepared statement continues to return stale pre-DDL keys (1, or 1,2 at earlier stages). Fresh SQL and a newly prepared statement return the converged nearest keys (7,3).
As a control, a statement prepared after the DDL changed correctly from 7,3 to 7,8 after a later pure UPDATE+INSERT and the same 8-second convergence wait.
White-box Analysis
initExecuteStmtParam in pkg/frontend/computation_wrapper.go is designed to rebuild a prepared plan when any object in preparePlan.Schemas has a newer catalog version.
However, GetParamRule.MatchNode in pkg/sql/plan/visit_plan_rule.go only records schemas for TABLE_SCAN, INSERT, and MULTI_UPDATE. FULLTEXT and vector-index access is rewritten through function/index-specific plan nodes. Their hidden/meta/index tables and DDL-dependent configuration are not reliably represented in the prepared statement's schema-version set.
Consequences observed here match that gap:
- FULLTEXT keeps a stale hidden-table binding and returns no matches.
- IVF_FLAT keeps an old hidden table UUID or combines old
lists=2state with the newlists=3layout. - HNSW keeps searching the cached pre-DDL hidden index even after the recreated index has converged.
Expected Behavior
After CREATE/DROP/ALTER REINDEX changes an index used by a prepared statement, execution must either:
- detect the catalog/index version change and rebuild/recompile the statement; or
- return a normal stale-plan error that allows the client to reprepare.
It must not silently return an empty set, silently skip UPDATE rows, access a deleted hidden table, retain a pre-DDL HNSW snapshot, or panic because old IVF metadata is combined with a new layout.
Acceptance Criteria
- Track all FULLTEXT, IVF_FLAT, and HNSW hidden/meta/index tables referenced by prepared plans.
- Invalidate and safely rebuild SELECT and DML plans after DROP INDEX, CREATE INDEX, and ALTER REINDEX.
- Cover same-name and different-name index recreation.
- Cover changed IVF
listsvalues without stale slice sizing or centroid state. - Verify old prepared, fresh prepared, and non-prepared results agree after DDL.
- Cover Proxy, same-CN, and cross-CN DDL/execution.
- Add SELECT, UPDATE, and DELETE regressions, including ordinary secondary-index controls.
Activity
[-][Bug]: Prepared FULLTEXT and vector queries keep stale hidden-index plans after index DDL[/-][+][Bug]: Prepared FULLTEXT and vector statements keep stale hidden-index plans after index DDL[/+]fix: invalidate prepared special-index plans after index rebuild (#25669
Ariznawlll commentedon Jul 14, 2026
已在最新
main服务上执行实际 SQL 验证。验证版本
0977fc07c51067ce76b769c7853d7374cb2fccecgit_version():0977fc07c验证过程
DROP INDEX + CREATE INDEX,再次执行旧 prepared statement,并与 fresh SQL 对比。DROP/CREATE,再执行旧 statement。lists=2改为lists=3 force_sync后再次执行旧 statement。实际结果
id=1。id=1,2。index out of rangepanic。结论与边界
FULLTEXT 和 IVF_FLAT 的主要复现路径已在当前 main 上通过。计划层的 hidden-index schema 收集回归也已 PASS。此次没有等待并验证 HNSW 异步 CDC 收敛后的 UPDATE/DELETE/INSERT 完整变体,因此 HNSW 长链路仍属于未单独重跑的边界。
Ariznawlll commentedon Jul 14, 2026
已将本 issue 的 special-index prepared plan 黑盒回归加入
matrixorigin/motr#48。MOTR 用例
14_issue_regression.issue_25625_prepared_special_index_ddlissue_25625_prepared_special_index_ddl.test黑盒覆盖
id=1,不能静默返回空集;1,2,不能引用已删除的旧 hidden table;lists=2改成lists=3 force_sync后再次执行旧 statement,必须继续返回1,2,不能触发 index-out-of-range panic。HNSW 的异步收敛部分没有用固定 sleep 冒充稳定回归,后续需要单独的异步场景测试。
运行结果
在 MO
main@0977fc07c51067ce76b769c7853d7374cb2fccec上连续 3 轮均通过;两 CN + Proxy 下整套并发回归也通过。1 remaining item
Ariznawlll commentedon Jul 28, 2026
Reopening after reproducing the stale IVF hidden-table plan on the latest
main.Verified version
maind17b5a1f8e83cee4999181b9509af6126517985cCurrent behavior
The existing same-session regression now passes:
This passed five consecutive runs, including
ALTER REINDEX. The behavior is covered by the session-level DDL generation added in00d7bf28f/ #26021: DDL executed by the same session invalidates its prepared plans.The cross-session path is still broken:
-- Session A execute vector_ps;Actual result, reproduced twice with fresh databases:
The UUID in the error belongs to the deleted pre-DDL IVF entries table; the recreated index has a different hidden-table UUID.
Root-cause evidence
EXPLAINfor the prepared query contains only:The IVF index-only rewrite removes the base
TABLE_SCAN. Prepared schema collection still does not register the base/hidden-index dependencies from thisFUNCTION_SCAN. A same-session DDL changesddlVersionand masks the missing dependency, while DDL from Session B does not change Session A's generation. Session A therefore reuses the old plan and accesses the deleted hidden table.Required regression
The permanent regression must use two live sessions:
The current MOTR case is same-session only and will be temporarily removed until this cross-session path is fixed and can be covered correctly.
Ariznawlll commentedon Jul 28, 2026
The misleading same-session MOTR regression is being temporarily removed in matrixorigin/motr#68.
After the cross-session prepared-plan dependency path is fixed, the case should be restored with two live sessions: prepare in Session A, rebuild the IVF index in Session B, then execute the existing statement in Session A.
fix(plan): invalidate prepared plugin-index plans after DDL (#26359)
Ariznawlll commentedon Aug 1, 2026
测试版本
main15a2d07c687a62a0984cf62846b092912a28c0f1原问题验证
会话 A 对 FULLTEXT、IVF 和 HNSW 查询分别 PREPARE;会话 B DROP INDEX、修改向量/文本、以同名索引重新 CREATE。连续 3 轮中,会话 A 复用旧 prepared statement 后均读取到重建索引后的新结果,未返回旧 hidden-index 数据。
Happy Path 覆盖
alpha初始命中id=1,重建后更新为gamma时旧词为 0 行,再改为alpha recreated后重新命中id=1。id=1切换为id=2。id=2。Unhappy Path 覆盖
白盒验证
回归测试
DROP + CREATE同名索引、旧语句复用和新鲜 SQL 对照;HNSW 为异步 CDC 路径,仍保留本次专项审计验证,不将时序敏感断言纳入稳定 motr 基线。测试证据
PASS 25625_cross_session_prepared_fulltext_ivf_hnsw_after_drop_recreate_index。测试结论
测试通过。
fix: invalidate prepared special-index plans after index rebuild (mat…
fix(plan): invalidate prepared plugin-index plans after DDL (matrixor…
fix: invalidate prepared special-index plans after index rebuild (mat…
fix(plan): invalidate prepared plugin-index plans after DDL (matrixor…
fix: invalidate prepared special-index plans after index rebuild (mat…
fix(plan): invalidate prepared plugin-index plans after DDL (matrixor…