Subject Re: Query that never ends (Firebird 2.5.3)
Author Dmitry Yemanov
26.02.2015 00:02, martin_gorriti@... [firebird-support] пишет:
>
> After reading your answer, I thought to try changing the order of the
> things and it Works very quick (I have to check if it Works for my
> purposes, but it seams it will work). I can´t understand why it Works
> fine this way but not in the other:
>
> Starting transaction...
> Preparing query: select t1.*, t2.* from
>
> (select b1."BJTX",b1."TKEYT",b2."OWNR" as "TOWNR",b2."BJAR",b2."DSCR" as
> "TDSCR",b2."VOCE",b2."RICH",b2."TEXT" from "TL1_2" b1 left outer join
> "BJTX" b2 on b1."BJTX"=b2."BJTX") t1
>
> left outer join
>
> (select a1."BJAR",a1."TKEY",a2."OWNR",a2."TIPO",a2."DSCR" as "ADSCR"
> from "TL1_1" a1 left outer join "BJAR" a2 on a1."BJAR"=a2."BJAR") t2
>
> on t1."BJAR"=t2."BJAR"

This makes a huge difference...

> PLAN SORT (JOIN (JOIN (T1 B1 NATURAL, T1 B2 INDEX (BJTX_PK)), JOIN (T2
> A1 INDEX (TL1_1_PK), T2 A2 INDEX (BJAR_PK))))

and the plan confirms that. This query allows the whole join chain to be
index-based.


Dmitry