Repository navigation
Description
Fix in the existing unmerged PR
This regression was introduced by the Cartesian-estimate change in the unmerged PR; it is not a main-at-c2 defect. Both findings are repaired in PR #29527, not deferred to a separate PR.
Conservative metadata observations and existing cache/generation admission remove the missing-statistics tiny-writer regression. Final default no-PK/PK/multiple-UNIQUE/regular-index ratios versus main are 0.93/0.84/1.01/1.02x. The earlier review at aa83017933 was reopened for three concrete follow-up findings; these are also repaired in the same PR. Commit 91e413abca893f1337495ebdce45e85251f24237 preserves the remote main merge and passes the final GPT-6.1-sol / xhigh review. See updated validation and provenance. Public SQL verifies a flushed five-row source plus five own writes yields 80 CROSS rows, wide growth preserves its 8200-byte estimate, and a finite 4.29B auto-ID hint reserves only 10,000 IDs with a successful cold allocator write after service restart. No exact row scans or extra state are added. Fresh normal controls show no repeated slowdown; performance limits remain explicit. This issue remains open until the fixing PR merges.
Original diagnosis at f93762e
Is there an existing issue for performance?
- Checked existing issues. [Bug]: SF1000 seed order_line INSERT exhausts HashBuild memory budget #29497 and [Bug]: RIGHT DEDUP admission ignores the query memory limit with accurate statistics #29529 cover memory failures; this report covers a repeatable small-output performance regression exposed by their planner repair in Fix Cartesian DML memory planning and transient statistics reuse #29527.
Environment
- Matched base:
c2abd6a54b7cd3e13c1b1494388cd7a81b8369d4. - PR Fix Cartesian DML memory planning and transient statistics reuse #29527 head:
f93762ed90e618f477a37ecee640ce8395c72d8e. - Linux x86_64, Intel i7-11700, 16 logical CPUs; Go 1.26.4, GOAMD64=v3, GOEXPERIMENT=simd.
- One LOG + one TN + one CN, DISK-V2 on local NVMe, same configuration and native libraries for both binaries.
processLimitationSize=67108864,max_dop=2,join_spill_mem=0.
Details of Performance
Correct Cartesian output estimation is necessary, but existing downstream decisions can multiply the default 1,000-row estimates for tiny unflushed sources and select expensive fixed-overhead paths. Only 40 actual rows were inserted in each measured case below; this is not a capacity benchmark.
Two full comparisons ran sequentially as base1 -> fixed1 -> base2 -> fixed2. The full matrix contains 90 SQL/statistics cells, 360 phase records and 2,128 timed statements. Each write case has five timed samples per phase after a warmup, with a fresh/truncated target for every sample. The table combines ten samples per version; round ratios compare each phase's median. Timings include public SQL planning, execution and commit, but exclude TRUNCATE and stats patching. Every read result and final DML row count passed an independent oracle. This is a local warm-service comparison, not a universal latency prediction.
| Actual 40-row INSERT shape; missing source statistics | Base median ms | PR median ms | PR/base | Round 1 / 2 ratios |
|---|---|---|---|---|
| No explicit PK | 4.885 | 17.651 | 3.61x | 4.39x / 3.23x |
| Composite PK | 9.262 | 20.798 | 2.25x | 2.39x / 1.93x |
| Composite PK + two UNIQUE constraints | 18.668 | 57.329 | 3.07x | 3.16x / 2.61x |
| Ordinary secondary index | 5.019 | 27.771 | 5.53x | 5.78x / 5.09x |
| Integer PK + DOUBLE UNIQUE | 13.975 | 30.116 | 2.16x | 2.16x / 2.26x |
| No PK, 4 KiB payload | 5.919 | 18.410 | 3.11x | 4.49x / 2.92x |
| INSERT IGNORE, composite PK | 9.712 | 20.347 | 2.10x | 2.13x / 2.15x |
The same small-data cases with accurate source/target/index statistics have identical normalized physical shapes between versions and do not exhibit these large plan-changing regressions. INSERT ... LIMIT 1 stays close to the base (9.145 -> 9.627 ms). Plain INSERT SELECT / VALUES, conditioned joins, ordinary UPDATE/DELETE and inline LOAD are nearest controls; no material causal regression is asserted from timing noise in unchanged plans.
Reduced reproduction
Use the same isolated service configuration for base and PR binaries. Create fresh small tables without forcing objects to flush. First confirm EXPLAIN VERBOSE gives 1,000 rows for each source scan; otherwise this is a different statistics condition.
CREATE DATABASE small_cartesian_perf;
USE small_cartesian_perf;
SET max_dop=2;
SET join_spill_mem=0;
CREATE TABLE a(n INT PRIMARY KEY);
CREATE TABLE b(n INT PRIMARY KEY);
INSERT INTO a VALUES(0),(1),(2),(3),(4);
INSERT INTO b VALUES(0),(1),(2),(3),(4),(5),(6),(7);
CREATE TABLE tn(a INT,b INT,payload VARCHAR(8192));
CREATE TABLE ts(a INT,b INT,payload VARCHAR(8192),INDEX kb(b));
EXPLAIN VERBOSE
INSERT INTO tn SELECT a.n,b.n,'p' FROM a CROSS JOIN b;
INSERT INTO tn SELECT a.n,b.n,'p' FROM a CROSS JOIN b;
SELECT COUNT(*) FROM tn; -- 40
EXPLAIN VERBOSE
INSERT INTO ts SELECT a.n,b.n,'p' FROM a CROSS JOIN b;
INSERT INTO ts SELECT a.n,b.n,'p' FROM a CROSS JOIN b;
SELECT COUNT(*) FROM ts; -- 40
-- For timing, TRUNCATE only the target before every sample, and time only INSERT.For a same-data statistics control, recreate/reset targets and patch exact counts, then repeat:
SELECT table_cnt FROM table_stats('small_cartesian_perf.a','patch',
'{"table_cnt":5,"block_number":1,"accurate_object_number":1,"ndv_map":{"n":5}}') g;
SELECT table_cnt FROM table_stats('small_cartesian_perf.b','patch',
'{"table_cnt":8,"block_number":1,"accurate_object_number":1,"ndv_map":{"n":8}}') g;The full matrix also patches the accurate target and hidden-index counts after each TRUNCATE; no actual source rows change. EXPLAIN PHYPLAN executes the statement on this version, so it must not be used as a read-only DML plan probe.
Root cause and existing owners
- GlobalStats.get returns nil when the subscribed table has no data objects, absent a published observation. calcScanStats / DefaultStats then use the existing default 1,000-row estimate. This behavior is unchanged by the PR.
- The PR correctly changes a no-ON INNER JOIN from approximately 1,000 to
1,000 * 1,000 = 1,000,000estimated rows. Actual input remains 5 * 8 = 40 rows. Reverting the product would reintroduce [Bug]: SF1000 seed order_line INSERT exhausts HashBuild memory budget #29497. - compileMultiUpdate chooses WriteS3 when estimated output * 300 bytes > 10 MiB. The no-PK and regular-index plans change from one inline multi-update action to WriteS3 + FlushS3Info; the one-million-row estimate crosses this threshold.
- flushTailAndWriteToOutput Syncs remaining insert sinkers to objects at EOF, even for the tiny actual tail. There is no actual-small-tail inline fallback at this owner.
- DEDUP shuffle selection selects ordinary hash shuffle above 320,000 estimated incoming rows. Composite PK/multiple-UNIQUE cases acquire one/multiple shuffle stages. In the default-statistics composite-PK control, both versions already use ordinary DEDUP because target statistics are unknown; this is not a RIGHT DEDUP query-cap regression. The no-PK case proves an independent writer cause.
Expected behavior / acceptance
Preserve the correct Cartesian product and safe query-cap admission. Avoid paying large object-write and/or partitioning overhead for tiny actual output solely because missing or stale leaf statistics were multiplied. Investigate the existing statistics and multi-update writer owners; do not add per-SQL exception flags, a second budget/estimator, planner COUNT(*) scans or a new execution state machine to disguise the regression.
A solution needs small black-box cases for no PK, composite PK, ordinary index, multiple UNIQUE, wide payload, LIMIT and empty input, plus the existing real spill/large-write controls. Any change to tail handling must preserve row/index contents, duplicate atomicity, rollback, cancellation and parallel/multi-CN writer cleanup. Performance measurements must distinguish real plan changes from sub-millisecond noise.
Additional information
Corrected estimates also expose a separate pre-existing RIGHT SEMI preserved-side statistics defect in DELETE subqueries; it will be tracked separately. Remote object-store latency, concurrent throughput and long-term small-object/compaction costs were not measured. Current-head CI run 36704837860 succeeds; existing correctness CI does not test this performance regression. No performance fix is claimed in this report.
Activity
Fix Cartesian DML memory planning and transient statistics reuse (#29527