Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 9B08413C6999 for ; Fri, 4 May 2012 13:39:16 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SQLXH-0004lo-ED for pgsql-performance@postgresql.org; Fri, 04 May 2012 16:39:16 +0000 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 q44Gd2pw007298; Fri, 4 May 2012 12:39:02 -0400 (EDT) To: Richard Jones cc: pgsql-performance@postgresql.org Subject: Re: Partitioned/inherited tables with check constraints causing slower query plans In-reply-to: References: Comments: In-reply-to Richard Jones message dated "Fri, 04 May 2012 16:01:00 +0100" Date: Fri, 04 May 2012 12:39:02 -0400 Message-ID: <7297.1336149542@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201205/54 X-Sequence-Number: 46878 Richard Jones writes: > I'm seeing poor query performance using partitioned tables with check > constraints, seems like the plan is much worse than when querying the > individual partitions manually. > select version(); --> PostgreSQL 9.1.1 on x86_64-unknown-linux-gnu, > compiled by gcc (Debian 4.4.5-8) 4.4.5, 64-bit I get a reasonable-looking plan when I try to duplicate this issue in 9.1 branch tip. I think the reason you're not getting the right behavior is that you are missing this as-yet-unreleased patch: http://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=ef03b34550e3577c4be3baa25b70787f5646c57b which means it can't figure out that the available index on the child table produces the desired sort order. If you're in a position to compile from source, a current nightly snapshot of the 9.1 branch ought to work for you; otherwise, wait for 9.1.4. (Note: although that patch is a one-liner, I would *not* recommend trying to just cherry-pick the patch by itself; I think it probably interacts with other planner fixes made since 9.1.1.) regards, tom lane