Skip to content

test: cover secondary indexes in publication subscriptions - #28284

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-28279-852c4c6c
Sep 6, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-28279-852c4c6c

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:

Related to #28279

What this PR does / why we need it:

Root cause

On v4.1.4 (a185c23b375956afe098320baf8df39000a43936) and v4.2.1 (d2393868a7aaa6343518d80849fe4696aa3577e9), TxnCompilerContext.ResolveIndexTableByRef rebuilt subscription metadata with the publisher tenant only. getRelation uses SubscriptionMeta.DbName; the empty value replaced the publisher database name, so a planner-selected hidden regular-index table was looked up in the wrong database and the query failed with no such table ...__mo_index_secondary_<uuid>.

The current main branch already contains the production correction, DbName: ref.SchemaName, from merged PR #26702. This PR adds executable regression coverage for the ordinary secondary-index path described by #28279 and intentionally does not duplicate or alter that production logic.

Changes

  • Add TestResolveIndexTableByRefUsesPublisherDatabase, which asserts the publisher database name, publisher tenant context, hidden-index relation, and returned ObjectRef at the frontend resolver boundary.
  • Add a publication/subscription BVT with 100,000 rows and two regular secondary indexes. It covers natural optimizer selection of both indexes, base-table and IGNORE INDEX controls, separate subscription aliases/accounts, database-level and table-level publications, unpublished-object denial, membership revoke/restore, publication removal, prepared statements, and cleanup.
  • Keep the change test-only: no fallback path, duplicate resolver logic, or unrelated SHOW INDEX behavior is included.

Issue-to-test proof

#28279 behavior Regression proof
The resolver must retain the publisher database while resolving a hidden secondary-index table. TestResolveIndexTableByRefUsesPublisherDatabase requires Database(..., "publisher_db", ...); temporarily removing the existing DbName: ref.SchemaName line made this test fail because the database argument was empty.
Database publication queries must work when the optimizer selects either regular secondary index. pub_sub_secondary_index.sql asserts EXPLAIN selects idx_event_type and idx_created_at, and both queries return the expected count of 2.
Indexed and base-table paths must agree, while bypassing indexes remains a control. The BVT checks COUNT(*) = 100000, both natural indexed predicates, and the equivalent IGNORE INDEX query.
Subscription context must remain scoped to the authorized object and survive normal aliases. The BVT uses two subscriber accounts, separate database aliases, a table-level publication, and verifies that the unpublished private_events table is denied by the table-level subscription.
Publication membership and removal must invalidate indexed prepared queries cleanly. The BVT verifies the expected authorization error after revocation, success after membership restore, and the expected missing-publication error after publication removal.

Investigation and baseline

  • The exact missing field was confirmed in both reported release tags; the corresponding line is present on current main through fix: support fulltext scans over publications #26702.
  • A clean v4.1.2 instance also reproduced the hidden-index lookup failure with a natural indexed predicate.
  • The generated BVT result was manually inspected against the SQL semantics before acceptance: 100,000 total rows, two matching rows for each indexed predicate, successful database-publication access, table-publication denial for private_events, and the expected revoke/removal errors.

Tests run

  • NATIVE_BUILD_JOBS=4 make cgo
  • NATIVE_BUILD_JOBS=4 make build
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run '^TestResolveIndexTableByRefUsesPublisherDatabase$' ./pkg/frontend
  • .agents/skills/mo-dev/scripts/mo-cgo-test -p=1 -count=1 -timeout=20m ./pkg/frontend
  • Generated and ran pub_sub_secondary_index with mo-tester against an isolated service built from current main; the final run passed 54/54 with a 100% success rate.

Residual risks

  • The local BVT used one direct CN because the shared local Docker service occupied port 6001; the SQL case is written for the repository's distributed runner and does not depend on a single-CN cache.
  • This PR targets main and contains the regression guard. Release branches that do not yet contain DbName: ref.SchemaName still require the scoped production backport and their normal release validation.

@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.

Deep-reviewed exact head d7af899c2559edb595d659fa535b351de2b99a82.

The test-only scope is appropriate because current main already contains the production correction. The resolver UT has direct regression kill power for both publisher database and tenant context. The BVT proves natural optimizer selection of both regular secondary indexes, compares indexed and IGNORE INDEX results, and covers database/table publication boundaries, multiple subscribers, prepared execution, revoke/restore, publication removal, and cleanup.

Counterexample review found no path where a base scan can make the indexed witness pass: each indexed query is preceded by an explicit plan assertion. The exact-head distributed BVT ran this case successfully at 54/54 in about 2.994 seconds, so the 100k-row cardinality is currently bounded and justified by deterministic index selection. Exact-head UT/SCA/BVT CI is green. No blocking correctness, unhappy-path, performance, or test-quality issue found.

@mergify mergify Bot added the queued label Sep 6, 2026
@mergify

mergify Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-06 13:10 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-06 13:11 UTC · at 2da034110cbce7875c7adec3f12c2e8a8c4e4f7a · squash

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

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

@mergify
mergify Bot merged commit 2da0341 into matrixorigin:main Sep 6, 2026
53 of 54 checks passed
@mergify mergify Bot removed the queued label Sep 6, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#28284)

### Root cause

On v4.1.4 (`a185c23b375956afe098320baf8df39000a43936`) and v4.2.1 (`d2393868a7aaa6343518d80849fe4696aa3577e9`), `TxnCompilerContext.ResolveIndexTableByRef` rebuilt subscription metadata with the publisher tenant only. `getRelation` uses `SubscriptionMeta.DbName`; the empty value replaced the publisher database name, so a planner-selected hidden regular-index table was looked up in the wrong database and the query failed with `no such table ...__mo_index_secondary_<uuid>`.

The current `main` branch already contains the production correction, `DbName: ref.SchemaName`, from merged PR matrixorigin#26702. This PR adds executable regression coverage for the ordinary secondary-index path described by matrixorigin#28279 and intentionally does not duplicate or alter that production logic.

### Changes

- Add `TestResolveIndexTableByRefUsesPublisherDatabase`, which asserts the publisher database name, publisher tenant context, hidden-index relation, and returned `ObjectRef` at the frontend resolver boundary.
- Add a publication/subscription BVT with 100,000 rows and two regular secondary indexes. It covers natural optimizer selection of both indexes, base-table and `IGNORE INDEX` controls, separate subscription aliases/accounts, database-level and table-level publications, unpublished-object denial, membership revoke/restore, publication removal, prepared statements, and cleanup.
- Keep the change test-only: no fallback path, duplicate resolver logic, or unrelated `SHOW INDEX` behavior is included.

### Issue-to-test proof

| matrixorigin#28279 behavior | Regression proof |
| --- | --- |
| The resolver must retain the publisher database while resolving a hidden secondary-index table. | `TestResolveIndexTableByRefUsesPublisherDatabase` requires `Database(..., "publisher_db", ...)`; temporarily removing the existing `DbName: ref.SchemaName` line made this test fail because the database argument was empty. |
| Database publication queries must work when the optimizer selects either regular secondary index. | `pub_sub_secondary_index.sql` asserts `EXPLAIN` selects `idx_event_type` and `idx_created_at`, and both queries return the expected count of 2. |
| Indexed and base-table paths must agree, while bypassing indexes remains a control. | The BVT checks `COUNT(*) = 100000`, both natural indexed predicates, and the equivalent `IGNORE INDEX` query. |
| Subscription context must remain scoped to the authorized object and survive normal aliases. | The BVT uses two subscriber accounts, separate database aliases, a table-level publication, and verifies that the unpublished `private_events` table is denied by the table-level subscription. |
| Publication membership and removal must invalidate indexed prepared queries cleanly. | The BVT verifies the expected authorization error after revocation, success after membership restore, and the expected missing-publication error after publication removal. |

### Investigation and baseline

- The exact missing field was confirmed in both reported release tags; the corresponding line is present on current `main` through matrixorigin#26702.
- A clean v4.1.2 instance also reproduced the hidden-index lookup failure with a natural indexed predicate.
- The generated BVT result was manually inspected against the SQL semantics before acceptance: 100,000 total rows, two matching rows for each indexed predicate, successful database-publication access, table-publication denial for `private_events`, and the expected revoke/removal errors.

### Tests run

