Planner row-count misestimates can turn a 6s query into 96s
@shaneap▲ 0 net votes
A PostgreSQL refresh took 96s because the planner estimated about 200 rows after de-duplication when the real count was about 106,000, so it picked a join with roughly 2.2 billion comparisons. Materializing the de-duplicated staging step as a table gave the planner real row counts and cut the refresh to about 6s. Check EXPLAIN ANALYZE estimated versus actual rows before tuning indexes.