X-Intend[超级打算]
每个人都有自己的想法,哪怕仅仅一瞬间~!

SQLite测试报告

KingFo 于 2008-05-13 01:44:20 发表  开发者

测试 1: 1000 INSERTs

CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100));
INSERT INTO t1 VALUES(1,13153,'thirteen thousand one hundred fifty three');
INSERT INTO t1 VALUES(2,75560,'seventy five thousand five hundred sixty');
... 995 lines omitted
INSERT INTO t1 VALUES(998,66289,'sixty six thousand two hundred eighty nine');
INSERT INTO t1 VALUES(999,24322,'twenty four thousand three hundred twenty two');
INSERT INTO t1 VALUES(1000,94142,'ninety four thousand one hundred forty two');
PostgreSQL:    4.373
MySQL:    0.114
SQLite 2.7.6:    13.061
SQLite 2.7.6 (nosync):    0.223

因为没有一个中央服务器来控制访问,SQLite必须先关闭再打开数据库文件,这样高速缓存器就失去了作用。在这个测试中,每个 SQL语句都是一个独立的事务元,所以数据库文件必须被打开和关闭,高速缓存必须刷新1000次。 尽管这样,异步版本的SQLite还是和MYSQL一样快。但同步版本的却是非常慢。SQLite在每个同步事务元后调用fsync(),因而确保了磁盘表面所有的数据都是安全的。13秒的测试时间大部分都被用于磁盘I/O。

Test 2: 25000 INSERTs in a transaction

BEGIN;
CREATE TABLE t2(a INTEGER, b INTEGER, c VARCHAR(100));
INSERT INTO t2 VALUES(1,298361,'two hundred ninety eight thousand three hundred sixty one');
... 24997 lines omitted
INSERT INTO t2 VALUES(24999,447847,'four hundred forty seven thousand eight hundred forty seven');
INSERT INTO t2 VALUES(25000,473330,'four hundred seventy three thousand three hundred thirty');
COMMIT;

SQLite 3.3.3 (sync):    0.764
SQLite 3.3.3 (nosync):    0.748
SQLite 2.8.17 (sync):    0.698
SQLite 2.8.17 (nosync):    0.663
PostgreSQL 8.1.2:    16.454
MySQL 5.0.18 (sync):    7.833
MySQL 5.0.18 (nosync):    7.038
FirebirdSQL 1.5.2:    4.280

Test 3: 25000 INSERTs into an indexed table

BEGIN;
CREATE TABLE t3(a INTEGER, b INTEGER, c VARCHAR(100));
CREATE INDEX i3 ON t3(c);
... 24998 lines omitted
INSERT INTO t3 VALUES(24999,442549,'four hundred forty two thousand five hundred forty nine');
INSERT INTO t3 VALUES(25000,423958,'four hundred twenty three thousand nine hundred fifty eight');
COMMIT;

SQLite 3.3.3 (sync):    1.778
SQLite 3.3.3 (nosync):    1.832
SQLite 2.8.17 (sync):    1.526
SQLite 2.8.17 (nosync):    1.364
PostgreSQL 8.1.2:    19.236
MySQL 5.0.18 (sync):    11.524
MySQL 5.0.18 (nosync):    12.427
FirebirdSQL 1.5.2:    6.351

Test 4: 100 SELECTs without an index

SELECT count(*), avg(b) FROM t2 WHERE b>=0 AND b<1000;
SELECT count(*), avg(b) FROM t2 WHERE b>=100 AND b<1100;
SELECT count(*), avg(b) FROM t2 WHERE b>=200 AND b<1200;
... 94 lines omitted
SELECT count(*), avg(b) FROM t2 WHERE b>=9700 AND b<10700;
SELECT count(*), avg(b) FROM t2 WHERE b>=9800 AND b<10800;
SELECT count(*), avg(b) FROM t2 WHERE b>=9900 AND b<10900;

