Skip site navigation (1) Skip section navigation (2)

Re: Strange explain on partitioned tables

From: Greg Smith <greg(at)2ndquadrant(dot)com>
To: Philippe Rimbault <primbault(at)edd(dot)fr>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Strange explain on partitioned tables
Date: 2010-07-22 13:32:36
Message-ID: 4C484874.3060609@2ndquadrant.com (view raw or flat)
Thread:
Lists: pgsql-performance
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(at)2ndQuadrant(dot)com   www.2ndQuadrant.us


In response to

Responses

pgsql-performance by date

Next:From: Philippe RimbaultDate: 2010-07-22 14:10:51
Subject: Re: Strange explain on partitioned tables
Previous:From: Philippe RimbaultDate: 2010-07-22 10:03:12
Subject: Re: Strange explain on partitioned tables

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group