Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id E174F633296 for ; Thu, 22 Jul 2010 10:32:49 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 11675-09 for ; Thu, 22 Jul 2010 13:32:39 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.187]) by mail.postgresql.org (Postfix) with ESMTP id CA5726309F0 for ; Thu, 22 Jul 2010 10:32:40 -0300 (ADT) Received: from [192.168.1.5] (static-71-179-240-8.bltmmd.fios.verizon.net [71.179.240.8]) by mrelayeu.kundenserver.de (node=mrbap0) with ESMTP (Nemesis) id 0MELXc-1OmyUw1cZk-00FjKd; Thu, 22 Jul 2010 15:32:39 +0200 Message-ID: <4C484874.3060609@2ndquadrant.com> Date: Thu, 22 Jul 2010 09:32:36 -0400 From: Greg Smith User-Agent: Thunderbird 2.0.0.24 (X11/20100317) MIME-Version: 1.0 To: Philippe Rimbault CC: pgsql-performance@postgresql.org Subject: Re: Strange explain on partitioned tables References: <4C47F8C8.10005@edd.fr> In-Reply-To: <4C47F8C8.10005@edd.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:YPq2xSuMGv+q2JWSoLfNfGd85zMYls5qlQX3VRrR1Bk FWfDJif9+Aqy0thnMOjm88yaII+UK3ogvfS502vfNcmLUIe8yT b19jGbjDcSLVecLfp7zluJjV5iGXLOpsukdhn3Moiem9T66YjX cQHqLJ0ZMV4e1eV3D/DLDZFeQ/EfFcYwRIlSinrMXz47IsI17T VMUS0SAINeAHWc8jegcF/y2P8hJj6QPmRYXz3SAhZc= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.001 tagged_above=-10 required=5 tests=BAYES_20=-0.001, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201007/320 X-Sequence-Number: 39709 Philippe Rimbault wrote: > I have one thousand inherited tables like this one (with a different > check constraint on each) : The PostgreSQL partitioning system is aimed to support perhaps a hundred inherited tables. You can expect to get poor performance on queries if you create 1000 of them. That's not the cause of your current problem, just pointing out there's a larger design problem here you'll probably have to fix one day. > EXPLAIN ANALYZE > select > documents.id, > documents.num, > sources.name, > l.name > from > documents, > locations l, > sources > where > documents.id_source = 113 and > documents.id_location=l.id and > documents.id_source=sources.id > order by > documents.id desc > limit 5; Please don't put your EXPLAIN plans surrounded in " marks; it makes it harder to copy out of your message to analyze them with tools. I put this bad one into http://explain.depesz.com/s/XD and it notes that the "public.documents.id_location = l.id" search is underestimating the number of rows by a factor of 8.7. You might get a better plan if you can get better table statistics on that column. Did you run ANALYZE since the partitioning was done? If not, that could be making this worse. You might increase the amount of table statistics on this specific column too, not sure what would help without knowing exactly what's in there. Another thing you can try is suggest the optimizer not use a hash join here and see if it does the right thing instead; be a useful bit of feedback to see what that plan turns out to be. Just put "set enable_hashjoin=off;" before the rest of the query, it will only impact that session. -- Greg Smith 2ndQuadrant US Baltimore, MD PostgreSQL Training, Services and Support greg@2ndQuadrant.com www.2ndQuadrant.us