Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 351D42E0051 for ; Wed, 21 May 2008 07:48:20 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 13540-10 for ; Wed, 21 May 2008 07:48:10 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from pih-relay08.plus.net (pih-relay08.plus.net [212.159.14.134]) by developer.postgresql.org (Postfix) with ESMTP id 41BEA2E002C for ; Wed, 21 May 2008 07:48:14 -0300 (ADT) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by pih-relay08.plus.net with esmtp (Exim) id 1JylrZ-00014o-SB; Wed, 21 May 2008 11:48:06 +0100 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 95255274063; Wed, 21 May 2008 11:48:05 +0100 (BST) Message-ID: <4833FDE5.8090603@archonet.com> Date: Wed, 21 May 2008 11:48:05 +0100 From: Richard Huxton User-Agent: Thunderbird 2.0.0.14 (X11/20080421) MIME-Version: 1.0 To: Albert Cervera Areny CC: pgsql-performance@postgresql.org Subject: Re: Posible planner improvement? References: <200805211228.48248.albert@sedifa.com> In-Reply-To: <200805211228.48248.albert@sedifa.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Plusnet-Relay: 6d6a2b7df1bc17b06c525c8d0f024d81 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/287 X-Sequence-Number: 30255 Albert Cervera Areny wrote: > I've got a query similar to this: > > select * from t1, t2 where t1.id > 158507 and t1.id = t2.id; > > That took > 84 minutes (the query was a bit longer but this is the part that > made the difference) after a little change the query took ~1 second: > > select * from t1, t2 where t1.id > 158507 and t2.id > 158507 and t1.id = > t2.id; Try posting EXPLAIN ANALYSE SELECT ... for both of those queries and we'll see why it's better at the second one. -- Richard Huxton Archonet Ltd