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 1leIZ1-0005wX-TB for pgsql-bugs@arkaria.postgresql.org; Wed, 05 May 2021 14:31:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1leIYU-0007m7-Pw for pgsql-bugs@arkaria.postgresql.org; Wed, 05 May 2021 14:31:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1leIYU-0007lz-0l for pgsql-bugs@lists.postgresql.org; Wed, 05 May 2021 14:31:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1leIYR-0001JB-VV for pgsql-bugs@lists.postgresql.org; Wed, 05 May 2021 14:31:13 +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 145EVAo34016384; Wed, 5 May 2021 10:31:10 -0400 From: Tom Lane To: a.schnabl@synedra.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16993: Query Planner does not use index for EXISTS-query on a large table with all equal foreign key values In-reply-to: <16993-1298e8dc9c41ab97@postgresql.org> References: <16993-1298e8dc9c41ab97@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Wed, 05 May 2021 13:24:05 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4016382.1620225070.1@sss.pgh.pa.us> Date: Wed, 05 May 2021 10:31:10 -0400 Message-ID: <4016383.1620225070@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: > ... EXPLAIN ANALYZE shows the following query plan: > Merge Join (cost=179053.41..179054.24 rows=1 width=8) (actual > time=2140.820..2140.822 rows=1 loops=1) > [ but with ] SET enable_seqscan = false: > Nested Loop Semi Join (cost=0.57..12.85 rows=1 width=8) (actual > time=0.877..0.920 rows=1 loops=1) Yeah, that seems *extremely* broken. The planner correctly estimates the second plan as much cheaper, so why did it fail to choose that one without help? Will look into this. regards, tom lane