SQLite 3.3.3 (sync):    3.153
SQLite 3.3.3 (nosync):    3.088
SQLite 2.8.17 (sync):    3.993
SQLite 2.8.17 (nosync):    3.983
PostgreSQL 8.1.2:    5.740
MySQL 5.0.18 (sync):    2.718
MySQL 5.0.18 (nosync):    1.641
FirebirdSQL 1.5.2:    2.976

Test 5: 100 SELECTs on a string comparison

SELECT count(*), avg(b) FROM t2 WHERE c LIKE '%one%';
SELECT count(*), avg(b) FROM t2 WHERE c LIKE '%two%';
SELECT count(*), avg(b) FROM t2 WHERE c LIKE '%three%';
... 94 lines omitted
SELECT count(*), avg(b) FROM t2 WHERE c LIKE '%ninety eight%';
SELECT count(*), avg(b) FROM t2 WHERE c LIKE '%ninety nine%';
SELECT count(*), avg(b) FROM t2 WHERE c LIKE '%one hundred%';

SQLite 3.3.3 (sync):    4.853
SQLite 3.3.3 (nosync):    4.868
SQLite 2.8.17 (sync):    4.511
SQLite 2.8.17 (nosync):    4.500
PostgreSQL 8.1.2:    6.565
MySQL 5.0.18 (sync):    3.424
MySQL 5.0.18 (nosync):    2.090
FirebirdSQL 1.5.2:    5.803

Test 6: INNER JOIN without an index

SELECT t1.a FROM t1 INNER JOIN t2 ON t1.b=t2.b;

SQLite 3.3.3 (sync):    14.473
SQLite 3.3.3 (nosync):    14.445
SQLite 2.8.17 (sync):    47.776
SQLite 2.8.17 (nosync):    47.750
PostgreSQL 8.1.2:    0.176
MySQL 5.0.18 (sync):    3.421
MySQL 5.0.18 (nosync):    3.443
FirebirdSQL 1.5.2:    0.141

Test 7: Creating an index

CREATE INDEX i2a ON t2(a);
CREATE INDEX i2b ON t2(b);

SQLite 3.3.3 (sync):    0.552
SQLite 3.3.3 (nosync):    0.526
SQLite 2.8.17 (sync):    0.650
SQLite 2.8.17 (nosync):    0.605
PostgreSQL 8.1.2:    0.276
MySQL 5.0.18 (sync):    1.159
MySQL 5.0.18 (nosync):    0.275
FirebirdSQL 1.5.2:    0.264

测试9: 有索引的25000 UPDATEs

BEGIN;
UPDATE t2 SET b=468026 WHERE a=1;
UPDATE t2 SET b=121928 WHERE a=2;
... 24996 lines omitted
UPDATE t2 SET b=35065 WHERE a=24999;
UPDATE t2 SET b=347393 WHERE a=25000;
COMMIT;

PostgreSQL:    18.797
MySQL:    8.134
SQLite 2.7.6:    3.520
SQLite 2.7.6 (nosync):    3.104

在这个测试中,最近的2.7.0 版 SQLite和MYSQL运行速度一样,但是最近对SQLite的优化使它速度比UPDATEs快一倍。

测试10: 有索引的25000 text UPDATEs

BEGIN;
UPDATE t2 SET c='one hundred forty eight thousand three hundred eighty two' WHERE a=1;
UPDATE t2 SET c='three hundred sixty six thousand five hundred two' WHERE a=2;
... 24996 lines omitted
UPDATE t2 SET c='three hundred eighty three thousand ninety nine' WHERE a=24999;
UPDATE t2 SET c='two hundred fifty six thousand eight hundred thirty' WHERE a=25000;
COMMIT;

PostgreSQL:    48.133
MySQL:    6.982
SQLite 2.7.6:    2.408
SQLite 2.7.6 (nosync):    1.725

2.7.0 版本的SQLite过去和MYSQL运行速度一样,但现在2.7.6 版的SQLite的速度是MYSQL的两倍,是PostgreSQL的20倍。

在这个测试中,PostgreSQL也很慢,一个有经验的管理者可以通过调试服务器使之运行的快些。

Test 11: 来于SELECT的INSERTs

