Subject Re: Insertion speed
Author Svein Erling Tysvær
--- In firebird-support@yahoogroups.com, "Todd Pinel" wrote:
> Wow, you were right the execute time dropped from ~40s to ~20s. I'm
> happy with that!

Nice to hear you're happy, I was actually disappointed that it didn't
drop considerably more (either each issue has too few customers or
each customer buy too many copies!).

> I have some other things I need to tweak before I get too hung up on
> performance like this. This was great! Now could someone explain
> why this worked the way it did?;)

Arno is the expert able to tell you what's going on and exactly how he
made the optimizer "think". But I can give you my 'novice version':

You have an index on issue and one on buyer. Each issue sells
considerably more copies than each buyer buys. Hence, if you locate
one issue in its index, you still have a lot of buyers to choose from.
However, if you go the opposite way finding the buyer in its index,
then he has bought so few issues that going through all of them to
find the correct issue isn't very demanding.

When the indexes are approximately equally selective, then you may
benefit from using both indexes, when you have one selective and one
non-selective, then preventing use of the non-selective one may
greatly affect execution speed (it wouldn't surprise me if - in
extreme cases - it was possible to improve from hours to subsecond,
though I've never experienced that dramatic an improvement)

> Also I have been trying to be very selective in where I place my own
> indexes, I've found its only helped me in a couple select places and
> I can justify them due to the performance benefit they've given.

Good, I started off creating too many indexes when I first began using
InterBase.

> I have assumed while building my DB that as I create foreign keys
> between tables indices are created automatically. The indices you
> see in use in the plan below are indices created from adding foreign
> keys, should I take them out? (I've always assumed an index was
> good, with negative performance if you went overboard with them)

Sometimes it may be justified to replace foreign keys with triggers,
primarily when the referenced table rarely change. Indexes ought to be
good, it's the optimizer that isn't perfect (although it is greatly
improved since Firebird 1.0, which I'm still on). Not knowing your
tables, I think I'd recommend you to keep your foreign keys and rather
use the trick I showed you whenever appropriate.

Set