Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id BFC3064FD64 for ; Thu, 13 Nov 2008 09:31:57 -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 06732-02 for ; Thu, 13 Nov 2008 09:31:53 -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 6FD6D64FCC7 for ; Thu, 13 Nov 2008 09:31:53 -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 mADDVoja005164; Thu, 13 Nov 2008 08:31:50 -0500 (EST) To: Bruno Baguette cc: pgsql-performance@postgresql.org Subject: Re: Slow SQL query (14-15 seconds) In-reply-to: <491C0962.9060405@gmail.com> References: <491C0962.9060405@gmail.com> Comments: In-reply-to Bruno Baguette message dated "Thu, 13 Nov 2008 12:02:58 +0100" Date: Thu, 13 Nov 2008 08:31:50 -0500 Message-ID: <5163.1226583110@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/123 X-Sequence-Number: 31854 Bruno Baguette writes: > I'm having a problem with this query (below) that takes betweend 14 and > 15 seconds to run, which is too long for the end-user. > I've done a EXPLAIN ANALYZE (below below) but I'm having difficulties to > see which part of that query is taking so many times. It's the repeatedly executed EXISTS subplan that's hurting you: > SubPlan > -> Nested Loop (cost=35.56..378.16 > rows=2 width=0) (actual time=16.511..16.511 rows=0 loops=818) 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. regards, tom lane