Subject | Order of inner's and left's in the SQL |
---|---|
Author | thiago_bor |
Post date | 2007-03-28T12:41:15Z |
I noticied very diferents results in plan (and consequently velocity)
in complex SQL's when experimented diferents positions for the inner
and left clauses.
The plan bellow is returned with inners not closed to the from clause
(select ... from table left, inner, left, inner, left ...):
PLAN SORT (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN
(JOIN (JOIN (JOIN (JOIN (JOIN (P NATURAL, PS INDEX (PK_PRODSERV)), PR
INDEX (PK_PRODUTO)), G INDEX (PK_GRUPO)), SG INDEX (PK_SUBGRUPO)), B
INDEX (PK_CPGBAIXA)), L INDEX (PK_LANCAMEN)), PG INDEX
(RDB$PRIMARY22)), C INDEX (PK_CABPAGAR)), TD INDEX (PK_TIPDOC)), F IN
DEX (PK_FORNEC)), CF INDEX (PK_CATEGFOR)), T INDEX (PK_TRANSAC)), N
INDEX (FK_NOTACPG_RLC_CABPAGAR)), NT INDEX (KNOTA1, PK_NOTA)), I INDEX
(KINOTA_SALDOINI)))
When the inner's are closed to the from clause, the firebird chooses
better plans of execution. (select ... from table inner, inner, left,
left ...):
PLAN SORT (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN
(JOIN (JOIN (C INDEX (FK_CABPAGAR_RLC_TRANSAC, KCABPAGAR_DMOV_CPG),
PG INDEX (FK_PAGAR_RLC_CABPAGAR), B INDEX (FK_CPGBAIXA_RLC_PAGAR),
P INDEX (FK_CPGBAIPR_RLC_CPGBAIXA), N INDEX
(FK_NOTACPG_RLC_CABPAGAR)), PS INDEX (PK_PRODSERV)), PR INDEX
(PK_PRODUTO)), G INDEX (PK_GRUPO)), SG INDEX (PK_SUBGRUPO)),
L INDEX (PK_LANCAMEN)), TD INDEX(PK_TIPDOC)), F INDEX (PK_FORNEC)),
CF INDEX (PK_CATEGFOR)), T INDEX (PK_TRANSAC)), NT INDEX (KNOTA1,
PK_NOTA)), I INDEX (KINOTA_SALDOINI)))
The first plan has three join operations more and a NATURAL access.
For comparison only, I tested the same sql in Oracle and the plans are
the sames, when the inners comes first or not.
Can anyone explain or knows where I find documentation about this?
Sorry for the English.
Thanks,
--
Thiago Borges
in complex SQL's when experimented diferents positions for the inner
and left clauses.
The plan bellow is returned with inners not closed to the from clause
(select ... from table left, inner, left, inner, left ...):
PLAN SORT (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN
(JOIN (JOIN (JOIN (JOIN (JOIN (P NATURAL, PS INDEX (PK_PRODSERV)), PR
INDEX (PK_PRODUTO)), G INDEX (PK_GRUPO)), SG INDEX (PK_SUBGRUPO)), B
INDEX (PK_CPGBAIXA)), L INDEX (PK_LANCAMEN)), PG INDEX
(RDB$PRIMARY22)), C INDEX (PK_CABPAGAR)), TD INDEX (PK_TIPDOC)), F IN
DEX (PK_FORNEC)), CF INDEX (PK_CATEGFOR)), T INDEX (PK_TRANSAC)), N
INDEX (FK_NOTACPG_RLC_CABPAGAR)), NT INDEX (KNOTA1, PK_NOTA)), I INDEX
(KINOTA_SALDOINI)))
When the inner's are closed to the from clause, the firebird chooses
better plans of execution. (select ... from table inner, inner, left,
left ...):
PLAN SORT (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (JOIN
(JOIN (JOIN (C INDEX (FK_CABPAGAR_RLC_TRANSAC, KCABPAGAR_DMOV_CPG),
PG INDEX (FK_PAGAR_RLC_CABPAGAR), B INDEX (FK_CPGBAIXA_RLC_PAGAR),
P INDEX (FK_CPGBAIPR_RLC_CPGBAIXA), N INDEX
(FK_NOTACPG_RLC_CABPAGAR)), PS INDEX (PK_PRODSERV)), PR INDEX
(PK_PRODUTO)), G INDEX (PK_GRUPO)), SG INDEX (PK_SUBGRUPO)),
L INDEX (PK_LANCAMEN)), TD INDEX(PK_TIPDOC)), F INDEX (PK_FORNEC)),
CF INDEX (PK_CATEGFOR)), T INDEX (PK_TRANSAC)), NT INDEX (KNOTA1,
PK_NOTA)), I INDEX (KINOTA_SALDOINI)))
The first plan has three join operations more and a NATURAL access.
For comparison only, I tested the same sql in Oracle and the plans are
the sames, when the inners comes first or not.
Can anyone explain or knows where I find documentation about this?
Sorry for the English.
Thanks,
--
Thiago Borges