Skip to content

[4.2] fix: resolve secondary indexes in subscriptions - #28280

Merged
XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
gouhongshen:codex/fix-4-2-subscription-secondary-index
Sep 6, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
gouhongshen:codex/fix-4-2-subscription-secondary-index

Conversation

@gouhongshen

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:

Fixes #28279

What this PR does / why we need it:

Regular secondary-index scans over a subscribed database resolve the hidden index table under the publisher account. ResolveIndexTableByRef carried the publisher account ID but omitted the publisher database name, so getRelation replaced the valid source database with an empty name and returned no such table <publisher_db>.__mo_index_secondary_*.

This PR:

  • sets SubscriptionMeta.DbName from the planner-resolved published table reference;
  • adds a deterministic publication/subscription BVT with a different subscription alias, 100,000 flushed rows, and forced scans over two regular secondary indexes;
  • asserts that the plan actually uses idx_event_type, preventing the regression case from silently falling back to a table scan.

This is the focused 4.2-dev backport of the subscription metadata fix already merged into main by #26702. It does not backport the unrelated FULLTEXT implementation from that PR.

Validation:

  • Base c8b8e2c046: the regression SQL reproduced the production failure for both hidden secondary-index tables.
  • Head 7f32413fbb: pub_sub_secondary_index passed, 19/19 statements.
  • The fixed BVT query pair also passed three consecutive runs before adding the explicit plan assertion.
  • make build passed.
  • git diff --check passed.

QA required: yes. The BVT reproduces and verifies the single-node planner/resolver path; normal 4.2 CI and publication/subscription testing should run on the PR.

Set the publisher database on subscription metadata when resolving hidden index tables. Add BVT coverage that forces regular secondary-index scans through a subscription alias.\n\nRefs matrixorigin#28279
@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 →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REQUEST_CHANGES(reviewed commit 7f32413fbb05249b1f489c2a2f5c6d672dbd23a7)。

生产修复方向正确:ResolveIndexTableByRef 必须同时携带 publisher tenant 和 ref.SchemaName(publisher database);非订阅路径不受影响,生产性能风险可忽略。

需要补齐以下测试门禁:

  1. 缺少 resolver 边界的确定性 UT。 这是本次修复的直接不变量:publisher tenant、publisher database、隐藏 index relation 和返回的 subscription identity 必须同时正确。当前只有依赖优化器/统计信息的 BVT。main 的 #28284 已有可直接 backport 的 TestResolveIndexTableByRefUsesPublisherDatabase,建议补到 4.2。
  2. 第二个索引没有证明实际走索引。 idx_created_at 查询只有 FORCE INDEX 和结果断言,没有 EXPLAIN。4.2 受影响版本可能静默退化成 base-table scan,结果仍可能为 2。请补充对应 plan-shape 断言,或删除这个不能独立证明的重复场景。
  3. BVT 使用固定 sleep(1),且 100k/flush 的成本没有说明。 sleep 不是同步条件,慢环境仍可能不够,快环境固定浪费时间。请改为可观测条件/去除不必要等待;若 100k 是为了让优化器选择二级索引,请给出最小必要基数及 BVT 时间增量,否则缩小 fixture。main 的同类覆盖已使用 100k 但没有固定 sleep。

以上不是生产逻辑方向问题,而是回归证据的确定性、覆盖边界和 CI 成本问题。补齐后我可以重新审核。

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE。

生产修复本身正确:ResolveIndexTableByRef 补齐 publisher database 后,订阅表的普通二级索引可以在正确的 publisher tenant/database 下解析;非订阅路径不变,生产性能风险可忽略。

补充的非阻塞建议(不影响本次合入):

  • 可 backport main #28284 的 resolver 边界 UT,直接锁定 publisher tenant/database 不变量;
  • idx_created_at 最好补对应 EXPLAIN,避免仅凭结果值误判为索引扫描;
  • BVT 的固定 sleep(1) 和 100k/flush 成本可后续优化为可观测同步或更小 fixture。

这些属于测试证据和 CI 成本改进,不是生产逻辑缺陷。

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 kind/test-ci size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants