Re: Question about LEFT JOIN and query plan - Mailing list pgsql-performance

From Kevin Grittner
Subject Re: Question about LEFT JOIN and query plan
Date
Msg-id 4C80E73402000025000351AF@gw.wicourts.gov
Whole thread Raw
In response to Question about LEFT JOIN and query plan  (Kaloyan Iliev Iliev <kaloyan@digsys.bg>)
Responses Re: Question about LEFT JOIN and query plan
List pgsql-performance
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

pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: Major performance problem after upgrade from 8.3 to 8.4
Next
From: Gerhard Wiesinger
Date:
Subject: Re: Major performance problem after upgrade from 8.3 to 8.4