Repository navigation
Description
Summary
A publication can reference a database owned by another account. That target account can DROP DATABASE successfully while the publication still references the deleted physical database ID. This was reproduced with public SQL on an isolated pessimistic RC service.
This bug is a dependency of #29400: a post-admission DROP check must use the physical database identity across publisher accounts, and publication mutations must participate in the same database lifecycle scope before the new protocol can be enabled.
Reproduction
On a fresh isolated service, using the sys root session unless noted:
CREATE ACCOUNT qa29400_xpub_target ADMIN_NAME='admin' IDENTIFIED BY '111';
-- Connect as qa29400_xpub_target:admin:
CREATE DATABASE qa29400_xpub_db;
CREATE TABLE qa29400_xpub_db.t(a INT PRIMARY KEY);
SELECT dat_id FROM mo_catalog.mo_database WHERE datname='qa29400_xpub_db';
-- Result: 272664.
-- Connect as sys root:
CREATE PUBLICATION qa29400_xpub_pub DATABASE qa29400_xpub_db ACCOUNT qa29400_xpub_target;
SELECT account_id,database_name,database_id,pub_name
FROM mo_catalog.mo_pubs WHERE pub_name='qa29400_xpub_pub';
-- Result: 0, qa29400_xpub_db, 272664, qa29400_xpub_pub.
-- Connect as qa29400_xpub_target:admin:
DROP DATABASE qa29400_xpub_db;
SELECT COUNT(*) FROM mo_catalog.mo_database WHERE datname='qa29400_xpub_db';
-- DROP succeeds; count = 0.
-- Connect as sys root:
SELECT account_id,database_name,database_id,pub_name
FROM mo_catalog.mo_pubs WHERE pub_name='qa29400_xpub_pub';
-- The same publication row still points at database_id 272664.
SELECT COUNT(*) FROM mo_catalog.mo_database WHERE dat_id=272664;
-- 0.The publication and test account were then dropped; fresh sys queries found no test publication, account or physical DB. The owned service shut down cleanly (exit 0).
Same-name new incarnation control
I restarted the same isolated service after cleanup and repeated the cross-account setup. The target DB was physical ID 283024, the sys publication row stored (account_id=0,database_id=283024), and target-admin DROP DATABASE again succeeded. Sys then created a new, same-named database with physical ID 283025. Sys DROP DATABASE qa29400_xpub_db failed with:
ERROR 20101 (HY000): internal error: can not drop database 'qa29400_xpub_db' which is publishing
At that time the only matching publication row referred to old ID 283024; it did not reference new ID 283025. Thus the same name-only predicate also falsely blocks a new physical incarnation when its publisher account matches the DROP account. After dropping the old publication, sys dropped the new DB and test account; all three fresh catalog counts were zero and the restarted owned service exited cleanly.
Expected / actual
Expected: the target physical database cannot be removed while a publication references it, unless the publication is removed or updated atomically according to the product's publication policy.
Actual: DROP DATABASE returns success and leaves a dangling mo_pubs.database_id.
Root cause and scope
resolvePublicationDatabaseByName in pkg/frontend/publication_subscription.go resolves the publisher's database first, then permitted target accounts' databases. The publication row still stores the publisher in mo_pubs.account_id, while database_id can identify a target account's database. isDbPublishing uses getDbPubCountFormat, which counts only account_id=<dropping account> AND database_name=<name> and does not compare the stored physical database_id. buildDropDatabase calls this check at plan time; Scope.DropDatabase does not repeat it after waiting for locks. A same-name replacement also makes a name-only test unsafe.
This report confirms both sequential cross-account orphaning and same-name new-incarnation false blocking. Concurrent RC/SI races and subscriber-visible effects remain source-derived risks, not claimed as reproduced here. Account-wide DATABASE * stores ID 0 and requires a separate policy decision/test; it should not be silently treated as a named physical database.
Suggested fix: query publication references by the resolved physical database ID across publisher accounts, keeping name/account consistency checks; revalidate in the DROP transaction after admission. For #29400, CREATE/ALTER/DROP PUBLICATION must claim the actual target database D scope (ALTER old and new IDs) so fixed SI observes conflicts even across snapshots. Test cross-account and same-account publications, move/rename, same-name new database generation, both commit orders under RC/SI, rollback/cancellation and wildcard semantics.
Evidence
- Isolated binary SHA256:
eb8429f5b66093bb3361202a8559e1c3e0f1fd344ee9aa5a8fd45e759606080f. - Raw outputs under
/private/tmp/mo29400-pub-qa:create-pub.outSHA256afe67d775250afc093a9ab26d8aeb8519ac3f50bb414a0fd8b9fed76d6ad0cf4,drop-target.out9a271f2a916b0b6ee6cecb2426f0b3206ef074578be55d9bc94f6f3fe3ab86aa,post-drop-sys.out0cd0bc2321f7345dc8337ca1c221c1ac2046175ad9a8eda5265df1089cb92101,cleanup.outf456c1ffc6a33cd5dae1ca90cf499aadeabb167b9e687175a8fc62476833374c. Corresponding stderr files are empty. - Recreated-name control raw outputs:
reuse-target-before.outSHA2560c0b5b407c00379f67305e0cd6339ef326b5bad5bc459c71ca93fcaa4bf4afdb,reuse-create-pub.out9c1afede0d06ad7996154585f10b3375419d99cac8668e309792009c1bfea189,reuse-sys-newdb.out7f6a80556e2e650f6a2b029e89c293820c243e087b6273065374c3649ac189b2,reuse-sys-drop.err84a56997d83a7ed336b7781e6526f528a1f7c265ac91b3db04e8ce599da83b7c,reuse-cleanup.outf456c1ffc6a33cd5dae1ca90cf499aadeabb167b9e687175a8fc62476833374c. Successful SQL controls have empty stderr.
Additional QA and release constraints (2026-09-28)
A direct tenant query cannot read sys mo_pubs (ERROR 1146), while a sys query can see both the tenant mo_database row and the sys publication. The DROP predicate must keep the existing shared-transaction BackgroundExec's sys execution context while filtering the original target account in the database lookup. A plain sys query is not proof of the actual tenant shared-transaction path; that path needs a public RC/SI regression.
The existing wildcard publication (DATABASE *) stores physical ID 0 and has dynamic account coverage. The named physical-ID guard should keep the existing nonblocking wildcard DROP behavior; test wildcard-only and named-plus-wildcard cases.
At 1,000,000 unrelated publications on an isolated one-CN service, an exact-ID inner JOIN scanned all million rows and used 19.45 MiB JOIN memory on a miss. A semantically equivalent scalar physical-DBID lookup with LIMIT 1 and an outer COUNT returned 0/1 with about 1.02 MiB scan memory and p95 7.654 ms for an adversarial million-row miss; an exact-ID hit had p95 0.293 ms. These are 100 warm one-connection samples, not a concurrent or cold-I/O guarantee. The miss still scanned all million rows. A nonunique mo_pubs(database_id) index, bootstrap/upgrade validation, and actual internal-query indexed plan are required before this already-serving predicate change is pushed/released. Do not restore the publisher-account filter to improve cost.
mo_pubs.database_id is nullable in the catalog schema and historical v2.0.1 migration copied the old ID without re-resolving it. Before serving the exact-ID predicate, a stopped-catalog audit must fail closed on named rows with NULL/0 or a live physical ID/name contradiction. A positive ID whose database is already absent is a distinct orphan: keep the administrative publication deletion path and never bind it to a new same-name database. The planned full maintenance cutover for #29400 supplies an opportunity for this audit but does not make old data valid by assumption.
Raw local receipts: /private/tmp/mo29400-pub-qa/query-bench-alternatives-miss.json SHA256 d67082dc81a0f38b357cde426584fb2950d1401a7b0b0d78c20a123b8e425cea, HIT e11d3e545ba2383e40faed498abd048754836b772bc7b0a2b85890e1924ab8b4, scalar MISS plan 2b41d1fc9c8a958bb95fef08acfb0b9577a544de2c222b3e4e11500e74facdeb, HIT plan 5287e27e38e0368282dbd0b171bd5ac9ed68f4714b1f57e4ec22c1d4446aa5e2. Synthetic publication/database cleanup was verified at counts 0/0 and the owned service stopped cleanly. Public cross-account and recreated-name controls above remain the bug oracles.
Activity
fix: preserve publication references to physical databases (#29423)
Ariznawlll commentedon Oct 2, 2026
测试版本
maind50a2d475a406829f67127fef7b2ad4abc1c1d3d原问题验证
在上述 commit 运行 issue 对应的定向回归。DROP database 与 publication 生命周期被同一锁序列化;物理 DB 删除前不会留下可见 cross-account publication。
Happy Path 覆盖
覆盖 publication 正常创建/删除和 subscriber 访问。
Unhappy Path 覆盖
覆盖并发 DROP、跨 account 引用和等待窗口;最终 catalog 无悬挂 publication。
白盒验证
关联修复 #29423 已进入当前
main。直接执行并检查的定向测试为:pkg/tests/issues/issue_29414_publication_drop_test.go::TestIssue29414PublicationWaitsForPhysicalDatabaseDrop。回归测试
本问题依赖内部故障注入、并发时序、catalog/optimizer 状态或多组件协议边界,无法由普通 SQL golden 稳定构造,因此不放入 MOTR;回归保留在 MatrixOne UT/BVT 层。对应定向测试在精确 commit 上通过,且未修改用户工作区。
测试证据
d50a2d475a406829f67127fef7b2ad4abc1c1d3dpkg/tests/issues/issue_29414_publication_drop_test.go::TestIssue29414PublicationWaitsForPhysicalDatabaseDrop测试结论
测试通过。