Re: Search query is curious - Mailing list pgsql-performance

From Maciek Sakrejda
Subject Re: Search query is curious
Date
Msg-id AANLkTim0gvJ9xtvNEbRLxVM1DYBjOOYCZ5TzH5zb+Kzp@mail.gmail.com
Whole thread Raw
In response to Re: Search query is curious  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-performance
> without ORDER BY database returns first 15 rows where predicate is
> true. With ORDER BY the database has to find all rows where predicate
> is true and then has to sort it. So first case can be a much faster
> because there are not necessary full table scan.

Right. Essentialy, the ORDER BY happens before the LIMIT (so you have
to sort everything before you take the first 15). If it were the other
way around, you would take the first 15 rows Postgres happens to find
(in an arbitrary order) and then sort these 15, which is probably not
that useful. Consider Thom's suggestion.

---
Maciek Sakrejda | System Architect | Truviso

1065 E. Hillsdale Blvd., Suite 215
Foster City, CA 94404
(650) 242-3500 Main
www.truviso.com

pgsql-performance by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Quesion on the use of indexes
Next
From:
Date:
Subject: Re: Quesion on the use of indexes