From: jkoceniak@mediamath.com
To: pgsql-bugs@postgresql.org
Subject: BUG #14399: Order by id DESC causing bad query plan
Date: Fri, 28 Oct 2016 00:16:36 +0000
Message-ID: <20161028001636.15988.55966@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
The following bug has been logged on the website:
Bug reference: 14399
Logged by: Jamie Koceniak
Email address: jkoceniak@mediamath.com
PostgreSQL version: 9.4.6
Operating system: Linux
Description:
One table has 2M records (orders) joining to another table with 75K records
(customers).
Query:
select * FROM
orders t1
JOIN customer t2 ON (t1.customer_id = t2.id)
WHERE
t2.id IN (select distinct customer_id from valid_customers)
ORDER BY t1.id
LIMIT 10 ;
-- valid customers subquery contains 200 records.
For some reason the nested join is doing filter:
Rows Removed by Join Filter: 410976415
See anonymized query plan here:
https://explain.depesz.com/s/k9s5
If I removed order by, query returns in 1.5ms
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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: jkoceniak@mediamath.com
Subject: Re: BUG #14399: Order by id DESC causing bad query plan
In-Reply-To: <20161028001636.15988.55966@wrigleys.postgresql.org>
References: <20161028001636.15988.55966@wrigleys.postgresql.org>
* 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