From: Jamie Koceniak <jkoceniak@mediamath.com>
To: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14399: Order by id DESC causing bad query plan
Date: Tue, 1 Nov 2016 19:43:51 +0000
Message-ID: <40BA41BD-88B4-4CDB-8528-60E2CE5B0B34@mediamath.com> (raw)
In-Reply-To: <20161028001636.15988.55966@wrigleys.postgresql.org>
References: <20161028001636.15988.55966@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Hi I was wondering if this could get approved by the moderator.
One added note: if I actually drop the index then the query plan does a top-N heap sort instead of nested join filter and runs in 28ms.
Sort Method: top-N heapsort Memory: 94kB
Thanks!
On 10/27/16, 5:16 PM, "jkoceniak@mediamath.com" <jkoceniak@mediamath.com> wrote:
>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: <40BA41BD-88B4-4CDB-8528-60E2CE5B0B34@mediamath.com>
References: <20161028001636.15988.55966@wrigleys.postgresql.org> <40BA41BD-88B4-4CDB-8528-60E2CE5B0B34@mediamath.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