You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Performance]: index presence flips join to nested-loop, 18x slower than hash #32017
Adding a secondary index on the join column makes an 8M-row join 17.6× slower: the planner switches from a hash join (full scan of the large table, tiny build side) to a nested-loop INDEX join driven by 8M index-ordered probes, and there is no row-count threshold to stop it.
-- big10m: 8,000,000 rows (k PK, k2 INT, KEY idx_k2 (k2)); b: 100k rows, 200 match grp<100SELECTb.grp, COUNT(*) FROM big10m JOIN b ONbig10m.k2=b.grpWHEREb.grp<100GROUP BYb.grp;
-- 853.4 ms (plan: Index Table Scan on big10m.idx_k2 driving Join Type: INDEX per-row probes of b)SELECTb.grp, COUNT(*) FROM big10m_noidx JOIN b ONbig10m_noidx.k2=b.grpWHEREb.grp<100GROUP BYb.grp;
-- 48.5 ms (identical table without idx_k2; plan: hash join, full scan + 200-row build)
Identical results (1,600,000). The only difference between the tables is the presence of idx_k2.
Related family (same root assumption that per-row indexed access is cheap): #32015 (filter-side join-back never yields to full scan, 200× at 10% selectivity) and #32013 (semijoin runtime-filter path, 27×). This case is the join-side variant: for an 8M-row outer with a 200-row inner, nested-loop probing is chosen over hashing with no cardinality gate — MySQL's optimizer makes the opposite call here (hash/block-nested-loop with join buffer, or in 8.0 hash join outright).
Note: a manual pre-aggregation rewrite (GROUP BY k2 first, then join) runs the same semantics in 81.1 ms, confirming the 853 ms plan is the worst of the three available strategies.
Activity