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 1u0uc1-00AL8n-Nl for pgsql-bugs@arkaria.postgresql.org; Sat, 05 Apr 2025 03:54:29 +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 1u0uc0-008XRy-CD for pgsql-bugs@arkaria.postgresql.org; Sat, 05 Apr 2025 03:54:28 +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.94.2) (envelope-from ) id 1u0uc0-008XRp-3m for pgsql-bugs@lists.postgresql.org; Sat, 05 Apr 2025 03:54:28 +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.96) (envelope-from ) id 1u0ubx-003Tgl-2V for pgsql-bugs@lists.postgresql.org; Sat, 05 Apr 2025 03:54:27 +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 5353sMU92387815; Fri, 4 Apr 2025 23:54:22 -0400 From: Tom Lane To: luy70@psu.edu cc: pgsql-bugs@lists.postgresql.org, Alvaro Herrera Subject: Re: BUG #18877: PostgreSQL triggers assertion failure In-reply-to: <18877-c3c3ad75845833bb@postgresql.org> References: <18877-c3c3ad75845833bb@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Fri, 04 Apr 2025 18:48:21 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2387813.1743825262.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Apr 2025 23:54:22 -0400 Message-ID: <2387814.1743825262@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > In the debug build of PostgreSQL 17.4, compiled with `configure > --enable-debug --prefix=3D$(pwd) --exec-prefix=3D$(pwd) --enable-cassert= `, > triggered Assertion Failure when executing the following statement: = > ```sql > SELECT ALL GROUP BY ALL ( ), CUBE ( CASE WHEN FALSE THEN TRUE END ) > INTERSECT ALL SELECT ALL FROM JSON_ARRAY ( WITH any_cte_name AS ( ( TABL= E > v00 ) ) VALUES ( FALSE ) ), any_table_name GROUP BY CUBE ( CASE WHEN TRU= E > THEN FALSE END ); > ``` Minimized a bit, that's regression=3D# SELECT 1 FROM JSON_ARRAY ( WITH any_cte_name AS ( ( select = 1 ) ) VALUES ( FALSE ) ); server closed the connection unexpectedly This is another case of "don't let the parser process the same querytree twice". I can make it go away with diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_ex= pr.c index 9caf1e481a2..bc602f00ae3 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -3772,7 +3772,7 @@ transformJsonArrayQueryConstructor(ParseState *pstat= e, /* Transform query only for counting target list entries. */ qpstate =3D make_parsestate(pstate); = - query =3D transformStmt(qpstate, ctor->query); + query =3D transformStmt(qpstate, copyObject(ctor->query)); = if (count_nonjunk_tlist_entries(query->targetList) !=3D 1) ereport(ERROR, However ... it's possible that this isn't the stupidest, most brute-force code in Postgres, but I'll wager it's in the top ten. Is it really necessary to transform the subquery twice just to produce this error? It seems like the constructed EXPR_SUBLINK should produce the same error all by itself. I tried nuking this whole stanza to see whether that would happen, and then there are a couple of regression test cases that don't produce the same results. But I feel like it could be made to work with a bit more thought. regards, tom lane