Repository navigation
test: cover secondary indexes in publication subscriptions - #28284
Conversation
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
Merge Queue Status
This pull request spent 23 seconds in the queue, including 2 seconds running CI. Required conditions to merge
|
…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
…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
…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
What type of PR is this?
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.ResolveIndexTableByRefrebuilt subscription metadata with the publisher tenant only.getRelationusesSubscriptionMeta.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 withno such table ...__mo_index_secondary_<uuid>.The current
mainbranch 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
TestResolveIndexTableByRefUsesPublisherDatabase, which asserts the publisher database name, publisher tenant context, hidden-index relation, and returnedObjectRefat the frontend resolver boundary.IGNORE INDEXcontrols, separate subscription aliases/accounts, database-level and table-level publications, unpublished-object denial, membership revoke/restore, publication removal, prepared statements, and cleanup.SHOW INDEXbehavior is included.Issue-to-test proof
TestResolveIndexTableByRefUsesPublisherDatabaserequiresDatabase(..., "publisher_db", ...); temporarily removing the existingDbName: ref.SchemaNameline made this test fail because the database argument was empty.pub_sub_secondary_index.sqlassertsEXPLAINselectsidx_event_typeandidx_created_at, and both queries return the expected count of 2.COUNT(*) = 100000, both natural indexed predicates, and the equivalentIGNORE INDEXquery.private_eventstable is denied by the table-level subscription.Investigation and baseline
mainthrough fix: support fulltext scans over publications #26702.private_events, and the expected revoke/removal errors.Tests run
NATIVE_BUILD_JOBS=4 make cgoNATIVE_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/frontendpub_sub_secondary_indexwithmo-testeragainst an isolated service built from currentmain; the final run passed54/54with a 100% success rate.Residual risks
mainand contains the regression guard. Release branches that do not yet containDbName: ref.SchemaNamestill require the scoped production backport and their normal release validation.