BEGIN;
INSERT INTO t1 SELECT b,a,c FROM t2;
INSERT INTO t2 SELECT b,a,c FROM t1;
COMMIT;

PostgreSQL:    61.364
MySQL:    1.537
SQLite 2.7.6:    2.787
SQLite 2.7.6 (nosync):    1.599

在这个测试中,异步的SQLite比MYSQL慢(MYSQL似乎特别擅长INSERT...SELECT语句)。 PostgreSQL引擎仍然是非常慢的, 61秒中的大部分时间被用来等待磁盘I/O。

测试 12: 没有索引的DELETE

DELETE FROM t2 WHERE c LIKE '%fifty%';

PostgreSQL:    1.509
MySQL:    0.975
SQLite 2.7.6:    4.004
SQLite 2.7.6 (nosync):    0.560

在这个测试中,The synchronous version of同步版本的 SQLite是这组中最慢的,但异步版本的SQLite是最快的。不同的是,它需要额外的时间去执行fsync()。

测试 13: 有索引的DELETE

DELETE FROM t2 WHERE a>10 AND a<20000;

PostgreSQL:    1.316
MySQL:    2.262
SQLite 2.7.6:    2.068
SQLite 2.7.6 (nosync):    0.752

这个测试非常重要,因为在这里PostgreSQL比MySQL要快。SQLite比前两者都要快。

测试 14: 一个大 DELETE之后的一个大INSERT

INSERT INTO t2 SELECT * FROM t1;

PostgreSQL:    13.168
MySQL:    1.815
SQLite 2.7.6:    3.210
SQLite 2.7.6 (nosync):    1.485

一些老版的SQLite(2.4.0 以前的版本)在执行完DELETEs及新INSERTs后明显慢下来,但在这个测试中我们可以看到,这个问题已经被解决了。

测试 15: 一个大的DELETE及许多小INSERTs

BEGIN;
DELETE FROM t1;
INSERT INTO t1 VALUES(1,10719,'ten thousand seven hundred nineteen');
... 11997 lines omitted
INSERT INTO t1 VALUES(11999,72836,'seventy two thousand eight hundred thirty six');
INSERT INTO t1 VALUES(12000,64231,'sixty four thousand two hundred thirty one');
COMMIT;

PostgreSQL:    4.556
MySQL:    1.704
SQLite 2.7.6:    0.618
SQLite 2.7.6 (nosync):    0.406

SQLite通常总是会在一个事务处理程序中执行INSERTs,这也许就是为什么在这个测试中SQLite通常比其它数据库快很多的原因。

测试 16: DROP TABLE

DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;

PostgreSQL:    0.135
MySQL:    0.015
SQLite 2.7.6:    0.939
SQLite 2.7.6 (nosync):    0.254

SQLite在执行撤销表格这一操作时比其它数据库要慢一些。 这也许是因为当SQLite撤销一个表格的时候,它必须全面检查并清除数据库文件中的记录。与之不同的是,MySQL和 PostgreSQL分别的文件夹来代表每个表格,所以如果它们想撤销一个表格,它们只需删除一个文件,这当然要快一些了。

但是,撤销表格并不是一个常用的操作,所以SQLite慢一些也不会有什么问题.

被阅 507 次, 0投一票
    1 / 0 / 0 | « 1 » |
    1 / 0 / 0 | « 1 » |
  • 看完了要说点啥么?
  • 昵称 (不填说不了话)
  • 信箱地址 (不会被公开,但是不填也说不了话)
  • 网址 (这个不填也成)

Google 网上论坛
订阅 XIntend
电子邮件:
访问此论坛

文章分类

站点统计

  • 文章总数: 87 篇
  • 评论总数: 6 条
  • 附件总数: 53 个
  • 留言总数: 0 份
  • 建站日期: 2008-1-1
  • 访问总数: 96309 人次

最新留言

赞助商

友情链接

Design by Free CSS Templates & TiSkin, Powered by Roclog v3.2.13

滇ICP备05000389号, Copyright © 2007 X-Intend[超级打算]. All rights reserved.