Skip to content

fix: maintain covering secondary indexes (cherry-pick #25342) - #25474

Merged
mergify[bot] merged 9 commits into
matrixorigin:3.0-devfrom
ck89119:issue-25460-3.0-dev
Jul 7, 2026
Merged

mergify[bot] merged 9 commits into
matrixorigin:3.0-devfrom
ck89119:issue-25460-3.0-dev

Conversation

@ck89119

@ck89119 ck89119 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

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/notCoverPk gate
  • test/distributed/cases/optimizer/index.test: 添加回归 BVT(单列 PK + covering 复合索引 + DML 陈旧)

验证(实测):

阶段 via_index via_scan 一致
修复前基线 0 ❌ 1000 ❌
修复后基线 1000 ✅ 1000 ✅
修复后DML 850 ✅ 850 ✅

注意: 这是最小等价修复, 仅包含 getValidIndexes 改动。未包含 #25342 中读取编码统一 serial→serial_full 的部分(NULL 读写一致性, 独立于 #25460), 因为对全非 NULL 列(#25460 场景)两者编码相同, 无需变更。

🤖 Generated with Claude Code

…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]>
@ck89119
ck89119 requested review from aunjgr and ouyuanning as code owners July 6, 2026 08:15
@ck89119
ck89119 requested a review from a user July 6, 2026 08:15
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify
mergify Bot requested a review from XuPeng-SH July 6, 2026 08:16
ck89119 and others added 2 commits July 6, 2026 16:22
…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]>
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]>
@mergify

mergify Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-07 06:10 UTC · Rule: release-3.0 · triggered by rule Automatic queue on approval for release-3.0
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-07-07 06:10 UTC · at 747668015a45527b0823ed711b6df660184ba121 · squash

This pull request spent 12 seconds in the queue, including 2 seconds running CI.

Required conditions to merge
  • github-review-approved [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI (3.0) / Coverage
    • check-neutral = Matrixone Utils CI (3.0) / Coverage
    • check-skipped = Matrixone Utils CI (3.0) / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants