X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A2EF011F6AB5 for ; Fri, 7 Apr 2006 14:37:02 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 98663-06 for ; Fri, 7 Apr 2006 14:36:59 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id D25B011F6976 for ; Fri, 7 Apr 2006 14:36:59 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k37HawKa014670; Fri, 7 Apr 2006 13:36:59 -0400 (EDT) To: Rafael Martinez Guerrero cc: pgsql-performance@postgresql.org Subject: Re: Same SQL, 104296ms of difference between 7.4.12 and 8.0.7 In-reply-to: <12251.1144423772@sss.pgh.pa.us> References: <1144413933.24060.253.camel@bbking.uio.no> <12251.1144423772@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Fri, 07 Apr 2006 11:29:32 -0400" Date: Fri, 07 Apr 2006 13:36:58 -0400 Message-ID: <14669.1144431418@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.132 required=5 tests=[AWL=0.132] X-Spam-Score: 0.132 X-Spam-Level: X-Archive-Number: 200604/143 X-Sequence-Number: 18227 I wrote: > Rafael Martinez Guerrero writes: >> I have a sql statement that takes 108489.780 ms with 8.0.7 in a >> RHEL4/amd64linux server with 2xAMD Opteron(tm) Processor 275 2.00GHz / >> 8GB RAM and only 4193.588 ms with 7.4.12 in a RHEL3/386linux server with >> 2xIntel(R) Xeon(TM) CPU 2.40GHz / 4GB RAM. > I think you've discovered a planner regression. > Simplified test case using the regression database: > explain select * from tenk1 a, tenk1 b > where (a.ten = b.ten and (a.unique1 = 100 or a.unique1 = 101)) > or (a.hundred = b.hundred and a.unique1 = 42); I've repaired the assertion crash in 8.1/HEAD, but I don't think it's practical to teach 8.0 to optimize queries like this nicely. The reason 7.4 can do it is that 7.4 forces the WHERE condition into CNF, ie (a.hundred = b.hundred OR a.ten = b.ten) AND (a.unique1 = 42 OR a.ten = b.ten) AND (a.hundred = b.hundred OR a.unique1 = 100 OR a.unique1 = 101) AND (a.unique1 = 42 OR a.unique1 = 100 OR a.unique1 = 101) from which it's easy to extract the index condition for A. We decided that forcing to CNF wasn't such a hot idea, so 8.0 and later don't do it, but 8.0's logic for extracting index conditions from joinquals isn't up to the problem of handling sub-ORs. Fixing that looks like a larger change than I care to back-patch into an old release. My recommendation is to update to 8.1.4 when it comes out. regards, tom lane