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 1p03NY-0007Rh-44 for pgsql-bugs@arkaria.postgresql.org; Tue, 29 Nov 2022 16:22:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p03NX-0006tf-2D for pgsql-bugs@arkaria.postgresql.org; Tue, 29 Nov 2022 16:22:39 +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 1p03NW-0006tU-QA for pgsql-bugs@lists.postgresql.org; Tue, 29 Nov 2022 16:22:38 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p03NU-00052S-HB for pgsql-bugs@lists.postgresql.org; Tue, 29 Nov 2022 16:22:37 +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 2ATGMX82968497; Tue, 29 Nov 2022 11:22:34 -0500 From: Tom Lane To: Daniel Gustafsson cc: xinwen@stu.scu.edu.cn, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17702: An assert failed in parse_utilcmd.c In-reply-to: References: <17702-ad24fdcdd1e9047a@postgresql.org> Comments: In-reply-to Daniel Gustafsson message dated "Tue, 29 Nov 2022 12:31:08 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <968495.1669738953.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 29 Nov 2022 11:22:33 -0500 Message-ID: <968496.1669738953@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Daniel Gustafsson writes: >> On 29 Nov 2022, at 03:45, PG Bug reporting form wrote: >> When executing the following query: >> = >> CREATE FUNCTION function0 () RETURNS INT LANGUAGE SQL AS $$ CREATE TABL= E >> table1 ( column0 INT CHECK ( 'x' =3D 'x' )) ; SELECT 1 ; $$ ; >> SELECT function0 () FROM ( VALUES ( 1 ) , ( 1 ) ) AS alias0; >> = >> I get a failed assertion with the following stacktrace: > This is AFAICT due to the utility statement already having gone through = parse > analysis and thus have the constraints list already set here. Forcing a= read- > only protection via the functionality from 7c337b6b5 the assertion is av= oided > and the function executes as expected: Right. > Maintaining a list of statements that scribble and force those to readon= ly > could be a way forward? Forcing processing of all utility statements to= be > readonly seems like a blunt instrument here, not sure what the best cour= se of > action would be. No, I think that's exactly what we should do. This is just a silly oversight in 7c337b6b5 --- I should have thought about SQL functions executing more than once in a query. (Eventually we ought to nuke functions.c's private version of a plan cache in favor of using plancache.c, but nobody's got to that yet. It'd be more obvious then that we have to protect the cached copy.) regards, tom lane