X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 734DC9FB319 for ; Mon, 31 Jul 2006 09:44:20 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 82576-10 for ; Mon, 31 Jul 2006 09:44:00 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 00D679FB1E0 for ; Mon, 31 Jul 2006 09:43:15 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k6VCgvAp013553; Mon, 31 Jul 2006 08:42:57 -0400 (EDT) To: Martin Lesser cc: pgsql-performance@postgresql.org Subject: Re: Partitioning / constrain exlusion not working with %-operator In-reply-to: <87ejw27yuz.fsf@fs-home.bettercom.de> References: <87ejw27yuz.fsf@fs-home.bettercom.de> Comments: In-reply-to Martin Lesser message dated "Mon, 31 Jul 2006 14:17:08 +0200" Date: Mon, 31 Jul 2006 08:42:57 -0400 Message-ID: <13552.1154349777@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.003 tagged_above=0 required=5 tests=AWL, SPF_HELO_SOFTFAIL, SPF_SOFTFAIL X-Spam-Level: ** X-Archive-Number: 200607/305 X-Sequence-Number: 20165 Martin Lesser writes: > I try to partition a large table (~ 120 mio. rows) into 50 smaller > tables but using the IMO immutable %-function constraint exclusion > does not work as expected: The constraint exclusion mechanism is not as bright as you think. There are some very limited cases where it can make a deduction that a WHERE clause implies a CHECK constraint that's not an exact textual equivalent ... but all those cases have to do with related b-tree operators, and % is not one. It's usually better to use partitioning rules that have something to do with the WHERE-clauses you'd be using anyway. For instance, try to partition on ranges of id1 instead of id1 % 50. That works because the CHECK clauses will be like "id1 >= x and id1 < y" and those operators are btree-related to the "id1 = z" clauses you'll have in the query. regards, tom lane