ANALYZE on a mostly-NULL column 0 ▲ boringSQL | Supercharge your SQL & PostgreSQL powers 1 hour ago · 11 min read2184 words · Tech · hide One of the production databases I snapshot with dryrun has a 172 GB table that autovacuum analyzes about three times a day. dryrun keeps the planner statistics from every snapshot, so I could line up what pg_stats said about one of its columns over six days in November: 736, 899, 948, 520, 659, 461, 1087, 299 That's n_distinct, the planner's guess at how many different values the column holds. The table grows by a few percent a week, and the guess moved by more than a factor of three. Over sixty days it also went negative 14 times. The column is NULL in 99.8% of the rows. The cause is one if in analyze.c and the birthday problem, and both show up on a lab table where every row can be counted. Two tickets in a thousand The lab is a support desk. Tickets get escalated to an agent now and then, and for the other 99.8% of them escalated_to stays NULL: CREATE TABLE agents ( id int PRIMARY KEY, team_id int NOT NULL, -- 20 teams of 100 name text NOT NULL ); CREATE TABLE tickets ( id bigint… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town