Subject RE: [firebird-support] First query very slow
Author Svein Erling Tysvær
Hi Josef!

>> 1) Why do you group on something not an output field? I didn't think
>> that was allowed.
>
>It is. I am not sure if it has any reasonable use, but it is possible.

Always good to learn something new...

>> 2) LEFT JOIN followed by referencing to a field in the table being NOT
>> NULL makes the LEFT JOIN in reality become a (inner) JOIN, sometimes
>> that's OK for optimization, but you haven't mentioned that being the
>> case here.
>
>Maybe my queries are wrong, but my experience has been that LEFT JOIN + IS NOT NULL is very often far
>faster than an (INNER) JOIN. These days I just use LEFT JOIN + IS NOT NULL everywhere because the speed
>tends to be good all the time, unlike JOIN (where I may get a good speed in one query and horrible
>speed in another; incidentally, LEFT JOIN + IS NOT NULL doesn't seem to be any slower than a JOIN on my
>queries).

Using LEFT JOIN reduces the options for the optimizer. It can be slower, as fast as or quicker than an INNER JOIN. If you're careful about how you use it and verify your plans, then there's nothing inherently wrong with a LEFT JOIN. I generally start of by trying to get the right result and only care about optimization if I notice things being suboptimal. So I let the optimizer do its job and only restrict it if it makes bad choices. Hence, I start off with INNER JOIN and add +0 to my JOINs when required (I think +0 in this regard should be equal to LEFT JOIN + IS NOT NULL).

Set