- `NATIVE_BUILD_JOBS=4 make cgo`
- `NATIVE_BUILD_JOBS=4 make build`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run '^TestResolveIndexTableByRefUsesPublisherDatabase$' ./pkg/frontend`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -p=1 -count=1 -timeout=20m ./pkg/frontend`
- Generated and ran `pub_sub_secondary_index` with `mo-tester` against an isolated service built from current `main`; the final run passed `54/54` with a 100% success rate.

### Residual risks

- The local BVT used one direct CN because the shared local Docker service occupied port 6001; the SQL case is written for the repository's distributed runner and does not depend on a single-CN cache.
- This PR targets `main` and contains the regression guard. Release branches that do not yet contain `DbName: ref.SchemaName` still require the scoped production backport and their normal release validation.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#28284)

### Root cause

On v4.1.4 (`a185c23b375956afe098320baf8df39000a43936`) and v4.2.1 (`d2393868a7aaa6343518d80849fe4696aa3577e9`), `TxnCompilerContext.ResolveIndexTableByRef` rebuilt subscription metadata with the publisher tenant only. `getRelation` uses `SubscriptionMeta.DbName`; the empty value replaced the publisher database name, so a planner-selected hidden regular-index table was looked up in the wrong database and the query failed with `no such table ...__mo_index_secondary_<uuid>`.

The current `main` branch already contains the production correction, `DbName: ref.SchemaName`, from merged PR matrixorigin#26702. This PR adds executable regression coverage for the ordinary secondary-index path described by matrixorigin#28279 and intentionally does not duplicate or alter that production logic.

### Changes

- Add `TestResolveIndexTableByRefUsesPublisherDatabase`, which asserts the publisher database name, publisher tenant context, hidden-index relation, and returned `ObjectRef` at the frontend resolver boundary.
- Add a publication/subscription BVT with 100,000 rows and two regular secondary indexes. It covers natural optimizer selection of both indexes, base-table and `IGNORE INDEX` controls, separate subscription aliases/accounts, database-level and table-level publications, unpublished-object denial, membership revoke/restore, publication removal, prepared statements, and cleanup.
- Keep the change test-only: no fallback path, duplicate resolver logic, or unrelated `SHOW INDEX` behavior is included.

### Issue-to-test proof

| matrixorigin#28279 behavior | Regression proof |
| --- | --- |
| The resolver must retain the publisher database while resolving a hidden secondary-index table. | `TestResolveIndexTableByRefUsesPublisherDatabase` requires `Database(..., "publisher_db", ...)`; temporarily removing the existing `DbName: ref.SchemaName` line made this test fail because the database argument was empty. |
| Database publication queries must work when the optimizer selects either regular secondary index. | `pub_sub_secondary_index.sql` asserts `EXPLAIN` selects `idx_event_type` and `idx_created_at`, and both queries return the expected count of 2. |
| Indexed and base-table paths must agree, while bypassing indexes remains a control. | The BVT checks `COUNT(*) = 100000`, both natural indexed predicates, and the equivalent `IGNORE INDEX` query. |
| Subscription context must remain scoped to the authorized object and survive normal aliases. | The BVT uses two subscriber accounts, separate database aliases, a table-level publication, and verifies that the unpublished `private_events` table is denied by the table-level subscription. |
| Publication membership and removal must invalidate indexed prepared queries cleanly. | The BVT verifies the expected authorization error after revocation, success after membership restore, and the expected missing-publication error after publication removal. |

### Investigation and baseline

- The exact missing field was confirmed in both reported release tags; the corresponding line is present on current `main` through matrixorigin#26702.
- A clean v4.1.2 instance also reproduced the hidden-index lookup failure with a natural indexed predicate.
- The generated BVT result was manually inspected against the SQL semantics before acceptance: 100,000 total rows, two matching rows for each indexed predicate, successful database-publication access, table-publication denial for `private_events`, and the expected revoke/removal errors.

### Tests run

- `NATIVE_BUILD_JOBS=4 make cgo`
- `NATIVE_BUILD_JOBS=4 make build`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run '^TestResolveIndexTableByRefUsesPublisherDatabase$' ./pkg/frontend`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -p=1 -count=1 -timeout=20m ./pkg/frontend`
- Generated and ran `pub_sub_secondary_index` with `mo-tester` against an isolated service built from current `main`; the final run passed `54/54` with a 100% success rate.

### Residual risks

