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 1us0nR-00G6NW-8M for pgsql-bugs@arkaria.postgresql.org; Fri, 29 Aug 2025 15:13: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 1us0nQ-00Al7Q-Ig for pgsql-bugs@arkaria.postgresql.org; Fri, 29 Aug 2025 15:13:45 +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 1us0nQ-00Al7I-Aj for pgsql-bugs@lists.postgresql.org; Fri, 29 Aug 2025 15:13: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 1us0nO-002NxA-1m for pgsql-bugs@lists.postgresql.org; Fri, 29 Aug 2025 15:13:44 +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 57TFDg1O2163313; Fri, 29 Aug 2025 11:13:42 -0400 From: Tom Lane To: 798604270@qq.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19036: Failed prepared INSERT statement make another SELECT query generate wrong result In-reply-to: <19036-ef3954ff85feefe2@postgresql.org> References: <19036-ef3954ff85feefe2@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Fri, 29 Aug 2025 11:39:42 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2163311.1756480422.1@sss.pgh.pa.us> Date: Fri, 29 Aug 2025 11:13:42 -0400 Message-ID: <2163312.1756480422@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 following test case, the `EXECUTE` statement will fail with an error > `result of range union would not be contiguous`. The final SELECT query > should return 1 row as there is only one value `1` in t1.c0 and only one > value `1` in t3.c0, however, the query returns 0 rows. I don't see a bug here particularly. If you check the contents of table t3 at the end of the test, you will see c0 | c1 ----+------------------------ 2 | [-761818403,793731612) (1 row) in the "wrong" case. This shows that the prepared insert advanced the sequence underlying "c0 bigserial" before failing, whereas in the default plan_cache_mode the error occurred before touching the sequence. This discrepancy isn't a bug. It occurs because in the default mode the planner will attempt to constant-fold that messy range expression during planning, and thus it will hit the range union failure before anything is done to the sequence. In the generic case the failure occurs in the executor, and the sequence has already been advanced. regards, tom lane