From: Greg Stark <gsstark@mit.edu>
To: D. Dante Lorenso <dante@lorenso.com>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Cc: pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Find original number of rows before applied LIMIT/OFFSET?
Date: 07 Jan 2004 14:41:04 -0500
Message-ID: <873carwnqn.fsf@stark.dyndns.tv> (raw)
In-Reply-To: <3FFC3A82.4000401@lorenso.com>
References: <3FFC3A82.4000401@lorenso.com>
"D. Dante Lorenso" <dante@lorenso.com> writes:
> Any thoughts? Sure, the PHP function I'm using above 'works', but is it
> the most efficient? I hope I'm not actually pulling all 100,000 records
> across the wire when I only intend to show 10 at a time. See what I'm
> getting at?
I tend to do it using a separate select count(*). My thinking is that the
count(*) query can be simplified and exclude things like the ORDER BY clause
and any select list entries that require extra work. It can often even exclude
whole joins.
By doing a separate query I can do that extra work only for the rows that i
actually need for display. Hopefully using an index to pull up those rows. And
do the count(*) in the most efficient way possible, probably a sequential scan
with no joins for foreign keys etc.
But I suspect the two methods both work out to suck about equally.
--
greg
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: gsstark@mit.edu, dante@lorenso.com, pgsql-general@postgresql.org
Subject: Re: [PERFORM] Find original number of rows before applied LIMIT/OFFSET?
In-Reply-To: <873carwnqn.fsf@stark.dyndns.tv>
* 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