From: danielk1977 Date: Mon, 29 Dec 2008 18:33:32 +0000 (+0000) Subject: Add test file where8.test. (CVS 6072) X-Git-Tag: version-3.6.10~112 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fdc4019b460012788a400eab5b9477bf17e5737e;p=thirdparty%2Fsqlite.git Add test file where8.test. (CVS 6072) FossilOrigin-Name: bff460ec2c3e250de034a6b34312b897bb2f3749 --- diff --git a/manifest b/manifest index 65136f4a22..7de5f820ce 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sold\svariable\sdeclaration\sthat\swas\scommented\sout\susing\sa\sC++\scomment.\s(CVS\s6071) -D 2008-12-29T14:51:06 +C Add\stest\sfile\swhere8.test.\s(CVS\s6072) +D 2008-12-29T18:33:33 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 77635d0909c2067cee03889a1e04ce910d8fb809 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -207,7 +207,7 @@ F src/vdbeblob.c b0dcebfafedcf9c0addc7901ad98f6f986c08935 F src/vdbemem.c f9c859ac17e2e05a0f249868ce4f191f69edd31d F src/vtab.c e39e011d7443a8d574b1b9cde207a35522e6df43 F src/walker.c 488c2660e13224ff70c0c82761118efb547f8f0d -F src/where.c a102f06e77603fc3db0d1bc9ad637fb034bb7520 +F src/where.c 90b1fa8ad8b27b3e80f380bb745d38f500e37566 F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/alias.test 597662c5d777a122f9a3df0047ea5c5bd383a911 @@ -656,6 +656,7 @@ F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2 F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2 F test/where6.test 42c4373595f4409d9c6a9987b4a60000ad664faf F test/where7.test 3ed6a8cb7d3e1e8c289e5e21f460c7a4d3f129e2 +F test/where8.test fa8782186387b3391266e5e7abacf9591dbb9ee8 F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31 F test/zeroblob.test 792124852ec61458a2eb527b5091791215e0be95 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b @@ -686,7 +687,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 03d0350441ef5fa5a9f22fcb0b760200614cf9f9 -R e6df0aec1c2fd3ed6e98c372cd9a8d74 +P 0b972f14f00340cbd4e310dea6d1a4f1c05f5628 +R 618248255cc0db65a1e451c19324ecc5 U danielk1977 -Z da88efba546d400f6b796c5b557437c9 +Z ebf06715c02d5bd51f7609b7ab009886 diff --git a/manifest.uuid b/manifest.uuid index 378b5423f0..240890e43b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0b972f14f00340cbd4e310dea6d1a4f1c05f5628 \ No newline at end of file +bff460ec2c3e250de034a6b34312b897bb2f3749 \ No newline at end of file diff --git a/src/where.c b/src/where.c index ff557c2df0..d6dc6710f7 100644 --- a/src/where.c +++ b/src/where.c @@ -16,7 +16,7 @@ ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** -** $Id: where.c,v 1.348 2008/12/29 14:51:06 danielk1977 Exp $ +** $Id: where.c,v 1.349 2008/12/29 18:33:33 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -734,7 +734,7 @@ static void transferJoinMarkings(Expr *pDerived, Expr *pBase){ ** WhereTerm.u.pOrInfo = a dynamically allocated WhereOrTerm object ** ** The term being analyzed must have two or more of OR-connected subterms. -** A single subterms might be a set of AND-connected sub-subterms. +** A single subterm might be a set of AND-connected sub-subterms. ** Examples of terms under analysis: ** ** (A) t1.x=t2.y OR t1.x=t2.z OR t1.y=15 OR t1.z=t3.a+5 diff --git a/test/where8.test b/test/where8.test new file mode 100644 index 0000000000..276b893aed --- /dev/null +++ b/test/where8.test @@ -0,0 +1,232 @@ +# 2008 December 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 +# is testing of where.c. More specifically, the focus is the optimization +# of WHERE clauses that feature the OR operator. +# +# $Id: where8.test,v 1.1 2008/12/29 18:33:33 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Test organization: +# +# where8-1.*: Tests to demonstrate simple cases work with a single table +# in the FROM clause. +# +# where8-2.*: Tests surrounding virtual tables and the OR optimization. +# +# where8-3.*: Tests with more than one table in the FROM clause. +# + +proc execsql_status {sql {db db}} { + set result [uplevel $db eval [list $sql]] + concat $result [db status step] [db status sort] +} + +proc execsql_status2 {sql {db db}} { + set ::sqlite_search_count 0 +breakpoint + set result [uplevel [list execsql_status $sql $db]] + concat $result $::sqlite_search_count +} + +do_test where8-1.1 { + execsql { + CREATE TABLE t1(a, b, c); + CREATE INDEX i1 ON t1(a); + CREATE INDEX i2 ON t1(b); + + INSERT INTO t1 VALUES(1, 'one', 'I'); + INSERT INTO t1 VALUES(2, 'two', 'II'); + INSERT INTO t1 VALUES(3, 'three', 'III'); + INSERT INTO t1 VALUES(4, 'four', 'IV'); + INSERT INTO t1 VALUES(5, 'five', 'V'); + INSERT INTO t1 VALUES(6, 'six', 'VI'); + INSERT INTO t1 VALUES(7, 'seven', 'VII'); + INSERT INTO t1 VALUES(8, 'eight', 'VIII'); + INSERT INTO t1 VALUES(9, 'nine', 'IX'); + INSERT INTO t1 VALUES(10, 'ten', 'X'); + } +} {} + +do_test where8-1.2 { + execsql_status2 { SELECT c FROM t1 WHERE a = 1 OR b = 'nine' } +} {I IX 0 0 6} + +do_test where8-1.3 { + execsql_status2 { SELECT c FROM t1 WHERE a > 8 OR b = 'two' } +} {II IX X 0 0 6} + +do_test where8-1.4 { + execsql_status2 { SELECT c FROM t1 WHERE a > 8 OR b GLOB 't*' } +} {II III IX X 0 0 9} + +do_test where8-1.5 { + execsql_status2 { SELECT c FROM t1 WHERE a > 8 OR b GLOB 'f*' } +} {IV V IX X 0 0 9} + +do_test where8-1.6 { + execsql_status { SELECT c FROM t1 WHERE a = 1 OR b = 'three' ORDER BY rowid } +} {I III 0 0} + +do_test where8-1.7 { + execsql_status { SELECT c FROM t1 WHERE a = 1 OR b = 'three' ORDER BY a } +} {I III 0 1} + +do_test where8-1.8 { + # 18 searches. 9 on the index cursor and 9 on the table cursor. + execsql_status2 { SELECT c FROM t1 WHERE a > 1 AND c LIKE 'I%' } +} {II III IV IX 0 0 18} + +do_test where8-1.9 { + execsql_status2 { SELECT c FROM t1 WHERE a >= 9 OR b <= 'eight' } +} {VIII IX X 0 0 6} + +do_test where8-1.10 { + execsql_status2 { + SELECT c FROM t1 WHERE (a >= 9 AND c != 'X') OR b <= 'eight' + } +} {VIII IX 0 0 7} + +do_test where8-1.11 { + execsql_status2 { + SELECT c FROM t1 WHERE (a >= 4 AND a <= 6) OR b = 'nine' + } +} {IV V VI IX 0 0 10} + +do_test where8-1.12.1 { + execsql_status2 { + SELECT c FROM t1 WHERE a IN(1, 2, 3) OR a = 5 + } +} {I II III V 0 0 14} + +do_test where8-1.12.2 { + execsql_status2 { + SELECT c FROM t1 WHERE +a IN(1, 2, 3) OR +a = 5 + } +} {I II III V 9 0 9} + + +#-------------------------------------------------------------------------- +# Tests where8-2.*: Virtual tables +# + +if 0 { +ifcapable vtab { + # Register the 'echo' module used for testing virtual tables. + # + register_echo_module [sqlite3_connection_pointer db] + + do_test where8-2.1 { + execsql { + CREATE VIRTUAL TABLE e1 USING echo(t1); + SELECT b FROM e1; + } + } {one two three four five six seven eight nine ten} + + do_test where8-2.2.1 { + set echo_module "" + execsql { + SELECT c FROM e1 WHERE a=1 OR b='three'; + } + } {I III} + do_test where8-2.2.2 { + set echo_module + } {TODO: What should this be?} +} +} + +#-------------------------------------------------------------------------- +# Tests where8-3.*: Cases with multiple tables in the FROM clause. +# +do_test where8-3.1 { + execsql { + CREATE TABLE t2(d, e, f); + CREATE INDEX i3 ON t2(d); + CREATE INDEX i4 ON t2(e); + + INSERT INTO t2 VALUES(1, NULL, 'I'); + INSERT INTO t2 VALUES(2, 'four', 'IV'); + INSERT INTO t2 VALUES(3, NULL, 'IX'); + INSERT INTO t2 VALUES(4, 'sixteen', 'XVI'); + INSERT INTO t2 VALUES(5, NULL, 'XXV'); + INSERT INTO t2 VALUES(6, 'thirtysix', 'XXXVI'); + INSERT INTO t2 VALUES(7, 'fortynine', 'XLIX'); + INSERT INTO t2 VALUES(8, 'sixtyeight', 'LXIV'); + INSERT INTO t2 VALUES(9, 'eightyone', 'LXXXIX'); + INSERT INTO t2 VALUES(10, NULL, 'C'); + } +} {} + +do_test where8-3.2 { + execsql_status { + SELECT a, d FROM t1, t2 WHERE b=e + } +} {4 2 9 0} + +do_test where8-3.3 { + execsql_status { + SELECT a, d FROM t1, t2 WHERE (a = 2 OR a = 3) AND d = 6 + } +} {2 6 3 6 0 0} + +do_test where8-3.4 { + execsql_status { + SELECT a, d FROM t1, t2 WHERE (a = 2 OR a = 3) AND d = a + } +} {2 2 3 3 0 0} + +do_test where8-3.5 { + execsql_status { + SELECT a, d FROM t1, t2 WHERE (a = 2 OR a = 3) AND (d = a OR e = 'sixteen') + } +} {2 2 2 4 3 3 3 4 0 0} + +do_test where8-3.6 { + # The first part of the WHERE clause in this query, (a=2 OR a=3) is + # transformed into "a IN (2, 3)". This is why the sort is required. + # + execsql_status { + SELECT a, d + FROM t1, t2 + WHERE (a = 2 OR a = 3) AND (d = a OR e = 'sixteen') + ORDER BY t1.rowid + } +} {2 2 2 4 3 3 3 4 0 1} +do_test where8-3.7 { + execsql_status { + SELECT a, d + FROM t1, t2 + WHERE a = 2 AND (d = a OR e = 'sixteen') + ORDER BY t1.rowid + } +} {2 2 2 4 0 0} +do_test where8-3.8 { + execsql_status { + SELECT a, d + FROM t1, t2 + WHERE (a = 2 OR b = 'three') AND (d = a OR e = 'sixteen') + ORDER BY t1.rowid + } +} {2 2 2 4 3 3 3 4 0 0} + +do_test where8-3.9 { + execsql_status { + SELECT a, d + FROM t1, t2 + WHERE (a = 2 OR b = 'three' OR c = 'IX') AND (d = a OR e = 'sixteen') + ORDER BY t1.rowid + } +} {2 2 2 4 3 3 3 4 9 4 9 9 9 0} + +finish_test +