From: danielk1977 Date: Tue, 24 Jun 2008 11:21:20 +0000 (+0000) Subject: Add start of new test file "select9.test". To test LIMIT, OFFSET and ORDER BY on... X-Git-Tag: version-3.6.10~884 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9afe68477d9137bc7ba4d5e9a44693c5771bc603;p=thirdparty%2Fsqlite.git Add start of new test file "select9.test". To test LIMIT, OFFSET and ORDER BY on compound SELECT statements. (CVS 5293) FossilOrigin-Name: 3a13e943d8fb4060fc1f0f827a156a730ee64be0 --- diff --git a/manifest b/manifest index d04dec5a9a..58e234b2a5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\stypo\sin\sthe\sdocumentation\sfor\sthe\ssqlite3_bind_XXX()\sAPIs.\s(CVS\s5292) -D 2008-06-24T09:52:39 +C Add\sstart\sof\snew\stest\sfile\s"select9.test".\sTo\stest\sLIMIT,\sOFFSET\sand\sORDER\sBY\son\scompound\sSELECT\sstatements.\s(CVS\s5293) +D 2008-06-24T11:21:21 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7 F Makefile.in ff6f90048555a0088f6a4b7406bed5e55a7c4eff F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -428,7 +428,7 @@ F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47 F test/printf.test c3405535b418d454e8a52196a0fc592ec9eec58d F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 x F test/ptrchng.test 83150cb7b513e33cce90fdc68f4b1817551857c0 -F test/quick.test f040f7e8834699d4fd25271780e0c61bbff7a2e5 +F test/quick.test 7c786e7829cda4844e03c7d8924a0d758e6fb3bc F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6 F test/rdonly.test b34db316525440d3b42c32e83942c02c37d28ef0 F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b @@ -446,6 +446,7 @@ F test/select5.test 5ad14ea338aada2e6394ba98fa9aa40e3e50aec0 F test/select6.test 399f14b9ba37b768afe5d2cd8c12e4f340a69db8 F test/select7.test 7906735805cfbee4dddc0bed4c14e68d7f5f9c5f F test/select8.test 391de11bdd52339c30580dabbbbe97e3e9a3c79d +F test/select9.test 231bf2b40f2279202e387f2f667a0d0f9df49fca F test/server1.test f5b790d4c0498179151ca8a7715a65a7802c859c F test/shared.test c6769531e0cb751d46a9838c0532d3786606c0f6 F test/shared2.test 0ee9de8964d70e451936a48c41cb161d9134ccf4 @@ -544,7 +545,7 @@ F test/vacuum.test 0bc75ee74ab9c69322d6563aa2287375697e630b F test/vacuum2.test d3b9691541fe6ed5c711f547a1c7d70e9760ac6f F test/vacuum3.test 6149b24613f487915ca9cedfbb9147d5759714ec F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 -F test/veryquick.test fe7c32b95b7fe8cd9ad41760848cbc844e0d4d8f +F test/veryquick.test d93a2f36ef0f7bb0f1048ae339e9d8bda774c941 F test/view.test 4864e3841ab3213a95297718b94d5d6a8d3bc78b F test/vtab1.test 47092e3ac59141f08e09a6c0cc0df8997242bc79 F test/vtab2.test 1da49b015582965a8fc386aa23d051a5a622b08e @@ -592,7 +593,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P e2ba324cbcac0ba35bbde50048677e085abb092b -R 571f5a2a7c5833f8ac9443d6db08af85 +P 839457f128c91a20aeae7ba570b4840792d41239 +R 8f8e98a120d77a29c4edf47eb9916928 U danielk1977 -Z 3b8abaa5172f1cf18d7b1bca5e24fb2f +Z f25ae40ff085a198d7a1780e2a1acc69 diff --git a/manifest.uuid b/manifest.uuid index 684f5fa59b..1f8dc7a1a7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -839457f128c91a20aeae7ba570b4840792d41239 \ No newline at end of file +3a13e943d8fb4060fc1f0f827a156a730ee64be0 \ No newline at end of file diff --git a/test/quick.test b/test/quick.test index b9fb195015..161beb8db3 100644 --- a/test/quick.test +++ b/test/quick.test @@ -6,7 +6,7 @@ #*********************************************************************** # This file runs all tests. # -# $Id: quick.test,v 1.81 2008/06/21 18:07:37 danielk1977 Exp $ +# $Id: quick.test,v 1.82 2008/06/24 11:21:21 danielk1977 Exp $ proc lshift {lvar} { upvar $lvar l @@ -68,6 +68,7 @@ set EXCLUDE { onefile.test permutations.test quick.test + select9.test soak.test speed1.test speed1p.test diff --git a/test/select9.test b/test/select9.test new file mode 100644 index 0000000000..d27fa885aa --- /dev/null +++ b/test/select9.test @@ -0,0 +1,254 @@ +# 2008 June 24 +# +# 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. +# +# $Id: select9.test,v 1.1 2008/06/24 11:21:21 danielk1977 Exp $ + +# The tests in this file are focused on test compound SELECT statements +# that have any or all of an ORDER BY, LIMIT or OFFSET clauses. As of +# version 3.6.0, SQLite contains code to use SQL indexes where possible +# to optimize such statements. +# + +# TODO Points: +# +# * Are there any "column affinity" issues to consider? + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +#------------------------------------------------------------------------- +# test_compound_select TESTNAME SELECT RESULT +# +# This command is used to run multiple LIMIT/OFFSET test cases based on +# the single SELECT statement passed as the second argument. The SELECT +# statement may not contain a LIMIT or OFFSET clause. This proc tests +# many statements of the form: +# +# "$SELECT limit $X offset $Y" +# +# for various values of $X and $Y. +# +# The third argument, $RESULT, should contain the expected result of +# the command [execsql $SELECT]. +# +# The first argument, $TESTNAME, is used as the base test case name to +# pass to [do_test] for each individual LIMIT OFFSET test case. +# +proc test_compound_select {testname sql result} { + + set nCol 1 + db eval $sql A { + set nCol [llength $A(*)] + break + } + set nRow [expr {[llength $result] / $nCol}] + + set ::compound_sql $sql + do_test $testname { + execsql $::compound_sql + } $result +#return + + set iLimitIncr 1 + set iLimitEnd [expr $nRow+1] + + set iOffsetIncr 1 + set iOffsetEnd $nRow + + for {set iOffset 0} {$iOffset <= $iOffsetEnd} {incr iOffset $iOffsetIncr} { + for {set iLimit 0} {$iLimit <= ($nRow+1)} {incr iLimit} { + + set ::compound_sql "$sql LIMIT $iLimit" + if {$iOffset != 0} { + append ::compound_sql " OFFSET $iOffset" + } + + set iStart [expr {$iOffset*$nCol}] + set iEnd [expr {($iOffset*$nCol) + ($iLimit*$nCol) -1}] + + do_test $testname.limit=$iLimit.offset=$iOffset { + execsql $::compound_sql + } [lrange $result $iStart $iEnd] + } + } +} + +#------------------------------------------------------------------------- +# test_compound_select_flippable TESTNAME SELECT RESULT +# +# This command is for testing statements of the form: +# +# ORDER BY +# +# where each is a simple (non-compound) select statement +# and is one of "INTERSECT", "UNION ALL" or "UNION". +# +# This proc calls [test_compound_select] twice, once with the select +# statement as it is passed to this command, and once with the positions +# of exchanged. +# +proc test_compound_select_flippable {testname sql result} { + test_compound_select $testname $sql $result + + set select [string trim $sql] + set RE {(.*)(UNION ALL|INTERSECT|UNION)(.*)(ORDER BY.*)} + set rc [regexp $RE $select -> s1 op s2 order_by] + if {!$rc} {error "Statement is unflippable: $select"} + + set flipsql "$s2 $op $s1 $order_by" + test_compound_select $testname.flipped $flipsql $result +} + +############################################################################# +# Begin tests. +# + +# Create and populate a sample database. +# +do_test select9-1.0 { + execsql { + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(d, e, f); + BEGIN; + INSERT INTO t1 VALUES(1, 'one', 'I'); + INSERT INTO t1 VALUES(3, NULL, NULL); + INSERT INTO t1 VALUES(5, 'five', 'V'); + INSERT INTO t1 VALUES(7, 'seven', 'VII'); + INSERT INTO t1 VALUES(9, NULL, NULL); + INSERT INTO t1 VALUES(2, 'two', 'II'); + INSERT INTO t1 VALUES(4, 'four', 'IV'); + INSERT INTO t1 VALUES(6, NULL, NULL); + INSERT INTO t1 VALUES(8, 'eight', 'VIII'); + INSERT INTO t1 VALUES(10, 'ten', 'X'); + + INSERT INTO t2 VALUES(1, 'two', 'IV'); + INSERT INTO t2 VALUES(2, 'four', 'VIII'); + INSERT INTO t2 VALUES(3, NULL, NULL); + INSERT INTO t2 VALUES(4, 'eight', 'XVI'); + INSERT INTO t2 VALUES(5, 'ten', 'XX'); + INSERT INTO t2 VALUES(6, NULL, NULL); + INSERT INTO t2 VALUES(7, 'fourteen', 'XXVIII'); + INSERT INTO t2 VALUES(8, 'sixteen', 'XXXII'); + INSERT INTO t2 VALUES(9, NULL, NULL); + INSERT INTO t2 VALUES(10, 'twenty', 'XL'); + + COMMIT; + } +} {} + +# Each iteration of this loop runs the same tests with a different set +# of indexes present within the database schema. The data returned by +# the compound SELECT statements in the test cases should be the same +# in each case. +# +set iOuterLoop 1 +foreach indexes [list { + /* Do not create any indexes. */ +} { + CREATE INDEX i1 ON t1(a) +} { + CREATE INDEX i2 ON t1(b) +} { + CREATE INDEX i3 ON t2(d) +} { + CREATE INDEX i4 ON t2(e) +}] { + + do_test select9-1.$iOuterLoop.1 { + execsql $indexes + } {} + + # Test some 2-way UNION ALL queries. No WHERE clauses. + # + test_compound_select select9-1.$iOuterLoop.2 { + SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 + } {1 one 3 {} 5 five 7 seven 9 {} 2 two 4 four 6 {} 8 eight 10 ten 1 two 2 four 3 {} 4 eight 5 ten 6 {} 7 fourteen 8 sixteen 9 {} 10 twenty} + test_compound_select select9-1.$iOuterLoop.3 { + SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY 1 + } {1 one 1 two 2 two 2 four 3 {} 3 {} 4 four 4 eight 5 five 5 ten 6 {} 6 {} 7 seven 7 fourteen 8 eight 8 sixteen 9 {} 9 {} 10 ten 10 twenty} + test_compound_select select9-1.$iOuterLoop.4 { + SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY 2 + } {3 {} 9 {} 6 {} 3 {} 6 {} 9 {} 8 eight 4 eight 5 five 4 four 2 four 7 fourteen 1 one 7 seven 8 sixteen 10 ten 5 ten 10 twenty 2 two 1 two} + test_compound_select_flippable select9-1.$iOuterLoop.5 { + SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY 1, 2 + } {1 one 1 two 2 four 2 two 3 {} 3 {} 4 eight 4 four 5 five 5 ten 6 {} 6 {} 7 fourteen 7 seven 8 eight 8 sixteen 9 {} 9 {} 10 ten 10 twenty} + test_compound_select_flippable select9-1.$iOuterLoop.6 { + SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY 2, 1 + } {3 {} 3 {} 6 {} 6 {} 9 {} 9 {} 4 eight 8 eight 5 five 2 four 4 four 7 fourteen 1 one 7 seven 8 sixteen 5 ten 10 ten 10 twenty 1 two 2 two} + + # Test some 2-way UNION queries. + # + test_compound_select select9-1.$iOuterLoop.7 { + SELECT a, b FROM t1 UNION SELECT d, e FROM t2 + } {1 one 1 two 2 four 2 two 3 {} 4 eight 4 four 5 five 5 ten 6 {} 7 fourteen 7 seven 8 eight 8 sixteen 9 {} 10 ten 10 twenty} + + test_compound_select select9-1.$iOuterLoop.8 { + SELECT a, b FROM t1 UNION SELECT d, e FROM t2 ORDER BY 1 + } {1 one 1 two 2 four 2 two 3 {} 4 eight 4 four 5 five 5 ten 6 {} 7 fourteen 7 seven 8 eight 8 sixteen 9 {} 10 ten 10 twenty} + + test_compound_select select9-1.$iOuterLoop.9 { + SELECT a, b FROM t1 UNION SELECT d, e FROM t2 ORDER BY 2 + } {3 {} 6 {} 9 {} 4 eight 8 eight 5 five 2 four 4 four 7 fourteen 1 one 7 seven 8 sixteen 5 ten 10 ten 10 twenty 1 two 2 two} + + test_compound_select_flippable select9-1.$iOuterLoop.10 { + SELECT a, b FROM t1 UNION SELECT d, e FROM t2 ORDER BY 1, 2 + } {1 one 1 two 2 four 2 two 3 {} 4 eight 4 four 5 five 5 ten 6 {} 7 fourteen 7 seven 8 eight 8 sixteen 9 {} 10 ten 10 twenty} + + test_compound_select_flippable select9-1.$iOuterLoop.11 { + SELECT a, b FROM t1 UNION SELECT d, e FROM t2 ORDER BY 2, 1 + } {3 {} 6 {} 9 {} 4 eight 8 eight 5 five 2 four 4 four 7 fourteen 1 one 7 seven 8 sixteen 5 ten 10 ten 10 twenty 1 two 2 two} + + # Test some 2-way INTERSECT queries. + # + test_compound_select select9-1.$iOuterLoop.11 { + SELECT a, b FROM t1 INTERSECT SELECT d, e FROM t2 + } {3 {} 6 {} 9 {}} + test_compound_select_flippable select9-1.$iOuterLoop.12 { + SELECT a, b FROM t1 INTERSECT SELECT d, e FROM t2 ORDER BY 1 + } {3 {} 6 {} 9 {}} + test_compound_select select9-1.$iOuterLoop.13 { + SELECT a, b FROM t1 INTERSECT SELECT d, e FROM t2 ORDER BY 2 + } {3 {} 6 {} 9 {}} + test_compound_select_flippable select9-1.$iOuterLoop.14 { + SELECT a, b FROM t1 INTERSECT SELECT d, e FROM t2 ORDER BY 2, 1 + } {3 {} 6 {} 9 {}} + test_compound_select_flippable select9-1.$iOuterLoop.15 { + SELECT a, b FROM t1 INTERSECT SELECT d, e FROM t2 ORDER BY 1, 2 + } {3 {} 6 {} 9 {}} + + # Test some 2-way EXCEPT queries. + # + test_compound_select select9-1.$iOuterLoop.16 { + SELECT a, b FROM t1 EXCEPT SELECT d, e FROM t2 + } {1 one 2 two 4 four 5 five 7 seven 8 eight 10 ten} + + test_compound_select select9-1.$iOuterLoop.17 { + SELECT a, b FROM t1 EXCEPT SELECT d, e FROM t2 ORDER BY 1 + } {1 one 2 two 4 four 5 five 7 seven 8 eight 10 ten} + + test_compound_select select9-1.$iOuterLoop.18 { + SELECT a, b FROM t1 EXCEPT SELECT d, e FROM t2 ORDER BY 2 + } {8 eight 5 five 4 four 1 one 7 seven 10 ten 2 two} + + test_compound_select select9-1.$iOuterLoop.19 { + SELECT a, b FROM t1 EXCEPT SELECT d, e FROM t2 ORDER BY 1, 2 + } {1 one 2 two 4 four 5 five 7 seven 8 eight 10 ten} + + test_compound_select select9-1.$iOuterLoop.20 { + SELECT a, b FROM t1 EXCEPT SELECT d, e FROM t2 ORDER BY 2, 1 + } {8 eight 5 five 4 four 1 one 7 seven 10 ten 2 two} + + incr iOuterLoop +} + +finish_test + diff --git a/test/veryquick.test b/test/veryquick.test index 211e1e2745..67cb513377 100644 --- a/test/veryquick.test +++ b/test/veryquick.test @@ -6,7 +6,7 @@ #*********************************************************************** # This file runs all tests. # -# $Id: veryquick.test,v 1.6 2008/06/21 19:20:13 danielk1977 Exp $ +# $Id: veryquick.test,v 1.7 2008/06/24 11:21:21 danielk1977 Exp $ proc lshift {lvar} { upvar $lvar l @@ -90,6 +90,7 @@ set EXCLUDE { onefile.test permutations.test quick.test + select9.test soak.test speed1.test speed1p.test