A histogram on a skewed column, and the plan it fixed

A status column where one value covers ninety-four per cent of rows, and an optimiser assuming an even distribution.

ANALYZE TABLE orders UPDATE HISTOGRAM ON status WITH 16 BUCKETS;

-- before: estimated 200,000 rows for status='pending'
--         (2M rows / 10 distinct values)
--         chose a table scan
-- after:  estimated 4,100 — the real figure
--         chose the index

-- 2.4s → 11ms

Histograms are for columns that are skewed and not indexed, or indexed and used alongside another predicate — an evenly distributed column gains nothing. They are also not maintained automatically, so a column whose distribution changes needs the statement re-run, which is a scheduled job rather than a one-off and is the part people forget.