Subject Re: [firebird-support] Great variance in speed of an INSERT INTO ... SELECT
Author Ann Harrison
Pepak,


> I wonder - what could possibly cause a great variance in speeds of this
> statement?
>
> INSERT INTO backuptable (
> backup_key,
> original_key, original_value1, ..., original_valuen
> )
> SELECT GEN_ID(backupgen,1),
> source_key, source_value1, ..., source_valuen
> FROM sourcetable
> WHERE 1=1



The WHERE 1 = 1 is unnecessary, but doen't do any harm. There maybe
databases that require a WHERE clause, but Firebird doesn't. But that's not
the problem.

The normal cause of wild variations in the performance of queries is garbage
collection. For example, if you did this query twice, deleting all rows in
backuptable, then resetting the generator backupgen to 1, the second run
would have to remove all the old rows and deleted stubs and clean up the
indexes (assuming that source_key is actually a unique key).

Good luck,

Ann


[Non-text portions of this message have been removed]