"D. Dante Lorenso" <dante(at)lorenso(dot)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