"Jim C. Nasby" <jim(at)nasby(dot)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