pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mathias Kunter <mathiaskunter@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14107: Major query planner bug regarding subqueries and indices
Date: Thu, 28 Apr 2016 21:10:38 -0400
Message-ID: <18635.1461892238@sss.pgh.pa.us> (raw)
In-Reply-To: <629ecf23-b7b2-2d73-6792-150b111e83ab@gmail.com>
References: <20160421115638.22895.78902@wrigleys.postgresql.org>
	<CAKJS1f_Hv+gBpg8JF0T8PEyW0TzVgydkcp2dPZHeomkDUGsRyA@mail.gmail.com>
	<69e376c7-6c2c-c96d-2ad6-3734affb59b7@gmail.com>
	<CAGnEboiCo+NuGab0PEnUQ2Nf0DXZv2Rvo2xWhMbi88n=guZB5w@mail.gmail.com>
	<CA+bJJbyUF6CZPgH45JUdRRJ96qHMd31Fb-qHw0iN2aohRYMM6g@mail.gmail.com>
	<CAGnEbogfdNPxN7vvY_8b4bPj4VVDzEw5NaXVBRSWUMQgKZE-CA@mail.gmail.com>
	<44df2e58-87f5-282c-9871-c735240c55e4@gmail.com>
	<1461406942121-5900147.post@n5.nabble.com>
	<3ac6f379-08f8-d1db-639f-2dc3075d2eb4@gmail.com>
	<1461610493986-5900430.post@n5.nabble.com>
	<629ecf23-b7b2-2d73-6792-150b111e83ab@gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Mathias Kunter <mathiaskunter@gmail.com> writes:
> Does anybody care? Shouldn't something like this be fixed ASAP??

As was already stated upthread, this is not a bug; it's an opportunity
for future improvement.  It's unlikely to get "fixed ASAP" because there
would be quite a bit of work involved, possibly including new executor
infrastructure not just planner work.

As far as the first case goes, the executor doesn't currently have any
direct way to treat "a.x IN (SELECT ...)" as an indexqual for a.x.
In simple cases the planner can work around that by transforming the query
into a join against a unique-ified version of the sub-select, but that
doesn't work if the IN is underneath an OR.  If you know that the
sub-select isn't going to return very many rows, you could do

SELECT ... FROM a WHERE a.x = ? OR a.y = ANY(ARRAY(SELECT ...));

but this would blow up rather badly with a large sub-select result,
so I'm not sure I want to try to make the planner transform it that
way automatically.

I don't actually see any way to do very much with your second example at
all:

> SELECT ... FROM a JOIN b ON (...) WHERE a.x = ? OR b.y = ?;

There's no way to push anything down to either the A or B scans from
that WHERE condition: you can't remove any rows before the join because
they might join to rows on the other side that satisfy the other half
of the OR.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (20+ messages)  latest in thread

Message-ID: <18635.1461892238@sss.pgh.pa.us>
Permalink:  ../18635.1461892238@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/18635.1461892238@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, mathiaskunter@gmail.com
  Subject: Re: BUG #14107: Major query planner bug regarding subqueries and indices
  In-Reply-To: <18635.1461892238@sss.pgh.pa.us>
  References: <20160421115638.22895.78902@wrigleys.postgresql.org> <CAKJS1f_Hv+gBpg8JF0T8PEyW0TzVgydkcp2dPZHeomkDUGsRyA@mail.gmail.com> <69e376c7-6c2c-c96d-2ad6-3734affb59b7@gmail.com> <CAGnEboiCo+NuGab0PEnUQ2Nf0DXZv2Rvo2xWhMbi88n=guZB5w@mail.gmail.com> <CA+bJJbyUF6CZPgH45JUdRRJ96qHMd31Fb-qHw0iN2aohRYMM6g@mail.gmail.com> <CAGnEbogfdNPxN7vvY_8b4bPj4VVDzEw5NaXVBRSWUMQgKZE-CA@mail.gmail.com> <44df2e58-87f5-282c-9871-c735240c55e4@gmail.com> <1461406942121-5900147.post@n5.nabble.com> <3ac6f379-08f8-d1db-639f-2dc3075d2eb4@gmail.com> <1461610493986-5900430.post@n5.nabble.com> <629ecf23-b7b2-2d73-6792-150b111e83ab@gmail.com> <18635.1461892238@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