From: Tom Lane <tgl@sss.pgh.pa.us>
To: Maciek Sakrejda <m.sakrejda@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: pg_stats.avg_width
Date: Wed, 17 May 2023 21:15:29 -0400
Message-ID: <3619249.1684372529@sss.pgh.pa.us> (raw)
In-Reply-To: <CAOtHd0DfdSuMavVYK2cYPDLyySYnEwP-FcszXEcFh_wA-78omQ@mail.gmail.com>
References: <CAOtHd0DfdSuMavVYK2cYPDLyySYnEwP-FcszXEcFh_wA-78omQ@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, m.sakrejda@gmail.com
Subject: Re: pg_stats.avg_width
In-Reply-To: <3619249.1684372529@sss.pgh.pa.us>
References: <CAOtHd0DfdSuMavVYK2cYPDLyySYnEwP-FcszXEcFh_wA-78omQ@mail.gmail.com> <3619249.1684372529@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox