X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id D164C9FA279 for ; Fri, 26 May 2006 09:11:48 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 07855-01 for ; Fri, 26 May 2006 09:11:40 -0300 (ADT) X-Greylist: delayed 00:06:37.498503 by SQLgrey- Received: from smtp-31.ig.com.br (smtp-31.ig.com.br [200.226.132.31]) by postgresql.org (Postfix) with ESMTP id DDF579F9B01 for ; Fri, 26 May 2006 09:11:39 -0300 (ADT) Received: (qmail 31784 invoked from network); 26 May 2006 12:04:56 -0000 Received: from 70.131.226.200.in-addr.arpa.ig.com.br (HELO localhost.localdomain) ([200.226.131.70]) (envelope-sender ) by email-31.ig.com.br (qmail-ldap-1.03) with SMTP for ; 26 May 2006 12:04:56 -0000 To: pgsql-performance@postgresql.org From: wmiro@ig.com.br Subject: Why the 8.1 plan is worst than 7.4? Date: Fri, 26 May 2006 09:04:56 -0300 X-Priority: 3 (Normal) Message-ID: <20060526_120456_040065.wmiro@ig.com.br> X-Originating-IP: [10.17.1.70]192.168.3.243, 200.171.147.216 X-Mailer: iGMail [www.ig.com.br] X-user: wmiro@ig.com.br Teste: asaes MIME-Version: 1.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.024 tagged_above=0 required=5 tests=BAYES_20, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, FORGED_RCVD_HELO, RCVD_IN_NJABL_PROXY X-Spam-Level: ** Content-Description: Mail message body Content-Type: text/plain; charset=ISO-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Archive-Number: 200605/543 X-Sequence-Number: 19330 Hi, I have 2 servers, one of them has a 7.4 postgres and the other has a 8.1 I have this query: select fagrempr,fagrdocr,fagrserr,fagrparr from arqcfat left join arqfagr on fagrorig = 'CFAT' and fagrdocu = cfatdocu and fagrempe = cfatempe and fagrseri = cfatseri where cfatdata between '2006-01-01' and '2006-01-31' and cfattipo = 'VD' and cfatstat <> 'C' and fagrform = 'CT' and fagrtipr = 'REC' group by fagrempr,fagrdocr,fagrserr,fagrparr The 8.1 give me this plan: HashAggregate (cost=59.07..59.08 rows=1 width=20) -> Nested Loop (cost=0.00..59.06 rows=1 width=20) -> Index Scan using arqfagr_arqfa3_key on arqfagr (cost=0.00..53.01 rows=1 width=36) Index Cond: ((fagrorig = 'CFAT'::bpchar) AND (fagrform = 'CT'::bpchar)) Filter: (fagrtipr = 'REC'::bpchar) -> Index Scan using arqcfat_arqcfat1_key on arqcfat (cost=0.00..6.03 rows=1 width=16) Index Cond: (("outer".fagrempe = arqcfat.cfatempe) AND ("outer".fagrdocu = arqcfat.cfatdocu) AND ("outer".fagrseri = arqcfat.cfatseri)) Filter: ((cfatdata >= '01-01-2006'::date) AND (cfatdata <= '31-01-2006'::date) AND (cfattipo = 'VD'::bpchar) AND (cfatstat <> 'C'::bpchar)) The 7.4 give me this plan: HashAggregate (cost=2163.93..2163.93 rows=1 width=19) -> Nested Loop (cost=0.00..2163.92 rows=1 width=19) -> Index Scan using arqcfat_arqcfat2_key on arqcfat (cost=0.00..2145.78 rows=3 width=15) Index Cond: ((cfatdata >= '01-01-2006'::date) AND (cfatdata <= '31-01-2006'::date)) Filter: ((cfattipo = 'VD'::bpchar) AND (cfatstat <> 'C'::bpchar)) -> Index Scan using arqfagr_arqfa1_key on arqfagr (cost=0.00..6.03 rows=1 width=34) Index Cond: ((arqfagr.fagrorig = 'CFAT'::bpchar) AND (arqfagr.fagrempe = "outer".cfatempe) AND (arqfagr.fagrdocu = "outer".cfatdocu) AND (arqfagr.fagrseri = "outer".cfatseri)) Filter: ((fagrform = 'CT'::bpchar) AND (fagrtipr = 'REC'::bpchar)) Why the plan is worst in postgres 8.1? I know the best plan is read fisrt the table which has a date index as the 7.4 did, because in a few days I will have few lines too, so the query will be faster. Is there some thing I have to change in 8.1 to make the plans as the 7.4? Thanks , Waldomiro C. Neto.