Subject | Re: Very poor insert performance (with UUID primary keys) |
---|---|
Author | Fabiano |
Post date | 2011-10-19T19:17:20Z |
Hi again,
I created a test case which shows the problem, using a new database.
Firebird CS 2.5.1 running on Windows 7, default firebird.conf.
Time to insert 200.000 records in a single-field table:
/*
* Integer field, no PK
*/
create table t1 (
id integer not null);
set term !! ;
execute block
as
declare variable i integer;
begin
i = 0;
while (i < 200000) do
begin
insert into t1 values (:i);
i = i + 1;
end
end !!
set term ; !!
TIME: 2s199ms
/*
* Integer field, with PK
*/
create table t2 (
id integer not null);
alter table t2
add constraint pkt2 primary key (id);
set term !! ;
execute block
as
declare variable i integer;
begin
i = 0;
while (i < 200000) do
begin
insert into t2 values (:i);
i = i + 1;
end
end !!
set term ; !!
TIME: 3s869ms
/*
* UUID field, no PK
*/
create table t3 (
id char(16) character set octets not null);
set term !! ;
execute block
as
declare variable i integer;
begin
i = 0;
while (i < 200000) do
begin
insert into t3 values (gen_uuid());
i = i + 1;
end
end !!
set term ; !!
TIME: 2s542ms
/*
* UUID field, with PK
*/
create table t4 (
id char(16) character set octets not null);
alter table t4
add constraint pkt4 primary key (id);
set term !! ;
execute block
as
declare variable i integer;
begin
i = 0;
while (i < 200000) do
begin
insert into t4 values (gen_uuid());
i = i + 1;
end
end !!
set term ; !!
TIME: 1m53s587ms <-------------------
I created a new database and ran the last test again:
TIME: 4m00s881ms <-------------------
Regards,
Fabiano
I created a test case which shows the problem, using a new database.
Firebird CS 2.5.1 running on Windows 7, default firebird.conf.
Time to insert 200.000 records in a single-field table:
/*
* Integer field, no PK
*/
create table t1 (
id integer not null);
set term !! ;
execute block
as
declare variable i integer;
begin
i = 0;
while (i < 200000) do
begin
insert into t1 values (:i);
i = i + 1;
end
end !!
set term ; !!
TIME: 2s199ms
/*
* Integer field, with PK
*/
create table t2 (
id integer not null);
alter table t2
add constraint pkt2 primary key (id);
set term !! ;
execute block
as
declare variable i integer;
begin
i = 0;
while (i < 200000) do
begin
insert into t2 values (:i);
i = i + 1;
end
end !!
set term ; !!
TIME: 3s869ms
/*
* UUID field, no PK
*/
create table t3 (
id char(16) character set octets not null);
set term !! ;
execute block
as
declare variable i integer;
begin
i = 0;
while (i < 200000) do
begin
insert into t3 values (gen_uuid());
i = i + 1;
end
end !!
set term ; !!
TIME: 2s542ms
/*
* UUID field, with PK
*/
create table t4 (
id char(16) character set octets not null);
alter table t4
add constraint pkt4 primary key (id);
set term !! ;
execute block
as
declare variable i integer;
begin
i = 0;
while (i < 200000) do
begin
insert into t4 values (gen_uuid());
i = i + 1;
end
end !!
set term ; !!
TIME: 1m53s587ms <-------------------
I created a new database and ran the last test again:
TIME: 4m00s881ms <-------------------
Regards,
Fabiano