1
0
mirror of https://github.com/sqlite/sqlite.git synced 2026-01-06 08:01:16 +03:00

Add speed-test scripts that also show EXPLAIN output. (CVS 5017)

FossilOrigin-Name: d11f5dafdaf7c18c43615d0ac018c7d221460244
This commit is contained in:
drh
2008-04-16 12:57:48 +00:00
parent a0af99f91c
commit 4c68e6d28a
4 changed files with 657 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
C Make\ssure\sthe\sdatabase\sconnection\smutex\sis\sheld\sbefore\scalling\nsqlite3SafetyOn()\sor\ssqlite3SafetyOff().\s\sTicket\s#3059.\s(CVS\s5016)
D 2008-04-16T00:49:12
C Add\sspeed-test\sscripts\sthat\salso\sshow\sEXPLAIN\soutput.\s(CVS\s5017)
D 2008-04-16T12:57:48
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in 25b3282a4ac39388632c2fb0e044ff494d490952
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -442,10 +442,12 @@ F test/soak.test 64f9b27fbcdec43335a88c546ce1983e6ba40d7b
F test/softheap1.test c9146eda576eedb62192b771293a2115d9af8456
F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5
F test/speed1.test 22e1b27af0683ed44dcd2f93ed817a9c3e65084a
F test/speed1p.explain d841e650a04728b39e6740296b852dccdca9b2cb
F test/speed1p.test 5f79987671f930a8aa651091c2952c1782b0df83
F test/speed2.test 53177056baf6556dcbdcf032bbdfc41c1aa74ded
F test/speed3.test e312d7e442a5047d730569fdae2ba99bc94e1a13
F test/speed4.test 20d8ea20bea3ca09c3ef3b5ec820a17e58e132cb
F test/speed4p.explain 6b5f104ebeb34a038b2f714150f51d01143e59aa
F test/speed4p.test 0e51908951677de5a969b723e03a27a1c45db38b
F test/sqllimits1.test 68f7eab0bfc27ef68d677864d37e37e38f67db00
F test/subquery.test 8203f85db56ba022a57a0589890090c8feed4e59
@@ -630,7 +632,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P cce8deae2d556916e2817e0cb9748dceb162085d
R 7a340507e41c10c8a2cb1cddf539eada
P d35dea059e2cb936e4277f513f036b9b0bdfc4a5
R c0b22004b0ac521d974e7b893302fd7e
U drh
Z ea939e8bf0d325aad906011ffe8ec67e
Z 1ac53e97ed99016f506aa1047f716fd9

View File

@@ -1 +1 @@
d35dea059e2cb936e4277f513f036b9b0bdfc4a5
d11f5dafdaf7c18c43615d0ac018c7d221460244

366
test/speed1p.explain Normal file
View File

