Repository navigation
Description
Summary
When an ordinary UPDATE changes a primary-key value, the base table is updated but synchronous irregular indexes keep the old primary-key lookup value. The row then becomes invisible to FULLTEXT/IVF_FLAT index queries, and deleting/reinserting the old key can expose stale index entries.
This is reproducible on the current tree (7821d21c723372e45a8f65da3bbb896a157b1036) with the default synchronous IVF_FLAT path and FULLTEXT. HNSW and explicit ASYNC IVF use CDC and eventually reconcile, so this report focuses on synchronous FULLTEXT/IVF maintenance.
FULLTEXT reproduction
SET experimental_fulltext_index = 1;
CREATE DATABASE repro_pk_irregular;
USE repro_pk_irregular;
CREATE TABLE ft (
id BIGINT PRIMARY KEY,
body TEXT,
FULLTEXT fti(body)
);
INSERT INTO ft VALUES (1, 'alpha one'), (2, 'beta two');
SELECT id FROM ft WHERE MATCH(body) AGAINST('alpha');
-- expected: 1
UPDATE ft SET id = 5 WHERE id = 1;
SELECT * FROM ft ORDER BY id;
-- returns the base row (5, 'alpha one')
SELECT id FROM ft WHERE MATCH(body) AGAINST('alpha');
-- actual: empty; expected: 5The hidden FULLTEXT table still contains doc_id = 1, so the index lookup cannot join the row after the base primary key becomes 5. The stale entry survives CN changes and service restart. If id=5 is deleted and id=1 is inserted again with different text, the old alpha tokens can be returned for the new row.
Synchronous IVF_FLAT reproduction
SET experimental_ivf_index = 1;
CREATE TABLE iv (
id BIGINT PRIMARY KEY,
v VECF32(3)
);
INSERT INTO iv VALUES (1, '[1,1,1]'), (2, '[9,9,9]');
CREATE INDEX ix USING IVFFLAT
ON iv(v) LISTS = 2 OP_TYPE 'vector_l2_ops';
UPDATE iv SET id = 5 WHERE id = 1;
SELECT * FROM iv ORDER BY id;
-- base table contains id=5
SELECT id
FROM iv
ORDER BY l2_distance(v, '[1,1,1]')
LIMIT 2;
-- actual: id=2 only; expected to include id=5The hidden IVF entries retain the old origin_pk = 1. After deleting id=5 and inserting id=1 with a different vector, stale and new entries can both map to id=1, producing stale/duplicate KNN results.
Code path
- Ordinary UPDATE accepts primary-key changes:
pkg/sql/plan/bind_update.go. - FULLTEXT delete maintenance joins hidden
doc_idwith the source primary key:pkg/sql/plan/build_dml_util.go. - IVF delete/reinsert maintenance similarly uses the source/origin primary key.
The primary-key documentation says primary-key values are immutable. If that contract is intended, ordinary UPDATE should reject this statement consistently. If primary-key UPDATE remains accepted, synchronous FULLTEXT/IVF maintenance must carry and remove the old key before inserting the new key.
Validation
- Reproduced through proxy and both CN ports.
- Reproduced after service restart.
- Regular/unique secondary indexes do not show this stale-key behavior.
- HNSW and explicit ASYNC IVF eventually reconcile through CDC.
Environment: macOS arm64, MatrixOne standalone multi-CN launch-with-proxy.
Activity
Ariznawlll commentedon Jul 11, 2026
Additional validation on the same build:
UPDATE ftfail SET id = id + 1;
The base rows become ids 2 and 3, but FULLTEXT MATCH queries return no rows. The equivalent synchronous IVF_FLAT update leaves the base rows at ids 2 and 3 while KNN returns only one old-key match.
This broadens the scope to ordinary and temporary tables, single-row/multi-row updates, and composite primary keys.
Ariznawlll commentedon Jul 11, 2026
Prepared-statement coverage on the same build:
Therefore prepared execution does not introduce a separate corruption path; it reaches the same primary-key maintenance gap.
test: expect PK-update reject in array_index BVT (matrixorigin#25617 …
fix(plan): reject primary-key UPDATE on tables with a synchronous ful…
Ariznawlll commentedon Jul 15, 2026
最新 main 可复核验证(MOTR)
实际执行命令
f1c0a92d882dbdad469ffd2c96f607796207c797git_version()=f1c0a92d835/35 success,380/380条语句符合预期,0 failed。本 issue 实际用例
UPDATE ... SET id=5 WHERE id=1。20313: unsupported DML: update primary key on a table with a synchronous full-text/vector index。fix(plan): reject primary-key UPDATE on tables with a synchronous ful…
fix(plan): reject primary-key UPDATE on tables with a synchronous ful…
fix(plan): reject primary-key UPDATE on tables with a synchronous ful…
feat(plan): plan DML on FULLTEXT/vector-indexed tables with the new D…