Subject Re: Optimiser chooses wrong plan?
Author Svein Erling Tysvær
Hi Filip!

> You wrote:
>
>
> Hi,
>
> Firebird 1.5 optimiser chooses wrong plan on following query. I
> can't figure out why it does so or how to correct it. The only
> sollution i found was to change the first inner join by a left join
> or to use an explicited plan.
>
> Could someone help me out, i prefer not to use explicited plans. Are
> explicited plans safe to use with regard to backup/restore DBs (Risc
> of changed Index Names)?

In your case yes - they are safe. The names have been chosen by you
and do not change. The chances of changing I think are limited to the
system generated index names - e.g. rdb$primary44.

> SELECT ...
> FROM
> LYDGB A
> INNER JOIN
> LYDOC B
> on
> A.LYDGBKJ = B.LYDCBKJ AND
> A.LYDGCODE = B.LYDCDGB

change to

A.LYDGBKJ+0 = B.LYDCBKJ

The +0 prevents the "poor" plan, whereas the "good" plan still can be
used. If LYDGBKJ is a character field, use

A.LYDGBKJ || '' = B.LYDCBKJ

This should help,
Set