Re: Understanding INNER JOIN versus IN subquery

From: Grzegorz Jaśkiewicz <gryzman(at)gmail(dot)com>
To: Robert James <srobertjames(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Understanding INNER JOIN versus IN subquery
Date: 2009-07-20 14:28:34
Message-ID: 2f4958ff0907200728u14f43f0bre14411237c6af355@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Jul 20, 2009 at 2:37 PM, Robert James<srobertjames(at)gmail(dot)com> wrote:
> I have two queries which should be equivalent.  The Planner plans them
> differently, although they are both about the same time.  Can someone
> explain why?
> select word from dict
> where
>  word in
>  (select substr('moon', 0, generate_series(3,length('moon'))))
>
> select * from dict
> inner join (select substr('moon', 0, generate_series(3,length('moon')))) as
> m
> on dict.word = m.substr
>
> Is one preferred?

it is hard to say from your example. But in my general expierence, I
noticed similar thing many times.
Needless to say, I prefer personally to choose JOINs instead of IN(),
because those tend to be faster on postgresql.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2009-07-20 15:14:27 Re: Documentation Improvement suggestions
Previous Message Greg Stark 2009-07-20 14:21:54 Re: Understanding INNER JOIN versus IN subquery