Subject Great variance in speed of an INSERT INTO ... SELECT
Author Josef Kokeš
Hi!

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 -- all records

The statement takes anything between minutes and hours (in different
databases, the same database usually takes approximately the same time),
and I just can't figure out what could cause this variance. The SELECT
itself is quite fast (seconds), traversing its resultset as well (tens
of seconds). Source_value* is either a DOUBLE PRECISION or an INTEGER.
The backuptable only has three indices including the primary key (the
other two cover INTEGERs). The size of the sourcetable is approximately
600K records, the size of backuptable approximately 26M records. The
Firebird version (1.5, 2.1, 2.5) doesn't seem to have a significant
effect on this).

Thanks,

Pepak