Re: BUG #14399: Order by id DESC causing bad query plan

From: Jamie Koceniak <jkoceniak(at)mediamath(dot)com>
To: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14399: Order by id DESC causing bad query plan
Date: 2016-11-01 19:43:51
Message-ID: 40BA41BD-88B4-4CDB-8528-60E2CE5B0B34@mediamath.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-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(at)mediamath(dot)com" <jkoceniak(at)mediamath(dot)com> wrote:

>The following bug has been logged on the website:
>
>Bug reference: 14399
>Logged by: Jamie Koceniak
>Email address: jkoceniak(at)mediamath(dot)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
>

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Pavel Hanák 2016-11-01 21:56:28 Problems with "pg.dropped" column after upgrade 9.5 to 9.6
Previous Message vcolborn 2016-11-01 19:26:55 BUG #14408: Schema not found error when 2 or more indices declared on temporary table