Subject Query Optimizer (Join vs Where clause)
Author Salim Naufal
Using Firebird 1.0, I have encountered an interesting case where, the same
query, written in two different ways, results in a drastic reduction in the
execution time.

The original (long execution time) query:

SELECT
...
FROM SALES
JOIN ITEMS ON (SALES.ITEM_PKEY = ITEMS.PKEY)
JOIN SALE_HDR ON (SALES.HDR_PKEY = SALE_HDR.PKEY)
LEFT OUTER JOIN ...
WHERE (SALES.ORDER_PKEY = :ORDER_PKEY)

Then the modified query that yields a much better performance

SELECT
...
FROM SALES
JOIN ITEMS ON ((SALES.ITEM_PKEY = ITEMS.PKEY) AND (SALES.ORDER_PKEY =
:ORDER_PKEY))
JOIN SALE_HDR ON (SALES.HDR_PKEY = SALE_HDR.PKEY)
LEFT OUTER JOIN ...


I have simply placed the where clause condition in the first join.

Is it a "good" practice to do what I did in the above query? Can the
optimiser be forced to generate the query plan generated by the second
query?

Thanks to all
Salim