Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 4CFD32E003C for ; Tue, 6 May 2008 11:17:19 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 75296-04 for ; Tue, 6 May 2008 11:17:07 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by developer.postgresql.org (Postfix) with ESMTP id 290EB2E0039 for ; Tue, 6 May 2008 11:17:16 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m46EHA3J013552; Tue, 6 May 2008 10:17:10 -0400 (EDT) To: Frank van Vugt cc: pgsql-performance@postgresql.org Subject: Re: plan difference between set-returning function with ROWS within IN() and a plain join In-reply-to: <200805061021.43448.ftm.van.vugt@foxi.nl> References: <200805061021.43448.ftm.van.vugt@foxi.nl> Comments: In-reply-to Frank van Vugt message dated "Tue, 06 May 2008 10:21:43 +0200" Date: Tue, 06 May 2008 10:17:10 -0400 Message-ID: <13551.1210083430@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/78 X-Sequence-Number: 30046 Frank van Vugt writes: > db=# explain analyse > select sum(base_total_val) > from sales_invoice > where id in (select id from si_credit_tree(80500007)); Did you check whether this query even gives the right answer? The EXPLAIN output shows that 21703 rows of sales_invoice are being selected, which is a whole lot different than the other behavior. I think you forgot the alias foo(id) in the subselect and it's actually reducing to "where id in (id)", ie, TRUE. regards, tom lane