Repository navigation
Description
Environment
- Affected change: fix(plan): use bounded key-set access for composite index IN prefixes (#32410) #32567, head
eb222b3b8bd927bd04382088efdfea4506dcfb51 - Same-base comparison:
a1a6ab604f85ec9f74b3f79ef01aa9a3c7f1660b - Branch:
4.2-dev - Local one-CN launch on macOS arm64; Go 1.26.4 build
- Flushed and analyzed statistics; the base-table scan cost is 1000
Details of Performance
The new non-covering key-set cost gate admits exactly 100 points because 100 <= 1000 * 0.1, but the selected plan is substantially slower than the table-scan plan for prepared execution.
I interleaved 80 prepared EXECUTE pairs in one session, with the order shuffled per pair, after warming both plans:
| Version / plan | Median | p95 | Plan |
|---|---|---|---|
| PR head, automatic | 0.2071875 ms | 0.253375 ms | non-covering unique key set |
PR head, IGNORE INDEX |
0.134479 ms | 0.182333 ms | table scan |
| Base, automatic | 0.1602085 ms | 0.206583 ms | table scan |
Base, IGNORE INDEX |
0.1578755 ms | 0.213917 ms | table scan |
Thus the PR's automatic choice is 54.07% slower than its own scan oracle and 29.32% slower than base automatic execution.
The adjacent 101-point case falls back as intended: PR head automatic 0.126896 ms versus IGNORE INDEX 0.1287495 ms, both table scans. The 128-point case also falls back. The regression is therefore not a generic prepared-statement slowdown; it occurs at the admitted key-set boundary.
All query results were identical: count(*)=100, sum(payload)=5050. This is a performance regression, not a correctness failure.
Steps to Reproduce
CREATE DATABASE qa_threshold;
USE qa_threshold;
CREATE TABLE t(
id INT PRIMARY KEY,
a INT NOT NULL,
b INT NOT NULL,
payload INT,
UNIQUE KEY uq_ab(a,b)
);
INSERT INTO t SELECT result,1,result,result FROM generate_series(1,1000) g;
SELECT mo_ctl('dn','flush','qa_threshold.t');
ANALYZE TABLE t;Generate the two constant lists with vals(n) = ','.join(str(i) for i in range(1,n+1)), then prepare and compare:
-- n = 100; repeat with n = 101 as the fallback control.
SELECT count(*),sum(payload) FROM t
WHERE a=1 AND b IN (<vals(n)>);
SELECT count(*),sum(payload) FROM t IGNORE INDEX(uq_ab)
WHERE a=1 AND b IN (<vals(n)>);EXPLAIN at n=100 shows Index Table Scan only for automatic execution; IGNORE INDEX uses the base-table scan. Prepare both statements, warm each five times, then execute them in shuffled AB/BA order for 80 pairs and measure client-side EXECUTE latency.
Expected Behavior
The cost gate should not choose a non-covering key-set/index-join plan when the scan is materially faster. The earlier 128-point small-table regression should not merely move to the 100-point boundary. A prepared-execution benchmark around 100/101 points on a flushed 1,000-row table would cover this boundary.
Additional Information
The same QA run found no correctness mismatch in 35 indexed-versus-scan pairs (70 result oracles). The final revision also fixes the previously reported wide-IN planning amplification, and a flushed 60,000-row table still benefits from automatic key-set access (0.301209 ms versus 0.646791 ms with IGNORE INDEX). This report is narrowly scoped to the remaining small-table cost-gate boundary regression.
Activity
fix(plan): use bounded key-set access for composite index IN prefixes (…