Re: A limit clause can cause a poor index choice - Mailing list pgsql-general

From Nick Cleaton
Subject Re: A limit clause can cause a poor index choice
Date
Msg-id CAFgz3kuMbs=yzwwsdOx0t8FUBuOSnt8xgsDaFB6no8TuR9xk3Q@mail.gmail.com
Whole thread Raw
In response to Re: A limit clause can cause a poor index choice  (Mohamed Wael Khobalatte <mkhobalatte@grubhub.com>)
List pgsql-general
On Tue, 19 May 2020 at 21:56, Mohamed Wael Khobalatte
<mkhobalatte@grubhub.com> wrote:

> I believe a second ordering, by id desc, will get your query to use the right index, and shouldn't be functionally
differentfrom what you would expect.
 

Thanks, that works nicely on our production table, even with much
larger sets of customer_id values.

> What happens when you raise the limit? Say to a 1000?

A limit of 1000 makes it choose the fast plan. A limit of 100 causes
it to choose the fast plan if I raise the stats target on that column
to 250 or above, otherwise not.



pgsql-general by date:

Previous
From: pabloa98
Date:
Subject: Re: Q: Comparing PostgreSQL and Oracle
Next
From: Nick Cleaton
Date:
Subject: Re: A limit clause can cause a poor index choice