Repository navigation
fix: maintain covering secondary indexes (cherry-pick #25342) - #25474
Merged
Merged
Conversation
…results When a regular secondary index table exists and its parts include the full primary key, DML must still maintain the hidden index table. Otherwise the optimizer can select the stale index table for leading-prefix predicates (via prefix_eq), causing incorrect query results. This is a manual minimal backport equivalent to matrixorigin#25342 on main, which cannot be cherry-picked mechanically due to missing infrastructure (index_helpers.go, range/prefix index framework) on 3.0-dev. Root cause: getValidIndexes in bind_insert.go had a notCoverPk gate that skipped DML maintenance for indexes whose parts covered the full primary key. The fix unconditionally maintains all regular secondary indexes that have a hidden index table. Fixes matrixorigin#25460. Co-Authored-By: Claude <[email protected]>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
…xorigin#25460) Co-Authored-By: Claude <[email protected]>
…mment - Manually append only new test case golden results in original format (avoid bulk reformatting by mo-tester) - Remove issue number from SQL comment per repository convention Co-Authored-By: Claude <[email protected]>
ghost
approved these changes
Jul 6, 2026
mo_ctl returns a JSON string with commas/braces; without the @Separator:table directive mo-tester mis-parses the column and the two flush statements fail. Matches the existing mo_ctl flush calls in the same file. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The previous change maintained every regular index, but an index whose parts are exactly the primary key (e.g. KEY this_id(id) on primary key(id)) is redundant with the PK and its hidden table cannot be maintained through the DML path here, which silently turned DELETE/ UPDATE into no-ops (ddl/delete.sql regression). Skip only that degenerate parts==PK case; still maintain indexes that cover the full PK but carry extra columns (matrixorigin#25460), so index-only scans see fresh data. Co-Authored-By: Claude Opus 4.8 <[email protected]>
aunjgr
approved these changes
Jul 7, 2026
Contributor
Merge Queue Status
This pull request spent 12 seconds in the queue, including 2 seconds running CI. Required conditions to merge
|
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
issue #25460
What this PR does / why we need it:
3.0-dev 上的最小等效回迁修复(#25342 在 main 上的对应改动)。
根因:
bind_insert.go中getValidIndexes有一个notCoverPk判断: 当二级索引的 parts 覆盖了完整主键时, DML 跳过对该隐藏索引表的维护。但优化器仍可能通过tryIndexOnlyScan/prefix_eq选中该索引表做 leading-prefix 谓词读取 → 隐藏表内容陈旧 → 走索引 vs 不走索引结果不一致(#25460 表现为 over-count)。修复: 对存在隐藏索引表的常规二级索引无条件维护, 删除
notCoverPk/ 主键覆盖判断。改动:
pkg/sql/plan/bind_insert.go: 移除getValidIndexes中的colMap/notCoverPkgatetest/distributed/cases/optimizer/index.test: 添加回归 BVT(单列 PK + covering 复合索引 + DML 陈旧)验证(实测):
注意: 这是最小等价修复, 仅包含
getValidIndexes改动。未包含 #25342 中读取编码统一serial→serial_full的部分(NULL 读写一致性, 独立于 #25460), 因为对全非 NULL 列(#25460 场景)两者编码相同, 无需变更。🤖 Generated with Claude Code