Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wSKuV-0037I2-0S for pgsql-hackers@arkaria.postgresql.org; Wed, 27 May 2026 20:31:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wSKuT-009TEz-0Y for pgsql-hackers@arkaria.postgresql.org; Wed, 27 May 2026 20:31:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wSKuS-009TEr-2s for pgsql-hackers@lists.postgresql.org; Wed, 27 May 2026 20:31:25 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wSKuR-00000001kNE-3XGq for pgsql-hackers@lists.postgresql.org; Wed, 27 May 2026 20:31:25 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 64RKVGjQ711248; Wed, 27 May 2026 16:31:16 -0400 From: Tom Lane To: Tomas Vondra cc: Alexandra Wang , jian he , pgsql-hackers@lists.postgresql.org, Andrei Lepikhov , Corey Huinker , hs@cybertec.at, Jeff Davis Subject: Re: Is there value in having optimizer stats for joins/foreignkeys? In-reply-to: <48aaff7c-5f37-44e1-9df0-859b168d8b1f@vondra.me> References: <3c477f2f-10e4-4705-bb21-90ccbe67e9d2@gmail.com> <24247.1779395113@sss.pgh.pa.us> <910a4628-720a-4912-af8f-8b5a96a0b336@vondra.me> <2468544.1779721437@sss.pgh.pa.us> <48aaff7c-5f37-44e1-9df! 0-859b168d8b1f@vondra.me> Comments: In-reply-to Tomas Vondra message dated "Wed, 27 May 2026 21:08:34 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <711246.1779913876.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 27 May 2026 16:31:16 -0400 Message-ID: <711247.1779913876@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tomas Vondra writes: > On 5/27/26 19:49, Alexandra Wang wrote: >> One question about the pg_stats_ext view: currently it has two compleme= ntary >> columns: >> = >> - attnames (name[]) =E2=80=94 Names of the columns included in the stat= istics object >> - exprs (text[]) =E2=80=94 Expressions included in the statistics objec= t >> = >> With stxkeys gone from the catalog, should the view: >> (a) Stay as-is: keep attnames and exprs as separate columns with the sa= me >> semantics. Implemented via a helper function that extracts plain column >> names from the unified stxexprs. >> or >> (b) Mirror the catalog: remove attnames, make exprs show all entries (b= oth >> column names and expressions together in one text[] array). > My 2c: AFAIR there's no fundamental reason to keep those two lists > separate, other than that expressions were "bolted on" later, after we > already had stats on plain attributes. In hindsight, it might have been > better to just unify the view back then, probably. Yeah. There are some other oddities that arise from that: expressions get shoved to the end. For example, if I put in create statistics my_stats (mcv) on ten, (ten+four), four from tenk1; pg_dump will regurgitate that as CREATE STATISTICS public.my_stats (mcv) ON four, ten, (ten + four) FROM pu= blic.tenk1; and I see that that column ordering is consistent with what appears in pg_stats_ext and perhaps other places. I'd expect a rewritten version to stop doing that and preserve the user-written column order. So there are going to be some potential minor incompatibilities for anything that is looking too closely at this view, and it seems to me that it might be better for such code to fail noisily rather than perhaps silently mis-associate stats with columns. (It might be a good idea to have some test cases that exercise this kind of scenario in pg_upgrade, especially now that we are trying to transfer extended stats in upgrades...) regards, tom lane