X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C0375DA17D for ; Thu, 6 Oct 2005 13:32:24 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62245-03 for ; Thu, 6 Oct 2005 16:32:18 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 15192D8833 for ; Thu, 6 Oct 2005 13:32:17 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j96GWH7N020943; Thu, 6 Oct 2005 12:32:17 -0400 (EDT) To: "Dmitri Bichko" Cc: pgsql-sql@postgresql.org Subject: Re: UNION index use help In-reply-to: References: Comments: In-reply-to "Dmitri Bichko" message dated "Thu, 06 Oct 2005 11:59:51 -0400" Date: Thu, 06 Oct 2005 12:32:17 -0400 Message-ID: <20942.1128616337@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200510/57 X-Sequence-Number: 22910 "Dmitri Bichko" writes: > Ok, I'm thoroughly confused. You didn't say which PG version you are using, but if it's something reasonably recent then it should be able to push upper qual conditions down into a UNION. I think you are getting bit by this restriction: * 3. For subqueries using UNION/UNION ALL/INTERSECT/INTERSECT ALL, we can * push quals into each component query, but the quals can only reference * subquery columns that suffer no type coercions in the set operation. * Otherwise there are possible semantic gotchas. You're getting burnt because you're unioning a text with a varchar. Make the column types the same and it'll work better. regards, tom lane