Subject RE: [firebird-support] Slow query in Firebird/Interbase
Author Alan McDonald
> select A.*, ( SELECT SUM(DEPOSIT_AMT - CHK_AMT) FROM LEDGER B
> where ((b.effective_date < a.effective_date) or ((b.effective_date =
> a.effective_date) and (b.entered_date < a.entered_date)) or
> ((b.effective_date = a.effective_date) and
> (b.entered_date = a.entered_date) and (b.id <= a.id))) AND
> B.COMPANY_ID = 54 AND B.LEDGER_TYPE = 2)
> Balance from LEDGER A WHERE A.COMPANY_ID = 54
> AND A.LEDGER_TYPE = 2
> ORDER BY EFFECTIVE_DATE, ENTERED_DATE, ID

Have you run the sub-query by itself in both cases to see if it's this sub
or the main query which is slow?

SELECT SUM(DEPOSIT_AMT - CHK_AMT) FROM LEDGER B
> where ((b.effective_date < a.effective_date) or ((b.effective_date =
> a.effective_date) and (b.entered_date < a.entered_date)) or
> ((b.effective_date = a.effective_date) and
> (b.entered_date = a.entered_date) and (b.id <= a.id))) AND
> B.COMPANY_ID = 54 AND B.LEDGER_TYPE = 2
Alan