Re: Why LIMIT after scanning the table?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: jim(at)nasby(dot)net
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Why LIMIT after scanning the table?
Date: 2003-04-30 14:22:25
Message-ID: 21975.1051712545@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

"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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Peter Darley 2003-04-30 14:39:24 Query Plan far worse in 7.3.2 than 7.2.1
Previous Message Stephan Szabo 2003-04-30 14:19:41 Re: Why LIMIT after scanning the table?