Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 7D657B5DBE8 for ; Wed, 8 Jun 2011 12:52:16 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 46918-04 for ; Wed, 8 Jun 2011 15:52:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f46.google.com (mail-fx0-f46.google.com [209.85.161.46]) by mail.postgresql.org (Postfix) with ESMTP id 27B12B5DF88 for ; Wed, 8 Jun 2011 12:52:08 -0300 (ADT) Received: by fxm17 with SMTP id 17so420213fxm.19 for ; Wed, 08 Jun 2011 08:52:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=Yy9dyYhC32HMu4r5BAWP/gMrcIi44/odob/JGcBa81Y=; b=AvDTtzhPfJVeKzRYH1JJRmG1JH8lOjPrbPyraA357LU7YExYZjJMUB9/kZI8ZizDrf a+iaDUzenFpfR0X+0YJh2OqgYYbHl+O85T7xb7vlCemSz+9kJ+cEF/PB52awdn+A6bK5 jcgg9zpa9FD4iy9GLMwV4VxkY/CJ/niTaIF1U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=q2GSZsdJG5K5WCHMgpbg87v6OWnc7ssPFr12kWpMve0IXYFYOS/YQWgWpm3aDMd853 Z3TZgJdXqLjh/wvuUL2i/GyNf9cUwh7AAzZp2eCuAg3j1AGwvqylXukgoRFdqo3oDj7G d9QIGflelcAXXxD+0A/YP4JftqW2ZHWos4K5A= Received: by 10.223.74.83 with SMTP id t19mr937189faj.149.1307548328152; Wed, 08 Jun 2011 08:52:08 -0700 (PDT) Received: from [10.64.1.26] ([213.108.72.250]) by mx.google.com with ESMTPS id x15sm294633fah.46.2011.06.08.08.52.06 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 08 Jun 2011 08:52:07 -0700 (PDT) Message-ID: <4DEF9AA5.2000803@gmail.com> Date: Wed, 08 Jun 2011 18:52:05 +0300 From: Vitalii Tymchyshyn User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110424 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: Tony Capobianco CC: Tom Lane , pgsql-performance@postgresql.org Subject: Re: Oracle v. Postgres 9.0 query performance References: <1307545892.1990.23.camel@tony1.localdomain> <10260.1307547185@sss.pgh.pa.us> <1307547634.1990.26.camel@tony1.localdomain> In-Reply-To: <1307547634.1990.26.camel@tony1.localdomain> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.03 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_ENVFROM_END_DIGIT=1.553, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001, SARE_MILLIONSOF=0.315 X-Spam-Level: X-Archive-Number: 201106/72 X-Sequence-Number: 44005 08.06.11 18:40, Tony Capobianco написав(ла): > pg_dw=# set enable_nestloop =0; > SET > Time: 0.165 ms > pg_dw=# explain CREATE TABLE ecr_opens with (FILLFACTOR=100) > pg_dw-# as > pg_dw-# select o.emailcampaignid, count(memberid) opencnt > pg_dw-# from openactivity o,ecr_sents s > pg_dw-# where s.emailcampaignid = o.emailcampaignid > pg_dw-# group by o.emailcampaignid; > QUERY > PLAN > ----------------------------------------------------------------------------------------- > HashAggregate (cost=4391163.81..4391288.05 rows=9939 width=12) > -> Hash Join (cost=14.78..4344767.23 rows=9279316 width=12) > Hash Cond: (o.emailcampaignid = s.emailcampaignid) > -> Seq Scan on openactivity o (cost=0.00..3529930.67 > rows=192540967 width=12) > -> Hash (cost=8.79..8.79 rows=479 width=4) > -> Seq Scan on ecr_sents s (cost=0.00..8.79 rows=479 > width=4) > > Yikes. Two sequential scans. Yep. Can you see another options? Either you take each of 479 records and try to find matching records in another table using index (first plan), or you take both two tables fully (seq scan) and join - second plan. First plan is better if your large table is clustered enough on emailcampaignid field (479 index reads and 479 sequential table reads). If it's not, you may get a 479 table reads transformed into a lot or random reads. BTW: May be you have different data clustering in PostgreSQL & Oracle? Or data in Oracle may be "hot" in caches? Also, sequential scan is not too bad thing. It may be cheap enough to read millions of records if they are not too wide. Please show "select pg_size_pretty(pg_relation_size('openactivity'));" Have you tried to explain analyze second plan? Best regards, Vitalii Tymchyshyn > > On Wed, 2011-06-08 at 11:33 -0400, Tom Lane wrote: >> Tony Capobianco writes: >>> pg_dw=# explain CREATE TABLE ecr_opens with (FILLFACTOR=100) >>> pg_dw-# as >>> pg_dw-# select o.emailcampaignid, count(memberid) opencnt >>> pg_dw-# from openactivity o,ecr_sents s >>> pg_dw-# where s.emailcampaignid = o.emailcampaignid >>> pg_dw-# group by o.emailcampaignid; >>> QUERY >>> PLAN >>> ------------------------------------------------------------------------------------------------------------- >>> GroupAggregate (cost=0.00..1788988.05 rows=9939 width=12) >>> -> Nested Loop (cost=0.00..1742467.24 rows=9279316 width=12) >>> -> Index Scan using ecr_sents_ecid_idx on ecr_sents s >>> (cost=0.00..38.59 rows=479 width=4) >>> -> Index Scan using openact_emcamp_idx on openactivity o >>> (cost=0.00..3395.49 rows=19372 width=12) >>> Index Cond: (o.emailcampaignid = s.emailcampaignid) >>> (5 rows) >>> Should this query be hashing the smaller table on Postgres rather than >>> using nested loops? >> Yeah, seems like it. Just for testing purposes, do "set enable_nestloop >> = 0" and see what plan you get then.