From: Michael Landin Hostbaek <mich@freebsdcluster.org>
To: PostgresSQL list <pgsql-sql@postgresql.org>
Subject: Double query (limit and offset)
Date: Tue, 11 Oct 2005 17:11:05 +0200
Message-ID: <20051011151105.GA29943@mich2.itxmarket.com> (raw)
List,
I'm using the OFFSET / LIMIT combo in order to split up my query, so it
only parses 20 rows at a time (for my php-scripted webpage).
I'm using two queries; the first basically doing a select count(*) from
[bla bla]; the second grabbing the actual data while setting LIMIT and
OFFSET.
In addition, I'm using the first query plus some calculations to parse
total hits to the query, and number of pages etc etc.
Now, my problem is this, the first query is simply counting all rows
from the main table, whereas the second query has plenty of JOINS, and a
GROUB BY statement - it's a fairly heavy query. The total (reported by
the first query), it not at all the same as the amount of rows returned
by the second query. I'd like to avoid having to run the "heavy" query
twice, just in order to get the number of rows.
Is there a smarter way of doing it ?
Thanks,
/mich
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-sql@postgresql.org
Cc: mich@freebsdcluster.org
Subject: Re: Double query (limit and offset)
In-Reply-To: <20051011151105.GA29943@mich2.itxmarket.com>
* 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