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.94.2) (envelope-from ) id 1urkSD-00BlMd-6g for pgsql-hackers@arkaria.postgresql.org; Thu, 28 Aug 2025 21:46:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1urkSC-004tyH-7D for pgsql-hackers@arkaria.postgresql.org; Thu, 28 Aug 2025 21:46:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1urkSB-004ty9-TN for pgsql-hackers@lists.postgresql.org; Thu, 28 Aug 2025 21:46:44 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1urkS9-002FsE-2q for pgsql-hackers@postgresql.org; Thu, 28 Aug 2025 21:46:43 +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 57SLkdlS1942414; Thu, 28 Aug 2025 17:46:39 -0400 From: Tom Lane To: =?utf-8?Q?=C3=81lvaro?= Herrera cc: jian he , PostgreSQL-development , Kirill Reshke Subject: Re: misleading error message in ProcessUtilitySlow T_CreateStatsStmt In-reply-to: <202508282133.uwntzsze7cdl@alvherre.pgsql> References: <202508282133.uwntzsze7cdl@alvherre.pgsql> Comments: In-reply-to =?utf-8?Q?=C3=81lvaro?= Herrera message dated "Thu, 28 Aug 2025 23:33:42 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1942412.1756417599.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 28 Aug 2025 17:46:39 -0400 Message-ID: <1942413.1756417599@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk =3D?utf-8?Q?=3DC3=3D81lvaro?=3D Herrera writes: > I propose to use this report: > ERROR: cannot create statistics on specified relation > DETAIL: CREATE STATISTICS only supports tables, materialized views, for= eign tables, and partitioned tables. WFM, although I think you could shorten it to "tables, materialized views, and foreign tables". We generally expect that partitioned tables are included when saying "tables", no? I'm not dead set on that either way, though. > While looking at this whole thing, I noticed that this code is somewhat > bogus in a different way: we're resolving the relation name twice, both > here in ProcessUtilitySlow() (to pass to transformStatsStmt), and later > again inside CreateStatistics(). It's really strange that we decided > not to pass the relation Oids as a list argument to CreateStatistics. I > suggest to change that as the first attached patch. I think this is a good idea, but I'm not sure that the locking considerations are straight in this version. Once we translate a relation name to OID, we'd better hold lock on the rel continuously to the end of usage of that OID. It looks like you do, but then couldn't the + rel =3D relation_open(relid, ShareUpdateExclusiveLock); in CreateStatistics use NoLock to signify that we expect to have the lock already? Alternatively, maybe the right fix is to move the parse-analysis work into CreateStatistics altogether. I think there is not a very good argument for ProcessUtilitySlow doing all that stuff. It's supposed to mainly just be a dispatching switch(), IMO. regards, tom lane