Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 96F5647688F for ; Thu, 4 Jul 2002 20:32:17 -0400 (EDT) Mailbox-Line: From tgl@sss.pgh.pa.us Thu Jul 4 20:32:17 2002 Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 748A3476839 for ; Thu, 4 Jul 2002 20:28:14 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g650Rv206648; Thu, 4 Jul 2002 20:27:57 -0400 (EDT) To: Stephan Szabo Cc: Gaetano Mendola , pgsql-admin@postgresql.org Subject: Re: Union strange explain In-reply-to: <20020704115011.T19207-100000@megazone23.bigpanda.com> References: <20020704115011.T19207-100000@megazone23.bigpanda.com> Comments: In-reply-to Stephan Szabo message dated "Thu, 04 Jul 2002 11:53:37 -0700" Date: Thu, 04 Jul 2002 20:27:57 -0400 Message-ID: <6645.1025828877@sss.pgh.pa.us> From: Tom Lane X-Spam-Status: No, hits=-4.2 required=5.0 tests=IN_REP_TO,X_NOT_PRESENT,DOUBLE_CAPSWORD version=2.30 X-Spam-Level: X-Archive-Number: 200207/75 X-Sequence-Number: 4761 Stephan Szabo writes: > I think there was some question about > whether it was safe to do that optimization (ie, > is select * from (a union [all] b) where condition > always the same as > select * from a where condition union [all] > select * from b where condition > ) > This was discussed recently, but I forget what the final determination > was. There wasn't any final determination --- it's still an open issue whether there are any limitations the planner would have to consider when trying to push down conditions into UNIONs. Offhand it seems to me that the change is always safe when dealing with UNION ALL, but I'm not quite convinced about UNION. And what of INTERSECT and EXCEPT? Another interesting question is whether there are cases where the planner could legally push down the condition, but should not because it would end up with a slower plan. I can't think of any examples offhand, but that doesn't mean there aren't any. regards, tom lane