X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D2F2F3A18B5 for ; Sat, 15 Jan 2005 20:24:23 +0000 (GMT) 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 50133-10 for ; Sat, 15 Jan 2005 20:24:14 +0000 (GMT) Received: from davinci.ethosmedia.com (server227.ethosmedia.com [209.128.84.227]) by svr1.postgresql.org (Postfix) with ESMTP id C22F03A2CF7 for ; Sat, 15 Jan 2005 20:24:14 +0000 (GMT) X-EthosMedia-Virus-Scanned: no infections found Received: from [63.195.55.98] (account josh@agliodbs.com HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 6911214 for pgsql-performance@postgresql.org; Sat, 15 Jan 2005 12:25:53 -0800 From: Josh Berkus Organization: Aglio Database Solutions To: Subject: IN() Optimization issue in 8.0rc5 Date: Sat, 15 Jan 2005 12:23:10 -0800 User-Agent: KMail/1.6.2 MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <200501151223.10372.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.007 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/196 X-Sequence-Number: 9886 Tom, Hmmm ... I'm seeing an issue with IN() optimization -- or rather the lack of it -- in 8.0rc5. It seems to me that this worked better in 7.4, although I've not been able to load this particular database and test dm=# explain dm-# SELECT personid FROM mr.person_attributes_old dm-# WHERE personid NOT IN (SELECT personid FROM mr.person_attributes); QUERY PLAN ----------------------------------------------------------------------------------- Seq Scan on person_attributes_old (cost=0.00..3226144059.85 rows=235732 width=4) Filter: (NOT (subplan)) SubPlan -> Seq Scan on person_attributes (cost=0.00..12671.07 rows=405807 width=4) (4 rows) dm=# explain select pao.personid from mr.person_attributes_old pao dm-# left outer join mr.person_attributes p on pao.personid = p.personid dm-# where p.personid is null; QUERY PLAN --------------------------------------------------------------------------------------------------------------- Merge Left Join (cost=0.00..34281.83 rows=471464 width=4) Merge Cond: ("outer".personid = "inner".personid) Filter: ("inner".personid IS NULL) -> Index Scan using idx_opa_person on person_attributes_old pao (cost=0.00..13789.29 rows=471464 width=4) -> Index Scan using idx_pa_person on person_attributes p (cost=0.00..14968.25 rows=405807 width=4) (5 rows) It seems like the planner ought to recognize that the first form of the query is optimizable into the 2nd form, and that I've seen it do so in 7.4. However, *no* amount of manipulation of query parameters I did on the 1st form of the query were successful in getting the planner to recognize that it could use indexes for the IN() form of the query. Thoughts? -- Josh Berkus Aglio Database Solutions San Francisco