Kaloyan Iliev Iliev <kaloyan@digsys.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