Subject Re: [firebird-support] Re: A View, a Left Join and a very strange plan
Author Mischa Kuchinke
Mischa Kuchinke schrieb:

> Svein Erling Tysvær schrieb:
>
> > Writing your own plan is possible, and you could avoid left joins in
> > views (I don't use left joins enough to give you any useful advice).
> > Though I'd simply do this little change in your query to hint the
> > optimizer:
> >
> > SELECT *
> > FROM ScherenOberstange
> > JOIN SchOberFarbe
> > ON ScherenOberstange.Farbe_ID = SchOberFarbe.ID
> > JOIN V_TextBaustein Farbe
> > ON Farbe.TB_ID = SchOberFarbe.Bezeichnung_TB+0
> > WHERE ScherenOberstange.Artikel_ID = 162
> >

There is another effect. The Query:

SELECT *
FROM ScherenOberstange
JOIN SchOberFarbe
ON ScherenOberstange.Farbe_ID = SchOberFarbe.ID
LEFT JOIN V_TextBaustein Farbe
ON Farbe.TB_ID = SchOberFarbe.Bezeichnung_TB
WHERE ScherenOberstange.Artikel_ID = 162

also uses the correct plan. I changed the Join from the View to a Left
Join.
This seems to be the best solution, because there is alway an entry in
V_Textbaustein. So it is the same if I use an INNER JOIN or an LEFT Join.