@@ -0,0 +1,366 @@
# 2008 March 21
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is measuring executing speed.
#
# This is a copy of speed1.test modified to user prepared statements.
#
# $Id: speed1p.explain,v 1.1 2008/04/16 12:57:48 drh Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
speed_trial_init speed1
# Set a uniform random seed
expr srand(0)
set sqlout [open speed1.txt w]
proc tracesql {sql} {
puts $::sqlout $sql\;
}
#db trace tracesql
# The number_name procedure below converts its argment (an integer)
# into a string which is the English-language name for that number.
#
# Example:
#
# puts [number_name 123] -> "one hundred twenty three"
#
set ones {zero one two three four five six seven eight nine
ten eleven twelve thirteen fourteen fifteen sixteen seventeen
eighteen nineteen}
set tens {{} ten twenty thirty forty fifty sixty seventy eighty ninety}
proc number_name {n} {
if {$n>=1000} {
set txt "[number_name [expr {$n/1000}]] thousand"
set n [expr {$n%1000}]
} else {
set txt {}
}
if {$n>=100} {
append txt " [lindex $::ones [expr {$n/100}]] hundred"
set n [expr {$n%100}]
}
if {$n>=20} {
append txt " [lindex $::tens [expr {$n/10}]]"
set n [expr {$n%10}]
}
if {$n>0} {
append txt " [lindex $::ones $n]"
}
set txt [string trim $txt]
if {$txt==""} {set txt zero}
return $txt
}
# Create a database schema.
#
do_test speed1p-1.0 {
execsql {
PRAGMA page_size=1024;
PRAGMA cache_size=8192;
PRAGMA locking_mode=EXCLUSIVE;
CREATE TABLE t1(a INTEGER, b INTEGER, c TEXT);
CREATE TABLE t2(a INTEGER, b INTEGER, c TEXT);
CREATE INDEX i2a ON t2(a);
CREATE INDEX i2b ON t2(b);
}
execsql {
SELECT name FROM sqlite_master ORDER BY 1;
}
} {i2a i2b t1 t2}
# 50000 INSERTs on an unindexed table
#
set list {}
for {set i 1} {$i<=50000} {incr i} {
set r [expr {int(rand()*500000)}]
set x [number_name $r]
lappend list $i $r $x
}
set script {
foreach {i r x} $::list {
db eval {INSERT INTO t1 VALUES($i,$r,$x)}
}
}
explain {INSERT INTO t1 VALUES($i,$r,$x)}
db eval BEGIN
speed_trial_tcl speed1p-insert1 50000 row $script
db eval COMMIT
# 50000 INSERTs on an indexed table
#
set list {}
for {set i 1} {$i<=50000} {incr i} {
set r [expr {int(rand()*500000)}]
set x [number_name $r]
lappend list $i $r $x
}
set script {
foreach {i r x} $::list {
db eval {INSERT INTO t2 VALUES($i,$r,$x)}
}
}
explain {INSERT INTO t2 VALUES($i,$r,$x)}
db eval BEGIN
speed_trial_tcl speed1p-insert2 50000 row $script
db eval COMMIT
# 50 SELECTs on an integer comparison. There is no index so
# a full table scan is required.
#
set list {}
for {set i 0} {$i<50} {incr i} {
set lwr [expr {$i*100}]
set upr [expr {($i+10)*100}]
lappend list $lwr $upr
}
set script {
foreach {lwr upr} $::list {
db eval {SELECT count(*), avg(b) FROM t1 WHERE b>=$lwr AND b<$upr}
}
}
explain {SELECT count(*), avg(b) FROM t1 WHERE b>=$lwr AND b<$upr}
db eval BEGIN
speed_trial_tcl speed1p-select1 [expr {50*50000}] row $script
db eval COMMIT
# 50 SELECTs on an LIKE comparison. There is no index so a full
# table scan is required.
#
set list {}
for {set i 0} {$i<50} {incr i} {
lappend list "%[number_name $i]%"
}
set script {
foreach pattern $::list {
db eval {SELECT count(*), avg(b) FROM t1 WHERE c LIKE $pattern}
}
}
explain {SELECT count(*), avg(b) FROM t1 WHERE c LIKE $pattern}
db eval BEGIN
speed_trial_tcl speed1p-select2 [expr {50*50000}] row $script
db eval COMMIT
# Create indices
#
explain {CREATE INDEX i1a ON t1(a)}
explain {CREATE INDEX i1b ON t1(b)}
db eval BEGIN
speed_trial speed1p-createidx 150000 row {
CREATE INDEX i1a ON t1(a);
CREATE INDEX i1b ON t1(b);
CREATE INDEX i1c ON t1(c);
}
db eval COMMIT
# 5000 SELECTs on an integer comparison where the integer is
# indexed.
#
set list {}
for {set i 0} {$i<5000} {incr i} {
set lwr [expr {$i*100}]
set upr [expr {($i+10)*100}]
lappend list $lwr $upr
}
set script {
foreach {lwr upr} $::list {
db eval {SELECT count(*), avg(b) FROM t1 WHERE b>=$lwr AND b<$upr}
}
}
explain {SELECT count(*), avg(b) FROM t1 WHERE b>=$lwr AND b<$upr}
db eval BEGIN
speed_trial_tcl speed1p-select3 5000 stmt $script
db eval COMMIT
# 100000 random SELECTs against rowid.
#
set list {}
for {set i 1} {$i<=100000} {incr i} {
set id [expr {int(rand()*50000)+1}]
lappend list $id
}
set script {
foreach id $::list {
db eval {SELECT c FROM t1 WHERE rowid=$id}
}
}
explain {SELECT c FROM t1 WHERE rowid=$id}
db eval BEGIN
speed_trial_tcl speed1p-select4 100000 row $script
db eval COMMIT
# 100000 random SELECTs against a unique indexed column.
#
set list {}
for {set i 1} {$i<=100000} {incr i} {
set id [expr {int(rand()*50000)+1}]
lappend list $id
}
set script {
foreach id $::list {
db eval {SELECT c FROM t1 WHERE a=$id}
}
}
explain {SELECT c FROM t1 WHERE a=$id}
db eval BEGIN
speed_trial_tcl speed1p-select5 100000 row $script
db eval COMMIT
# 50000 random SELECTs against an indexed column text column
#
set list [db eval {SELECT c FROM t1 ORDER BY random() LIMIT 50000}]
set script {
foreach c $::list {
db eval {SELECT c FROM t1 WHERE c=$c}
}
}
explain {SELECT c FROM t1 WHERE c=$c}
db eval BEGIN
speed_trial_tcl speed1p-select6 50000 row $script
db eval COMMIT
# Vacuum
speed_trial speed1p-vacuum 100000 row VACUUM
# 5000 updates of ranges where the field being compared is indexed.
#
set list {}
for {set i 0} {$i<5000} {incr i} {
set lwr [expr {$i*2}]
set upr [expr {($i+1)*2}]
lappend list $lwr $upr
}
set script {
foreach {lwr upr} $::list {
db eval {UPDATE t1 SET b=b*2 WHERE a>=$lwr AND a<$upr}
}
}
explain {UPDATE t1 SET b=b*2 WHERE a>=$lwr AND a<$upr}
db eval BEGIN
speed_trial_tcl speed1p-update1 5000 stmt $script
db eval COMMIT
# 50000 single-row updates. An index is used to find the row quickly.
#
set list {}
for {set i 0} {$i<50000} {incr i} {
set r [expr {int(rand()*500000)}]
lappend list $i $r
}
set script {
foreach {i r} $::list {
db eval {UPDATE t1 SET b=$r WHERE a=$i}
}
}
explain {UPDATE t1 SET b=$r WHERE a=$i}
db eval BEGIN
speed_trial_tcl speed1p-update2 50000 row $script
db eval COMMIT
# 1 big text update that touches every row in the table.
#
explain {UPDATE t1 SET c=a}
speed_trial speed1p-update3 50000 row {
UPDATE t1 SET c=a;
}
# Many individual text updates. Each row in the table is
# touched through an index.
#
set list {}
for {set i 1} {$i<=50000} {incr i} {
set r [expr {int(rand()*500000)}]
lappend list $i [number_name $r]
}
set script {
foreach {i x} $::list {
db eval {UPDATE t1 SET c=$x WHERE a=$i}
}
}
explain {UPDATE t1 SET c=$x WHERE a=$i}
db eval BEGIN
speed_trial_tcl speed1p-update4 50000 row $script
db eval COMMIT
# Delete all content in a table.
#
explain {DELETE FROM t1}
speed_trial speed1p-delete1 50000 row {DELETE FROM t1}
# Copy one table into another
#
explain {INSERT INTO t1 SELECT * FROM t2}
speed_trial speed1p-copy1 50000 row {INSERT INTO t1 SELECT * FROM t2}
# Delete all content in a table, one row at a time.
#
explain {DELETE FROM t1 WHERE 1}
speed_trial speed1p-delete2 50000 row {DELETE FROM t1 WHERE 1}
# Refill the table yet again
#
speed_trial speed1p-copy2 50000 row {INSERT INTO t1 SELECT * FROM t2}
# Drop the table and recreate it without its indices.
#
explain {DROP TABLE t1}
explain {CREATE TABLE tX(a INTEGER, b INTEGER, c TEXT)}
db eval BEGIN
speed_trial speed1p-drop1 50000 row {
DROP TABLE t1;
CREATE TABLE t1(a INTEGER, b INTEGER, c TEXT);
}
db eval COMMIT
# Refill the table yet again. This copy should be faster because
# there are no indices to deal with.
#
speed_trial speed1p-copy3 50000 row {INSERT INTO t1 SELECT * FROM t2}
# Select 20000 rows from the table at random.
#
explain {SELECT rowid FROM t1 ORDER BY random() LIMIT 20000}
speed_trial speed1p-random1 50000 row {
SELECT rowid FROM t1 ORDER BY random() LIMIT 20000
}
# Delete 20000 random rows from the table.
#
explain {DELETE FROM t1 WHERE rowid IN
(SELECT rowid FROM t1 ORDER BY random() LIMIT 20000)}
speed_trial speed1p-random-del1 20000 row {
DELETE FROM t1 WHERE rowid IN
(SELECT rowid FROM t1 ORDER BY random() LIMIT 20000)
}
do_test speed1p-1.1 {
db one {SELECT count(*) FROM t1}
} 30000
# Delete 20000 more rows at random from the table.
#
speed_trial speed1p-random-del2 20000 row {
DELETE FROM t1 WHERE rowid IN
(SELECT rowid FROM t1 ORDER BY random() LIMIT 20000)
}
do_test speed1p-1.2 {
db one {SELECT count(*) FROM t1}
} 10000
speed_trial_summary speed1
finish_test

