From: | Josh Kupershmidt <schmiddy(at)gmail(dot)com> |
---|---|
To: | AI Rumman <rummandba(at)gmail(dot)com> |
Cc: | pgsql-performance(at)postgresql(dot)org |
Subject: | Re: how to get the total number of records in report |
Date: | 2010-10-18 15:52:45 |
Message-ID: | AANLkTi=EjBmxJacZbH10BRHLE33_AhE04a9no7KkZrvF@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
On Mon, Oct 18, 2010 at 1:16 AM, AI Rumman <rummandba(at)gmail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Jon Nelson | 2010-10-18 20:59:26 | unexpected query failure: ERROR: GIN indexes do not support whole-index scans |
Previous Message | Tom Lane | 2010-10-18 15:02:15 | Re: Help with duration of statement: EXECUTE <unnamed> [PREPARE: COMMIT] |