Re: - Slow Query

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
Cc: Rui Carvalho <rui(dot)hmcarvalho(at)gmail(dot)com>, Mike Ivanov <mikei(at)activestate(dot)com>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: - Slow Query
Date: 2009-07-01 18:07:15
Message-ID: 14166.1246471635@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com> writes:
> On Wed, Jul 1, 2009 at 11:52 AM, Tom Lane<tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com> writes:
>>> Sometimes putting a where clause portion into the on clause helps.
>>> like:
>>> select * from a left join b on (a.id=b.id) where a.somefield=2
>>> might run faster with
>>> select * from a left join b on (a.id=bid. and a.somefield=2);
>>> but it's hard to say.
>>
>> Uh, those are not the same query ... they will give different results
>> for rows with a.somefield different from 2.

> How so? Neither should return any rows with a.somefield <> 2.

Wrong. The second will return rows with somefield <> 2, null-extended
(whether or not there is any match on id).

regards, tom lane

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Sergey Burladyan 2009-07-02 00:08:14 regression ? 8.4 do not apply One-Time Filter to subquery
Previous Message Scott Marlowe 2009-07-01 18:00:06 Re: - Slow Query