Re: WHERE vs ORDER BY vs LIMIT why not using the correct index?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "D(dot) Dante Lorenso" <dante(at)lorenso(dot)com>
Cc: Postgres-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: WHERE vs ORDER BY vs LIMIT why not using the correct index?
Date: 2008-01-09 00:00:37
Message-ID: 21632.1199836837@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Eric Davies 2008-01-09 00:28:11 Experiences with extensibility
Previous Message Christopher Siwy 2008-01-08 23:50:20 Re: Cannot connect to PgPool