pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mathias Kunter <mathiaskunter@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14107: Major query planner bug regarding subqueries and indices
Date: Wed, 11 May 2016 13:55:07 +0200
Message-ID: <fad91c29-5250-f856-2347-61122d4901ab@gmail.com> (raw)
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>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Sorry for bumping this one more time, but I'd like to share some more 
real-life performance test results of using ANY(ARRAY(...)) instead of 
IN(...), hoping that you'd maybe still consider implementing such an 
optimization into the query planner. Since the test results indicate 
that the performance boost can really be massive on certain query types 
(factor 1000), I think that it'd really be worth the work.


===== Test setup =====

The tables "mb.release" and "mb.release_group" both contain about 1.5 
million rows of real data, taken from the MusicBrainz database, and are 
of course properly indexed. All performance tests have been repeated a 
few times to be comparable.

The test covers subqueries which return just a few rows and also 
subqueries which return more than 100000 rows. The queries test the 
performance of IN vs. ANY(ARRAY()) when used in different scenarios.

For reference, the full query plans of all used queries are linked below.


===== Tested queries =====

1) SELECT id FROM mb.release WHERE release_group IN (SELECT id FROM 
mb.release_group WHERE name = 'Bear');

2) SELECT id FROM mb.release WHERE release_group IN (SELECT id FROM 
mb.release_group WHERE name < 'Bear');

3) SELECT id FROM mb.release WHERE name = 'Tiger' OR release_group IN 
(SELECT id FROM mb.release_group WHERE name = 'Bear');

4) SELECT id FROM mb.release WHERE name = 'Tiger' OR release_group IN 
(SELECT id FROM mb.release_group WHERE name < 'Bear');

5) SELECT id FROM mb.release WHERE name = 'Tiger' AND release_group IN 
(SELECT id FROM mb.release_group WHERE name = 'Bear');

6) SELECT id FROM mb.release WHERE name = 'Tiger' AND release_group IN 
(SELECT id FROM mb.release_group WHERE name < 'Bear');


===== Test results =====

All numbers are given in milliseconds and show the total query time 
(planning + execution).

-------------------------------------------
| Query |    IN (...) | = ANY(ARRAY(...)) |
-------------------------------------------
|     1 |         0.7 |               0.4 |
|     2 |      6001.1 |            2517.8 |
|     3 |       711.3 |               0.5 |
|     4 | > 1000000.0 |            1962.6 |
|     5 |         0.8 |               0.5 |
|     6 |         0.9 |             492.7 |
-------------------------------------------

Note: Query 4 using the IN operator has been canceled after running for 
more than 15 minutes.


===== Full query plans =====

For reference, all query plans of this performance test have been 
recorded using EXPLAIN (ANALYZE, BUFFERS). Please find them at 
http://pastebin.com/zymkbcSf


-- 
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: <fad91c29-5250-f856-2347-61122d4901ab@gmail.com>
Permalink:  ../fad91c29-5250-f856-2347-61122d4901ab@gmail.com/
Also on:    postgresql.org/message-id/fad91c29-5250-f856-2347-61122d4901ab@gmail.com

 · 

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: mathiaskunter@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: BUG #14107: Major query planner bug regarding subqueries and indices
  In-Reply-To: <fad91c29-5250-f856-2347-61122d4901ab@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> <18635.1461892238@sss.pgh.pa.us> <fad91c29-5250-f856-2347-61122d4901ab@gmail.com>

* 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