SQLite

Check-in [063755c815]
Login

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

Overview
Comment:Add tests to restore full coverage of fts5 code.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 063755c81574800e7db12a42e17d982a8c1e5181
User & Date: dan 2016-02-02 21:19:21.156
Context
2016-02-03
01:55
Enhance the internal sqlite3VdbeAddOpList() interface to automatically update jump destinations. Use this feature to simplify the AUTOINCREMENT code generator. (check-in: ae8b9d2edf user: drh tags: trunk)
2016-02-02
21:19
Add tests to restore full coverage of fts5 code. (check-in: 063755c815 user: dan tags: trunk)
17:40
Enhance the performance of fts5 AND and OR queries. (check-in: 62ea9e5ab8 user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ext/fts5/fts5_expr.c.
1333
1334
1335
1336
1337
1338
1339
1340

1341
1342
1343
1344
1345
1346
1347
    /* If not at EOF but the current rowid occurs earlier than iFirst in
    ** the iteration order, move to document iFirst or later. */
    if( pRoot->bEof==0 && fts5RowidCmp(p, pRoot->iRowid, iFirst)<0 ){
      rc = fts5ExprNodeNext(p, pRoot, 1, iFirst);
    }

    /* If the iterator is not at a real match, skip forward until it is. */
    while( pRoot->bNomatch && rc==SQLITE_OK && pRoot->bEof==0 ){

      rc = fts5ExprNodeNext(p, pRoot, 0, 0);
    }
  }
  return rc;
}

/*







|
>







1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
    /* If not at EOF but the current rowid occurs earlier than iFirst in
    ** the iteration order, move to document iFirst or later. */
    if( pRoot->bEof==0 && fts5RowidCmp(p, pRoot->iRowid, iFirst)<0 ){
      rc = fts5ExprNodeNext(p, pRoot, 1, iFirst);
    }

    /* If the iterator is not at a real match, skip forward until it is. */
    while( pRoot->bNomatch ){
      assert( pRoot->bEof==0 && rc==SQLITE_OK );
      rc = fts5ExprNodeNext(p, pRoot, 0, 0);
    }
  }
  return rc;
}

