From: Carmen Sarlo <SarloC@Jevic.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: 'dev@archonet.com' <dev@archonet.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Poor performance on a right join
Date: Mon, 17 Mar 2003 15:34:40 -0500
Message-ID: <3BCE0BA7092FD311BE570008C75DB4F80A46ABCD@EXCHANGE> (raw)
I found that when I do an inner join, I get better performance.
Carmen
-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Monday, March 17, 2003 3:31 PM
To: Carmen Sarlo
Cc: 'dev@archonet.com'; pgsql-sql@postgresql.org
Subject: Re: [SQL] Poor performance on a right join
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
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: SarloC@Jevic.com, tgl@sss.pgh.pa.us, dev@archonet.com
Subject: Re: Poor performance on a right join
In-Reply-To: <3BCE0BA7092FD311BE570008C75DB4F80A46ABCD@EXCHANGE>
* 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