Subject concatenation faster than AND in WHERE clause?
Author tomasz007
Hi,

Can someone explain why following example:

SELECT KT.*
FROM KOMPLET_TOWAR KT
JOIN KOMPLET K
ON KT.SYS_FILIA_ID = K.SYS_FILIA_ID AND KT.KOMPLET_ID = K.KOMPLET_ID
LEFT OUTER JOIN TOWAR T
ON KT.SYS_FILIA_ID = T.SYS_FILIA_ID AND KT.TOWAR_ID = T.TOWAR_ID
LEFT OUTER JOIN TOWAR_TYP TT
ON T.TOWAR_TYP_ID = TT.TOWAR_TYP_ID
WHERE
KT.SYS_FILIA_ID = 1 and KT.KOMPLET_ID = 112

has this plan (why using some FK?):

PLAN JOIN (JOIN (JOIN (K NATURAL,KT INDEX
(RDB$PRIMARY34,RDB$FOREIGN76)),T
INDEX (RDB$PRIMARY29)),TT INDEX (RDB$PRIMARY26))

...and execution time about 850ms whilst if I replace WHERE clause
with:

KT.SYS_FILIA_ID ||','|| KT.KOMPLET_ID = '1,112'

the plan looks right:

PLAN JOIN (JOIN (JOIN (K NATURAL,KT INDEX (RDB$PRIMARY34)),T INDEX
(RDB$PRIMARY29)),TT INDEX (RDB$PRIMARY26))

..and the execution time gets almost TEN TIMES less (90ms)!!??

FB 1.0.2

Thanks, cheers,
Tomasz