Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
#29429 concerns long-held locks, transaction errors and unfinished transactions on a different run. This report concerns five completed TPCC configurations with zero transaction errors and a large increase in repeated prepared planning. Historical #27804 and #27807 concern other prepared fast-path regressions. #29533 concerns tiny Cartesian INSERT/REPLACE planning, not this prepared-update invalidation loop.
Branch Name
main
Commit ID
- Previous measured version:
c2abd6a54b7cd3e13c1b1494388cd7a81b8369d4. - Intermediate slow version:
f6eb974d5a77346e22bf29be9de05fbdcb256dc8, merge of Fix Cartesian DML memory planning and transient statistics reuse #29527. - Latest nightly measured version:
32f54981401fd3888702f2dab8702d2e62c6997a. - Exact parent used for the small SQL counterexample:
52eecb55bee9b55e776d09c64dfbaa55d5db8f1f. - Current main checked on October 2:
b75086c6fab613b147bff4e474dddac7e237c637. It still contains the same stats admission guard; this head was not the nightly measured version.
Other Environment Information
- Tencent Cloud TKE, weekly-shadow-1x2 family: one TP CN, two AP CNs.
- CN: 14 CPUs, 55Gi container limit, 16Gi FileService memory cache, 1800Gi disk cache on a 2000Gi directpv-min-io PVC.
- CN runtime: GOMEMLIMIT=25000MiB, GOGC=200; runtime environment matches between the two main comparison runs.
- TN: 14 CPUs, 32Gi container limit, 5Gi memory cache.
- mo-tpcc pinned to
69ebaac65be330115eeb7f0d22488f11079bb5ffin both runs; case durations are five minutes. - Local causal SQL diagnostic: macOS arm64, Go 1.26.4, isolated embedded MO cluster and real MySQL COM_STMT_PREPARE/COM_STMT_EXECUTE. Native inputs were identical between the exact parent and merge commit. No TKE cluster or formal workflow was modified.
Actual Behavior
All five completed TPCC configurations lose 53-71% of tpmC:
| Warehouses / terminals | c2abd6a | f6eb974 manual run | 32f5498 nightly | Nightly change |
|---|---|---|---|---|
| 10 / 10 | 6582.39 | 2585.97 | 2619.53 | -60.2% |
| 10 / 100 | 11734.66 | 3673.37 | 3783.81 | -67.8% |
| 100 / 100 | 12927.58 | 3667.49 | 3742.52 | -71.1% |
| 100 / 1000 | 11662.58 | 3400.92 | 3391.40 | -70.9% |
| 1000 / 1000 | 5102.44 | 2373.20 | 2382.96 | -53.3% |
Transaction Error is zero and consistency checks pass for these configurations. The new nightly TP job is green despite the throughput regression. The earlier baseline TP job failed later and its overall run was canceled; only the completed five TPCC configurations above are used as baseline evidence, not an assertion that the entire baseline run passed.
Runtime evidence: prepared planning replaces the previous fast path
CPU profiles collected on the TP CN during the first 10W/10T interval show:
| Inclusive sampled CPU share | Previous version | New nightly |
|---|---|---|
| initExecuteStmtParamWithResolverInSession | 3.48% | 46.93% |
| buildPlanWithStats | 0.127% | 28.08% |
| plan.BuildPlan | 0.126% | 25.62% |
| walkExpressionsInOwner | 0.177% | 20.70% |
| rebuildPreparePlan | Not observed in the matched profile | 13.70% |
These are inclusive, overlapping CPU shares, not additive components. The direct CachedPlanStatsChanged cost is approximately 0.53%; the important cost is the rebuilding and traversal it induces.
For the corresponding four-minute window, Prometheus increase(mo_txn_statement_duration_seconds_count{type="build-plan"}[240s]) is approximately 170 on the previous TP CN and 581,222 on the new one. The series was checked by instance/job/pod and is not a duplicate-scrape sum. These are extrapolated histogram observation counts, not exact SQL or transaction counts. The BuildPlan label also includes light EXECUTE wrapping and must not by itself be interpreted as a rebuild counter.
Expected Behavior
Ordinary prepared point updates should retain their reusable plan generation when schema, parameter domains and relevant execution contracts are unchanged. Repeated ordinary DML in a transaction should not repeatedly perform full planning solely because a conservative workspace estimate grows by one row version.
Statistics-sensitive admission must retain the safety introduced by #29527 without broadly destroying prepared point-query/update reuse.
Steps to Reproduce
The causal counterexample is much smaller than TPCC and does not require COS or a large dataset:
- Start an isolated MO service at the exact parent and at the merge commit using the same configuration.
- Create
t(id INT PRIMARY KEY, v INT)and insert 128 committed rows, all with v=0. - Prepare
SELECT v FROM t WHERE id=?andUPDATE t SET v=v+1 WHERE id=?using the real MySQL protocol. - In a read-only transaction, execute the SELECT 20 times; commit.
- Begin another transaction and execute the UPDATE for keys 1 through 20, using the same prepared handle. Each update affects exactly one row.
- Execute the SELECT 20 times against key 1 and verify v=1; rollback.
- Read the existing
TxnStatementBuildPlanHistogramsample count immediately before and after each loop, excluding BEGIN/COMMIT/ROLLBACK and setup.
Actual local results, with unmodified production source at both exact commits:
| Phase, 20 real protocol EXECUTEs | Parent 52eecb5 | Merge f6eb974 |
|---|---|---|
| Read-only point SELECT: BuildPlan observations | 20 | 20 |
| Point UPDATE, 20 distinct keys: BuildPlan observations | 1 | 58 |
| Point SELECT in dirty workspace: BuildPlan observations | 20 | 22 |
Both tests completed successfully, including all returned-value and RowsAffected assertions. This comparison is of planning observations, not a local tpmC benchmark. Repeating updates to the same key is a weaker counterexample because workspace writes can coalesce; distinct keys make the estimate growth repeatable.
Separate bounded diagnostic logging, confined to the scratch cluster, shows successive comparisons such as:
cached=128 observed=129 readonly=false
cached=129 observed=130 readonly=false
cached=130 observed=131 readonly=false
...
cached=146 observed=147 readonly=false
No table-cardinality growth is necessary: these are UPDATE row versions, not inserted business rows. The diagnostic print was removed before the clean parent/merge result above.
Additional information
Code-level cause and introducing PR
#29527 adds the following chain:
- Prepared admission calls CachedPlanStatsChanged on an otherwise reusable plan, setting needRebuild when it reports a change.
- CachedPlanStatsChanged compares fresh unfiltered cardinality with the cached scan's TableCnt using exact inequality. A one-row difference is enough.
- txnTable.Stats combines snapshot-visible partition estimates and workspace INSERT entries, including new versions generated by UPDATE.
- StatsCacheEligible disables the ordinary fast cache in a writing workspace; admission sees the changing transient estimate.
- Each mismatch invokes the existing full prepared rebuild path, invalidating the generation again as the next workspace version is added.
A single-change counterfactual keeps all of f6eb974 but omits only the new prepared CachedPlanStatsChanged admission block in a scratch worktree. The three phase counts return to 20 / 1 / 20, identical to the parent. This counterfactual also passes all real-SQL result assertions. The temporary source change is not a proposed or submitted production fix.
This establishes a newly introduced, publicly reachable repeated-replanning defect and identifies the triggering admission check, not just a timestamp correlation. Production profiling and counters match the predicted expensive path. The exact percentage of the full five-case TPCC drop attributable to this defect still needs a same-slot whole-workload parent/fix A/B; the local diagnostic does not claim to reproduce those full throughput percentages.
Original evidence
- Previous TP job, completed TPCC phases.
- Intermediate manual run already at the low throughput level.
- New nightly TPCC/Sysbench job.
- Introducing PR #29527.
The five commits after the nightly measured SHA must not be judged from that nightly result. Likewise, the five commits between f6eb974 and 32f5498 cannot be the earliest cause of a slowdown already visible at f6eb974.
Do not conflate this with Q9's separate join-order/spill regression tracked in #29565, even though the same PR is implicated. No result corruption has been observed in this TPCC comparison.
Activity
Fix statistics-driven plan churn and predicate-aware join ordering (#…