Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id C3B21650160 for ; Thu, 13 Nov 2008 10:30:16 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 18875-07 for ; Thu, 13 Nov 2008 10:30:13 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 7872665012D for ; Thu, 13 Nov 2008 10:30:11 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id mADEU8Uv014561; Thu, 13 Nov 2008 09:30:08 -0500 (EST) To: Bruno Baguette cc: pgsql-performance@postgresql.org Subject: Re: Slow SQL query (14-15 seconds) In-reply-to: <491C377E.3070904@gmail.com> References: <491C0962.9060405@gmail.com> <5163.1226583110@sss.pgh.pa.us> <491C377E.3070904@gmail.com> Comments: In-reply-to Bruno Baguette message dated "Thu, 13 Nov 2008 15:19:42 +0100" Date: Thu, 13 Nov 2008 09:30:08 -0500 Message-ID: <14560.1226586608@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200811/127 X-Sequence-Number: 31858 Bruno Baguette writes: > Le 13/11/08 14:31, Tom Lane a écrit : >> 16.511 * 818 = 13505.998, so this is all but about 100 msec of the >> runtime. Can't tell if there's any easy way to improve it. In >> pre-8.4 releases trying to convert the EXISTS into an IN might help. > Can you explain why a IN is fastest than an EXISTS subquery ? The planner is smarter about IN than EXISTS --- it can usually convert the former into a join plan instead of a subplan. (This situation will improve in 8.4.) > Do you think I can improve again the performance of that query ? You've still got a subplan in there, not quite sure why. Anyway, increasing work_mem might get it to change to a hashed subplan, which'd likely be faster. regards, tom lane