X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id DD8DAD1B486 for ; Mon, 12 Jan 2004 21:47:49 +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 70224-06 for ; Mon, 12 Jan 2004 17:47:20 -0400 (AST) Received: from bramble.mmrd.com (unknown [65.217.53.66]) by svr1.postgresql.org (Postfix) with ESMTP id E5AC5D1B47A for ; Mon, 12 Jan 2004 17:47:15 -0400 (AST) Received: from thorn.mmrd.com (thorn.mmrd.com [172.25.10.100]) by bramble.mmrd.com (8.12.8/8.12.8) with ESMTP id i0CL1ZcM031493; Mon, 12 Jan 2004 16:01:36 -0500 Received: from gnvex001.mmrd.com (gnvex001.mmrd.com [192.168.3.55]) by thorn.mmrd.com (8.11.6/8.11.6) with ESMTP id i0CLgCl26901; Mon, 12 Jan 2004 16:42:15 -0500 Received: from camel.mmrd.com ([172.25.5.213]) by gnvex001.mmrd.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2657.72) id XT870T8W; Mon, 12 Jan 2004 16:42:10 -0500 Subject: Re: COUNT & Pagination From: Robert Treat To: "david@shadovitz.com" Cc: "pgsql-performance@postgresql.org" , "'Richard Huxton'" In-Reply-To: <01C3D8DF.271378C0.david@shadovitz.com> References: <01C3D8DF.271378C0.david@shadovitz.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 12 Jan 2004 16:42:12 -0500 Message-Id: <1073943732.29178.153.camel@camel> Mime-Version: 1.0 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/126 X-Sequence-Number: 5301 On Mon, 2004-01-12 at 10:37, David Shadovitz wrote: > > If you only need the count when you've got the results, most PG client > > interfaces will tell you how many rows you've got. What language is your app > > in? > > PHP. > But I have only a subset of the results, retrieved via a query with a "LIMIT > " clause, so $pg_numrows is m. > And retrieving all results (i.e. no LIMIT) is at least as expensive as > COUNT(*). > Depending on frequency of updates and need for real time info, you could cache the count in session as long as the user stays within the given piece of your app. Robert Treat -- Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL