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 1nlqLZ-0000y6-K8 for pgsql-performance@arkaria.postgresql.org; Tue, 03 May 2022 11:05:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nlqLX-00013y-Lf for pgsql-performance@arkaria.postgresql.org; Tue, 03 May 2022 11:05:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nlqLX-00013p-9J for pgsql-performance@lists.postgresql.org; Tue, 03 May 2022 11:05:35 +0000 Received: from mx.zeyos.com ([88.99.153.70]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nlqLU-0004Eu-TT for pgsql-performance@postgresql.org; Tue, 03 May 2022 11:05:34 +0000 Received: from mx.zeyos.com (localhost [127.0.0.1]) by mx.zeyos.com (Postfix) with ESMTP id 3DFE26205B for ; Tue, 3 May 2022 13:05:31 +0200 (CEST) Authentication-Results: mx.zeyos.com (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=zeyos.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=zeyos.com; h= content-transfer-encoding:content-type:content-type:mime-version :message-id:to:from:from:subject:subject:date:date; s=dkim; t= 1651575931; x=1652439932; bh=cowhI2Fg6PKhEUFJa+T1IUBcoNyiSqGBoQs 2oukvzes=; b=kgF/ZZ09xaYLgKBVOYI2qwavF+iN5fP33bTp6Cno3Ev4JPEBwMP GSjaRhIJceoWLWEp9zJAh9Zd4H/7eUB8HCCQkCXFTyxU9e59iomTML4aMQ4L2QmD jiOlzh74MqbyAHIlGu9aaCx4ICVtXQmKj1UGn4nemfGR/EQxgnNLRPjI= X-Virus-Scanned: Debian amavisd-new at mx.zeyos.com Received: from mx.zeyos.com ([127.0.0.1]) by mx.zeyos.com (mx.zeyos.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 4Z-9sMVBY7vG for ; Tue, 3 May 2022 13:05:31 +0200 (CEST) Received: from cloud.zeyos.com (static.182.82.88.23.clients.your-server.de [23.88.82.182]) by mx.zeyos.com (Postfix) with ESMTPSA id 03AF36205A; Tue, 3 May 2022 13:05:30 +0200 (CEST) Date: Tue, 03 May 2022 13:05:30 +0200 Subject: Useless memoize path generated for unique join on primary keys From: Benjamin Coutu To: pgsql-performance@postgresql.org Cc: David Rowley Message-ID: <34e2bc3e1eaa52429a11@zeyos.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello,=0A=0AI have come across a plan that should never get generated IMHO:= =0A=0ASELECT 1=0AFROM extdataregular e1=0AINNER JOIN extdataempty e2 ON e1.= field =3D e2.field AND e1.index =3D e2.index=0A=0Agenerates the following p= lan:=0A=0ANested Loop (cost=3D1.13..528540.89 rows=3D607604 width=3D4) (ac= tual time=3D9298.504..9298.506 rows=3D0 loops=3D1)=0A -> Index Only Scan = using pk_extdataempty on extdataempty e2 (cost=3D0.56..157969.52 rows=3D40= 78988 width=3D16) (actual time=3D0.026..641.248 rows=3D4067215 loops=3D1)= =0A Heap Fetches: 268828=0A -> Memoize (cost=3D0.58..0.67 rows=3D= 1 width=3D16) (actual time=3D0.002..0.002 rows=3D0 loops=3D4067215)=0A = Cache Key: e2.field, e2.index=0A Cache Mode: logical=0A Hi= ts: 0 Misses: 4067215 Evictions: 3228355 Overflows: 0 Memory Usage: 655= 37kB=0A Buffers: shared hit=3D16268863=0A -> Index Only Scan= using pk_extdataregular on extdataregular e1 (cost=3D0.57..0.66 rows=3D1 = width=3D16) (actual time=3D0.001..0.001 rows=3D0 loops=3D4067215)=0A = Index Cond: ((field =3D e2.field) AND (index =3D e2.index))=0A = Heap Fetches: 2=0A=0APlease note that the memoize node has no cache= hits, which is not surprising given that we are joining on two primary key= s that are unique by definition ("field" and "index" make up the primary ke= y of both tables).=0AWhy would it ever make sense to generate a memoize pla= n for a unique join?=0A=0AI think this issue might tie in with the current = discussion over on the hackers mailing list [1]=0A=0ACheers, Ben=0A=0A[1] h= ttps://www.postgresql.org/message-id/flat/CAApHDvpFsSJAThNLtqaWvA7axQd-VOFc= t%3DFYQN5muJV-sYtXjw%40mail.gmail.com=0A=0A-- =0A=0ABejamin Coutu=0Aben.cou= tu@zeyos.com=0A=0AZeyOS GmbH & Co. KG=0Ahttp://www.zeyos.com