Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 1F9219FB5D4 for ; Sat, 23 Jun 2007 10:15:27 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 70664-07 for ; Sat, 23 Jun 2007 10:15:23 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.237]) by postgresql.org (Postfix) with ESMTP id 7460B9FB463 for ; Sat, 23 Jun 2007 10:15:23 -0300 (ADT) Received: by wx-out-0506.google.com with SMTP id s16so990271wxc for ; Sat, 23 Jun 2007 06:15:22 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=YHttQfawAdXDYZqeIee37z5R6Bn1+OzDEV2cKD5aXmN4MYJnYynsc/IJHb2L8fDIe1oy4F78YoACubzXTNFg+1ILCGLJuYse8WOz2686eYnhRGVaFd4ieTR7sJ18koBKx8xefjjJT16VkDkTnRIB2XPslcvMInat3jLjTkipGdw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=UBXieJhHA7BFnqRDig1X6OCggvBp+C9BLx1mzG1FmDMNQwfB7wmIgAqtjeVN4rUpoD0/BvblHwFjj/K4JR1BdRjMcDTRe9QWprcHLoKSuFeue/f3B4WMpC6+jD+CBaQFXxVl/bMdhv+6TY+8oTgz+k2ogKvEUCPexMUE/bvh4gA= Received: by 10.90.119.15 with SMTP id r15mr3317530agc.1182604522239; Sat, 23 Jun 2007 06:15:22 -0700 (PDT) Received: by 10.90.86.20 with HTTP; Sat, 23 Jun 2007 06:15:22 -0700 (PDT) Message-ID: Date: Sat, 23 Jun 2007 15:15:22 +0200 From: "Stefan Arentz" To: "Andreas Kretschmer" Subject: Re: Counting all rows Cc: pgsql-sql@postgresql.org In-Reply-To: <20070623103856.GE7307@KanotixBox> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20070623103856.GE7307@KanotixBox> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/186 X-Sequence-Number: 28676 On 6/23/07, Andreas Kretschmer wrote: > Stefan Arentz schrieb: > > > I need to get statistics from a bunch of tables. Simply the number of > > records in them. > > > > The query plan looks like this: > > > > => explain select count(id) from stuff; > > QUERY PLAN > > ------------------------------------------------------------------- > > Aggregate (cost=1629.69..1629.70 rows=1 width=8) > > -> Seq Scan on stuff (cost=0.00..1517.75 rows=44775 width=8) > > > > The sequential scan kind of worries me. Is there a better/faster way to do > > this? > > Yes. > > A "select count(*) from foo;" enforces a seq. scan. Solutions for this > are discussed here: http://www.varlena.com/GeneralBits/120.php Thank you Andreas. That is exactly what I was looking for. S.