Received: from kosh.pollcities.com (kosh.pollcities.com [202.186.13.219]) by hub.org (8.10.1/8.10.1) with ESMTP id e797gOG35057 for ; Wed, 9 Aug 2000 03:42:33 -0400 (EDT) Received: (from angch@localhost) by kosh.pollcities.com (8.9.3/8.9.3) id PAA06038 for pgsql-sql@postgresql.org; Wed, 9 Aug 2000 15:33:37 +0800 Date: Wed, 9 Aug 2000 15:33:37 +0800 From: Ang Chin Han To: pgsql-sql@postgresql.org Subject: Re: Aggregate functions, fast! (long) Message-ID: <20000809153337.A6032@pintoo.com> References: <20000809145345.B5894@pintoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i In-Reply-To: <20000809145345.B5894@pintoo.com>; from angch@pintoo.com on Wed, Aug 09, 2000 at 02:53:45PM +0800 X-Archive-Number: 200008/68 On Wed, Aug 09, 2000 at 02:53:45PM +0800, Ang Chin Han wrote: > The queries making use of these might be rewritten as: > 1. select min(a) from t_sum; -- same as above, > -- but we've less rows to scan > 2. select cnt from t_sum where a = 1 and b = 3; Sorry, bugfix: select sum(cnt) from t_sum where a = 1 and b = 3; since c is not referenced. > 3. select sum(d * cnt) as sum from t_sum where a = 1 and c > 3; > 4. select sum(b * cnt) / cnt as avg from t_sum where c = 1;