pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: jim@nasby.net
Cc: pgsql-performance@postgresql.org
Subject: Re: Why LIMIT after scanning the table?
Date: Wed, 30 Apr 2003 10:22:25 -0400
Message-ID: <21975.1051712545@sss.pgh.pa.us> (raw)
In-Reply-To: <20030430010425.T66185@flake.decibel.org>
References: <20030430010425.T66185@flake.decibel.org>

"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




view thread (4+ messages)  latest in thread

Message-ID: <21975.1051712545@sss.pgh.pa.us>
Permalink:  ../21975.1051712545@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21975.1051712545@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jim@nasby.net
  Subject: Re: Why LIMIT after scanning the table?
  In-Reply-To: <21975.1051712545@sss.pgh.pa.us>
  References: <20030430010425.T66185@flake.decibel.org> <21975.1051712545@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox