Analyze on a Mostly-Null Column
Comments on “Analyze on a Mostly-Null Column”
Claim-checked. Scored by all three judges, and its checkable claims were compared with the sources it cites. How far stories are checked
Radim Marek of boringSQL shows why PostgreSQL's n_distinct for a mostly-NULL column swings between runs of ANALYZE. On a 10-million-row lab table where 0.2% of rows are non-NULL, the sample holds about 60 values. If none repeat, analyze.c declares the column unique, and about 75 of 200 runs did. That flips the join plan, and a stable fix is a higher statistics target or a manual n_distinct. The tests cover one synthetic table on PostgreSQL 18.7.
Why it ranked
No. 4 of 77 with a score of 0.71. The panel rated it highest on technical depth (0.96) and substantiated (0.96), lowest on significance (0.51).
- AI judgeJudge 2claude-haiku-5-5
- Deep, reproducible PostgreSQL planner analysis of ANALYZE's n_distinct behavior with experiments and practical fixes; highly relevant to database builders, modest broader significance.
- AI judgeJudge 3gpt-5.6-luna
- A highly reproducible PostgreSQL engineering investigation explains unstable n_distinct estimates for sparse nullable columns, demonstrates plan flips and costs, and provides tested mitigations. It is technically deep and actionable, though mainly relevant to PostgreSQL practitioners.
Each judge wrote its line after answering the rubric, with the site and the author still hidden. Every answer behind this is in the table under Score.
Score
0.71total under rubric v2.3
- Significance0.51
- Reader interest0.81
- Audience breadth0.52
- Practical relevance0.83
- Substantiated0.96
- Technical depth0.96
- New information0.90
- Counts against: Promotional0.03
- Counts against: Overclaim0.12
Each judge’s answer per question (0–1), their mean and spread, and what the question adds to the score (weight × mean).
| Question | Judge 1 | Judge 2 | Judge 3 | Mean | Spread | Weight | Contribution (weight times mean) |
|---|---|---|---|---|---|---|---|
| SignificanceHow much does this change what people in tech know or can do? | 0.51 | 0.35 | 0.67 | 0.51 | 0.32 | +0.24 | +0.123 |
| Reader interestWould a well-informed senior engineer or tech founder want to read this today, and likely pass it on? | 0.72 | 0.80 | 0.90 | 0.81 | 0.18 | +0.26 | +0.210 |
| Audience breadthHow many people who build technology does it concern? | 0.50 | 0.50 | 0.55 | 0.52 | 0.05 | +0.13 | +0.067 |
| Practical relevanceHow useful is it to someone who builds software or tech products? | 0.78 | 0.85 | 0.88 | 0.83 | 0.10 | +0.22 | +0.184 |
| SubstantiatedHow well is it backed? Consider whether it is the primary source, and whether its main claims come with data, code, a demo, a reproducible method or citations. | 0.99 | 0.92 | 0.96 | 0.96 | 0.07 | +0.05 | +0.048 |
| Technical depthHow technically substantive is it? | 1.00 | 0.95 | 0.94 | 0.96 | 0.06 | +0.05 | +0.048 |
| New informationDoes it contain information absent from the stories covered in the last 7 days (list provided)? | 0.83 | 0.90 | 0.98 | 0.90 | 0.15 | +0.05 | +0.045 |
| PromotionalIs it mainly marketing with little substance (a press release, ad or sponsored post with no real information)? A launch post that carries real news is not promotional. | 0.03 | 0.05 | 0.01 | 0.03 | 0.04 | −0.19 | −0.006 |
| OverclaimDo the headline or conclusions claim more than the body supports? | 0.14 | 0.15 | 0.08 | 0.12 | 0.07 | −0.11 | −0.014 |
| Sum of contributions | +0.705 | ||||||
| Claim-check penalty | 0.000 | ||||||
| Total, as published | 0.705 | ||||||
Spread is the highest minus the lowest judge answer. marks a spread above 0.40: the judges disagree, and the story is marked contested.
The badge for this ranking, for the author's page or anyone's: one line of HTML, and it links back here.
<a href="https://rubric.hrih.si/editions/2026-11-28/4/"><img src="https://rubric.hrih.si/badge/2026-11-28/4.svg" alt="Ranked #4 on Rubric, 28 Nov 2026" width="238" height="28"></a>Claim check
Claim check: 1 matches source · 6 no source given · 1 couldn’t check. Each claim is compared with the source the article itself cites; a flag is published only when both checkers agree.
Matches sourceNumber
With the default statistics target of 100, PostgreSQL's ANALYZE samples 30,000 rows (a multiplier of 300 set in analyze.c).
The cited source says the same thing.
The article says “With the default default_statistics_target of 100 it samples 30,000 rows (the multiplier of 300 is in analyze.c”
The source says “With the default target of 100, that's 30,000 rows”
Source cited by the article: boringsql.com/posts/postgresql-statistics
No source givenCausal conclusion
In compute_scalar_stats, if no repeated non-null values are found in the sample, PostgreSQL treats the column as unique and sets stadistinct to minus the non-NULL fraction.
The article gives no link or citation for it.
The article says “If none did, the column is declared unique, and the stored value is minus the non-NULL share of the table”
The source says No source to compare with.
Couldn’t checkNumber
Over 200 ANALYZE runs on the lab table, escalated_to n_distinct ranged from -0.0025666952 to 2696 with 75 negative results, while customer_id stayed between 183672 and 206763.
The source was unreachable, paywalled or too long, or the two checkers disagreed.
The article says “escalated_to | 200 | -0.0025666952 | 2696 | 94 | 75”
The source says No passage could be compared.
Source cited by the article: boringsql.com/files/analyze-mostly-null-column/analyze-200.sql
No source givenNumber
The birthday-problem calculation predicts a repeat-free ("unique") sample in 44% of runs, versus 75 of 200 observed.
The article gives no link or citation for it.
The article says “predicts "unique" in 44% of runs. I got 75 of 200, and an earlier batch of 200 on the same data gave 96”
The source says No source to compare with.
No source givenCausal conclusion
With a foreign key between the join columns, the planner ignores n_distinct and assumes each referencing row matches one referenced row, giving an estimate about 490 times too high when the column is mostly NULL.
The article gives no link or citation for it.
The article says “a nullable foreign key trades an estimate that changes between runs for one that is stable and 490 times too high”
The source says No source to compare with.
No source givenNumber
In the team query, the plan picked after a sample with repeats (merge join) reads twice the buffers of the nested loop plan chosen after a repeat-free sample (11091 vs 5404).
The article gives no link or citation for it.
The article says “The better estimate picked the plan that reads twice the buffers”
The source says No source to compare with.
No source givenNumber
Raising the statistics target to 1000 on escalated_to removed negative estimates over 200 runs but raised ANALYZE time on tickets from 92 ms to 624 ms.
The article gives no link or citation for it.
The article says “ANALYZE tickets went from 92 ms to 624 ms, because the sample size for the whole table follows its most demanding column”
The source says No source to compare with.
No source givenCausal conclusion
Setting n_distinct = 2000 on the column makes pg_stats.n_distinct 2,000 on every run but does not freeze the plan cost, since histograms and other columns are still resampled.
The article gives no link or citation for it.
The article says “Pinning one column does not freeze the plan's cost either”
The source says No source to compare with.
Also covered by
No other coverage was clustered with this story.
Elsewhere
Elsewhere: HN 1 pts, not on front page
Recorded for context only, checked 28 Nov 2026, 05:47 UTC. It played no part in the ranking.