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 1rKolN-004coU-6t for pgsql-bugs@arkaria.postgresql.org; Wed, 03 Jan 2024 00:05:37 +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 1rKolL-002EC2-RJ for pgsql-bugs@arkaria.postgresql.org; Wed, 03 Jan 2024 00:05:35 +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 1rKolL-002EBu-Ij for pgsql-bugs@lists.postgresql.org; Wed, 03 Jan 2024 00:05:35 +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.94.2) (envelope-from ) id 1rKolJ-00FEnf-5H for pgsql-bugs@lists.postgresql.org; Wed, 03 Jan 2024 00:05:35 +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 40305URx091860; Tue, 2 Jan 2024 19:05:30 -0500 From: Tom Lane To: Amadeo Gallardo cc: pgsql-bugs@lists.postgresql.org, David Rowley Subject: Re: Postgres 16.1 - Bug: cache entry already complete In-reply-to: References: <4103444.1704216682@sss.pgh.pa.us> Comments: In-reply-to Amadeo Gallardo message dated "Tue, 02 Jan 2024 20:48:58 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <91858.1704240330.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 02 Jan 2024 19:05:30 -0500 Message-ID: <91859.1704240330@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Amadeo Gallardo writes: > Attached is a sample script that I used to reproduce the error. I had to > add some specific sample data and force-disable certain planner settings= , > as otherwise the problem did not occur. Thanks! EXPLAIN shows QUERY PLAN = = --------------------------------------------------------------------------= ---------------------- Nested Loop Left Join (cost=3D0.46..82.87 rows=3D315 width=3D1) Join Filter: (t3.t2_id =3D t2.id) -> Nested Loop Left Join (cost=3D0.30..32.29 rows=3D315 width=3D32) -> Nested Loop Left Join (cost=3D0.15..17.29 rows=3D315 width=3D= 32) -> Seq Scan on t4 (cost=3D0.00..6.15 rows=3D315 width=3D3= 2) -> Memoize (cost=3D0.15..0.19 rows=3D1 width=3D16) Cache Key: t4.t2_id Cache Mode: logical -> Index Only Scan using t2_pkey on t2 (cost=3D0.14= ..0.18 rows=3D1 width=3D16) Index Cond: (id =3D t4.t2_id) -> Memoize (cost=3D0.15..0.20 rows=3D1 width=3D16) Cache Key: t4.t1_id Cache Mode: logical -> Index Only Scan using t1_pkey on t1 (cost=3D0.14..0.19= rows=3D1 width=3D16) Index Cond: (id =3D t4.t1_id) -> Memoize (cost=3D0.16..0.55 rows=3D1 width=3D33) Cache Key: t1.id, t1.id Cache Mode: logical -> Index Scan using t3_t1_id_index on t3 (cost=3D0.15..0.54 row= s=3D1 width=3D33) Index Cond: (t1_id =3D t1.id) (20 rows) It's that last Memoize node with the duplicate cache keys that is failing. (It's unclear to me whether having duplicate cache keys is supposed to be a valid situation, and even less clear whether that has any direct connection to the failure.) What I guess is happening is that the single-row flag is getting set because t1.id is a primary key, despite the fact that it's coming from inside a join that could result in duplicates. regards, tom lane