Re: Poor performance on a right join - Mailing list pgsql-sql

From Tom Lane
Subject Re: Poor performance on a right join
Date
Msg-id 8129.1047933040@sss.pgh.pa.us
Whole thread Raw
In response to Re: Poor performance on a right join  (Carmen Sarlo <SarloC@Jevic.com>)
List pgsql-sql
Carmen Sarlo <SarloC@Jevic.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


pgsql-sql by date:

Previous
From: "John Guthrie"
Date:
Subject: upcasting multiplication in a query
Next
From: dev@archonet.com
Date:
Subject: Re: Poor performance on a right join