Repository navigation
Description
Description
When CREATE INDEX overlaps committed INSERTs from another connection, the DDL returns successfully but the new index can permanently miss committed rows. Fulltext indexes reproduce consistently; regular secondary indexes reproduce intermittently. Equivalent scans of the base table return the complete result set, and the mismatch survives a service restart.
Environment
- Branch:
main - Commit:
596b2f21131b9391f9fbef41f474feb57ca070d5 - Deployment: local Docker, 1 Log + 1 TN + 2 CN, querying a direct CN SQL endpoint.
- Client: MySQL Connector/J 8.0.33 with server prepared statements.
- Date:
2026-08-22
The same behavior was also observed on the then-current official matrixorigin/matrixone:latest image (v4.2.0, commit 01ae8ec).
Steps to reproduce
-
Create one of the following tables and insert 1,000 rows:
CREATE TABLE t(id BIGINT PRIMARY KEY, k INT); -- or CREATE TABLE t(id BIGINT PRIMARY KEY, body TEXT);
-
Use two independent connections. The writer commits row 1001, then both connections are released together. The writer commits rows 1002 through 1200 one at a time while the DDL connection runs:
CREATE INDEX idx ON t(k); -- or CREATE FULLTEXT INDEX idx ON t(body);
-
Wait for both connections to return successfully, then compare each index query with a semantically equivalent base-table scan:
-- regular index SELECT COUNT(*) FROM t WHERE k = 0; SELECT SUM(CASE WHEN k = 0 THEN 1 ELSE 0 END) FROM t; -- fulltext index SELECT COUNT(*) FROM t WHERE MATCH(body) AGAINST('officialracezebra'); SELECT COUNT(*) FROM t WHERE body LIKE '%officialracezebra%';
The JDBC reproducer uses a latch after the writer's first committed row; it is not based on sleeps or an unbounded background load.
Actual behavior
On the exact main commit above:
- Regular index: 13 of 20 runs returned
rows=1200, indexed=119, scanned=120. - Fulltext index: 13 of 13 runs returned
rows=1200, indexed=1189..1193, scanned=1200. - Keeping one reproduced database and restarting the complete local service set preserved the mismatch: regular index
119/120; fulltext index1187/1200.
EXPLAIN confirms that the regular query uses Index Table Scan on t.idx, while the fulltext query uses Table Function on fulltext_index_scan; these are not fallback base-table scans.
Expected behavior
If CREATE INDEX and every INSERT complete successfully, index results must contain exactly the committed base-table rows. A restart must not change that invariant.
Stability and controls
- Reproducer: regular index 13/20; fulltext index 13/13.
- Serial control: open the writer connection before DDL but write the 200 rows only after
CREATE INDEXreturns. Both variants were correct 3/3 (120/120for regular and1200/1200for fulltext). - Rejected-DDL atomicity: creating an already existing
idxreturned42000/1061for both variants, 3/3. Base-table and existing-index counts remained correct, and a later valid insert was indexed correctly. - No panic, fatal, or OOM marker was present in the service logs during the validation runs.
Evidence
Representative exact-main output:
RACE NORMAL r2 rows=1200 indexed=119 scanned=120
RACE NORMAL r3 rows=1200 indexed=119 scanned=120
RACE FULLTEXT r1 rows=1200 indexed=1190 scanned=1200
RACE FULLTEXT r2 rows=1200 indexed=1191 scanned=1200
RACE FULLTEXT r3 rows=1200 indexed=1191 scanned=1200
CONTROL NORMAL r1..r3 rows=1200 indexed=120 scanned=120
CONTROL FULLTEXT r1..r3 rows=1200 indexed=1200 scanned=1200
Code analysis
This is a code-path hypothesis, not a confirmed root cause. doCreateIndex first creates and backfills hidden index tables (regular indexes through handleRegularSecondaryIndexTable, fulltext through plugin HandleCreateIndex) and calls UpdateConstraint afterwards. A committed-write interval between the backfill read and the index-maintenance publication would match the observed small, durable gap.
Relevant locations:
pkg/sql/compile/ddl.go:2745-2815pkg/sql/compile/ddl_index_algo.go:55-72pkg/fulltext/plugin/compile/compile.go:51-102
Regression coverage
Do not baseline the failing behavior. After a fix, add a two-connection scenario under motr/suites/scenarios that covers regular and fulltext index creation, concurrent commits, and post-restart result equivalence.
Duplicate check
I searched open and closed Issues and PRs using CREATE INDEX + concurrent, fulltext + concurrent, index + missing rows, and fulltext_index_scan. I found no matching report for permanently incomplete index results after successful concurrent DDL/DML. #27142 concerns an irregular-index UPDATE lock-order issue and is not the same behavior.
Activity
[-][Bug]: CREATE INDEX 与并发已提交 INSERT 交错时,全文索引稳定漏项、普通索引间歇漏项[/-][+][Bug]: CREATE INDEX concurrent with committed INSERTs leaves index results incomplete[/+]cpegeric commentedon Aug 27, 2026
both regular index and fulltext index have the same problem. Better assign engine developer to take a look first.
fix: preserve insert metadata lock during index creation (#27792)
Ariznawlll commentedon Aug 31, 2026
测试版本
mainaa7b969f55e655f3f201fd3337589d070f99449452336df80596de93a3f279dfcd6c993d7227bcb9(PR fix: preserve insert metadata lock during index creation #27792)原问题验证
使用 1,000 行原始触发规模,通过两个独立连接验证
INSERT与CREATE INDEX的提交边界。测试不使用固定 sleep:先从mo_locks()识别 writer 在mo_tables上新增的 shared metadata lock,再启动另一 CN 的CREATE INDEX,确认同一个 lock 上已经出现 waiter 后才提交或回滚 writer。2e1be0927882349e3b1082c1847b60cbb0b0769b:无法观察到 writer 的目标表 metadata lock,按预期 RED,复现了修复前的锁缺口。ISSUE_27487_PASS runs=10 seed_rows=1000。Happy Path 覆盖
CREATE INDEX确认等待未提交 INSERT;writer 提交后 DDL 成功,FORCE INDEX(idx_k)与IGNORE INDEX(idx_k)结果完全一致,EXPLAIN确认真正使用Index Table Scan。CREATE FULLTEXT INDEX确认等待未提交 INSERT;writer 提交后,MATCH ... AGAINST与基表LIKE行数完全一致。Unhappy Path 覆盖
1061;错误后基础表和已有索引结果保持一致。SELECT 1和合法写入,连接可继续使用,未残留阻塞事务。transfer rowids failed、panic、fatal、OOM。白盒验证
TestMarkInsertTableScansNotLockMetaDoesNotMutateWriteTarget:连续 10/10 通过,验证 scan-localNotLockMeta不再污染 INSERT write target。TestIssue27487ConcurrentInsertIsIncludedInNewIndex:真实 2CN 集成测试连续 10/10 通过;每轮同时覆盖普通索引和 FULLTEXT 索引,并确认 DDL waiter 后再提交 writer。-race不适用:本问题验收目标是跨 CN SQL metadata-lock 与索引可见性,不涉及测试专用的 Go 对象生命周期或资源所有权;并发路径已由真实 2CN 黑盒和集成测试覆盖。回归测试
script/issue_27487_concurrent_index.pyCONCURRENT SCENARIO TEST,默认执行 1,000 行 × 10 轮,writer/DDL 使用不同 CN。validate通过(6m46s)。测试证据
测试结论
测试通过。
Ariznawlll commentedon Aug 31, 2026
测试版本
main3f05ced24a6e3b84e5ddf37e40d256a8fac02368原问题验证
使用 1,000 行初始数据,通过两个独立连接执行
INSERT与CREATE INDEX并发验证。测试通过mo_locks()确认 writer 持有目标表 metadata shared lock,并确认CREATE INDEX已进入该锁的 waiter 队列后,再提交或回滚 writer;不依赖固定 sleep。普通二级索引与 FULLTEXT 索引分别执行 commit、rollback 两种路径,连续运行 10 轮,共 40 个组合全部通过。最终输出:
Happy Path 覆盖
FORCE INDEX(idx_k)与IGNORE INDEX(idx_k)结果一致,EXPLAIN确认真正使用Index Table Scan。MATCH ... AGAINST与基表LIKE结果一致。Unhappy Path 覆盖
1061;错误后已有索引与基表结果仍一致。SELECT 1和合法写入,连接可继续使用,未残留阻塞事务。ISSUE_27487_FAIL、Traceback 或断言失败。白盒验证
修复 PR 已在
main中包含TestMarkInsertTableScansNotLockMetaDoesNotMutateWriteTarget与TestIssue27487ConcurrentInsertIsIncludedInNewIndex,分别覆盖 INSERT write target metadata lock 保留及真实 2 CN 锁交接路径。本轮验收重点为 TKE 黑盒回归,未重复执行白盒测试。回归测试
script/issue_27487_concurrent_index.pyCONCURRENT SCENARIO TESTvalidate与Linux contracts (offline TKE Family harness)均通过,等待 review/merge。测试证据
main测试结论
测试通过。
Ariznawlll commentedon Aug 31, 2026
测试版本
main3f05ced24a6e3b84e5ddf37e40d256a8fac02368原问题验证
使用 1,000 行初始数据,通过两个独立连接执行
INSERT与CREATE INDEX并发验证。测试通过mo_locks()确认 writer 持有目标表 metadata shared lock,并确认CREATE INDEX已进入该锁的 waiter 队列后,再提交或回滚 writer;不依赖固定 sleep。普通二级索引与 FULLTEXT 索引分别执行 commit、rollback 两种路径,连续运行 10 轮,共 40 个组合全部通过。最终输出:
Happy Path 覆盖
FORCE INDEX(idx_k)与IGNORE INDEX(idx_k)结果一致,EXPLAIN确认真正使用Index Table Scan。MATCH ... AGAINST与基表LIKE结果一致。Unhappy Path 覆盖
1061;错误后已有索引与基表结果仍一致。SELECT 1和合法写入,连接可继续使用,未残留阻塞事务。ISSUE_27487_FAIL、Traceback 或断言失败。白盒验证
修复 PR 已在
main中包含TestMarkInsertTableScansNotLockMetaDoesNotMutateWriteTarget与TestIssue27487ConcurrentInsertIsIncludedInNewIndex,分别覆盖 INSERT write target metadata lock 保留及真实 2 CN 锁交接路径。本轮验收重点为 TKE 黑盒回归,未重复执行白盒测试。回归测试
script/issue_27487_concurrent_index.pyCONCURRENT SCENARIO TESTd0e966d3410ed21f7a193f0fa4b0127fef10d32f;检查validate与Linux contracts (offline TKE Family harness)均通过。测试证据
main修复、最新
main黑盒验证及 MOTR 回归合入均已完成,关闭本 issue。测试结论
测试通过。
fix: preserve insert metadata lock during index creation (matrixorigi…
fix: preserve insert metadata lock during index creation (matrixorigi…
fix: preserve insert metadata lock during index creation (matrixorigi…