Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 9D1682E0120 for ; Tue, 4 Dec 2007 20:39:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 55588-01 for ; Tue, 4 Dec 2007 20:39:41 -0400 (AST) Received: from oxford.xeocode.com (unknown [87.127.95.196]) by postgresql.org (Postfix) with ESMTP id 684282E0101 for ; Tue, 4 Dec 2007 20:39:48 -0400 (AST) Received: from localhost ([127.0.0.1] helo=oxford.xeocode.com) by oxford.xeocode.com with esmtp (Exim 4.67) (envelope-from ) id 1IziIk-0002DO-21; Wed, 05 Dec 2007 00:39:46 +0000 To: "Julian Mehnle" Cc: Subject: Re: Bad query plans for queries on partitioned table In-Reply-To: <200712042027.01921.julian@mehnle.net> (Julian Mehnle's message of "Tue\, 4 Dec 2007 20\:27\:01 +0000") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX.performance" 3480) References: <200712041944.13543.julian@mehnle.net> <87ir3e6wti.fsf@oxford.xeocode.com> <200712042027.01921.julian@mehnle.net> From: Gregory Stark Organization: EnterpriseDB Date: Wed, 05 Dec 2007 00:39:45 +0000 Message-ID: <8763ze6kku.fsf@oxford.xeocode.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/61 X-Sequence-Number: 27877 "Julian Mehnle" writes: > I actually do have constraints on all the partitions, e.g. for week 34: > > Check constraints [for email_2007_week34]: > "email_2007_week34_ts_check" CHECK (ts >= '2007-08-20 00:00:00'::timestamp without time zone AND ts < '2007-08-27 00:00:00'::timestamp without time zone) > > Check constraints [for email_2007_week34_extras]: > "email_2007_week34_extras_ts_check" CHECK (ts >= '2007-08-20 00:00:00'::timestamp without time zone AND ts < '2007-08-27 00:00:00'::timestamp without time zone) > > Shouldn't this be enough to give the query planner a clue that it only > has to join the "email" and "email_extras" tables' partitions pair-wise, > as opposed to cross-joining them? Ah, well, this falls under "The optimizer is a bit dumb about partitioned tables". It only looks at the constraints to compare against your WHERE clause. It doesn't compare them against the constraints for other tables to see if they're partitioned on the same key and therefore can be joined table-by-table. I want 8.4 to be cleverer in this area but there's a ton of things it has to learn. -- Gregory Stark EnterpriseDB http://www.enterprisedb.com Get trained by Bruce Momjian - ask me about EnterpriseDB's PostgreSQL training!