SQLite

Check-in [0bacb879e1]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Disable the LIKE optimization if the column on the left-hand-side of the LIKE operator belongs to a virtual table.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0bacb879e18026f2a8e22fe3e4bc8d27de5c4416
User & Date: dan 2012-03-29 14:29:07.705
Context
2012-03-29
15:11
Merge fts4-incr-merge with trunk. (check-in: 4d6de3e9be user: dan tags: trunk)
14:29
Disable the LIKE optimization if the column on the left-hand-side of the LIKE operator belongs to a virtual table. (check-in: 0bacb879e1 user: dan tags: trunk)
07:51
Fix an out of date comment on sqlite3ArrayAllocate(). (check-in: 4afdd5ae53 user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/where.c.
682
683
684
685
686
687
688

689


690
691
692
693
694
695
696
    return 0;
  }
#ifdef SQLITE_EBCDIC
  if( *pnoCase ) return 0;
#endif
  pList = pExpr->x.pList;
  pLeft = pList->a[1].pExpr;

  if( pLeft->op!=TK_COLUMN || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT ){


    /* IMP: R-02065-49465 The left-hand side of the LIKE or GLOB operator must
    ** be the name of an indexed column with TEXT affinity. */
    return 0;
  }
  assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */

  pRight = pList->a[0].pExpr;







>
|
>
>







682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
    return 0;
  }
#ifdef SQLITE_EBCDIC
  if( *pnoCase ) return 0;
#endif
  pList = pExpr->x.pList;
  pLeft = pList->a[1].pExpr;
  if( pLeft->op!=TK_COLUMN 
   || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT 
   || IsVirtual(pLeft->pTab)
  ){
    /* IMP: R-02065-49465 The left-hand side of the LIKE or GLOB operator must
    ** be the name of an indexed column with TEXT affinity. */
    return 0;
  }
  assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */

  pRight = pList->a[0].pExpr;
Changes to test/vtab1.test.
11
12
13
14
15
16
17

18
19
20
21
22
23
24
# This file implements regression tests for SQLite library.  The
# focus of this file is creating and dropping virtual tables.
#
# $Id: vtab1.test,v 1.57 2008/08/01 17:51:47 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl


ifcapable !vtab||!schema_pragmas {
  finish_test
  return
}

#----------------------------------------------------------------------







>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# This file implements regression tests for SQLite library.  The
# focus of this file is creating and dropping virtual tables.
#
# $Id: vtab1.test,v 1.57 2008/08/01 17:51:47 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix vtab1

ifcapable !vtab||!schema_pragmas {
  finish_test
  return
}

#----------------------------------------------------------------------
38
39
40
41
42
43
44



45
46
47
48
49
50
51
# in that file for the special behaviour of the Tcl $echo_module variable.
#
# TODO: 
#   * How to test the sqlite3_index_constraint_usage.omit field?
#   * vtab1-5.*
#
# vtab1-14.*: Test 'IN' constraints - i.e. "SELECT * FROM t1 WHERE id IN(...)"



#


#----------------------------------------------------------------------
# Test cases vtab1.1.*
#








>
>
>







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# in that file for the special behaviour of the Tcl $echo_module variable.
#
# TODO: 
#   * How to test the sqlite3_index_constraint_usage.omit field?
#   * vtab1-5.*
#
# vtab1-14.*: Test 'IN' constraints - i.e. "SELECT * FROM t1 WHERE id IN(...)"
#
# vtab1-18.*: Check that the LIKE optimization is not applied when the lhs
#             is a virtual table column.
#


#----------------------------------------------------------------------
# Test cases vtab1.1.*
#

1214
1215
1216
1217
1218
1219
1220







1221













































1222
      DROP TABLE e5;
      SAVEPOINT one;
      ROLLBACK TO one;
    COMMIT;
  }
} {}








unset -nocomplain echo_module_begin_fail













































finish_test







>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
      DROP TABLE e5;
      SAVEPOINT one;
      ROLLBACK TO one;
    COMMIT;
  }
} {}

#-------------------------------------------------------------------------
# The following tests - vtab1-18.* - test that the optimization of LIKE
# constraints in where.c plays well with virtual tables.
#
#   18.1.*: Case-insensitive LIKE.
#   18.2.*: Case-sensitive LIKE.
#
unset -nocomplain echo_module_begin_fail

do_execsql_test 18.1.0 {
  CREATE TABLE t6(a, b TEXT);
  CREATE INDEX i6 ON t6(b, a);
  INSERT INTO t6 VALUES(1, 'Peter');
  INSERT INTO t6 VALUES(2, 'Andrew');
  INSERT INTO t6 VALUES(3, 'James');
  INSERT INTO t6 VALUES(4, 'John');
  INSERT INTO t6 VALUES(5, 'Phillip');
  INSERT INTO t6 VALUES(6, 'Bartholomew');
  CREATE VIRTUAL TABLE e6 USING echo(t6);
}

foreach {tn sql res filter} {
  1.1 "SELECT a FROM e6 WHERE b>'James'" {4 1 5}
    {xFilter {SELECT rowid, * FROM 't6' WHERE b > ?} James}

  1.2 "SELECT a FROM e6 WHERE b>='J' AND b<'K'" {3 4}
    {xFilter {SELECT rowid, * FROM 't6' WHERE b >= ? AND b < ?} J K}

  1.3 "SELECT a FROM e6 WHERE b LIKE 'J%'" {3 4}
    {xFilter {SELECT rowid, * FROM 't6'}}

  1.4 "SELECT a FROM e6 WHERE b LIKE 'j%'" {3 4}
    {xFilter {SELECT rowid, * FROM 't6'}}
} {
  set echo_module {}
  do_execsql_test 18.$tn.1 $sql $res
  do_test         18.$tn.2 { lrange $::echo_module 2 end } $filter
}

do_execsql_test 18.2.0 {  PRAGMA case_sensitive_like = ON }
foreach {tn sql res filter} {
  2.1 "SELECT a FROM e6 WHERE b LIKE 'J%'" {3 4}
    {xFilter {SELECT rowid, * FROM 't6'}}

  2.2 "SELECT a FROM e6 WHERE b LIKE 'j%'" {}
    {xFilter {SELECT rowid, * FROM 't6'}}
} {
  set echo_module {}
  do_execsql_test 18.$tn.1 $sql $res
  do_test         18.$tn.2 { lrange $::echo_module 2 end } $filter
}
do_execsql_test 18.2.x {  PRAGMA case_sensitive_like = OFF }

finish_test