pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: postgresql.20.drkshadow@spamgourmet.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16504: Wrapping query in EXISTS() causes sequential scans of tables
Date: Fri, 19 Jun 2020 10:09:06 -0400
Message-ID: <1647563.1592575746@sss.pgh.pa.us> (raw)
In-Reply-To: <16504-d8c5d6beb38e8b6e@postgresql.org>
References: <16504-d8c5d6beb38e8b6e@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> In this case, I have a query that selects from a table, joins a table, joins
> that same table, joins the first table, performs a NOT
> firsttable.value=lasttable.value to make sure that I'm not joining an item
> with itself. There are indexes for the conditions in each join. When I run
> this as a select query, the EXPLAIN output uses index scans the whole way
> through. When I SELECT EXISTS(thatquery) FROM firsttable WHERE firsttable.id
> IN (1,2,3), the EXPLAIN output switches to using sequential scans. This
> destroys performance on this 3.8m row table.

Are you claiming that 9.6 did better?  I'm not aware that we changed
anything significant about how a sub-select in a query's select list
works.

The table/view definitions alone are not enough to investigate this,
since it's unlikely that we'd get the same plans on an empty table
as a populated one.  Please see if you can make a self-contained test
case with some dummy data that reproduces the problem (ie better
plan on 9.6 than later).

			regards, tom lane





view thread (2+ messages)

Message-ID: <1647563.1592575746@sss.pgh.pa.us>
Permalink:  ../1647563.1592575746@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1647563.1592575746@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, postgresql.20.drkshadow@spamgourmet.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #16504: Wrapping query in EXISTS() causes sequential scans of tables
  In-Reply-To: <1647563.1592575746@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox