Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 01A032E009D for ; Sat, 10 May 2008 08:42:40 -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 79875-01-2 for ; Sat, 10 May 2008 08:42:24 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.155]) by developer.postgresql.org (Postfix) with ESMTP id AAC772E008A for ; Sat, 10 May 2008 08:42:30 -0300 (ADT) Received: by fg-out-1718.google.com with SMTP id 16so1941460fgg.23 for ; Sat, 10 May 2008 04:42:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=NxbQYrRDUgHonKdLW76rf9bdCYS4QLdFJSHMa6Zw8PI=; b=FnotW+C1DcdvVraiH6hiQjWmTbcRwMynsxW0uZjFAZksCuRRE3wsVPBNOKfOixqAfd8MGMXQRy2zqQW4d4P6jguoHnz0iNuUbqeNWWeQH9vCER8NkB6ps0kwnsr141smrUV2HhuyxPPl88Ez8t4wn8xMSF1i74ucDw50yZxpOKU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=K9mFEt5uObLYREifTU3jndnr8NyoM+WCbPuvtorExH+7737VYcabEOqgdmbtpu3mCxrCERdFppyCEHtmNF8DPdymvD6tyS8XEo7ipjjyyzXThj+m4YFr79YNJUxiRrxpHDkRLS84vvJ7sQDeKtd3Axf7szX63PtnGizaPfu7yfk= Received: by 10.82.178.3 with SMTP id a3mr659059buf.62.1210419748829; Sat, 10 May 2008 04:42:28 -0700 (PDT) Received: by 10.82.145.1 with HTTP; Sat, 10 May 2008 04:42:28 -0700 (PDT) Message-ID: Date: Sat, 10 May 2008 07:42:28 -0400 From: "Merlin Moncure" To: "Frank van Vugt" Subject: Re: plan difference between set-returning function with ROWS within IN() and a plain join Cc: pgsql-performance@postgresql.org, "Tom Lane" In-Reply-To: <200805061727.41210.ftm.van.vugt@foxi.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200805061021.43448.ftm.van.vugt@foxi.nl> <13551.1210083430@sss.pgh.pa.us> <200805061727.41210.ftm.van.vugt@foxi.nl> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/139 X-Sequence-Number: 30107 On Tue, May 6, 2008 at 11:27 AM, Frank van Vugt wrote: >> > 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? > > You knew the right answer to that already ;) > >> I think you forgot the alias foo(id) in the subselect and it's >> actually reducing to "where id in (id)", ie, TRUE. > > Tricky, but completely obvious once pointed out, that's _exactly_ what was > happening. This is one of the reasons why, for a table named 'foo', I name the columns 'foo_id', not 'id'. Also, if you prefix the id column with the table name, you can usually use JOIN USING which is a little bit tighter and easier than JOIN ON. merlin