/*
Changes to ext/fts5/test/fts5fault1.test.
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
} -test {
  faultsim_test_result {0 {}} {1 {vtable constructor failed: t1}}
}

reset_db
do_execsql_test 4.0 {
  CREATE VIRTUAL TABLE t2 USING fts5(a, b);
  INSERT INTO t2 VALUES('m f a jj th q jr ar',   'hj n h h sg j i m');
  INSERT INTO t2 VALUES('nr s t g od j kf h',    'sb h aq rg op rb n nl');
  INSERT INTO t2 VALUES('do h h pb p p q fr',    'c rj qs or cr a l i');
  INSERT INTO t2 VALUES('lk gp t i lq mq qm p',  'h mr g f op ld aj h');
  INSERT INTO t2 VALUES('ct d sq kc qi k f j',   'sn gh c of g s qt q');
  INSERT INTO t2 VALUES('d ea d d om mp s ab',   'dm hg l df cm ft pa c');
  INSERT INTO t2 VALUES('tc dk c jn n t sr ge',  'a a kn bc n i af h');
  INSERT INTO t2 VALUES('ie ii d i b sa qo rf',  'a h m aq i b m fn');







|







68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
} -test {
  faultsim_test_result {0 {}} {1 {vtable constructor failed: t1}}
}

reset_db
do_execsql_test 4.0 {
  CREATE VIRTUAL TABLE t2 USING fts5(a, b);
  INSERT INTO t2 VALUES('m f a jj th q gi ar',   'hj n h h sg j i m');
  INSERT INTO t2 VALUES('nr s t g od j kf h',    'sb h aq rg op rb n nl');
  INSERT INTO t2 VALUES('do h h pb p p q fr',    'c rj qs or cr a l i');
  INSERT INTO t2 VALUES('lk gp t i lq mq qm p',  'h mr g f op ld aj h');
  INSERT INTO t2 VALUES('ct d sq kc qi k f j',   'sn gh c of g s qt q');
  INSERT INTO t2 VALUES('d ea d d om mp s ab',   'dm hg l df cm ft pa c');
  INSERT INTO t2 VALUES('tc dk c jn n t sr ge',  'a a kn bc n i af h');
  INSERT INTO t2 VALUES('ie ii d i b sa qo rf',  'a h m aq i b m fn');
91
92
93
94
95
96
97

98
99
100
101
102
103
104
  3 { f*  }           {1 3 4 5 6 8 9 10}
  4 { m OR f }        {1 4 5 8 9 10}
  5 { sn + gh }       {5}
  6 { "sn gh" }       {5}
  7 { NEAR(r a, 5) }  {9}
  8 { m* f* }         {1 4 6 8 9 10}
  9 { m* + f* }       {1 8}

} {
  do_faultsim_test 4.$tn -prep {
    faultsim_restore_and_reopen
  } -body "
    execsql { SELECT rowid FROM t2 WHERE t2 MATCH '$expr' }
  " -test "
    faultsim_test_result {[list 0 $res]} {1 {vtable constructor failed: t2}}







>







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  3 { f*  }           {1 3 4 5 6 8 9 10}
  4 { m OR f }        {1 4 5 8 9 10}
  5 { sn + gh }       {5}
  6 { "sn gh" }       {5}
  7 { NEAR(r a, 5) }  {9}
  8 { m* f* }         {1 4 6 8 9 10}
  9 { m* + f* }       {1 8}
  10 { c NOT p }       {5 6 7 10}
} {
  do_faultsim_test 4.$tn -prep {
    faultsim_restore_and_reopen
  } -body "
    execsql { SELECT rowid FROM t2 WHERE t2 MATCH '$expr' }
  " -test "
    faultsim_test_result {[list 0 $res]} {1 {vtable constructor failed: t2}}
Changes to ext/fts5/test/fts5fault2.test.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# This file is focused on OOM errors.
#

source [file join [file dirname [info script]] fts5_common.tcl]
source $testdir/malloc_common.tcl
set testprefix fts5fault2

# If SQLITE_ENABLE_FTS3 is defined, omit this file.
ifcapable !fts5 {
  finish_test
  return
}

set doc [string trim [string repeat "x y z " 200]]
do_execsql_test 1.0 {







|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# This file is focused on OOM errors.
#

source [file join [file dirname [info script]] fts5_common.tcl]
source $testdir/malloc_common.tcl
set testprefix fts5fault2

# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
ifcapable !fts5 {
  finish_test
  return
}

set doc [string trim [string repeat "x y z " 200]]
do_execsql_test 1.0 {
Changes to ext/fts5/test/fts5fault7.test.
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109







110
111
112
  CREATE VIRTUAL TABLE xy USING fts5(x);
  INSERT INTO xy(rowid, x) VALUES(1, '1 2 3');
  INSERT INTO xy(rowid, x) VALUES(2, '2 3 4');
  INSERT INTO xy(rowid, x) VALUES(3, '3 4 5');
}
faultsim_save_and_close

do_faultsim_test 2 -faults oom-* -prep {
  faultsim_restore_and_reopen
} -body {
  db eval { UPDATE OR REPLACE xy SET rowid=3 WHERE rowid = 2 }
} -test {
  faultsim_test_result {0 {}}
}









finish_test








|







>
>
>
>
>
>
>



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
  CREATE VIRTUAL TABLE xy USING fts5(x);
  INSERT INTO xy(rowid, x) VALUES(1, '1 2 3');
  INSERT INTO xy(rowid, x) VALUES(2, '2 3 4');
  INSERT INTO xy(rowid, x) VALUES(3, '3 4 5');
}
faultsim_save_and_close

do_faultsim_test 2.1 -faults oom-* -prep {
  faultsim_restore_and_reopen
} -body {
  db eval { UPDATE OR REPLACE xy SET rowid=3 WHERE rowid = 2 }
} -test {
  faultsim_test_result {0 {}}
}

# Test fault-injection when an empty expression is parsed.
#
do_faultsim_test 2.2 -faults oom-* -body {
  db eval { SELECT * FROM xy('""') }
} -test {
  faultsim_test_result {0 {}}
}

finish_test

Changes to ext/fts5/test/fts5fault8.test.
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51





52


53
54
55
ifcapable !fts5 {
  finish_test
  return
}

foreach_detail_mode $testprefix {

fts5_aux_test_functions db
do_execsql_test 1.0 {
  CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=%DETAIL%);
  INSERT INTO t1 VALUES('a b c d', '1 2 3 4');
  INSERT INTO t1 VALUES('a b a b', NULL);
  INSERT INTO t1 VALUES(NULL, '1 2 1 2');
}

do_faultsim_test 1 -faults oom-* -body {
  execsql { 
    SELECT rowid, fts5_test_poslist(t1) FROM t1 WHERE t1 MATCH 'b OR 2' 
  }
} -test {
  faultsim_test_result {0 {1 {0.0.1 1.1.1} 2 {0.0.1 0.0.3} 3 {1.1.1 1.1.3}}} \
                       {1 SQLITE_NOMEM}
}

do_faultsim_test 2 -faults oom-* -body {
  execsql { 
    INSERT INTO t1(t1) VALUES('integrity-check');
  }
} -test {
  faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
}






}



finish_test








|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
|
<
|
|
|

>
>
>
>
>
|
>
>



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
ifcapable !fts5 {
  finish_test
  return
}

foreach_detail_mode $testprefix {

  fts5_aux_test_functions db
  do_execsql_test 1.0 {
    CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=%DETAIL%);
    INSERT INTO t1 VALUES('a b c d', '1 2 3 4');
    INSERT INTO t1 VALUES('a b a b', NULL);
    INSERT INTO t1 VALUES(NULL, '1 2 1 2');
  }
  
  do_faultsim_test 1 -faults oom-* -body {
    execsql { 
      SELECT rowid, fts5_test_poslist(t1) FROM t1 WHERE t1 MATCH 'b OR 2' 
    }
  } -test {
    faultsim_test_result {0 {1 {0.0.1 1.1.1} 2 {0.0.1 0.0.3} 3 {1.1.1 1.1.3}}} \
                         {1 SQLITE_NOMEM}
  }
  
  do_faultsim_test 2 -faults oom-* -body {

    execsql { INSERT INTO t1(t1) VALUES('integrity-check') }

  } -test {
    faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
  }

  if {[detail_is_none]==0} {
    do_faultsim_test 3 -faults oom-* -body {
      execsql { SELECT rowid FROM t1('b:2') }
    } -test {
      faultsim_test_result {0 {1 3}} {1 SQLITE_NOMEM}
    }
  }
} ;# foreach_detail_mode...

finish_test

Added ext/fts5/test/fts5faultA.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 2016 February 2
#
# 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 is focused on OOM errors.
#

source [file join [file dirname [info script]] fts5_common.tcl]
source $testdir/malloc_common.tcl
set testprefix fts5faultA

# If SQLITE_ENABLE_FTS3 is defined, omit this file.
ifcapable !fts5 {
  finish_test
  return
}

foreach_detail_mode $testprefix {
  do_execsql_test 1.0 {
    CREATE VIRTUAL TABLE o1 USING fts5(a, detail=%DETAIL%);
    INSERT INTO o1(o1, rank) VALUES('pgsz', 32);
  
    WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<300 )
    INSERT INTO o1 SELECT 'A B C' FROM s;
  
    INSERT INTO o1 VALUES('A X C');
  
    WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<300 )
    INSERT INTO o1 SELECT 'A B C' FROM s;
  }
  
  do_faultsim_test 1 -faults oom* -prep {
    sqlite3 db test.db
  } -body {
    execsql { SELECT rowid FROM o1('a NOT b') }
  } -test {
    faultsim_test_result {0 301}
  }
}

do_execsql_test 2.0 {
  CREATE VIRTUAL TABLE o2 USING fts5(a);
  
  INSERT INTO o2 VALUES('A B C');
  WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<300 )
  INSERT INTO o2 SELECT group_concat('A B C ') FROM s;
}

do_faultsim_test 2 -faults oom* -prep {
  sqlite3 db test.db
} -body {
  execsql { SELECT rowid FROM o2('a+b+c NOT xyz') }
} -test {
  faultsim_test_result {0 {1 2}}
}
finish_test

Changes to ext/fts5/test/fts5simple3.test.
34
35
36
37
38
39
40









































41
42
43
44
do_execsql_test 1.2 {
  SELECT rowid, fts5_test_collist(t1) FROM t1('b:x');
} {2 0.1}

do_execsql_test 1.3 {
  SELECT rowid, fts5_test_collist(t1) FROM t1('b:a');
} {}











































finish_test








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




34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
do_execsql_test 1.2 {
  SELECT rowid, fts5_test_collist(t1) FROM t1('b:x');
} {2 0.1}

do_execsql_test 1.3 {
  SELECT rowid, fts5_test_collist(t1) FROM t1('b:a');
} {}

#-------------------------------------------------------------------------
# Create detail=col and detail=full tables with 998 columns.
#
foreach_detail_mode $testprefix {
  if {[detail_is_none]} continue

  do_test 2.1 {
    execsql { DROP TABLE IF EXISTS t2 }
    set cols [list]
    set vals [list]
    for {set i 1} {$i <= 998} {incr i} {
      lappend cols "c$i"
      lappend vals "'val$i'"
    }
    execsql "CREATE VIRTUAL TABLE t2 USING fts5(detail=%DETAIL%,[join $cols ,])"
  } {}
  
  do_test 2.2 {
    execsql "INSERT INTO t2 VALUES([join $vals ,])"
  } {}
  
  foreach {tn q res} {
    1 { c1:val1 }     1
    2 { c300:val300 } 1
    3 { c300:val1 } {}
    4 { c1:val300 } {}
  } {
    do_execsql_test 2.3.$tn {
      SELECT rowid FROM t2($q)
    } $res
  }
}

do_execsql_test 3.0 {
  CREATE VIRTUAL TABLE x3 USING fts5(one);
  INSERT INTO x3 VALUES('a b c');
  INSERT INTO x3 VALUES('c b a');
  INSERT INTO x3 VALUES('o t t');
  SELECT * FROM x3('x OR y OR z');
}


finish_test