Subject Re: Optimizing a count query
Author dinol.softedge
Thanks very much everyone. I see that my indexes were very wrong and
how to fix that now. I will try and let you guys know if I get a big
performance boost

Thanks once again

--- In firebird-support@yahoogroups.com, "Leyne, Sean" <Sean@...> wrote:
>
> Dinol,
>
> > Plan:
> > ------------------------------------------------
> > PLAN (TBL_JOB_CARD_EMPLOYEE NATURAL)
> > PLAN SORT (JOIN (JOIN (TBL_JOB_CARD NATURAL,TBL_CLIENT INDEX
> > (RDB$PRIMARY2)),TBL_INSURER INDEX (RDB$PRIMARY3)))
>
> As Svein has already pointed out, you need to create an index on the
> JOB_CARD_ID column in the TBL_JOB_CARD_EMPLOYEE table!
>
> Second, you could turn the problem around ... and try:
>
> SELECT
> tjc.EXCESS_PAID,
> ...
> tjc.COORDINATES,
> tjc.VAT
> FROM (
> SELECT DISTINCT JOB_CARD_ID FROM TBL_JOB_CARD_EMPLOYEE
> ) TJCE
> JOIN TBL_JOB_CARD tjc = tjce.JOB_CARD_ID
> LEFT OUTER JOIN TBL_CLIENT tc ON (tc.CLIENT_ID = tjc.CLIENT_ID)
> LEFT OUTER JOIN TBL_INSURER ti ON (ti.INSURER_ID = tjc.INSURER_ID)
> ORDER BY
> tjc.JOB_CARD_ID DESC
>
>
> Sean
>