What does SET STATISTICS 0 do to the planner?
Column statistics disabled with SET STATISTICS 0
Note: this works and blocks nothing, but a performance regression is likely.
What happens
SET STATISTICS 0 tells ANALYZE to collect nothing for the column. From then on the planner estimates every predicate on it with hard-coded defaults (selectivity 0.5 for equality, 1/3 for ranges), row estimates go wrong by orders of magnitude, and with them join order, index choice, and memory sizing for every query that touches the column.
Why it is dangerous on a populated table
Nothing blocks, but the cost scales with the table and shows up as a slower query plan or a longer maintenance window rather than an outage.
Fires on
ALTER TABLE orders ALTER COLUMN region SET STATISTICS 0;The safe pattern
Leave the target at -1 (the server default, currently 100 buckets) or raise it for skewed columns; if ANALYZE is too slow on a wide table, lower the target rather than zero it. Setting it back to -1 restores the default.
SET lock_timeout = '5s';
ALTER TABLE orders ALTER COLUMN region SET STATISTICS -1;Fixtures
The rule ships with these files and the test suite runs them on every change: the first set must fire, the second must stay silent.
Fires (1)
SET lock_timeout = '5s';
ALTER TABLE orders ALTER COLUMN region SET STATISTICS 0;Stays silent (2)
SET lock_timeout = '5s';
ALTER TABLE orders ALTER COLUMN region SET STATISTICS -1;SET lock_timeout = '5s';
ALTER TABLE orders ALTER COLUMN region SET STATISTICS 500;How to check locally
This rule runs in the hosted service on Startup and above: add --remote with a team token, or use the GitHub Action. No install, nothing leaves your machine:
npx bolvrk check migration.sql --remote