Re: Returning the total number of rows as a separate column when using limit

From: Andreas Joseph Krogh <andreak(at)officenet(dot)no>
To: pgsql-sql(at)postgresql(dot)org
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Returning the total number of rows as a separate column when using limit
Date: 2007-11-05 14:38:34
Message-ID: 200711051538.34536.andreak@officenet.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Monday 05 November 2007 15:18:22 Tom Lane wrote:
> Andreas Joseph Krogh <andreak(at)officenet(dot)no> writes:
> > AFAICS the information about the *total* number of rows is in the
> > "result" somehow. When I execute a "limit 1" query with EXPLAIN ANALYZE,
> > I se the total number of columns in "rows=200819", so the information is
> > there.
>
> That's only an estimate. Since the query doesn't get executed to
> completion thanks to the LIMIT, Postgres really has no idea whether
> the estimate is accurate.

Ok. The query is ORDER-ed, but you're saying that it doesn't matter and PG
still doesn't have to know the total numbers even if it has to sort the
result?

Is there a way to perform the LIMIT-query only once and still be able to
extract the total number of rows from some "magic function", like
Oracle's "over()" analytic function? I will accept a simple "no" if that is
the case, but if it is possible (like it is in Oracle) I would appreciate to
know how to do it.

--
Andreas Joseph Krogh <andreak(at)officenet(dot)no>
Senior Software Developer / Manager
------------------------+---------------------------------------------+
OfficeNet AS | The most difficult thing in the world is to |
Karenslyst Allé 11 | know how to do a thing and to watch |
PO. Box 529 Skøyen | somebody else doing it wrong, without |
0214 Oslo | comment. |
NORWAY | |
Tlf: +47 24 15 38 90 | |
Fax: +47 24 15 38 91 | |
Mobile: +47 909 56 963 | |
------------------------+---------------------------------------------+

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2007-11-05 15:00:53 Re: Returning the total number of rows as a separate column when using limit
Previous Message Tom Lane 2007-11-05 14:18:22 Re: Returning the total number of rows as a separate column when using limit