pg_stats avg_width and null_frac

Started by Paul McGarryalmost 8 years ago2 messagesgeneral
Jump to latest
#1Paul McGarry
paul@paulmcgarry.com

Can anyone confirm that the "avg_width" reported in the pg_stats is the
avg_width not including any null rows?

ie if a field had:

avg_width: 6
null_frac: 0.5

Then
- 50% of the rows would be empty for this field
- The other 50% of the rows would have data with an avg_width of 6 bytes?
(according to the sampled data at least)

Paul

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: Paul McGarry (#1)
Re: pg_stats avg_width and null_frac

On Tue, Jun 5, 2018 at 5:49 PM, Paul McGarry <paul@paulmcgarry.com> wrote:

Can anyone confirm that the "avg_width" reported in the pg_stats is the
avg_width not including any null rows?

​Yes.

https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_statistic.h#L40

It actually is documented but only on the underlying catalog, not the view.

https://www.postgresql.org/docs/10/static/catalog-pg-statistic.html

David J.