Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
This is a 4.2-dev backport tracking issue for the known bug #27398, fixed on main by #27446. Searches for #27446, #27398 with 4.2, and nullable-index 4.2 reports found no separate branch-specific issue. Current branch reproduction evidence was also added to #27398.
Branch Name
4.2-dev
Commit ID
Failing 4.2-dev: 58edabfe8f9f8a6c126e0634e7246c031a6f0ade
Passing main control: 1d51125661c60ff5216c1216a897a3d312875336
These are the exact locally tested revisions, not a claim about future branch heads.
Other Environment Information
2026-11-05; macOS arm64, Go 1.27.1, local source builds, ordinary MySQL text protocol. Fresh synthetic tables, one bounded reproduction per branch, no source changes or manual hidden-index writes.
Actual Behavior
A nullable secondary-index UPDATE silently changes base values incorrectly. A subsequent DELETE succeeds but leaves matching rows behind. The original #27398 layout-sensitive fixture still fails on the tested 4.2-dev revision.
| Check | Expected / main actual | 4.2-dev actual |
|---|---|---|
| Base values differing from the per-id model after UPDATE | 0 | 1,729 |
| Base-scan n=0 count after UPDATE | 809 | 1,445 |
| Hidden index keys differing from current base values after UPDATE | 0 | 1,729 |
| Base rows after DELETE | 9,411 | 9,511 |
| Remaining rows satisfying id%17=0 | 0 | 100 |
Before UPDATE, both branches had 10,000 correct base rows and matching hidden-index keys. After UPDATE, base and index row counts still both equal 10,000: count-only comparison misses the corruption. After DELETE, 4.2 has 1,975 base-model/key discrepancies; main has none.
Expected Behavior
UPDATE must preserve the correct value for every primary key and maintain matching index keys. DELETE must remove all 589 matching rows, leaving 9,411 rows and no remaining id%17=0 matches.
Steps to Reproduce
Use a disposable database and an autocommit connection.
CREATE TABLE t(id INT PRIMARY KEY,n INT NULL);Preserve the original loading boundaries: 250 separate INSERT statements, each with 40 rows. With a connected Python SQL cursor:
for start in range(0, 10000, 40):
values = [
f"({i},{'NULL' if i % 7 == 0 else str(i % 19 - 9)})"
for i in range(start, start + 40)
]
cursor.execute("INSERT INTO t VALUES " + ",".join(values))Then execute:
CREATE INDEX idx_n ON t(n);
UPDATE t SET n=COALESCE(n,0) WHERE id%4=0;
SELECT SUM(IF(n=0,1,0)) FROM t IGNORE INDEX(idx_n);
-- Expected/main: 809; 4.2-dev base data: 1445.
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 IGNORE INDEX(idx_n);
-- Expected/main: 0; 4.2-dev: 1729.
DELETE FROM t WHERE id%17=0;
SELECT COUNT(*) FROM t;
SELECT COUNT(*) FROM t WHERE id%17=0;
-- Expected/main: 9411, 0; 4.2-dev: 9511, 100.The recorded branch run read all base rows through IGNORE INDEX, checked the same deterministic model in the client, and compared raw hidden keys against HEX(serial_full(n,id)). The aggregate SQL above expresses the same checks. No manual index corruption is required. Do not replace the batched loader with one INSERT SELECT; the historical issue identifies the layout as material.
Additional information
Effective fix missing, confirmed by code as well as reproduction:
- fix(vector): align null masks for offset shrink #27446 /
d6566684722323f6c66420dcf7e64582bf275c2bis in the tested main, absent from the tested 4.2-dev. - 4.2 shrinkFixedByMask moves payload using
selection + offset, but remaps NULL/grouping bitmaps with the offset-freeFilterByMaskInPlace. - The tested 4.2 nulls implementation has no equivalent offset adjustment. main uses
FilterByMaskInPlaceWithOffset(..., offset). This is not an inference from original-SHA ancestry alone.
Please backport/adapt #27446 to 4.2-dev and retain its null/vector regressions and the exact layout-sensitive 10,000-row SQL regression. Validate base values as well as hidden-index keys, both mask directions/offsets, and the subsequent DELETE result.
This tracks an already reproduced branch gap, not a new root cause. It is separate from #32247 (transaction-local DELETE/UPDATE followed by COPY ALTER) and does not explain the historical missing-only cohort in #32245.
Activity
fix(vector): align null masks for offset shrink (#27446) (#32347)
Ariznawlll commentedon Nov 12, 2026
测试版本
官方
4.2-dev:51c0af67a207f7a30dddb4bc385c3466ae5696de,包含回传修复 #32347。隔离 Linux 环境,1 LogService、1 TN、2 CN;两个 CN 的git_version()均与上述完整 SHA 一致。本 Issue 跟踪 4.2-dev 回传,main 原问题及修复分别见 #27398、#27446。原问题验证
严格保留原布局:新表分 250 次独立 INSERT、每次 40 行加载 10,000 行,再创建 nullable 二级索引;执行原报告 UPDATE 和 DELETE。原始 BVT 在两个 CN 各重复 3 次,6/6 次通过,每次 265/265 条语句,0 跳过。
新增 MOTR 复核同一数据模型:UPDATE 后
n=0为 809、逐主键值偏差 0;DELETE 后剩余 9,411 行、应删除但仍存在 0 行。分别检查更新前、更新后和删除后的隐藏索引:每一阶段索引行数与基表一致,索引键与对应基表值的序列化结果偏差均为 0。两 CN 各重复 3 次,6/6 通过。Happy Path 覆盖
覆盖 NULL 与非 NULL 混合值、跨批加载后建索引、将选中 NULL 更新为 0、未选中值保持,以及删除后的基表与索引一致性;逐值核对,避免仅凭行数一致漏掉错位。
Unhappy Path 覆盖
以原始缺陷输入作为负面回归:包含非零 offset 的批次、NULL bitmap、UPDATE 后紧接 DELETE;检查不存在旧值、错误键或漏删目标。本轮未做存储故障注入或更大规模性能压测,不将其算作通过。
白盒验证
在同一官方 4.2-dev SHA 上重复执行
TestShrinkByMaskKeepsNullsAlignedWithOffset、TestFilterByMaskInPlaceWithOffsetMatchesAllocatingPath各 3 次,均通过,覆盖 offset 下向量值与 NULL bitmap 的过滤对齐。证据见 CI 43165500523 的相关步骤。回归测试
新增
14_issue_regression.issue_32249_nullable_index_42,已提交 MOTR PR #329,标记为4.2-dev。现有每日 4.2-dev TKE MOTR 路径在 PR 合入后可选中该用例;目前不声称它已在每日定时任务中实际运行。测试证据
CI 43172200079 的原始 BVT 和新增 MOTR 两个步骤均成功。整个工作流不是绿色:另有 #32463 的 4.2-dev 外键错误码失败;取得本项证据后取消了后续重复的独立测试。此前新增用例的目录表名检查曾导致夹具失败,修正后上述回归重跑通过;该夹具失败不算作产品失败或测试通过。
测试结论
#32249 原始 10,000 行 nullable 二级索引 UPDATE/DELETE 及隐藏键对齐问题,在上述 4.2-dev 版本通过验收;回归已提交 MOTR PR,按约定关闭。