Re: pg_stats.avg_width - Mailing list pgsql-general

From Tom Lane
Subject Re: pg_stats.avg_width
Date
Msg-id 3619249.1684372529@sss.pgh.pa.us
Whole thread Raw
In response to pg_stats.avg_width  (Maciek Sakrejda <m.sakrejda@gmail.com>)
Responses Re: pg_stats.avg_width  (Maciek Sakrejda <m.sakrejda@gmail.com>)
List pgsql-general
Maciek Sakrejda <m.sakrejda@gmail.com> writes:
> The pg_stats.avg_width field is documented [1] as "Average width in
> bytes of column's entries" but it's not defined exactly what "entries"
> means here with respect to STORAGE (the underlying pg_statistic
> documentation doesn't clarify this either). I thought initially this
> was the "logical" size of the values, but I ran an experiment that
> suggests this interpretation is not right:

Nope.  What that's meant to be is the size of value that would be passed
around inside the executor.  In this case:

> maciek=# select avg_width from pg_stats where tablename = 'foo' and
> attname = 'a';
>  avg_width
> -----------
>         18

what you are getting is the size of the TOAST pointer.  That's correct
for the planner's purposes, because it'd be the TOAST pointer not the
detoasted value that would be passed through joins, sorts, hashes, etc.
And we really only care about how much space would be needed for
things like sort temp files.

            regards, tom lane



pgsql-general by date:

Previous
From: Maciek Sakrejda
Date:
Subject: pg_stats.avg_width
Next
From: Tony Xu
Date:
Subject: Re: Would PostgreSQL 16 native transparent data encryption support database level encryption?