Re: A limit clause can cause a poor index choice

From: Nick Cleaton <nick(at)cleaton(dot)net>
To: Mohamed Wael Khobalatte <mkhobalatte(at)grubhub(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: A limit clause can cause a poor index choice
Date: 2020-05-20 09:57:27
Message-ID: CAFgz3kuMbs=yzwwsdOx0t8FUBuOSnt8xgsDaFB6no8TuR9xk3Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 19 May 2020 at 21:56, Mohamed Wael Khobalatte
<mkhobalatte(at)grubhub(dot)com> wrote:

> I believe a second ordering, by id desc, will get your query to use the right index, and shouldn't be functionally different from 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Nick Cleaton 2020-05-20 10:41:05 Re: A limit clause can cause a poor index choice
Previous Message pabloa98 2020-05-20 08:24:10 Re: Q: Comparing PostgreSQL and Oracle