X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 07DAC528C3 for ; Sun, 19 Jun 2005 15:46:32 -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 93204-10 for ; Sun, 19 Jun 2005 18:46:26 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 0B8CD52896 for ; Sun, 19 Jun 2005 15:46:25 -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 j5JIkOXE018816; Sun, 19 Jun 2005 14:46:24 -0400 (EDT) To: "Erik Aronesty" Cc: pgsql-sql@postgresql.org Subject: Re: Putting an INDEX on a boolean field? In-reply-to: <000a01c57328$fe00f990$1400a8c0@yellow> References: <000a01c57328$fe00f990$1400a8c0@yellow> Comments: In-reply-to "Erik Aronesty" message dated "Fri, 17 Jun 2005 06:40:34 -0400" Date: Sun, 19 Jun 2005 14:46:24 -0400 Message-ID: <18815.1119206784@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.003 tagged_above=0 required=5 tests=AWL, URIBL_OB_SURBL X-Spam-Level: * X-Archive-Number: 200506/241 X-Sequence-Number: 21842 "Erik Aronesty" writes: > Should I start looking to figure out why the optimizer didn't figure out > that it should be doing this sort of thing? It looks to me that the problem is that convert_IN_to_join() is not being smart about where to attach the IN's subselect to the join tree. It's just adding it to the top FROM-expression, so that the join tree is effectively ((sites left join quota) IN-join usersites) and since we don't currently allow any rearrangement of outer joins, this cannot be rearranged into ((sites IN-join usersites) left join quota) as you'd like. The really clean solution to this would be to implement logic about when it is safe to rearrange the join order of outer joins. But I think that's a fairly hard problem in general. A shorter-term solution might be possible by teaching convert_IN_to_join() to attach the IN subselect further down in the join tree, using logic similar to what we use to decide where ordinary WHERE quals can bubble down to. regards, tom lane