283
test/speed4p.explain Normal file
View File

@@ -0,0 +1,283 @@
# 2007 October 23
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is measuring executing speed. More specifically,
# the focus is on the speed of:
#
# * joins
# * views
# * sub-selects
# * triggers
#
# $Id: speed4p.explain,v 1.1 2008/04/16 12:57:48 drh Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
speed_trial_init speed1
# Set a uniform random seed
expr srand(0)
set sqlout [open speed1.txt w]
proc tracesql {sql} {
puts $::sqlout $sql\;
}
#db trace tracesql
# The number_name procedure below converts its argment (an integer)
# into a string which is the English-language name for that number.
#
# Example:
#
# puts [number_name 123] -> "one hundred twenty three"
#
set ones {zero one two three four five six seven eight nine
ten eleven twelve thirteen fourteen fifteen sixteen seventeen
eighteen nineteen}
set tens {{} ten twenty thirty forty fifty sixty seventy eighty ninety}
proc number_name {n} {
if {$n>=1000} {
set txt "[number_name [expr {$n/1000}]] thousand"
set n [expr {$n%1000}]
} else {
set txt {}
}
if {$n>=100} {
append txt " [lindex $::ones [expr {$n/100}]] hundred"
set n [expr {$n%100}]
}
if {$n>=20} {
append txt " [lindex $::tens [expr {$n/10}]]"
set n [expr {$n%10}]
}
if {$n>0} {
append txt " [lindex $::ones $n]"
}
set txt [string trim $txt]
if {$txt==""} {set txt zero}
return $txt
}
# Summary of tests:
#
# speed4p-join1: Join three tables using IPK index.
# speed4p-join2: Join three tables using an index.
# speed4p-join3: Join two tables without an index.
#
# speed4p-view1: Querying a view.
# speed4p-table1: Same queries as in speed4p-view1, but run directly against
# the tables for comparison purposes.
#
# speed4p-subselect1: A SELECT statement that uses many sub-queries..
#
# speed4p-trigger1: An INSERT statement that fires a trigger.
# speed4p-trigger2: An UPDATE statement that fires a trigger.
# speed4p-trigger3: A DELETE statement that fires a trigger.
# speed4p-notrigger1: Same operation as trigger1, but without the trigger.
# speed4p-notrigger2: " trigger2 "
# speed4p-notrigger3: " trigger3 "
#
# Set up the schema. Each of the tables t1, t2 and t3 contain 50,000 rows.
# This creates a database of around 16MB.
execsql {
PRAGMA page_size=1024;
PRAGMA cache_size=8192;
PRAGMA locking_mode=EXCLUSIVE;
BEGIN;
CREATE TABLE t1(rowid INTEGER PRIMARY KEY, i INTEGER, t TEXT);
CREATE TABLE t2(rowid INTEGER PRIMARY KEY, i INTEGER, t TEXT);
CREATE TABLE t3(rowid INTEGER PRIMARY KEY, i INTEGER, t TEXT);
CREATE VIEW v1 AS SELECT rowid, i, t FROM t1;
CREATE VIEW v2 AS SELECT rowid, i, t FROM t2;
CREATE VIEW v3 AS SELECT rowid, i, t FROM t3;
}
for {set jj 1} {$jj <= 3} {incr jj} {
set stmt [string map "%T% t$jj" {INSERT INTO %T% VALUES(NULL, $i, $t)}]
for {set ii 0} {$ii < 50000} {incr ii} {
set i [expr {int(rand()*50000)}]
set t [number_name $i]
execsql $stmt
}
}
execsql {
CREATE INDEX i1 ON t1(t);
CREATE INDEX i2 ON t2(t);
CREATE INDEX i3 ON t3(t);
COMMIT;
}
# Before running these tests, disable the compiled statement cache built into
# the Tcl interface. This is because we want to test the speed of SQL
# compilation as well as execution.
#
db cache size 0
# Join t1, t2, t3 on IPK.
set sql "SELECT * FROM t1, t2, t3 WHERE t1.oid = t2.oid AND t2.oid = t3.oid"
explain $sql
speed_trial speed4p-join1 50000 row $sql
# Join t1, t2, t3 on the non-IPK index.
set sql "SELECT * FROM t1, t2, t3 WHERE t1.t = t2.t AND t2.t = t3.t"
explain $sql
speed_trial speed4p-join2 50000 row $sql
# Run 10000 simple queries against the views.
set script {
for {set ii 1} {$ii < 10000} {incr ii} {
set v [expr {$ii*3}]
set t [expr {$ii%3+1}]
db eval "SELECT * FROM v$t WHERE rowid = \$v"
}
}
explain {SELECT * FROm v1 WHERE rowid=$v}
speed_trial_tcl speed4p-view1 10000 stmt $script
# Run the same 10000 simple queries as in the previous test case against
# the underlying tables. The compiled vdbe programs should be identical, so
# the only difference in running time is the extra time taken to compile
# the view definitions.
#
set script {
for {set ii 1} {$ii < 10000} {incr ii} {
set v [expr {$ii*3}]
set t [expr {$ii%3+1}]
db eval "SELECT t FROM t$t WHERE rowid = \$v"
}
}
explain {SELECT * FROM t1 WHERE rowid=$v}
speed_trial_tcl speed4p-table1 10000 stmt $script
# Run a SELECT that uses sub-queries 10000 times. A total of 30000 sub-selects.
#
set script {
for {set ii 1} {$ii < 10000} {incr ii} {
set v [expr {$ii*3}]
db eval {
SELECT (SELECT t FROM t1 WHERE rowid = $v),
(SELECT t FROM t2 WHERE rowid = $v),
(SELECT t FROM t3 WHERE rowid = $v)
}
}
}
explain {
SELECT (SELECT t FROM t1 WHERE rowid = $v),
(SELECT t FROM t2 WHERE rowid = $v),
(SELECT t FROM t3 WHERE rowid = $v)
}
speed_trial_tcl speed4p-subselect1 10000 stmt $script
# The following block tests the speed of some DML statements that cause
# triggers to fire.
#
execsql {
CREATE TABLE log(op TEXT, r INTEGER, i INTEGER, t TEXT);
CREATE TABLE t4(rowid INTEGER PRIMARY KEY, i INTEGER, t TEXT);
CREATE TRIGGER t4_trigger1 AFTER INSERT ON t4 BEGIN
INSERT INTO log VALUES('INSERT INTO t4', new.rowid, new.i, new.t);
END;
CREATE TRIGGER t4_trigger2 AFTER UPDATE ON t4 BEGIN
INSERT INTO log VALUES('UPDATE OF t4', new.rowid, new.i, new.t);
END;
CREATE TRIGGER t4_trigger3 AFTER DELETE ON t4 BEGIN
INSERT INTO log VALUES('DELETE OF t4', old.rowid, old.i, old.t);
END;
BEGIN;
}
set list {}
for {set ii 1} {$ii < 10000} {incr ii} {
lappend list $ii [number_name $ii]
}
set script {
foreach {ii name} $::list {
db eval {INSERT INTO t4 VALUES(NULL, $ii, $name)}
}
}
explain {INSERT INTO t4 VALUES(NULL, $ii, $name)}
speed_trial_tcl speed4p-trigger1 10000 stmt $script
set list {}
for {set ii 1} {$ii < 20000} {incr ii 2} {
set ii2 [expr {$ii*2}]
lappend list $ii $ii2 [number_name $ii2]
}
set script {
foreach {ii ii2 name} $::list {
db eval {
UPDATE t4 SET i = $ii2, t = $name WHERE rowid = $ii;
}
}
}
explain {UPDATE t4 SET i = $ii2, t = $name WHERE rowid = $ii}
speed_trial_tcl speed4p-trigger2 10000 stmt $script
set script {
for {set ii 1} {$ii < 20000} {incr ii 2} {
db eval {DELETE FROM t4 WHERE rowid = $ii}
}
}
explain {DELETE FROM t4 WHERE rowid = $ii}
speed_trial_tcl speed4p-trigger3 10000 stmt $script
execsql {COMMIT}
# The following block contains the same tests as the above block that
# tests triggers, with one crucial difference: no triggers are defined.
# So the difference in speed between these tests and the preceding ones
# is the amount of time taken to compile and execute the trigger programs.
#
execsql {
DROP TABLE t4;
DROP TABLE log;
VACUUM;
CREATE TABLE t4(rowid INTEGER PRIMARY KEY, i INTEGER, t TEXT);
BEGIN;
}
set list {}
for {set ii 1} {$ii < 10000} {incr ii} {
lappend list $ii [number_name $ii]
}
set script {
foreach {ii name} $::list {
db eval {INSERT INTO t4 VALUES(NULL, $ii, $name);}
}
}
explain {INSERT INTO t4 VALUES(NULL, $ii, $name)}
speed_trial_tcl speed4p-notrigger1 10000 stmt $script
set list {}
for {set ii 1} {$ii < 20000} {incr ii 2} {
set ii2 [expr {$ii*2}]
lappend list $ii $ii2 [number_name $ii2]
}
set script {
foreach {ii ii2 name} $::list {
db eval {
UPDATE t4 SET i = $ii2, t = $name WHERE rowid = $ii;
}
}
}
explain {UPDATE t4 SET i = $ii2, t = $name WHERE rowid = $ii}
speed_trial_tcl speed4p-notrigger2 10000 stmt $script
set script {
for {set ii 1} {$ii < 20000} {incr ii 2} {
db eval {DELETE FROM t4 WHERE rowid = $ii}
}
}
explain {DELETE FROM t4 WHERE rowid = $ii}
speed_trial_tcl speed4p-notrigger3 10000 stmt $script
execsql {COMMIT}
speed_trial_summary speed4
finish_test