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 1u18re-00EorH-69 for pgsql-bugs@arkaria.postgresql.org; Sat, 05 Apr 2025 19:07:34 +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 1u18rc-001r5C-Gy for pgsql-bugs@arkaria.postgresql.org; Sat, 05 Apr 2025 19:07:32 +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 1u18rc-001r54-8i for pgsql-bugs@lists.postgresql.org; Sat, 05 Apr 2025 19:07:32 +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 1u18ra-003akQ-1V for pgsql-bugs@lists.postgresql.org; Sat, 05 Apr 2025 19:07:32 +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 535J7Sln2715648; Sat, 5 Apr 2025 15:07:28 -0400 From: Tom Lane To: luy70@psu.edu cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18878: PostgreSQL triggers Assertion Failure in Debug build In-reply-to: <18878-a26fa5ab6be2f2cf@postgresql.org> References: <18878-a26fa5ab6be2f2cf@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Fri, 04 Apr 2025 19:15:14 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2715646.1743880048.1@sss.pgh.pa.us> Date: Sat, 05 Apr 2025 15:07:28 -0400 Message-ID: <2715647.1743880048@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=$(pwd) --exec-prefix=$(pwd) --enable-cassert`, > triggered Assertion Failure when executing the following statement: > ```sql > WITH RECURSIVE ta01 AS NOT MATERIALIZED ( WITH RECURSIVE any_cte_name AS > MATERIALIZED ( TABLE ta01 ) DELETE FROM v00 RETURNING *, CASE WHEN FALSE > THEN TRUE WHEN FALSE THEN TRUE ELSE TRUE END IDENT ) SELECT FROM JSON_ARRAY > ( TABLE v00 ORDER BY CASE WHEN FALSE THEN TRUE END NULLS FIRST FOR READ > ONLY) GROUP BY ROLLUP ( CASE WHEN FALSE NOT BETWEEN ASYMMETRIC CASE WHEN > FALSE THEN TRUE END AND FALSE <> CASE WHEN EXISTS ( SELECT GROUP BY ALL ( ) > FOR READ ONLY ) > CASE WHEN FALSE THEN TRUE END THEN FALSE END IS NULL THEN > ARRAY ( ( TABLE ta01 ) ) ELSE CASE WHEN TRUE BETWEEN EXISTS ( SELECT GROUP > BY ALL ( ) FOR READ ONLY ) AND TRUE IS NOT FALSE > EXISTS ( SELECT ALL GROUP > BY ( ) FOR READ ONLY ) THEN TRUE END > CASE WHEN FALSE THEN TRUE END END ) > FOR READ ONLY; > ``` This can be reduced to WITH RECURSIVE ta01 AS ( WITH any_cte_name AS ( TABLE ta01 ) DELETE FROM v00 RETURNING * ) TABLE ta01; That should be rejected, because ta01 has a self-reference and is not in the allowed form "base-case UNION query-with-self-reference". However, we managed to miss the appearance of the self-reference because the code in charge of detecting it hadn't been taught that WITH is now allowed in INSERT/UPDATE/DELETE. (Which is a bit disheartening, but there you have it.) Fixed, thanks for the report! regards, tom lane