Re: how to get the total number of records in report - Mailing list pgsql-performance

From AI Rumman
Subject Re: how to get the total number of records in report
Date
Msg-id AANLkTi=XpukJfu8Pd9dR9KN0S0Q7NpO-u7aOFe75bjSo@mail.gmail.com
Whole thread Raw
In response to Re: how to get the total number of records in report  (Josh Kupershmidt <schmiddy@gmail.com>)
Responses Re: how to get the total number of records in report  (Greg Spiegelberg <gspiegelberg@gmail.com>)
List pgsql-performance
Not actualy. I used pagination with limit clause in details query and I need the total number of records in the detail query.

On Mon, Oct 18, 2010 at 9:52 PM, Josh Kupershmidt <schmiddy@gmail.com> wrote:
On Mon, Oct 18, 2010 at 1:16 AM, AI Rumman <rummandba@gmail.com> wrote:
> At present for reporting I use following types of query:
> select crm.*, crm_cnt.cnt
> from crm,
> (select count(*) as cnt from crm) crm_cnt;
> Here count query is used to find the total number of records.
> Same FROM clause is copied in both the part of the query.
> Is there any other good alternative way to get this similar value?

Well, it looks like you're currently executing two sequential scans
over the "crm" table. And you're including the total row-count as a
separate column in every row you get back, although you really only
need this piece of information once.

Since you're fetching all of the "crm" table anyway, why not get rid
of the COUNT(*) entirely and just keep a count on the client-side of
the total number of rows you've fetched?

Josh

pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: HashJoin order, hash the large or small table? Postgres likes to hash the big one, why?
Next
From: Scott Carey
Date:
Subject: Re: HashJoin order, hash the large or small table? Postgres likes to hash the big one, why?