The optimiser assumes an even distribution for a non-indexed column, which is wrong for a status column where one value is ninety per cent of the rows.
ANALYZE TABLE orders UPDATE HISTOGRAM ON state, currency
WITH 32 BUCKETS;
SELECT histogram->>'$."number-of-buckets-specified"'
FROM information_schema.column_statistics
WHERE table_name = 'orders';
-- they are NOT updated automatically. a large import
-- leaves them describing last month's distribution.
The manual refresh is the operational cost and the reason histograms are less used than they should be — a statistic that describes stale data can be worse than none. Adding the ANALYZE to whatever runs after a bulk import is the version that stays correct, and it belongs next to the import rather than in a maintenance job nobody reads.