X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CFA9011F6B15 for ; Fri, 7 Apr 2006 11:40:56 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 48536-02 for ; Fri, 7 Apr 2006 11:40:49 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from pih-relay05.plus.net (pih-relay05.plus.net [212.159.14.132]) by postgresql.org (Postfix) with ESMTP id 6F75011F6B02 for ; Fri, 7 Apr 2006 11:40:53 -0300 (ADT) Received: from [213.162.97.75] (helo=mail.metronet.co.uk) by pih-relay05.plus.net with esmtp (Exim) id 1FRs8q-0005DD-Sf; Fri, 07 Apr 2006 15:40:53 +0100 Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id CB60A7379A; Fri, 7 Apr 2006 15:41:59 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 2BF10FF04; Fri, 7 Apr 2006 15:40:52 +0100 (BST) Message-ID: <443679F3.20907@archonet.com> Date: Fri, 07 Apr 2006 15:40:51 +0100 From: Richard Huxton User-Agent: Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 To: Rafael Martinez Guerrero Cc: pgsql-performance@postgresql.org Subject: Re: Same SQL, 104296ms of difference between 7.4.12 and References: <1144413933.24060.253.camel@bbking.uio.no> <443669A5.2000603@archonet.com> <1144418444.24060.269.camel@bbking.uio.no> In-Reply-To: <1144418444.24060.269.camel@bbking.uio.no> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200604/131 X-Sequence-Number: 18215 Rafael Martinez Guerrero wrote: >>> Any ideas of what I can test/configurate to find out why this happens? >>> Thanks in advance. >> I haven't looked in detail at the plans, but what stands out to me is >> that you've got a sort with a lot of columns and you've halved sort_mem >> (work_mem). Try increasing it (perhaps to 32000 even). >> set work_mem = 32000; >> >> Give that a quick go and see what happens. If it doesn't work, we'll >> look at the plans in more detail. > > I know that this SQL could be done in a much better way, but I can not > change it at the moment. > > work_mem = 16384: > ----------------- > After restarting the database and running the explain two times: > 107911.229 ms > > work_mem = 32768: > ----------------- > After restarting the database and running the explain two times: > 103988.337 ms Damn! I hate it when I have to actually work at a problem :-) Well, the first thing that strikes me is that the row estimates are terrible for 7.4.12 (which runs quickly) and much better for 8.0.7 (which runs slowly). Which suggests you were lucky before. The second thing I notice is the bit that goes: Materialize ... Seq Scan on acl acl_2. If you compare the two you'll see that the 7.4 version loops 16,160 times but 8.0 loops 513,264 times. This is a bad choice, and I'm guessing it's made because it gets the row estimate wrong: Hash Join (cost=4667.85..51078.88 rows=62852 width=727) (actual time=649.028..13602.451 rows=513264 loops=1) That's the comparison Groups_3.id = CachedGroupMembers_4.GroupId if I'm reading this correctly. Is there anything unusual about those two columns? -- Richard Huxton Archonet Ltd