Re: WHERE vs ORDER BY vs LIMIT why not using the correct index? - Mailing list pgsql-general

From Tom Lane
Subject Re: WHERE vs ORDER BY vs LIMIT why not using the correct index?
Date
Msg-id 21632.1199836837@sss.pgh.pa.us
Whole thread Raw
In response to WHERE vs ORDER BY vs LIMIT why not using the correct index?  ("D. Dante Lorenso" <dante@lorenso.com>)
List pgsql-general
"D. Dante Lorenso" <dante@lorenso.com> writes:
> I don't understand why the ORDER BY condition would be affecting my
> WHERE criteria.  Shouldn't the ordering be done after the filter is
> first applied?

No, not necessarily.  The problem you've got is that the planner
thinks there are 1473 rows not 4 that have status = 'D', and that
affects the choice of plan.  Have you ANALYZEd this table lately?

You might need to push up the statistics target to get reasonable
stats for the very infrequent status values ...

            regards, tom lane

pgsql-general by date:

Previous
From: Ivan Sergio Borgonovo
Date:
Subject: benchmarking update/insert and random record update
Next
From: Eric Davies
Date:
Subject: Experiences with extensibility