X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id AE3C69FB2BA for ; Thu, 10 Aug 2006 04:30:44 -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 54727-01 for ; Thu, 10 Aug 2006 04:30:39 -0300 (ADT) X-Greylist: delayed 17:24:16.218149 by SQLgrey- Received: from mx.mall.cz (unknown [82.100.0.98]) by postgresql.org (Postfix) with ESMTP id D11529FB2B4 for ; Thu, 10 Aug 2006 04:30:39 -0300 (ADT) Received: from localhost (asterix [127.0.0.1]) by mx.mall.cz (Postfix) with ESMTP id AB5B613F63B for ; Thu, 10 Aug 2006 09:30:37 +0200 (CEST) Received: from mx.mall.cz ([127.0.0.1]) by localhost (asterix [127.0.0.1]) (amavisd-new, port 10025) with ESMTP id 13111-07 for ; Thu, 10 Aug 2006 09:30:35 +0200 (CEST) Message-ID: <44DAE09B.20009@mall.cz> Date: Thu, 10 Aug 2006 09:30:35 +0200 From: Michal Taborsky - Internet Mall Organization: Internet Mall, a.s. User-Agent: Thunderbird 1.5.0.5 (Windows/20060719) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: 3-table query optimization References: <44D9EBEB.9010704@mall.cz> <20367.1155136139@sss.pgh.pa.us> In-Reply-To: <20367.1155136139@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at mall.cz X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.827 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, SPF_PASS X-Spam-Level: X-Archive-Number: 200608/175 X-Sequence-Number: 20360 Tom Lane napsal(a): > Michal Taborsky - Internet Mall writes: >> SELECT product.product_id >> FROM action >> JOIN product ON (product.product_id=action.product_id) >> WHERE action.shop_group_id=1 >> AND EXISTS (SELECT 1 >> FROM catalog.product_program >> WHERE product_id=product.product_id >> AND product_program.program_id =1104322 >> ) > > Try converting the EXISTS subquery to an IN. The performance is roughly the same. For some groups it's better, for some groups, the bigger ones, it's a bit worse. I forgot to mention, that the server is running 8.0.2. Upgrading would be a bit painful, as it is a 24/7 production system, but if it would help significantly, we'd give it a go. -- Michal Táborský