SQL: a stale row estimate is why the planner chose the wrong join

The optimiser costs plans from statistics, not from the data. After a bulk load or a schema change those statistics are wrong, and it will confidently pick a nested loop over a million rows. EXPLAIN ANALYZE shows estimated against actual side by side.

Full code & output

This topic is available to PRO members.

Sign in Create a free account

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-25