Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add a couple of extra tests for the "WHERE ... OR" optimization. (CVS 6077) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
35c87585b81866e73a58adffe6af79dd |
User & Date: | danielk1977 2008-12-30 12:00:12.000 |
Context
2008-12-30
| ||
13:21 | Do not run savepoint4.test (crash simulation tests) in permutations.test. It slows things down too much. (CVS 6078) (check-in: 2df02b543e user: danielk1977 tags: trunk) | |
12:00 | Add a couple of extra tests for the "WHERE ... OR" optimization. (CVS 6077) (check-in: 35c87585b8 user: danielk1977 tags: trunk) | |
09:45 | Fix a bug in where.c causing a malfunction when an INDEXED BY clause specified an unusable index on other than the leftmost table in the FROM clause. Ticket #3560. (CVS 6076) (check-in: f8ff021212 user: danielk1977 tags: trunk) | |
Changes
Changes to src/where.c.
︙ | ︙ | |||
12 13 14 15 16 17 18 | ** This module contains C code that generates VDBE code used to process ** the WHERE clause of SQL statements. This module is responsible for ** generating the code that loops through a table looking for applicable ** rows. Indices are selected and used to speed the search when doing ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ** This module contains C code that generates VDBE code used to process ** the WHERE clause of SQL statements. This module is responsible for ** generating the code that loops through a table looking for applicable ** rows. Indices are selected and used to speed the search when doing ** 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.352 2008/12/30 12:00:12 danielk1977 Exp $ */ #include "sqliteInt.h" /* ** Trace output macros */ #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) |
︙ | ︙ | |||
518 519 520 521 522 523 524 | static u16 operatorMask(int op){ u16 c; assert( allowedOp(op) ); if( op==TK_IN ){ c = WO_IN; }else if( op==TK_ISNULL ){ c = WO_ISNULL; | < < < | 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | static u16 operatorMask(int op){ u16 c; assert( allowedOp(op) ); if( op==TK_IN ){ c = WO_IN; }else if( op==TK_ISNULL ){ c = WO_ISNULL; }else{ assert( (WO_EQ<<(op-TK_EQ)) < 0x7fff ); c = (u16)(WO_EQ<<(op-TK_EQ)); } assert( op!=TK_ISNULL || c==WO_ISNULL ); assert( op!=TK_IN || c==WO_IN ); assert( op!=TK_EQ || c==WO_EQ ); assert( op!=TK_LT || c==WO_LT ); assert( op!=TK_LE || c==WO_LE ); assert( op!=TK_GT || c==WO_GT ); assert( op!=TK_GE || c==WO_GE ); return c; |
︙ | ︙ |
Changes to test/where8.test.
︙ | ︙ | |||
8 9 10 11 12 13 14 | # 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. # | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # 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.2 2008/12/30 12:00:12 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 |
︙ | ︙ | |||
30 31 32 33 34 35 36 | 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 | < | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 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 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); |
︙ | ︙ | |||
110 111 112 113 114 115 116 117 118 119 120 121 122 123 | } {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 { | > > > > > > > > > > > > > > > > > > > > > > > > > > | 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | } {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} do_test where8-1.13 { execsql_status2 { SELECT c FROM t1 WHERE a = 2 OR b = 'three' OR a = 4 OR b = 'five' OR a = 6 ORDER BY rowid } } {II III IV V VI 0 0 15} do_test where8-1.14 { execsql_status2 { SELECT c FROM t1 WHERE a = 2 OR b = 'three' OR a = 4 OR b = 'five' OR a = 6 OR b = 'seven' OR a = 8 OR b = 'nine' OR a = 10 ORDER BY rowid } } {II III IV V VI VII VIII IX X 0 0 26} do_test where8-1.15 { execsql_status2 { SELECT c FROM t1 WHERE a BETWEEN 2 AND 4 OR b = 'nine' ORDER BY rowid } } {II III IV IX 0 0 10} #-------------------------------------------------------------------------- # Tests where8-2.*: Virtual tables # if 0 { |
︙ | ︙ | |||
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | 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 | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | 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 { # The "OR c = 'IX'" term forces a linear scan. 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} do_test where8-3.10 { execsql_status { SELECT d FROM t2 WHERE e IS NULL OR e = 'four' } } {1 2 3 5 10 0 0} do_test where8-3.11 { execsql_status { SELECT a, d FROM t1, t2 WHERE (a=d OR b=e) AND a<5 ORDER BY a } } {1 1 2 2 3 3 4 2 4 4 0 0} do_test where8-3.12 { execsql_status { SELECT a, d FROM t1, t2 WHERE (a=d OR b=e) AND +a<5 ORDER BY a } } {1 1 2 2 3 3 4 2 4 4 0 0} do_test where8-3.13 { execsql_status { SELECT a, d FROM t1, t2 WHERE (a=d OR b=e) AND +a<5 } } {1 1 2 2 3 3 4 2 4 4 9 0} do_test where8-3.14 { execsql_status { SELECT c FROM t1 WHERE a > (SELECT d FROM t2 WHERE e = b) OR a = 5 } } {IV V 9 0} do_test where8-3.15 { execsql_status { SELECT c FROM t1, t2 WHERE a BETWEEN 1 AND 2 OR a = ( SELECT sum(e IS NULL) FROM t2 AS inner WHERE t2.d>inner.d ) } } {I I I I I I I I I I II II II II II II II II II II III III III III III 99 0} #----------------------------------------------------------------------- # The following tests - where8-4.* - verify that adding or removing # indexes does not change the results returned by various queries. # do_test where8-4.1 { execsql { CREATE TABLE t3(a INTEGER, b REAL, c TEXT); CREATE TABLE t4(f INTEGER, g REAL, h TEXT); } } {} finish_test |
Added test/where8m.test.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # 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: where8m.test,v 1.1 2008/12/30 12:00:12 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl source $testdir/malloc_common.tcl do_malloc_test where8m-1 -sqlprep { CREATE TABLE t1(a, b, c); CREATE INDEX i1 ON t1(a); CREATE INDEX i2 ON t1(b); } -sqlbody { SELECT c FROM t1 WHERE a = 2 OR b = 'three' OR a = 4 OR b = 'five' OR a = 6 OR b = 'seven' OR a = 8 OR b = 'nine' OR a = 10 ORDER BY rowid; SELECT c FROM t1 WHERE a = 1 OR a = 2 OR a = 3 OR a = 4 OR a = 5 OR a = 6; SELECT c FROM t1 WHERE a BETWEEN 1 AND 3 AND b < 5 AND b > 2 AND c = 4; } finish_test |