📄 speed.tcl
字号:
SELECT count(*), avg(b) FROM t2 WHERE c LIKE '%ninety nine%';<br>SELECT count(*), avg(b) FROM t2 WHERE c LIKE '%one hundred%';<br>COMMIT;<br></blockquote><table border=0 cellpadding=0 cellspacing=0><tr><td>PostgreSQL:</td><td align="right"> 13.409</td></tr><tr><td>MySQL:</td><td align="right"> 4.640</td></tr><tr><td>SQLite 2.7.6:</td><td align="right"> 3.362</td></tr><tr><td>SQLite 2.7.6 (nosync):</td><td align="right"> 3.372</td></tr></table><p>This test still does 100 full table scans but it usesuses string comparisons instead of numerical comparisons.SQLite is over three times faster than PostgreSQL here and about 30%faster than MySQL.</p><h3>Test 6: Creating an index</h3><blockquote>CREATE INDEX i2a ON t2(a);<br>CREATE INDEX i2b ON t2(b);</blockquote><table border=0 cellpadding=0 cellspacing=0><tr><td>PostgreSQL:</td><td align="right"> 0.381</td></tr><tr><td>MySQL:</td><td align="right"> 0.318</td></tr><tr><td>SQLite 2.7.6:</td><td align="right"> 0.777</td></tr><tr><td>SQLite 2.7.6 (nosync):</td><td align="right"> 0.659</td></tr></table><p>SQLite is slower at creating new indices. This is not a huge problem(since new indices are not created very often) but it is something thatis being worked on. Hopefully, future versions of SQLite will do betterhere.</p><h3>Test 7: 5000 SELECTs with an index</h3><blockquote>SELECT count(*), avg(b) FROM t2 WHERE b>=0 AND b<100;<br>SELECT count(*), avg(b) FROM t2 WHERE b>=100 AND b<200;<br>SELECT count(*), avg(b) FROM t2 WHERE b>=200 AND b<300;<br><i>... 4994 lines omitted</i><br>SELECT count(*), avg(b) FROM t2 WHERE b>=499700 AND b<499800;<br>SELECT count(*), avg(b) FROM t2 WHERE b>=499800 AND b<499900;<br>SELECT count(*), avg(b) FROM t2 WHERE b>=499900 AND b<500000;<br></blockquote><table border=0 cellpadding=0 cellspacing=0><tr><td>PostgreSQL:</td><td align="right"> 4.614</td></tr><tr><td>MySQL:</td><td align="right"> 1.270</td></tr><tr><td>SQLite 2.7.6:</td><td align="right"> 1.121</td></tr><tr><td>SQLite 2.7.6 (nosync):</td><td align="right"> 1.162</td></tr></table><p>All three database engines run faster when they have indices to work with.But SQLite is still the fastest.</p><h3>Test 8: 1000 UPDATEs without an index</h3><blockquote>BEGIN;<br>UPDATE t1 SET b=b*2 WHERE a>=0 AND a<10;<br>UPDATE t1 SET b=b*2 WHERE a>=10 AND a<20;<br><i>... 996 lines omitted</i><br>UPDATE t1 SET b=b*2 WHERE a>=9980 AND a<9990;<br>UPDATE t1 SET b=b*2 WHERE a>=9990 AND a<10000;<br>COMMIT;<br></blockquote><table border=0 cellpadding=0 cellspacing=0><tr><td>PostgreSQL:</td><td align="right"> 1.739</td></tr><tr><td>MySQL:</td><td align="right"> 8.410</td></tr><tr><td>SQLite 2.7.6:</td><td align="right"> 0.637</td></tr><tr><td>SQLite 2.7.6 (nosync):</td><td align="right"> 0.638</td></tr></table><p>For this particular UPDATE test, MySQL is consistentlyfive or ten timesslower than PostgreSQL and SQLite. I do not know why. MySQL isnormally a very fast engine. Perhaps this problem has been addressedin later versions of MySQL.</p><h3>Test 9: 25000 UPDATEs with an index</h3><blockquote>BEGIN;<br>UPDATE t2 SET b=468026 WHERE a=1;<br>UPDATE t2 SET b=121928 WHERE a=2;<br><i>... 24996 lines omitted</i><br>UPDATE t2 SET b=35065 WHERE a=24999;<br>UPDATE t2 SET b=347393 WHERE a=25000;<br>COMMIT;<br></blockquote><table border=0 cellpadding=0 cellspacing=0><tr><td>PostgreSQL:</td><td align="right"> 18.797</td></tr><tr><td>MySQL:</td><td align="right"> 8.134</td></tr><tr><td>SQLite 2.7.6:</td><td align="right"> 3.520</td></tr><tr><td>SQLite 2.7.6 (nosync):</td><td align="right"> 3.104</td></tr></table><p>As recently as version 2.7.0, SQLite ran at about the same speed asMySQL on this test. But recent optimizations to SQLite have morethan doubled speed of UPDATEs.</p><h3>Test 10: 25000 text UPDATEs with an index</h3><blockquote>BEGIN;<br>UPDATE t2 SET c='one hundred forty eight thousand three hundred eighty two' WHERE a=1;<br>UPDATE t2 SET c='three hundred sixty six thousand five hundred two' WHERE a=2;<br><i>... 24996 lines omitted</i><br>UPDATE t2 SET c='three hundred eighty three thousand ninety nine' WHERE a=24999;<br>UPDATE t2 SET c='two hundred fifty six thousand eight hundred thirty' WHERE a=25000;<br>COMMIT;<br></blockquote><table border=0 cellpadding=0 cellspacing=0><tr><td>PostgreSQL:</td><td align="right"> 48.133</td></tr><tr><td>MySQL:</td><td align="right"> 6.982</td></tr><tr><td>SQLite 2.7.6:</td><td align="right"> 2.408</td></tr><tr><td>SQLite 2.7.6 (nosync):</td><td align="right"> 1.725</td></tr></table><p>Here again, version 2.7.0 of SQLite used to run at about the same speedas MySQL. But now version 2.7.6 is over two times faster than MySQL andover twenty times faster than PostgreSQL.</p><p>In fairness to PostgreSQL, it started thrashing on this test. Aknowledgeable administrator might be able to get PostgreSQL to run a lotfaster here by tweaking and tuning the server a little.</p><h3>Test 11: INSERTs from a SELECT</h3><blockquote>BEGIN;<br>INSERT INTO t1 SELECT b,a,c FROM t2;<br>INSERT INTO t2 SELECT b,a,c FROM t1;<br>COMMIT;</blockquote><table border=0 cellpadding=0 cellspacing=0><tr><td>PostgreSQL:</td><td align="right"> 61.364</td></tr><tr><td>MySQL:</td><td align="right"> 1.537</td></tr><tr><td>SQLite 2.7.6:</td><td align="right"> 2.787</td></tr><tr><td>SQLite 2.7.6 (nosync):</td><td align="right"> 1.599</td></tr></table><p>The asynchronous SQLite is just a shade slower than MySQL on this test.(MySQL seems to be especially adept at INSERT...SELECT statements.)The PostgreSQL engine is still thrashing - most of the 61 seconds it usedwere spent waiting on disk I/O.</p><h3>Test 12: DELETE without an index</h3><blockquote>DELETE FROM t2 WHERE c LIKE '%fifty%';</blockquote><table border=0 cellpadding=0 cellspacing=0><tr><td>PostgreSQL:</td><td align="right"> 1.509</td></tr><tr><td>MySQL:</td><td align="right"> 0.975</td></tr><tr><td>SQLite 2.7.6:</td><td align="right"> 4.004</td></tr><tr><td>SQLite 2.7.6 (nosync):</td><td align="right"> 0.560</td></tr></table><p>The synchronous version of SQLite is the slowest of the group in this test,but the asynchronous version is the fastest. The difference is the extra time needed to execute fsync().</p><h3>Test 13: DELETE with an index</h3><blockquote>DELETE FROM t2 WHERE a>10 AND a<20000;</blockquote><table border=0 cellpadding=0 cellspacing=0><tr><td>PostgreSQL:</td><td align="right"> 1.316</td></tr><tr><td>MySQL:</td><td align="right"> 2.262</td></tr><tr><td>SQLite 2.7.6:</td><td align="right"> 2.068</td></tr><tr><td>SQLite 2.7.6 (nosync):</td><td align="right"> 0.752</td></tr></table><p>This test is significant because it is one of the few wherePostgreSQL is faster than MySQL. The asynchronous SQLite is,however, faster then both the other two.</p><h3>Test 14: A big INSERT after a big DELETE</h3><blockquote>INSERT INTO t2 SELECT * FROM t1;</blockquote><table border=0 cellpadding=0 cellspacing=0><tr><td>PostgreSQL:</td><td align="right"> 13.168</td></tr><tr><td>MySQL:</td><td align="right"> 1.815</td></tr><tr><td>SQLite 2.7.6:</td><td align="right"> 3.210</td></tr><tr><td>SQLite 2.7.6 (nosync):</td><td align="right"> 1.485</td></tr></table><p>Some older versions of SQLite (prior to version 2.4.0)would show decreasing performance after asequence of DELETEs followed by new INSERTs. As this test shows, theproblem has now been resolved.</p><h3>Test 15: A big DELETE followed by many small INSERTs</h3><blockquote>BEGIN;<br>DELETE FROM t1;<br>INSERT INTO t1 VALUES(1,10719,'ten thousand seven hundred nineteen');<br><i>... 11997 lines omitted</i><br>INSERT INTO t1 VALUES(11999,72836,'seventy two thousand eight hundred thirty six');<br>INSERT INTO t1 VALUES(12000,64231,'sixty four thousand two hundred thirty one');<br>COMMIT;<br></blockquote><table border=0 cellpadding=0 cellspacing=0><tr><td>PostgreSQL:</td><td align="right"> 4.556</td></tr><tr><td>MySQL:</td><td align="right"> 1.704</td></tr><tr><td>SQLite 2.7.6:</td><td align="right"> 0.618</td></tr><tr><td>SQLite 2.7.6 (nosync):</td><td align="right"> 0.406</td></tr></table><p>SQLite is very good at doing INSERTs within a transaction, which probablyexplains why it is so much faster than the other databases at this test.</p><h3>Test 16: DROP TABLE</h3><blockquote>DROP TABLE t1;<br>DROP TABLE t2;<br>DROP TABLE t3;</blockquote><table border=0 cellpadding=0 cellspacing=0><tr><td>PostgreSQL:</td><td align="right"> 0.135</td></tr><tr><td>MySQL:</td><td align="right"> 0.015</td></tr><tr><td>SQLite 2.7.6:</td><td align="right"> 0.939</td></tr><tr><td>SQLite 2.7.6 (nosync):</td><td align="right"> 0.254</td></tr></table><p>SQLite is slower than the other databases when it comes to dropping tables.This probably is because when SQLite drops a table, it has to go through anderase the records in the database file that deal with that table. MySQL andPostgreSQL, on the other hand, use separate files to represent each tableso they can drop a table simply by deleting a file, which is much faster.</p><p>On the other hand, dropping tables is not a very common operation so if SQLite takes a little longer, that is not seen as a big problem.</p>}footer $rcsid
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -