X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3C5F3D1B1B6 for ; Tue, 29 Jun 2004 04:28:37 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 72772-02 for ; Tue, 29 Jun 2004 07:28:30 +0000 (GMT) Received: from houston.familyhealth.com.au (fhnet.arach.net.au [203.22.197.21]) by svr1.postgresql.org (Postfix) with ESMTP id BDCC2D1B26E for ; Tue, 29 Jun 2004 04:28:26 -0300 (ADT) Received: from [192.168.0.40] (work-40.internal [192.168.0.40]) by houston.familyhealth.com.au (8.12.9p1/8.12.9) with ESMTP id i5T7SQOf007342; Tue, 29 Jun 2004 15:28:26 +0800 (WST) (envelope-from chriskl@familyhealth.com.au) Message-ID: <40E11BF0.3020109@familyhealth.com.au> Date: Tue, 29 Jun 2004 15:36:16 +0800 From: Christopher Kings-Lynne User-Agent: Mozilla Thunderbird 0.7 (Windows/20040616) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Harald Lau (Sector-X)" Cc: pgsql-performance@postgresql.org Subject: Re: no index-usage on aggregate-functions? References: <007d01c45da4$3726dcd0$6602a8c0@spock> In-Reply-To: <007d01c45da4$3726dcd0$6602a8c0@spock> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/283 X-Sequence-Number: 7341 > f.e. querying against a 2.8-mio-records (2.800.000) table the_table > SELECT count(*) FROM the_table > => Seq scan -> takes about 12 sec This cannot be made O(1) in postgres due to MVCC. You just have to live with it. > SELECT Avg(num_found) AS NumFound FROM the_table --(index on num_found) > => Seq scan -> takes about 10 sec > > SELECT Sum(num_found) AS TotalFound FROM the_table --(index on num_found) > => Seq scan -> takes about 11 sec Average and sum can never use an index AFAIK, in any db server. You need information from every row. > SELECT Max(date_) AS LatestDate FROM the_table --(index on date_) > => Seq scan -> takes about 14 sec Yep, that's due to postgresql's type extensibility. You should use th workaround you point out below. > But > SELECT date_ AS LatestDate FROM the_table ORDER BY date_ DESC LIMIT 1; > => Index scan -> takes 0.18 msec > > MS SQLServer 2000: Use of an appropriate index _whenever_ aggregating. > > Am I doing something wrong? Nope. Chris