Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TUlC9-0005bR-1m for pgsql-performance@postgresql.org; Sat, 03 Nov 2012 21:23:57 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TUlC2-0002JG-DO for pgsql-performance@postgresql.org; Sat, 03 Nov 2012 21:23:56 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id qA3LNmPW029145 for ; Sat, 3 Nov 2012 17:23:48 -0400 (EDT) From: Tom Lane To: pgsql-performance@postgresql.org Subject: Re: Constraint exclusion in views In-reply-to: <50957270.80300@agliodbs.com> References: <50957270.80300@agliodbs.com> Comments: In-reply-to Josh Berkus message dated "Sat, 03 Nov 2012 12:37:20 -0700" Date: Sat, 03 Nov 2012 17:23:47 -0400 Message-ID: <29144.1351977827@sss.pgh.pa.us> X-Pg-Spam-Score: -2.5 (--) X-Archive-Number: 201211/18 X-Sequence-Number: 48384 Josh Berkus writes: >> Funny thing is, if I set constraint_exclusion=on, it works as >> expected. But not with constraint_exclusion=partition. > The difference between "on" and "partition" is how it treats UNION. > This seems to be working as designed. Well, what "partition" actually means is "only bother to try constraint exclusion proofs on appendrel members". UNION ALL trees will get flattened into appendrels in some cases. In a quick look at the code, it seems like in recent releases the restrictions are basically that the UNION ALL arms have to (1) each be a plain SELECT from a single table with no WHERE restriction; (2) all produce the same column datatypes; and (3) not have any volatile functions in the SELECT lists. I might be missing something relevant to the OP's case, but it's hard to tell without a concrete example. regards, tom lane