Skip to content

[Bug]: publication subscription queries fail when regular secondary indexes are selected on 4.1/4.2 #28279

Closed

Description

@LeftHandCold

Is there an existing issue for the same bug?

  • I searched open and closed issues for publication/subscription, __mo_index_secondary, ResolveIndexTableByRef, and secondary-index lookup failures.

Branch Name

4.1-dev / 4.2-dev (production confirmation on v4.2.1; code-path confirmation on v4.1.4)

Commit ID

  • v4.2.1 production build: d2393868a7aaa6343518d80849fe4696aa3577e9
  • v4.1.4 tag: a185c23b375956afe098320baf8df39000a43936

Other Environment Information

  • Production topology: distributed, multiple CNs.
  • The report is anonymized; no customer/account identifiers or credentials are included.
  • The same failure was recorded on two distinct CN UUIDs, excluding a single-CN cache anomaly.

Actual Behavior

A subscriber can scan a published table, but a predicate fails when the optimizer selects a regular secondary index:

ERROR 1146 (HY000): no such table publisher_db.__mo_index_secondary_<uuid>

Observed counterfactual on v4.2.1:

  1. COUNT(*) on the subscribed table succeeds.
  2. Adding a predicate that selects secondary index A fails with the hidden-table error.
  3. Ignoring index A causes the plan to select secondary index B, which fails with the same error for B's hidden table.
  4. Ignoring all regular secondary indexes succeeds and returns the expected base-table result.
  5. The referenced hidden index tables exist in the publisher database catalog.

The resolver reconstructs an incomplete subscription context:

subMeta = &plan.SubscriptionMeta{
    AccountId: ref.PubInfo.TenantId,
}

getRelation then replaces the valid publisher database with the empty subMeta.DbName, so the hidden index table cannot be resolved.

The same missing-DbName code is present in v4.1.4 and v4.2.1. This is therefore an existing 4.1/4.2 defect, not a newly introduced 4.2 regression. Runtime production evidence is currently from v4.2.1; v4.1.4 reachability is confirmed from the identical resolver path and still needs an isolated SQL reproduction.

Expected Behavior

Queries through a subscription must resolve planner-selected hidden index tables using the publisher account and publisher database derived from trusted ObjectRef.PubInfo metadata. A subscriber query should return the same authorized rows whether the optimizer chooses a base-table scan or a regular secondary-index scan.

Steps to Reproduce

-- Publisher account (sys)
CREATE DATABASE publisher_db;
CREATE TABLE publisher_db.events (
  id BIGINT PRIMARY KEY,
  event_type VARCHAR(64),
  created_at BIGINT,
  KEY idx_event_type(event_type),
  KEY idx_created_at(created_at)
);
INSERT INTO publisher_db.events VALUES
  (1, 'login_success', 1),
  (2, 'other', 2);
CREATE ACCOUNT subscriber ADMIN_NAME 'admin' IDENTIFIED BY '<password>';
CREATE PUBLICATION events_pub DATABASE publisher_db ACCOUNT subscriber;

Close the publisher connection and open a separate client as the subscriber account:

mysql -h <host> -P <port> -u 'subscriber:admin' -p

The remaining statements must run in that subscriber session, not in sys:

CREATE DATABASE subscribed_db FROM sys PUBLICATION events_pub;

-- Base-table path succeeds.
SELECT COUNT(*) FROM subscribed_db.events;

-- When the optimizer selects idx_event_type, this can fail with
-- no such table publisher_db.__mo_index_secondary_<uuid>.
SELECT COUNT(*)
FROM subscribed_db.events
WHERE event_type = 'login_success';

-- Bypassing all secondary indexes succeeds.
SELECT COUNT(*)
FROM subscribed_db.events
IGNORE INDEX (idx_event_type, idx_created_at)
WHERE event_type = 'login_success';

Use enough rows/statistics so that the natural predicate selects the secondary-index path. Do not use FORCE INDEX as the sole witness on 4.2: the affected build can silently fall back to a base-table scan. Confirm index selection with EXPLAIN.

Additional information

