Re: Why LIMIT after scanning the table? - Mailing list pgsql-performance

From Tom Lane
Subject Re: Why LIMIT after scanning the table?
Date
Msg-id 21975.1051712545@sss.pgh.pa.us
Whole thread Raw
In response to Why LIMIT after scanning the table?  ("Jim C. Nasby" <jim@nasby.net>)
List 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


pgsql-performance by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Why LIMIT after scanning the table?
Next
From: "Peter Darley"
Date:
Subject: Query Plan far worse in 7.3.2 than 7.2.1