Repository navigation
Description
Summary
The publication/subscription schema compatibility helper checkColExists queries the system-owned mo_catalog.mo_pubs / mo_catalog.mo_subs schema without constraining mo_columns.account_id.
This is a reproducible, account-count-dependent performance defect in both Main and 4.2-dev, not a demonstrated wrong-result or data-isolation bug. The helper's result concerns one system table, but its lookup cost grows with unrelated tenants' column metadata.
Root cause
The mo_columns compound primary key starts with:
(account_id, att_database, att_relname, attname)
The helper already runs with catalog.System_Account, but its SQL only supplies the last three key parts. Attaching the system execution identity does not supply the missing SQL key predicate.
All three current callers inspect the schema of the sys-owned mo_pubs or mo_subs tables. This is separate from the tenant publication/subscription data rows subsequently selected by those callers.
Source at tested revisions:
The original EXPLAIN has the three column filters but no complete compound-key equality. Adding only account_id = 0 produces __mo_cpkey_col equality and a block filter.
Controlled reproduction and measurements
Already reproduced on isolated local Main and 4.2 instances. Measurements compare two SQL forms against the same populated catalogue and connection, not different load runs. Each phase uses 24 alternating pairs, reversing query order on successive pairs and asserting identical complete returned rows.
| Tested version | Catalogue column rows after creating 96 accounts | Original query median before the accounts | Original query median after the accounts | Query with account_id=0 after the accounts |
|---|---|---|---|---|
Main 5669b1683cf2188652c4ea56390e6a77ab5d13d8 |
107,630 | 0.420 ms | 17.806 ms | 0.453 ms |
4.2-dev c3fa851d810306fac9b8dc3381a49d8193f27a19 |
105,976 | 0.816 ms | 14.808 ms | 0.442 ms |
The paired SQL forms returned the same answer, [(1,)], in both versions and every measured pair. The populated lookup is approximately 39x / 33x more expensive without the system-account predicate.
These are local lookup measurements, not formal TKE baseline results or end-to-end DROP ACCOUNT speedups.
Reproduction recipe
Use a disposable instance and a sys-authorized session; do not add test accounts to a customer environment.
- Before adding accounts, execute the two queries below in 24 alternating pairs. Compare all returned rows; record elapsed time and
EXPLAIN. - Create 96 ordinary accounts with one fresh, unique test prefix. Default per-account catalogue metadata is enough; no large business tables are necessary.
- Repeat the same paired queries on the same connection. Record
SELECT COUNT(*) FROM mo_catalog.mo_columns. - Delete only the accounts created in step 2 and verify that none of their exact names remain. Both recorded local probes completed account cleanup with no errors or remaining accounts.
Original helper query:
SELECT 1
FROM mo_catalog.mo_columns
WHERE att_database = 'mo_catalog'
AND att_relname = 'mo_subs'
AND attname = 'sub_account_name';Single-variable control:
SELECT 1
FROM mo_catalog.mo_columns
WHERE account_id = 0
AND att_database = 'mo_catalog'
AND att_relname = 'mo_subs'
AND attname = 'sub_account_name';Also inspect both using EXPLAIN. The equivalent mo_pubs/account_name compatibility check has the same missing-key-predicate code path; the timing numbers above are specifically for mo_subs/sub_account_name.
Expected behavior and minimal remediation
The cost of checking one system table's schema should not grow with unrelated tenants' catalogue columns.
Add account_id = catalog.System_Account to this compatibility query only. Preserve:
- Tenant publication/subscription data selection and cross-account publication behavior.
- Current/legacy schema presence and absence semantics.
- Caller context, cancellation, SQL errors, malformed-result errors and BackgroundExec ownership.
No catalogue cache, lifecycle lock, DDL transaction boundary, concurrency, retry policy or persistent format change is required.
Fixes and validation
- Main: perf(frontend): bound system catalog compatibility lookups by account #29662
- Equivalent 4.2-dev backport: [4.2-dev] fix(frontend): scope system catalogue compatibility lookups #29665
Both patches add the same one production predicate plus focused tests and exact-SQL mock updates. The seven helper cases cover current/legacy publication and subscription schemas, SQL failure, real context cancellation and malformed executor results. Both complete frontend packages and focused vet checks passed locally. Main additionally passed the existing authenticated two-CN publication consumer covering rollback, commit, source replacement and cancellation; that Main result is not claimed as an extra 4.2 integration run.
PR CI, review and merge status remain separate from these local results.
Scope and non-claims
- Main and 4.2 share this defect; the first introducing commit has not been established. This is not claimed as a newly introduced Main-only regression.
- No wrong answer, tenant data exposure, OOM or catalogue leak has been demonstrated by this reproduction.
- This lookup can amplify repeated schema-check work, but its fraction of total account-cleanup latency has not been isolated.
- This is not the global SNAPSHOT lifecycle lock convoy in #29400; these two patches do not resolve that separate mechanism.
- Keep cross-branch acceptance explicit: Main and 4.2 have separate fix PRs; a local query improvement alone is not grounds to declare all Nightly cleanup failures resolved.
Activity
perf(frontend): bound system catalog compatibility lookups by account (…
[4.2-dev] fix(frontend): scope system catalogue compatibility lookups (…