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 4B0933A4E28 for ; Wed, 12 Jan 2005 22:55:56 +0000 (GMT) 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 91540-08 for ; Wed, 12 Jan 2005 22:55:47 +0000 (GMT) Received: from ms-smtp-03-eri0.ohiordc.rr.com (ms-smtp-03-smtplb.ohiordc.rr.com [65.24.5.137]) by svr1.postgresql.org (Postfix) with ESMTP id 4C8033A5E45 for ; Wed, 12 Jan 2005 22:55:48 +0000 (GMT) Received: from enzo.mascari.com (dhcp065-024-156-214.columbus.rr.com [65.24.156.214]) by ms-smtp-03-eri0.ohiordc.rr.com (8.12.10/8.12.7) with ESMTP id j0CMtjwZ017674; Wed, 12 Jan 2005 17:55:45 -0500 (EST) Received: from [192.168.2.8] (mercedes.mascari.com [192.168.2.8]) by enzo.mascari.com (8.12.8/8.12.8) with ESMTP id j0CMtfnj013168; Wed, 12 Jan 2005 17:55:41 -0500 Message-ID: <41E5AAEB.2070706@mascari.com> Date: Wed, 12 Jan 2005 17:55:39 -0500 From: Mike Mascari User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Litao Wu Cc: pgsql-performance@postgresql.org Subject: Re: Postgres Optimizer is not smart enough? References: <20050112222506.32084.qmail@web13124.mail.yahoo.com> In-Reply-To: <20050112222506.32084.qmail@web13124.mail.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Mascari-MailScanner-Information: Please contact the ISP for more information X-Mascari-MailScanner: Found to be clean X-Mascari-MailScanner-SpamCheck: not spam, SpamAssassin (score=0, required 6, autolearn=not spam) X-MailScanner-From: mascarm@mascari.com X-Virus-Scanned: Symantec AntiVirus Scan Engine X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200501/155 X-Sequence-Number: 9845 Litao Wu wrote: > Hi All, > > Here is my test comparison between Postgres (7.3.2) > optimizer vs Oracle (10g) optimizer. > > It seems to me that Postgres optimizer is not smart > enough. > > Did I miss anything? Yeah, 7.4. 7.3.2 is *ancient*. Here's output from 7.4: [test@ferrari] explain analyze test-# SELECT module, sum(action_deny) test-# FROM test test-# WHERE created >= ('now'::timestamptz - '1 test'# day'::interval) AND customer_id='100' test-# AND domain='100' test-# GROUP BY module; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------- HashAggregate (cost=5.69..5.69 rows=1 width=13) (actual time=715.058..715.060 rows=1 loops=1) -> Index Scan using test_id1 on test (cost=0.00..5.68 rows=1 width=13) (actual time=0.688..690.459 rows=1 loops=1) Index Cond: ((customer_id = 100) AND (created >= '2005-01-11 17:52:22.364145-05'::timestamp with time zone) AND (("domain")::text = '100'::text)) Total runtime: 717.546 ms (4 rows) [test@ferrari] create index test_id2 on test(domain); CREATE INDEX [test@ferrari] analyze test; ANALYZE [test@ferrari] [test@ferrari] explain analyze test-# SELECT module, sum(action_deny) test-# FROM test test-# WHERE created >= ('now'::timestamptz - '1 test'# day'::interval) AND customer_id='100' test-# AND domain='100' test-# GROUP BY module; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------ HashAggregate (cost=5.68..5.69 rows=1 width=13) (actual time=10.778..10.780 rows=1 loops=1) -> Index Scan using test_id2 on test (cost=0.00..5.68 rows=1 width=13) (actual time=10.702..10.721 rows=1 loops=1) Index Cond: (("domain")::text = '100'::text) Filter: ((created >= '2005-01-11 17:53:16.720749-05'::timestamp with time zone) AND (customer_id = 100)) Total runtime: 11.039 ms (5 rows) [test@ferrari] select version(); PostgreSQL 7.4.5 on i686-pc-linux-gnu, compiled by GCC i686-pc-linux-gnu-gcc (GCC) 3.4.0 20040204 (prerelease) (1 row) Hope that helps, Mike Mascari