Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pzSEz-0008Kl-Ax for pgsql-general@arkaria.postgresql.org; Thu, 18 May 2023 01:15:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pzSEy-000492-3w for pgsql-general@arkaria.postgresql.org; Thu, 18 May 2023 01:15:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pzSEx-00048t-PW for pgsql-general@lists.postgresql.org; Thu, 18 May 2023 01:15:35 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pzSEt-000Ozq-Pr for pgsql-general@postgresql.org; Thu, 18 May 2023 01:15:34 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 34I1FTXS3619250; Wed, 17 May 2023 21:15:29 -0400 From: Tom Lane To: Maciek Sakrejda cc: pgsql-general@postgresql.org Subject: Re: pg_stats.avg_width In-reply-to: References: Comments: In-reply-to Maciek Sakrejda message dated "Wed, 17 May 2023 17:52:20 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3619248.1684372529.1@sss.pgh.pa.us> Date: Wed, 17 May 2023 21:15:29 -0400 Message-ID: <3619249.1684372529@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Maciek Sakrejda 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