Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id CF7869F99D3 for ; Mon, 5 Nov 2007 15:20:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 80620-02-5 for ; Mon, 5 Nov 2007 15:20:46 -0400 (AST) Received: from oxford.xeocode.com (unknown [87.127.95.196]) by postgresql.org (Postfix) with ESMTP id 18C249F99E2 for ; Mon, 5 Nov 2007 14:55:03 -0400 (AST) Received: from localhost ([127.0.0.1] helo=oxford.xeocode.com) by oxford.xeocode.com with esmtp (Exim 4.67) (envelope-from ) id 1Ip765-0001HM-Ar; Mon, 05 Nov 2007 18:54:53 +0000 To: "Andreas Joseph Krogh" Cc: , "Tom Lane" Subject: Re: Returning the total number of rows as a separate column when using limit In-Reply-To: <200711051733.10324.andreak@officenet.no> (Andreas Joseph Krogh's message of "Mon\, 5 Nov 2007 17\:33\:10 +0100") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX" 46543) References: <200711050836.38130.andreak@officenet.no> <19503.1194274853@sss.pgh.pa.us> <87ir4g67co.fsf@oxford.xeocode.com> <200711051733.10324.andreak@officenet.no> From: Gregory Stark Organization: EnterpriseDB Date: Mon, 05 Nov 2007 18:54:52 +0000 Message-ID: <87fxzkwmir.fsf@oxford.xeocode.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/19 X-Sequence-Number: 29547 "Andreas Joseph Krogh" writes: > That's what I'm doing now. I run the query with "limit+1" as limit and if it > results in more than limit, I know there is more data and I run count(*) to > count them all. But count(*) cannot use indices in PG so it's limited in > speed anyway AFAICS. Well count(*) can use indexes the same as the query can. > I really hoped there was an "Oracle over()" equivalent way in PG. I understand > that Oracle's LIMIT-hack with "3 subselects and rownum between 1 AND 20" is > rather expensive compared to PG's implementation of LIMIT. Oralce keeps > snapshot-info in the index, so counting only involves the index AFAIK. Well that's only going to be true if the index satisfies the whole query which is not going to be true for the simplest cases. -- Gregory Stark EnterpriseDB http://www.enterprisedb.com Ask me about EnterpriseDB's PostGIS support!