Suggested validation for the 4.1/4.2 fix:

  1. Reproduce the indexed predicate failure on an exact unpatched build.
  2. Backport the scoped DbName: ref.SchemaName fix from fix: support fulltext scans over publications #26702.
  3. Prove the same query succeeds without IGNORE INDEX and returns a typed/multiset-equal result to the base-table path.
  4. Add regular secondary-index publication/subscription BVT coverage, including different subscription aliases, two indexes, multiple CNs, revoke/drop, and unpublished-object denial.

Activity

  1. added
    kind/bug
    on Sep 6, 2026
  2. added
    severity/s0
    and removed on Sep 6, 2026
  3. added
    ai-easy
    on Sep 6, 2026
  4. gouhongshen commented on Sep 6, 2026

    @gouhongshen
    Contributor

    Investigation and regression coverage for this issue are complete.

    Findings:

    • The reported v4.1.4 tag (a185c23b375956afe098320baf8df39000a43936) and v4.2.1 tag (d2393868a7aaa6343518d80849fe4696aa3577e9) both reconstruct SubscriptionMeta with AccountId but omit DbName in TxnCompilerContext.ResolveIndexTableByRef.
    • getRelation uses SubscriptionMeta.DbName when resolving the hidden secondary-index relation. The empty database name causes the planner-selected __mo_index_secondary_<uuid> table lookup to fail, while the base-table path can still succeed.
    • Current main already contains the production line DbName: ref.SchemaName through merged PR fix: support fulltext scans over publications #26702. No additional production fallback or duplicate resolver logic is needed in this branch.
    • A clean v4.1.2 instance reproduced the same hidden-index lookup failure with a natural indexed predicate. The supplied v4.2.1 production evidence and the historical source path are consistent with that reproduction.

    Regression proof:

    • TestResolveIndexTableByRefUsesPublisherDatabase requires the publisher database name, publisher tenant context, hidden-index relation, and returned ObjectRef. Removing the existing DbName: ref.SchemaName line temporarily made this test fail because the database argument became empty; the line was restored before commit.
    • The new pub_sub_secondary_index BVT uses 100,000 rows and two regular secondary indexes. It verifies natural EXPLAIN selection of both indexes, expected indexed results, base-table and IGNORE INDEX controls, separate subscriber aliases/accounts, table-publication access boundaries, membership revoke/restore, publication removal, prepared statements, and cleanup.
    • The generated result was manually checked against the SQL semantics. The final BVT run against an isolated current-main service passed 54/54 with a 100% success rate; the focused UT and full ./pkg/frontend package also passed.

    Draft PR: #28284

    The PR is intentionally test/CI-only because the production correction is already present on main; release branches without that line still need their scoped backport and normal release validation.

  5. gouhongshen commented on Sep 6, 2026

    @gouhongshen
    Contributor

    PR #28284 is trying to fix this issue.

  6. gouhongshen commented on Sep 6, 2026

    @gouhongshen
    Contributor

    PR #28284 has merged and is awaiting manual validation. The issue remains open.

  7. added a commit that references this issue on Sep 6, 2026
    33640a3
  8. added and removed
    severity/s0
    on Sep 16, 2026
  9. Ariznawlll commented on Sep 17, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • commit:8e8e1998ef02b1f6233ddb1c2d3208f3b70d2d83
    • 部署:隔离的单 CN / 单 TN / 单 LogService 本地集群,通过 MySQL 协议执行。
    • 日期:2026-09-17

    原问题验证

    使用发布账户与订阅账户构建 100,000 行带普通索引的发布表,在订阅侧验证索引可用性。按 event_type 和 created_at 的查询计划均出现 Index Table Scan;订阅表、强制基础表扫描控制查询和 prepare 查询的计数结果一致。

    Happy Path 覆盖

    覆盖多账户 publication/subscription、100K 数据、两种索引谓词、EXPLAIN 与 prepared statement。

    Unhappy Path 覆盖

    不适用:该 issue 的验收目标是订阅侧索引可见、可选且结果正确;同时验证测试结束后完整清理发布、订阅和账户资源。

    白盒验证

    通过 EXPLAIN 检查 Index Table Scan,并以 IGNORE INDEX 的基础表扫描结果作为对照。

    回归测试

    已加入 MOTR PR #181:issue_28279_subscription_secondary_indexes.py。本地连续 3 轮通过。

    测试证据

    motr --repeat 3 08_multitenant_rbac.issue_28279_subscription_secondary_indexes:3/3 通过,跨账户索引计划和结果对照均一致。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions