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.