pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Merlin Moncure <mmoncure@gmail.com>
To: Frank van Vugt <ftm.van.vugt@foxi.nl>
Cc: pgsql-performance@postgresql.org, "Tom Lane" <tgl@sss.pgh.pa.us>
Subject: Re: plan difference between set-returning function with ROWS within IN() and a plain join
Date: Sat, 10 May 2008 07:42:28 -0400
Message-ID: <b42b73150805100442n103701c4ud105cddac6f391e0@mail.gmail.com> (raw)
In-Reply-To: <200805061727.41210.ftm.van.vugt@foxi.nl>
References: <200805061021.43448.ftm.van.vugt@foxi.nl>
	<13551.1210083430@sss.pgh.pa.us>
	<200805061727.41210.ftm.van.vugt@foxi.nl>

On Tue, May 6, 2008 at 11:27 AM, Frank van Vugt <ftm.van.vugt@foxi.nl> 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



view thread (6+ messages)

Message-ID: <b42b73150805100442n103701c4ud105cddac6f391e0@mail.gmail.com>
Permalink:  ../b42b73150805100442n103701c4ud105cddac6f391e0@mail.gmail.com/
Also on:    postgresql.org/message-id/b42b73150805100442n103701c4ud105cddac6f391e0@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: mmoncure@gmail.com, ftm.van.vugt@foxi.nl, tgl@sss.pgh.pa.us
  Subject: Re: plan difference between set-returning function with ROWS within IN() and a plain join
  In-Reply-To: <b42b73150805100442n103701c4ud105cddac6f391e0@mail.gmail.com>
  References: <200805061021.43448.ftm.van.vugt@foxi.nl> <13551.1210083430@sss.pgh.pa.us> <200805061727.41210.ftm.van.vugt@foxi.nl> <b42b73150805100442n103701c4ud105cddac6f391e0@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox