Re: Poor performance on a right join

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Carmen Sarlo <SarloC(at)Jevic(dot)com>
Cc: "'dev(at)archonet(dot)com'" <dev(at)archonet(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Poor performance on a right join
Date: 2003-03-17 20:30:40
Message-ID: 8129.1047933040@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Carmen Sarlo <SarloC(at)Jevic(dot)com> writes:
> EXPLAIN ANALYZE SELECT a.CALL_DATE, a.OPERATOR_ID, a.CUST_CODE FROM
> PHONE as b right join CALLHIST as a on (a.CUST_CODE=b.CUST_CODE) where
> (b.PHONE = '847-478-2100') order by a.call_date desc;

This query is rather pointless as-is: the WHERE clause will eliminate
any null-extended rows produced by the RIGHT JOIN (because null b.PHONE
cannot satisfy the '=' condition). So you may as well reduce the right
join to a plain join. That will result in a much better plan, because
then the WHERE clause can be pushed down to the scan of b.

7.4 will be bright enough to make that deduction by itself, but 7.3 is
not, and certainly not 7.2 ...

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message dev 2003-03-17 20:33:07 Re: Poor performance on a right join
Previous Message John Guthrie 2003-03-17 20:21:29 upcasting multiplication in a query