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 CF93D9FB338 for ; Mon, 31 Jul 2006 09:25:13 -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 82602-01 for ; Mon, 31 Jul 2006 09:24:57 -0300 (ADT) X-Greylist: delayed 00:07:20.516489 by SQLgrey- Received: from h1.bettercom.de (h1.bettercom.de [213.239.194.41]) by postgresql.org (Postfix) with ESMTP id 4AB5D9FB34A for ; Mon, 31 Jul 2006 09:24:42 -0300 (ADT) Received: (qmail 6449 invoked by uid 208); 31 Jul 2006 12:17:08 -0000 Received: from 213.39.204.54 by h1 (envelope-from , uid 0) with qmail-scanner-1.23 (clamdscan: 0.87. spamassassin: 3.04. Clear:RC:1(213.39.204.54):. Processed in 0.021805 secs); 31 Jul 2006 12:17:08 -0000 Received: from unknown (HELO fs-home.bettercom.de) ([213.39.204.54]) (envelope-sender ) by h1.bettercom.de (qmail-ldap-1.03) with SMTP for ; 31 Jul 2006 12:17:08 -0000 Received: (nullmailer pid 2740 invoked by uid 1000); Mon, 31 Jul 2006 12:17:08 -0000 From: Martin Lesser To: pgsql-performance@postgresql.org Subject: Partitioning / constrain exlusion not working with %-operator X-Face: "d[&>8')a)wbF:+L#^<_cohnX6#m5RCCeKF/6_gD(iQ9bX?xe2~Aq*!')D(1ks`?YhomOYbL3R:{4e4a]qft_]<.q/Lf4hIr,`G+LX33&TYp}XGfe~^5m$28R"$C(EwnB\n8t Date: Mon, 31 Jul 2006 14:17:08 +0200 Message-ID: <87ejw27yuz.fsf@fs-home.bettercom.de> User-Agent: Gnus/5.110004 (No Gnus v0.4) XEmacs/21.4.18 (linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.816 tagged_above=0 required=5 tests=SPF_HELO_SOFTFAIL, SPF_SOFTFAIL, UPPERCASE_25_50 X-Spam-Level: *** X-Archive-Number: 200607/303 X-Sequence-Number: 20163 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: CREATE TABLE tt_m (id1 int, cont varchar); CREATE TABLE tt_0 (check (id1 % 50 = 0)) INHERITS (tt_m); CREATE TABLE tt_1 (check (id1 % 50 = 1)) INHERITS (tt_m); .... CREATE RULE ins_tt_0 AS ON INSERT TO tt_m WHERE id1 % 50 = 0 DO INSTEAD INSERT INTO tt_0 VALUES (new.*); CREATE RULE ins_tt_1 AS ON INSERT TO tt_m WHERE id1 % 50 = 1 DO INSTEAD INSERT INTO tt_1 VALUES (new.*); ... INSERT INTO tt_m (id1,cont) VALUES (0,'Test1'); INSERT INTO tt_m (id1,cont) VALUES (1,'Test2'); .... EXPLAIN SELECT * FROM tt_m WHERE id1=1; QUERY PLAN ----------------------------------------------------------------------- Result (cost=0.00..73.50 rows=18 width=36) -> Append (cost=0.00..73.50 rows=18 width=36) -> Seq Scan on tt_m (cost=0.00..24.50 rows=6 width=36) Filter: (id1 = 1) -> Seq Scan on tt_0 tt_m (cost=0.00..24.50 rows=6 width=36) Filter: (id1 = 1) -> Seq Scan on tt_1 tt_m (cost=0.00..24.50 rows=6 width=36) Filter: (id1 = 1) ... Only adding an explicit %-call to the query results in the expected plan: EXPLAIN SELECT * FROM tt_m WHERE id1=1 AND id1 % 50 = 1; QUERY PLAN ----------------------------------------------------------------------- Result (cost=0.00..60.60 rows=2 width=36) -> Append (cost=0.00..60.60 rows=2 width=36) -> Seq Scan on tt_m (cost=0.00..30.30 rows=1 width=36) Filter: ((id1 = 1) AND ((id1 % 50) = 1)) -> Seq Scan on tt_1 tt_m (cost=0.00..30.30 rows=1 width=36) Filter: ((id1 = 1) AND ((id1 % 50) = 1)) Did I miss something and/or how could I force the planner to use constraint exclusion without adding the explicit second condition above? TIA, Martin