- The local BVT used one direct CN because the shared local Docker service occupied port 6001; the SQL case is written for the repository's distributed runner and does not depend on a single-CN cache.
- This PR targets `main` and contains the regression guard. Release branches that do not yet contain `DbName: ref.SchemaName` still require the scoped production backport and their normal release validation.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#28284)

### Root cause

On v4.1.4 (`a185c23b375956afe098320baf8df39000a43936`) and v4.2.1 (`d2393868a7aaa6343518d80849fe4696aa3577e9`), `TxnCompilerContext.ResolveIndexTableByRef` rebuilt subscription metadata with the publisher tenant only. `getRelation` uses `SubscriptionMeta.DbName`; the empty value replaced the publisher database name, so a planner-selected hidden regular-index table was looked up in the wrong database and the query failed with `no such table ...__mo_index_secondary_<uuid>`.

The current `main` branch already contains the production correction, `DbName: ref.SchemaName`, from merged PR matrixorigin#26702. This PR adds executable regression coverage for the ordinary secondary-index path described by matrixorigin#28279 and intentionally does not duplicate or alter that production logic.

### Changes

- Add `TestResolveIndexTableByRefUsesPublisherDatabase`, which asserts the publisher database name, publisher tenant context, hidden-index relation, and returned `ObjectRef` at the frontend resolver boundary.
- Add a publication/subscription BVT with 100,000 rows and two regular secondary indexes. It covers natural optimizer selection of both indexes, base-table and `IGNORE INDEX` controls, separate subscription aliases/accounts, database-level and table-level publications, unpublished-object denial, membership revoke/restore, publication removal, prepared statements, and cleanup.
- Keep the change test-only: no fallback path, duplicate resolver logic, or unrelated `SHOW INDEX` behavior is included.

### Issue-to-test proof

| matrixorigin#28279 behavior | Regression proof |
| --- | --- |
| The resolver must retain the publisher database while resolving a hidden secondary-index table. | `TestResolveIndexTableByRefUsesPublisherDatabase` requires `Database(..., "publisher_db", ...)`; temporarily removing the existing `DbName: ref.SchemaName` line made this test fail because the database argument was empty. |
| Database publication queries must work when the optimizer selects either regular secondary index. | `pub_sub_secondary_index.sql` asserts `EXPLAIN` selects `idx_event_type` and `idx_created_at`, and both queries return the expected count of 2. |
| Indexed and base-table paths must agree, while bypassing indexes remains a control. | The BVT checks `COUNT(*) = 100000`, both natural indexed predicates, and the equivalent `IGNORE INDEX` query. |
| Subscription context must remain scoped to the authorized object and survive normal aliases. | The BVT uses two subscriber accounts, separate database aliases, a table-level publication, and verifies that the unpublished `private_events` table is denied by the table-level subscription. |
| Publication membership and removal must invalidate indexed prepared queries cleanly. | The BVT verifies the expected authorization error after revocation, success after membership restore, and the expected missing-publication error after publication removal. |

### Investigation and baseline

- The exact missing field was confirmed in both reported release tags; the corresponding line is present on current `main` through matrixorigin#26702.
- A clean v4.1.2 instance also reproduced the hidden-index lookup failure with a natural indexed predicate.
- The generated BVT result was manually inspected against the SQL semantics before acceptance: 100,000 total rows, two matching rows for each indexed predicate, successful database-publication access, table-publication denial for `private_events`, and the expected revoke/removal errors.

### Tests run

- `NATIVE_BUILD_JOBS=4 make cgo`
- `NATIVE_BUILD_JOBS=4 make build`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run '^TestResolveIndexTableByRefUsesPublisherDatabase$' ./pkg/frontend`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -p=1 -count=1 -timeout=20m ./pkg/frontend`
- Generated and ran `pub_sub_secondary_index` with `mo-tester` against an isolated service built from current `main`; the final run passed `54/54` with a 100% success rate.

### Residual risks

- The local BVT used one direct CN because the shared local Docker service occupied port 6001; the SQL case is written for the repository's distributed runner and does not depend on a single-CN cache.
- This PR targets `main` and contains the regression guard. Release branches that do not yet contain `DbName: ref.SchemaName` still require the scoped production backport and their normal release validation.

Approved by: @XuPeng-SH

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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants