X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id C0E3DD1CA7D; Wed, 7 Jan 2004 19:42:19 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 82634-08; Wed, 7 Jan 2004 15:41:36 -0400 (AST) Received: from smtp.istop.com (dci.doncaster.on.ca [66.11.168.194]) by svr1.postgresql.org (Postfix) with ESMTP id 0A560D1B4AC; Wed, 7 Jan 2004 15:40:58 -0400 (AST) Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) by smtp.istop.com (Postfix) with ESMTP id 80E1E36C88; Wed, 7 Jan 2004 14:41:04 -0500 (EST) Received: from localhost ([127.0.0.1] helo=stark.dyndns.tv ident=foobar) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1AeJY8-0005gj-00; Wed, 07 Jan 2004 14:41:04 -0500 To: "D. Dante Lorenso" Cc: "pgsql-general@postgresql.org" , pgsql-performance@postgresql.org Subject: Re: [PERFORM] Find original number of rows before applied LIMIT/OFFSET? References: <3FFC3A82.4000401@lorenso.com> In-Reply-To: <3FFC3A82.4000401@lorenso.com> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 07 Jan 2004 14:41:04 -0500 Message-ID: <873carwnqn.fsf@stark.dyndns.tv> Lines: 22 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/280 X-Sequence-Number: 55308 "D. Dante Lorenso" writes: > Any thoughts? Sure, the PHP function I'm using above 'works', but is it > the most efficient? I hope I'm not actually pulling all 100,000 records > across the wire when I only intend to show 10 at a time. See what I'm > getting at? I tend to do it using a separate select count(*). My thinking is that the count(*) query can be simplified and exclude things like the ORDER BY clause and any select list entries that require extra work. It can often even exclude whole joins. By doing a separate query I can do that extra work only for the rows that i actually need for display. Hopefully using an index to pull up those rows. And do the count(*) in the most efficient way possible, probably a sequential scan with no joins for foreign keys etc. But I suspect the two methods both work out to suck about equally. -- greg