From e4dd73b4fae9ac795c05cd442b790f5b4d6ad3c6 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 26 Mar 2007 13:48:12 +0000 Subject: [PATCH] Avoid unnecessary calls to pager_unwritelock() when in exclusive-access mode. Add the speed2.test script to the test suite. (CVS 3718) FossilOrigin-Name: ab53f5086334ea2f6c20c8f9d043baff39fae8d7 --- manifest | 19 ++-- manifest.uuid | 2 +- src/pager.c | 4 +- test/quick.test | 3 +- test/speed1.test | 10 +- test/speed2.test | 271 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 293 insertions(+), 16 deletions(-) create mode 100644 test/speed2.test diff --git a/manifest b/manifest index 7de456eaed..3b43726a66 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Run\ssome\smalloc()\stests\swith\sexclusive-access\smode.\s(CVS\s3717) -D 2007-03-26T12:26:27 +C Avoid\sunnecessary\scalls\sto\spager_unwritelock()\swhen\sin\sexclusive-access\smode.\nAdd\sthe\sspeed2.test\sscript\sto\sthe\stest\ssuite.\s(CVS\s3718) +D 2007-03-26T13:48:13 F Makefile.in 1fe3d0b46e40fd684e1e61f8e8056cefed16de9f F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -86,7 +86,7 @@ F src/os_unix.c 4642f23ed0c1ae0f1440db1d2b4231348af69360 F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_win.c 1d1d0989b0f235751504292c2f28e81044be0d70 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b -F src/pager.c 75019bab2ddafdd443413c38f489c15d18b95ea2 +F src/pager.c d9b188cbe6bc502c328115181ae9426256c49058 F src/pager.h 3c16500c25051536e43fb19e246e58fc7cb51d9f F src/parse.y bcfe366c1fd61cfc40e5344eb69a31997a821af0 F src/pragma.c 9cb8b94e7d38ba35a86037bd517d07ba9870b4b2 @@ -279,7 +279,7 @@ F test/pagesize.test 05c74ea49f790734ec1e9ab765d9bf1cce79b8f2 F test/pragma.test 91739ef06ab9ecf91e90d25951858caba71d6fe7 F test/printf.test cdd8e20dd901382a385afcbaa777b9377815c2ad F test/progress.test 8b22b4974b0a95272566385f8cb8c341c7130df8 x -F test/quick.test 8c0496cfb3ad91811eca779a5fcaccb8e32fcbda +F test/quick.test c3eb0c3e37f165eed629cf806f43b4e4e1a3213e F test/quote.test 5891f2338980916cf7415484b4ce785294044adb F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b F test/rollback.test 673cd8c44c685ad54987fe7f0eeba84efa09685d @@ -300,7 +300,8 @@ F test/shared2.test 8b48f8d33494413ef4cf250110d89403e2bf6b23 F test/shared3.test 01e3e124dbb3859788aabc7cfb82f7ea04421749 F test/shared_err.test 841f7341eb07ed97c713bf89960a4e9199717193 F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5 -F test/speed1.test 4d6719b252fe90dc52f663a6b2a24cf6472ceac9 +F test/speed1.test a30faa084ded813ce8ca0a7319198d65f70d0374 +F test/speed2.test 7928c454cea00f779f91c2157830bb78d690f976 F test/subquery.test ae324ee928c5fb463a3ce08a8860d6e7f1ca5797 F test/subselect.test 2d13fb7f450db3595adcdd24079a0dd1d2d6abc2 F test/sync.test d05397b8f89f423dd6dba528692019ab036bc1c3 @@ -439,7 +440,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 72cb2e1a73cd09d32900bb473377f66ff55058fb -R 8b15b348ec37132c30876a8baf03451e -U danielk1977 -Z e3775c0c7c4664bdb34c4c33b61b1f75 +P 127454903764daff17390941a002f527ee2ffc87 +R f8f17a5fd0fcfb4206d3e1d9fe29a001 +U drh +Z 58bc375fdd0e58a8cbf0d31d7e7ab70d diff --git a/manifest.uuid b/manifest.uuid index a0a54ec78b..25e6d55da4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -127454903764daff17390941a002f527ee2ffc87 \ No newline at end of file +ab53f5086334ea2f6c20c8f9d043baff39fae8d7 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index e55f833a89..0c815dfb5e 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.297 2007/03/26 12:26:27 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.298 2007/03/26 13:48:13 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -3014,7 +3014,7 @@ int sqlite3PagerUnref(DbPage *pPg){ */ pPager->nRef--; assert( pPager->nRef>=0 ); - if( pPager->nRef==0 ){ + if( pPager->nRef==0 && !pPager->exclusiveMode ){ pagerUnlockAndRollback(pPager); } } diff --git a/test/quick.test b/test/quick.test index e8bd6145d9..15755ec9e8 100644 --- a/test/quick.test +++ b/test/quick.test @@ -6,7 +6,7 @@ #*********************************************************************** # This file runs all tests. # -# $Id: quick.test,v 1.49 2007/03/26 12:26:27 danielk1977 Exp $ +# $Id: quick.test,v 1.50 2007/03/26 13:48:14 drh Exp $ proc lshift {lvar} { upvar $lvar l @@ -53,6 +53,7 @@ set EXCLUDE { misuse.test quick.test speed1.test + speed2.test autovacuum_crash.test btree8.test diff --git a/test/speed1.test b/test/speed1.test index 53921cff62..b0b334a708 100644 --- a/test/speed1.test +++ b/test/speed1.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script is measuring executing speed. # -# $Id: speed1.test,v 1.2 2006/11/30 13:06:00 drh Exp $ +# $Id: speed1.test,v 1.3 2007/03/26 13:48:14 drh Exp $ # set testdir [file dirname $argv0] @@ -21,7 +21,7 @@ set sqlout [open speed1.txt w] proc tracesql {sql} { puts $::sqlout $sql\; } -db trace tracesql +#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. @@ -61,11 +61,15 @@ proc number_name {n} { # do_test speed1-1.0 { execsql { -pragma page_size=4096; + 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} diff --git a/test/speed2.test b/test/speed2.test new file mode 100644 index 0000000000..f7aabb41d5 --- /dev/null +++ b/test/speed2.test @@ -0,0 +1,271 @@ +# 2006 November 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. +# +# $Id: speed2.test,v 1.1 2007/03/26 13:48:14 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +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 speed1-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 sql {} +for {set i 1} {$i<=50000} {incr i} { + set r [expr {int(rand()*500000)}] + append sql "INSERT INTO t1 VALUES($i,$r,'[number_name $r]');\n" +} +db eval BEGIN +speed_trial speed1-insert1 50000 row $sql +db eval COMMIT + +# 50000 INSERTs on an indexed table +# +set sql {} +for {set i 1} {$i<=50000} {incr i} { + set r [expr {int(rand()*500000)}] + append sql "INSERT INTO t2 VALUES($i,$r,'[number_name $r]');\n" +} +db eval BEGIN +speed_trial speed1-insert2 50000 row $sql +db eval COMMIT + + + +# 50 SELECTs on an integer comparison. There is no index so +# a full table scan is required. +# +set sql {} +for {set i 0} {$i<50} {incr i} { + set lwr [expr {$i*100}] + set upr [expr {($i+10)*100}] + append sql "SELECT count(*), avg(b) FROM t1 WHERE b>=$lwr AND b<$upr;" +} +speed_trial speed1-select1 [expr {50*50000}] row $sql + +# 50 SELECTs on an LIKE comparison. There is no index so a full +# table scan is required. +# +set sql {} +for {set i 0} {$i<50} {incr i} { + append sql \ + "SELECT count(*), avg(b) FROM t1 WHERE c LIKE '%[number_name $i]%';" +} +speed_trial speed1-select2 [expr {50*50000}] row $sql + +# Create indices +# +db eval BEGIN +speed_trial speed1-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 sql {} +for {set i 0} {$i<5000} {incr i} { + set lwr [expr {$i*100}] + set upr [expr {($i+10)*100}] + append sql "SELECT count(*), avg(b) FROM t1 WHERE b>=$lwr AND b<$upr;" +} +speed_trial speed1-select3 5000 stmt $sql + +# 100000 random SELECTs against rowid. +# +set sql {} +for {set i 1} {$i<=100000} {incr i} { + set id [expr {int(rand()*50000)+1}] + append sql "SELECT c=='hi' FROM t1 WHERE rowid=$id;\n" +} +speed_trial speed1-select4 100000 row $sql + +# 100000 random SELECTs against a unique indexed column. +# +set sql {} +for {set i 1} {$i<=100000} {incr i} { + set id [expr {int(rand()*50000)+1}] + append sql "SELECT c FROM t1 WHERE a=$id;" +} +speed_trial speed1-select5 100000 row $sql + +# 50000 random SELECTs against an indexed column text column +# +set sql {} +db eval {SELECT c FROM t1 ORDER BY random() LIMIT 50000} { + append sql "SELECT c FROM t1 WHERE c='$c';" +} +speed_trial speed1-select6 50000 row $sql + +# Vacuum +speed_trial speed1-vacuum 100000 row VACUUM + +# 5000 updates of ranges where the field being compared is indexed. +# +set sql {} +for {set i 0} {$i<5000} {incr i} { + set lwr [expr {$i*2}] + set upr [expr {($i+1)*2}] + append sql "UPDATE t1 SET b=b*2 WHERE a>=$lwr AND a<$upr;" +} +db eval BEGIN +speed_trial speed1-update1 5000 stmt $sql +db eval COMMIT + +# 50000 single-row updates. An index is used to find the row quickly. +# +set sql {} +for {set i 0} {$i<50000} {incr i} { + set r [expr {int(rand()*500000)}] + append sql "UPDATE t1 SET b=$r WHERE a=$i;" +} +db eval BEGIN +speed_trial speed1-update2 50000 row $sql +db eval COMMIT + +# 1 big text update that touches every row in the table. +# +speed_trial speed1-update3 50000 row { + UPDATE t1 SET c=a; +} + +# Many individual text updates. Each row in the table is +# touched through an index. +# +set sql {} +for {set i 1} {$i<=50000} {incr i} { + set r [expr {int(rand()*500000)}] + append sql "UPDATE t1 SET c='[number_name $r]' WHERE a=$i;" +} +db eval BEGIN +speed_trial speed1-update4 50000 row $sql +db eval COMMIT + +# Delete all content in a table. +# +speed_trial speed1-delete1 50000 row {DELETE FROM t1} + +# Copy one table into another +# +speed_trial speed1-copy1 50000 row {INSERT INTO t1 SELECT * FROM t2} + +# Delete all content in a table, one row at a time. +# +speed_trial speed1-delete2 50000 row {DELETE FROM t1 WHERE 1} + +# Refill the table yet again +# +speed_trial speed1-copy2 50000 row {INSERT INTO t1 SELECT * FROM t2} + +# Drop the table and recreate it without its indices. +# +db eval BEGIN +speed_trial speed1-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 speed1-copy3 50000 row {INSERT INTO t1 SELECT * FROM t2} + +# Select 20000 rows from the table at random. +# +speed_trial speed1-random1 50000 row { + SELECT rowid FROM t1 ORDER BY random() LIMIT 20000 +} + +# Delete 20000 random rows from the table. +# +speed_trial speed1-random-del1 20000 row { + DELETE FROM t1 WHERE rowid IN + (SELECT rowid FROM t1 ORDER BY random() LIMIT 20000) +} +do_test speed1-1.1 { + db one {SELECT count(*) FROM t1} +} 30000 + + +# Delete 20000 more rows at random from the table. +# +speed_trial speed1-random-del2 20000 row { + DELETE FROM t1 WHERE rowid IN + (SELECT rowid FROM t1 ORDER BY random() LIMIT 20000) +} +do_test speed1-1.2 { + db one {SELECT count(*) FROM t1} +} 10000 + +finish_test