INSERT/UPDATE/DELETE 测试
下面您可以找到一个非常简单的测试(纯 SQL 编写),用于衡量 Firebird(4.0、3.0 和 2.5)中 INSERT/UPDATE/DELETE 操作的性能。该测试是单线程的,其结果主要取决于硬件(磁盘速度、CPU、RAM)和 Firebird 缓存大小。使用此测试快速评估您的硬件和 Firebird 性能,并与以下结果进行比较:好的硬件应位于表格的前 30%。
请将脚本执行结果连同您的磁盘、CPU 和 RAM 的详细信息发送至 [email protected],我们将把它添加到下表中。
以下是不同磁盘、Firebird 版本和计算机上的测试结果图表和 XLS 文件:

点击此处下载 测试结果 XLS 文件。
测试 SQL 脚本
要运行测试,请将以下文本复制粘贴到文本文件中,并更改数据库路径 - 在示例中,连接字符串采用 Firebird 3 TCP 格式,但您可以将其更改为 XNET(xnet://Disk:\path\database.fdb)或嵌入式(disk:\path\database.fdb)连接字符串。
请使用您平时使用的相同 firebird.conf(如果您需要调整配置,请使用这些优化配置文件之一)。
此测试会创建一个数据库,创建一个带有多个索引的表,然后执行 100 万次 INSERT、UPDATE 和 DELETE 操作。
如果您已将 SQL 文件存储到 c:\temp\dml-basic-benchmark.sql,请使用以下命令运行此脚本:
isql -i c:\temp\dml-basic-benchmark.sql
此脚本将创建一个约 3.6Gb 大小的数据库。测试后请记得删除它。
create database "localhost:e:\inserttest4.fdb" user "SYSDBA" password "masterkey" page_size 16384;
set term ^;
execute block as
begin
-- ######################################################
rdb$set_context('USER_SESSION', 'ROWS_TO_HANDLE', 1000000);
-- ######################################################
execute statement 'drop sequence g';
when any do
begin
end
end
^
set term ;^
commit;
create sequence g;
recreate table test(
id int
,grp smallint
,pid int
,dts timestamp
,code_sml varchar(15)
,code_med varchar(150)
,code_lrg varchar(1500)
,code_unq char(16) character set octets
,constraint test_pk primary key(id)
,constraint test_unq unique( code_unq )
);
create index test_pid on test(pid);
create descending index test_dts on test(dts);
create index test_dml on test(code_sml);
create index test_med on test(code_med);
create index test_lrg on test(code_lrg);
commit;
----------------------------------------------
set bail on;
set list on;
set stat on;
set term ^;
execute block returns( inserted_rows int, elap_ms int )
as
declare i int = 0;
declare t timestamp;
begin
inserted_rows = rdb$get_context('USER_SESSION', 'ROWS_TO_HANDLE');
t = 'now';
while ( i < inserted_rows ) do
begin
insert into test(id, grp, pid, dts, code_sml, code_med, code_lrg, code_unq)
values(
gen_id(g,1)
,rand() * 10
,rand() * 1000
,dateadd( rand()*1000000 second to timestamp '01.01.2019 00:00:00' )
,lpad('', 15, 'QWERTY' )
,lpad('', 150, 'QWERTY' )
,lpad('', 1500, 'QWERTY' )
,gen_uuid()
);
i = i + 1;
end
elap_ms = datediff(millisecond from t to cast('now' as timestamp));
suspend;
end
^
commit^
-----------------------------------------------
execute block returns( updated_rows int, elap_ms int )
as
declare i int = 0;
declare t timestamp;
begin
updated_rows = rdb$get_context('USER_SESSION', 'ROWS_TO_HANDLE');
t = 'now';
while ( i < updated_rows ) do
begin
update test set
grp = rand() * 10
,pid = rand() * 1000
,dts = dateadd( rand()*100000 second to timestamp '01.01.2019 00:00:00' )
,code_sml = lpad('', 15, 'ASDFGH' )
,code_med = lpad('', 150, 'ASDFGH' )
,code_lrg = lpad('', 1500, 'ASDFGH' )
,code_unq = gen_uuid()
where id = :i+1 ;
i = i + 1;
end
elap_ms = datediff(millisecond from t to cast('now' as timestamp));
suspend;
end
^
commit^
-----------------------------------------------
execute block returns( deleted_rows int, elap_ms int )
as
declare i int = 0;
declare t timestamp;
begin
deleted_rows = rdb$get_context('USER_SESSION', 'ROWS_TO_HANDLE');
t = 'now';
while ( i < deleted_rows ) do
begin
delete from test where id = :i+1 ;
i = i + 1;
end
elap_ms = datediff(millisecond from t to cast('now' as timestamp));
suspend;
end
^
set term ;^
commit;