Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 0EC1264FDBB for ; Thu, 13 Nov 2008 09:36:28 -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 06747-08 for ; Thu, 13 Nov 2008 09:36:21 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id EAB0064FCC7 for ; Thu, 13 Nov 2008 09:36:21 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.1/8.14.1) with ESMTP id mADDaENw096418 for ; Thu, 13 Nov 2008 09:36:14 -0400 (AST) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.1/8.14.1/Submit) id mADDG9xM077232 for pgsql-performance@postgresql.org; Thu, 13 Nov 2008 09:16:09 -0400 (AST) (envelope-from news) From: Tomasz Myrta X-Newsgroups: pgsql.performance Subject: Re: Slow SQL query (14-15 seconds) Date: Thu, 13 Nov 2008 14:16:09 +0100 Organization: Hub.Org Networking Services Lines: 31 Message-ID: References: <491C0962.9060405@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Thunderbird 2.0.0.16 (X11/20080724) In-Reply-To: <491C0962.9060405@gmail.com> To: pgsql-performance@postgresql.org 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/124 X-Sequence-Number: 31855 Bruno Baguette napisal 13.11.2008 12:02: > Hello ! > > Sorry for the subject, I didn't found a better one ! :-/ > > 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. > > If the lines are too long, your mailreader may cut them and make the SQL > query and the query plan unreadable, so I've put a copy of them on > pastebin.com : > > Can you give me some tips to see which part of the query is guilty ? 1. Your explain analyze points to a lot of loops in exists clause: Filter: ((NOT is_deleted) AND (subplan)) 16.5msec * 800loops = ~13sec. Try to replace exists() with in() or inner joins/distinct. 2. Those 3 left joins can be replaced with subselects: select (select count(*)... ) as societe_nbre_commandes from societes ... -- Regards, Tomasz Myrta