Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
No matching open Q9 issue was found. #29533 covers missing-statistics tiny Cartesian writers, not a six-table filtered TPCH SELECT. #26742 covers a different TPC-DS Q64 budget failure, and #29407 covers Q21 pipeline connection timeouts. None accurately tracks this zero-query-error, scale-dependent Q9 plan regression.
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 controlled planner comparison:
52eecb55bee9b55e776d09c64dfbaa55d5db8f1f. - Current main checked on October 2:
b75086c6fab613b147bff4e474dddac7e237c637. The relevant INNER estimation and join-construction paths are still present; this head was not the nightly measured version.
Other Environment Information
- Tencent Cloud TKE, weekly-shadow-1x2: one TP CN and two AP CNs; Q9 executes on both AP CNs in each comparison.
- Each CN: 14 CPUs, 55Gi limit, 16Gi FileService memory cache, 1800Gi disk cache on a 2000Gi directpv-min-io PVC.
- GOMEMLIMIT=25000MiB, GOGC=200; resource and runtime settings match.
- TN: 14 CPUs, 32Gi limit, 5Gi memory cache.
- mo-tpch version is identical:
77081d5b3f24fec6e57b660427f0470ff73639ab. - Controlled planner diagnostic: Go 1.26.4, macOS arm64; real SQL parser and normal optimizer with fixed synthetic statistics. It does not run a mock executor or represent a full 1T execution-time A/B.
Actual Behavior
Q9 becomes approximately 5.6 times slower at scale factor 1000, including warmup and both measured rounds:
| Q9 SF1000 duration, seconds | c2abd6a | f6eb974 manual run | 32f5498 nightly |
|---|---|---|---|
| Warmup | 144.560 | 815.956 | 825.455 |
| Measured round 1 | 146.714 | 811.679 | 804.655 |
| Measured round 2 | 143.616 | 803.449 | 813.286 |
SF100 Q9 also rises from approximately 11.6s to 20.4s. SF1000 suite duration rises from roughly 1544s to 2224s, with Q9 contributing the dominant individual-query increase. Most queries do not exhibit this magnitude.
The compared Q9 result files from both measured rounds, both versions, have the same SHA-256:
6a585f7ecdce92e26fb837d5d91af0f0c2e7e7547055e1f0247ab5162b3b753c
This observation is a performance regression, not a demonstrated wrong-result problem. A successful suite or identical result does not negate the performance problem.
Expected Behavior
Preserve correct genuine Cartesian-product estimates and memory safety, but do not use a not-yet-connected join-order construction node as though the logical SQL really requires an unfiltered Cartesian product.
Q9 should apply its selective part/partsupp/supplier/nation branch before performing the large lineitem/orders join when the same statistics support the previously efficient order. The fix must be general to the planner contract, not a Q9-specific exception.
Steps to Reproduce
Actual workload
Run the same pinned mo-tpch Q9 on SF100 and SF1000, keeping data, statistics, worker topology and resource settings fixed. The exact SQL uses %pink%:
SELECT nation, o_year, SUM(amount) AS sum_profit
FROM (
SELECT n_name AS nation,
EXTRACT(YEAR FROM o_orderdate) AS o_year,
l_extendedprice * (1-l_discount) - ps_supplycost * l_quantity AS amount
FROM part, supplier, lineitem, partsupp, orders, nation
WHERE s_suppkey = l_suppkey
AND ps_suppkey = l_suppkey
AND ps_partkey = l_partkey
AND p_partkey = l_partkey
AND o_orderkey = l_orderkey
AND s_nationkey = n_nationkey
AND p_name LIKE '%pink%'
) profit
GROUP BY nation, o_year
ORDER BY nation, o_year DESC;Controlled plan counterexample and single-change counterfactual
An isolated diagnostic parses the SQL above and invokes the normal NewBaseOptimizer. It supplies the identical completed named statistics to both exact commits through the existing MockCompilerContext/StatsCache fixture. No physical objects or execution-time counters are simulated.
Representative SF1000 row counts are:
nation=25
part=200,000,000
supplier=10,000,000
partsupp=800,000,000
orders=1,500,000,000
lineitem=6,001,215,000
Join-key NDVs use the corresponding part/supplier/order domains. Identical per-column size/range/NDV maps are supplied to both versions. The diagnostic is repeated at SF1, SF100 and SF1000. These are synthetic controlled statistics, not a claim to have exported the original TKE statistics.
At SF1000, the normal compacted plans are:
parent 52eecb55be:
filtered branch = partsupp JOIN filtered part JOIN supplier JOIN nation
node 9: lineitem JOIN filtered branch, estimated output 1,200,243,000
node 10: orders JOIN that filtered lineitem result
build-side estimate 1,200,243,000
merge f6eb974d5a:
node 2: lineitem JOIN orders BEFORE the filtered branch
estimated output 6,001,215,000
build-side orders estimate 1,500,000,000
node 10: the large node-2 result JOIN filtered branch
Both parent and merge tests pass and produce a real typed plan. A third run keeps all of #29527 except the changed INNER cardinality formula: it temporarily restores the parent's formula in the scratch worktree. All 33 scan/join JSON records across the three scale factors then become byte-identical to the parent diagnostic. This single-change reversal identifies the inducing estimation change, not merely any commit in the interval.
This is a diagnostic counterfactual, not a proposed production rollback. Reverting genuine Cartesian multiplication would reintroduce the memory-safety problem fixed by #29527. The temporary source change is not a submitted fix.
Additional information
Code-level interaction
- ReCalcNodeStats INNER estimation now multiplies child cardinalities when OnList is empty.
- buildSubJoinTree creates intermediate INNER nodes without OnList during join-order construction. It also sorts constructed dimension subtrees by their current statistics.
- appendNode immediately calculates those nodes' statistics.
- determineJoinOrder only later installs the gathered equality predicates through pushdownFilters.
- Applying genuine-Cartesian estimation to these temporary not-yet-connected nodes changes ordering decisions before the actual join predicates have been restored. The exact parent/merge and one-formula counterfactual above reproduce the resulting bad Q9 order.
Actual service evidence matches the changed plan
Matched measured-round-1 operations, in UTC:
| Previous run | New run | |
|---|---|---|
| Namespace | mo-main-family-36734661643-1 | mo-main-family-36881937434-1 |
| Start | 2026-09-30 18:36:29.448970 | 2026-10-01 18:53:09.849273 |
| End | 18:38:56.123153 | 19:06:34.464916 |
| Statement | 01a0f39a-9580-797e-964e-f891184ee86f | 01a0f8d0-3552-714f-8776-b88c82a3b06c |
| Trace | a3edd259-e057-d2ab-560d-3aa5d2d2bb98 | f4b13793-c5de-dfec-5082-fcea6eb2bc9a |
| HashBuild Spill node | 10 | 2 |
| Spill diagnostic workers | 14 per AP, 28 total | 14 per AP, 28 total |
| QueryHashBudgetCapBytes | 42,949,672,960 | 42,949,672,960 |
Both versions spill: the defect is not simply that the new version first introduced spilling. The observed node 10 -> node 2 transition matches the controlled plan's late filtered join -> early unfiltered orders/lineitem join. A complete production EXPLAIN and the original persisted statistics were not recovered, so this semantic node mapping is supported by the controlled counterexample rather than independently exported from the original runtime plan.
CPU profiles from the two AP CNs over the identified query intervals:
| Inclusive sampled CPU seconds | Previous | New |
|---|---|---|
| HashJoin.Call | 1582.48 | 5370.06 |
| Shuffle.Call | 1024.87 | 3870.38 |
| Shuffle.enqueueBySels | 250.47 | 2011.54 |
| SpillEngine.ScatterProbeTable | 81.31 | 1512.24 |
ScatterProbeTable CPU work increases about 18.6x. These inclusive measurements overlap; they must not be added together or confused with query wall time. Operator final QuerySpillDiskUsedBytes is a shared current-use gauge, not cumulative disk I/O, so it is not summed across worker summaries.
Confidence and remaining validation boundary
The introducing formula change and Q9 plan-order regression are causally established in the controlled planner comparison, and the original service trace shows the same old/new spill-node transition and large extra execution work. This is substantially stronger than a commit/date correlation or a cold-cache explanation.
An exact-parent/fix full SF1000 same-slot execution A/B has not yet been run. Therefore the local diagnostic does not independently prove that the formula accounts for every second of the observed 5.6x increase, or that any proposed fix fully restores performance.
Original evidence
- Previous AP job.
- Intermediate manual run, already slow.
- New nightly SSB/TPCH job.
- Introducing PR #29527.
The prepared-replanning TPCC defect is a separate contract tracked in #29564 and should not be inferred to cause Q9's execution-side slowdown.
Activity
Fix statistics-driven plan churn and predicate-aware join ordering (#…