Re: Question about LEFT JOIN and query plan

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: <kaloyan(at)digsys(dot)bg>,<pgsql-performance(at)postgresql(dot)org>
Subject: Re: Question about LEFT JOIN and query plan
Date: 2010-09-03 17:16:52
Message-ID: 4C80E73402000025000351AF@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Kaloyan Iliev Iliev <kaloyan(at)digsys(dot)bg> wrote:

> I thing they should be access only if there are rows from the
> where. Why the left join executes first?

Out of curiosity, what happens if you consistently us JOIN clauses,
rather than mixing that with commas?:

explain analyze
SELECT
DD.debtid,
ADD.amount as saldo,
DOM.fqdn ||DT.descr as domain_fqdn,
S.descr_bg as service_descr_bg,
ADD.pno,
ADD.amount,
M.name_bg as measure_name_bg,
AC.ino,
I.idate
FROM debts_desc DD
JOIN proforms P ON (ADD.pno = P.pno)
JOIN acc_debts ADD ON (DD.debtid = ADD.debtid)
JOIN services S ON (DD.serviceid = S.serviceid)
JOIN measures M ON (DD.measure_id = M.measure_id)
LEFT JOIN domeini DOM ON (DD.domain_id = DOM.id)
LEFT JOIN domain_type DT ON (DOM.domain_type_id = DT.id)
LEFT JOIN acc_debts ADC
ON (DD.debtid = ADC.debtid AND ADC.credit)
LEFT JOIN acc_clients AC
ON (AC.transact_no = ADC.transact_no AND NOT AC.credit)
LEFT JOIN invoices I ON (AC.ino = I.ino AND I.istatus = 0)
WHERE DD.active
AND NOT DD.paid
AND DD.has_proform
AND NOT DD.storned
AND NOT ADD.credit
AND P.person1_id = 287294
;

-Kevin

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2010-09-03 17:16:55 Re: Major performance problem after upgrade from 8.3 to 8.4
Previous Message Tom Lane 2010-09-03 17:14:43 Re: Question about LEFT JOIN and query plan