Re: Why LIMIT after scanning the table?

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: jim@nasby.net
Cc: pgsql-performance@postgresql.org
Date: 2003-04-30T14:22:25Z
Lists: pgsql-performance
"Jim C. Nasby" <jim@nasby.net> writes:
> explain select count(*)
>     FROM (SELECT * FROM email_rank WHERE project_id = :ProjectID LIMIT 100) AS t1;

> The idea is that the inner-most query would only read the first 100 rows
> it finds, then stop. Instead, if explain is to be believed (and speed
> testing seems to indicate it's accurate), we'll read the entire table,
> *then* pick the first 100 rows. Why is that?

You're misreading the EXPLAIN output.  Try EXPLAIN ANALYZE to see how
many rows really get fetched.

			regards, tom lane