Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 1F668475C8B for ; Wed, 8 Jan 2003 11:12:05 -0500 (EST) Received: from wolff.to (wolff.to [66.93.249.74]) by postgresql.org (Postfix) with SMTP id B21ED476EF2 for ; Wed, 8 Jan 2003 11:10:56 -0500 (EST) Received: (qmail 9065 invoked by uid 500); 8 Jan 2003 16:22:58 -0000 Date: Wed, 8 Jan 2003 10:22:58 -0600 From: Bruno Wolff III To: Nikola Ivacic Cc: pgsql-sql@postgresql.org Subject: Re: count(*) optimization Message-ID: <20030108162258.GA9033@wolff.to> Mail-Followup-To: Nikola Ivacic , pgsql-sql@postgresql.org References: <024d01c2b72f$a6a7dcc0$1100a8c0@rspi> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <024d01c2b72f$a6a7dcc0$1100a8c0@rspi> User-Agent: Mutt/1.3.25i X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/101 X-Sequence-Number: 10966 On Wed, Jan 08, 2003 at 17:04:40 +0100, Nikola Ivacic wrote: > Hi > > I have trouble executing count(*) statement. > On a large dataset it takes quite a while to return result. > Is there any other way to get number of tupples in relation > or is the only way to optimize count() function to index it? Indexes won't help count. If you retrieve counts a lot more than you do updates that will change their value, then you may want to keep the counts in another table and use triggers to keep them updated.