Repository navigation
Description
Problem
On a fresh table with a nullable single-column secondary index, an ordinary large UPDATE of the indexed column can silently misalign values with primary-key rows. The base-table path and secondary-index path then disagree, and a subsequent DELETE misses rows even though the statement succeeds.
This is not an inherited stale-index case: the database, table, data, and index are created from scratch on the tested main commit.
Versions and environment
- MatrixOne branch:
main - MatrixOne commit:
bcfa944abcacf9ab6fc4e2cd0925c64d5f5fe113(latestmaintested on 2026-08-20) - Build: local source build with Go
1.26.4 - Deployment: fresh single-process launch with new CN/TN/log data directories
- OS: macOS; MySQL protocol port
6001 - Client path: ordinary text-protocol SQL, not COM_STMT_PREPARE
Minimal reproduction
Create the table:
DROP DATABASE IF EXISTS nullable_index_update_repro;
CREATE DATABASE nullable_index_update_repro;
USE nullable_index_update_repro;
CREATE TABLE t (
id INT PRIMARY KEY,
n INT NULL
);Load 10,000 deterministic rows using 250 separate 40-row INSERT ... VALUES statements. The statement boundaries are significant for this reproduction. With any MySQL-compatible Python cursor connected to MatrixOne:
for start in range(0, 10000, 40):
values = []
for i in range(start, min(start + 40, 10000)):
n = "NULL" if i % 7 == 0 else str(i % 19 - 9)
values.append(f"({i},{n})")
cursor.execute("INSERT INTO t VALUES " + ",".join(values))Create the index, update its nullable key, and compare the indexed predicate with an equivalent full expression scan:
CREATE INDEX idx_n ON t(n);
UPDATE t
SET n = COALESCE(n, 0)
WHERE id % 4 = 0;
-- reports 2500 affected rows
SELECT COUNT(*) FROM t WHERE n = 0;
SELECT SUM(IF(n + 0 = 0, 1, 0))
FROM t;
SELECT SUM(IF(NOT(
n <=> CASE
WHEN id % 7 = 0 AND id % 4 = 0 THEN 0
WHEN id % 7 = 0 THEN NULL
ELSE id % 19 - 9
END
), 1, 0)) AS value_mismatches
FROM t;
DELETE FROM t WHERE id % 17 = 0;
SELECT COUNT(*) FROM t;
SELECT COUNT(*) FROM t WHERE id % 17 = 0;Actual result
After the UPDATE:
UPDATE affected rows 2500
SELECT COUNT(*) ... WHERE n = 0 809
expression/full-scan equivalent 1445
rows whose n differs from deterministic model 1729
The mismatch sample includes rows whose non-NULL values unexpectedly become NULL or 0, and rows expected to remain NULL that read as 0.
After the DELETE:
expected deleted rows 589
actual affected rows 489
expected final rows 9411
actual final rows 9511
remaining id % 17 = 0 100
The same 10,000-row case reproduced repeatedly with identical counts.
A separate Kafka-to-MatrixOne deterministic pipeline reproduced the downstream failure twice at 100,000 rows: expected final count 94,117, actual 95,061 (944 missed deletes). Kafka round-trip, initial row count, NULL aggregates, grouped aggregates, transaction atomicity, and pre-update index equivalence all passed before the indexed-column update.
Expected result
UPDATEmust preserve the association between every primary-key row and its value.- The indexed predicate and an equivalent base/full-scan expression must both return
809zero-valued rows. value_mismatchesmust be0.DELETE WHERE id % 17 = 0must delete589rows and leave9,411rows with no remaining matches.- If index maintenance cannot be completed consistently, the transaction must fail instead of committing silent wrong data.
Controls and boundary evidence
- The same update without a secondary index produces
0value mismatches and the correct delete count. - Creating an index but updating only a non-indexed column also passes.
- Dropping
idx_nbefore the update and recreating it afterward passes all checks. - Loading all rows through one
INSERT ... SELECT ... generate_series(...)did not reproduce; repeated 40-rowVALUESbatches did, indicating a data/block-layout-sensitive execution path. - In the original wider deterministic table, 9,996 rows passed and 9,997 rows failed for this load/update shape.
Existing-issue check
I searched open and closed issues for nullable secondary-index updates, row/index inconsistency, wrong-row updates, and deletes missing rows.
- [Bug]: nullable index UPDATE keeps Rowid from filtered NULL row #26334 is the closest report: nullable index UPDATE kept a Rowid from a filtered NULL row. It was closed after a two-row SQL regression passed on
820ee121. This fresh large-batch reproduction on a newermainmay be an uncovered large-batch path or a regression of the same Rowid-alignment class. - [Bug]: Secondary index loses most entries; UPDATE of indexed column silently succeeds without changing base row #25873 starts from historical hidden-index loss and then observes silent UPDATE no-ops; this case starts with a fresh, complete index and the UPDATE itself creates the inconsistency.
- [Bug]: 使用索引拿到的数据不正确 #25460 concerns an older full-primary-key covering-index maintenance bug fixed by fix: maintain covering secondary indexes #25342.
- [Bug]: protocol prepared UPDATE corrupts indexed readback for VARBINARY and BIGINT UNSIGNED #25437 concerns binary-protocol prepared UPDATE and specific
VARBINARY/BIGINT UNSIGNEDreadback; this reproduction uses ordinary SQL andINT NULL.
Workaround
Before modifying a nullable indexed column, drop the affected secondary index, perform and validate the update, then recreate the index. This workaround passed the reproduction. If the issue has already occurred, restore or recompute the affected base-column values from an authoritative source while the index is absent, then rebuild the index; rebuilding directly from already-corrupted base values is not sufficient.
Activity
fix(vector): align null masks for offset shrink (#27446)
Lundomn commentedon Sep 7, 2026
QA 转测(2026-09-07)
请在本 Issue 记录实际测试版本/环境、通过或失败结论、未覆盖项及补测要求。按流程,QA 明确通过后再关闭 Issue;如发现失败或回归请保持 open 并反馈复现信息。
Ariznawlll commentedon Sep 8, 2026
测试版本
原问题验证
严格使用原始 10,000 行、250 个独立 40 行 INSERT。创建 nullable 二级索引后执行 UPDATE COALESCE(n,0);3 轮中索引扫描和全表扫描均为 809,逐行确定性模型差异为 0。
Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
不适用:本次使用公开 SQL 重现原始大批量路径。
回归测试
已加入 motr#151:14_issue_regression.issue_27398_nullable_index_large,保留 10,000 行与 40 行分批边界,MOTR 3 轮通过。
测试证据
三轮输出一致:indexed=809、full=809、mismatches=0、rows=9411、indexed_zero=760。
测试结论
测试通过。
fix(vector): align null masks for offset shrink (matrixorigin#27446)
fix(vector): align null masks for offset shrink (matrixorigin#27446)
fix(vector): align null masks for offset shrink (matrixorigin#27446)
iamlinjunhong commentedon Nov 5, 2026
Revalidated this report's exact 10,000-row, 250 separate 40-row INSERT statements fixture on 2026-11-05. The bug remains reproducible on the tested 4.2-dev revision; the main control passes.
1d51125661c60ff5216c1216a897a3d31287533658edabfe8f9f8a6c126e0634e7246c031a6f0adeUsed the original sequence: nullable
n, INSERT batches,CREATE INDEX ... (n),UPDATE ... SET n=COALESCE(n,0) WHERE id%4=0, thenDELETE ... WHERE id%17=0. Before UPDATE, both branches had 10,000 correct base rows and matching index keys.Direct key-level comparison found no missing/orphan origin-PK mappings or duplicate origin-PK references in this fixture; the discrepancy is wrong/stale key values and corrupted base values. Main remains fully consistent after DELETE; 4.2 has 1,975 model/key discrepancies after DELETE. Counts alone do not detect this: the base and index row counts remain equal.
Code comparison confirms that the effective #27446 fix is absent from this 4.2-dev revision, not merely absent under its original SHA:
selection + offset, then calls the offset-freenulls.FilterByMaskInPlaceon the NULL/grouping bitmaps in both branches.FilterByMaskInPlaceWithOffset(..., offset)and contains fix(vector): align null masks for offset shrink #27446 (d6566684722323f6c66420dcf7e64582bf275c2b). The tested 4.2 nulls implementation has no equivalent offset adjustment.Please evaluate backporting #27446 to 4.2-dev with its vector/nulls and layout-sensitive SQL regressions. This is additional branch evidence for the existing issue, not a new root cause or a reproduction of the missing-only historical cohort in #32245. It is also separate from the transaction-local DELETE + COPY ALTER defect in #32247.