/ Check-in [352413ee]
Login

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

Overview
Comment:Further improvements to test coverage in fts3.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:352413eed469802665e7d2c17b7fe6e3a0b0b2209ce45bdc85fd4243cec50ea6
User & Date: dan 2017-04-17 16:07:25
Context
2017-04-17
18:02
Fix a problem in "PRAGMA foreign_key_check" in handling a WITHOUT ROWID child table with an INTEGER PRIMARY KEY parent key. Also, if an FK violation is detected in a WITHOUT ROWID child table, do not try to read and return the rowid. The second column returned by "PRAGMA foreign_key_check" in this case (WITHOUT ROWID child table) is now always set to NULL. check-in: 690870bd user: dan tags: trunk
16:07
Further improvements to test coverage in fts3. check-in: 352413ee user: dan tags: trunk
13:38
Improve coverage of code in fts3. check-in: 1a08a836 user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3.c.

368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
...
385
386
387
388
389
390
391
392


393
394
395
396
397
398
399
....
1843
1844
1845
1846
1847
1848
1849

1850
1851
1852
1853
1854
1855
1856
1857
....
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
    if( (c & 0x80)==0 ) break;
  }
  *v = b;
  return (int)(p - pStart);
}

/*
** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to a
** 32-bit integer before it is returned.
*/
int sqlite3Fts3GetVarint32(const char *p, int *pi){
  u32 a;

#ifndef fts3GetVarint32
  GETVARINT_INIT(a, p, 0,  0x00,     0x80, *pi, 1);
#else
................................................................................
  assert( a & 0x80 );
#endif

  GETVARINT_STEP(a, p, 7,  0x7F,     0x4000, *pi, 2);
  GETVARINT_STEP(a, p, 14, 0x3FFF,   0x200000, *pi, 3);
  GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
  a = (a & 0x0FFFFFFF );
  *pi = (int)(a | ((u32)(*p & 0x0F) << 28));


  return 5;
}

/*
** Return the number of bytes required to encode v as a varint
*/
int sqlite3Fts3VarintLen(sqlite3_uint64 v){
................................................................................
    ** the size of zBuffer if required.  */
    if( !isFirstTerm ){
      zCsr += fts3GetVarint32(zCsr, &nPrefix);
    }
    isFirstTerm = 0;
    zCsr += fts3GetVarint32(zCsr, &nSuffix);
    

    if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
      rc = FTS_CORRUPT_VTAB;
      goto finish_scan;
    }
    if( nPrefix+nSuffix>nAlloc ){
      char *zNew;
      nAlloc = (nPrefix+nSuffix) * 2;
      zNew = (char *)sqlite3_realloc(zBuffer, nAlloc);
................................................................................
      nOut += sqlite3Fts3PutVarint(&pOut[nOut], iDelta);
      pOut[nOut++] = 0x02;
      bWritten = 1;
    }
    fts3ColumnlistCopy(0, &p);
  }

  while( p<pEnd && *p==0x01 ){
    sqlite3_int64 iCol;
    p++;
    p += sqlite3Fts3GetVarint(p, &iCol);
    if( *p==0x02 ){
      if( bWritten==0 ){
        nOut += sqlite3Fts3PutVarint(&pOut[nOut], iDelta);
        bWritten = 1;







|
|







 







|
>
>







 







>
|







 







|







368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
...
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
....
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
....
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
    if( (c & 0x80)==0 ) break;
  }
  *v = b;
  return (int)(p - pStart);
}

/*
** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to 
** a non-negative 32-bit integer before it is returned.
*/
int sqlite3Fts3GetVarint32(const char *p, int *pi){
  u32 a;

#ifndef fts3GetVarint32
  GETVARINT_INIT(a, p, 0,  0x00,     0x80, *pi, 1);
#else
................................................................................
  assert( a & 0x80 );
#endif

  GETVARINT_STEP(a, p, 7,  0x7F,     0x4000, *pi, 2);
  GETVARINT_STEP(a, p, 14, 0x3FFF,   0x200000, *pi, 3);
  GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
  a = (a & 0x0FFFFFFF );
  *pi = (int)(a | ((u32)(*p & 0x07) << 28));
  assert( 0==(a & 0x80000000) );
  assert( *pi>=0 );
  return 5;
}

/*
** Return the number of bytes required to encode v as a varint
*/
int sqlite3Fts3VarintLen(sqlite3_uint64 v){
................................................................................
    ** the size of zBuffer if required.  */
    if( !isFirstTerm ){
      zCsr += fts3GetVarint32(zCsr, &nPrefix);
    }
    isFirstTerm = 0;
    zCsr += fts3GetVarint32(zCsr, &nSuffix);
    
    assert( nPrefix>=0 && nSuffix>=0 );
    if( &zCsr[nSuffix]>zEnd ){
      rc = FTS_CORRUPT_VTAB;
      goto finish_scan;
    }
    if( nPrefix+nSuffix>nAlloc ){
      char *zNew;
      nAlloc = (nPrefix+nSuffix) * 2;
      zNew = (char *)sqlite3_realloc(zBuffer, nAlloc);
................................................................................
      nOut += sqlite3Fts3PutVarint(&pOut[nOut], iDelta);
      pOut[nOut++] = 0x02;
      bWritten = 1;
    }
    fts3ColumnlistCopy(0, &p);
  }

  while( p<pEnd ){
    sqlite3_int64 iCol;
    p++;
    p += sqlite3Fts3GetVarint(p, &iCol);
    if( *p==0x02 ){
      if( bWritten==0 ){
        nOut += sqlite3Fts3PutVarint(&pOut[nOut], iDelta);
        bWritten = 1;

Changes to test/fts3aa.test.

238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
do_execsql_test 8.3 { COMMIT }
do_execsql_test 8.4 {
  SELECT docid FROM t0 WHERE t0 MATCH 'abc';
} {6 5}
do_execsql_test 8.5 {
  SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"';
} {}


do_execsql_test 9.1 {
  CREATE VIRTUAL TABLE t9 USING fts4(a, "", '---');
}
do_execsql_test 9.2 {
  CREATE VIRTUAL TABLE t10 USING fts3(<, b, c);
}

finish_test







<









238
239
240
241
242
243
244

245
246
247
248
249
250
251
252
253
do_execsql_test 8.3 { COMMIT }
do_execsql_test 8.4 {
  SELECT docid FROM t0 WHERE t0 MATCH 'abc';
} {6 5}
do_execsql_test 8.5 {
  SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"';
} {}


do_execsql_test 9.1 {
  CREATE VIRTUAL TABLE t9 USING fts4(a, "", '---');
}
do_execsql_test 9.2 {
  CREATE VIRTUAL TABLE t10 USING fts3(<, b, c);
}

finish_test

Changes to test/fts3corrupt3.test.

14
15
16
17
18
19
20



21

22
23
24
25
26
27
28
..
32
33
34
35
36
37
38



















39
40
41
42
source $testdir/tester.tcl

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

set ::testprefix fts3corrupt3




do_execsql_test 1.0 {

  CREATE VIRTUAL TABLE t1 USING fts3;
  BEGIN;
    INSERT INTO t1 VALUES('one');
    INSERT INTO t1 VALUES('one');
    INSERT INTO t1 VALUES('one');
  COMMIT;
}
................................................................................
do_execsql_test 1.2 {
  UPDATE t1_segdir SET root = X'00036F6E650EFFFFFFFFFFFFFFFFFFFFFFFF0200';
}
do_catchsql_test 1.3 {
  SELECT rowid FROM t1 WHERE t1 MATCH 'one'
} {0 -1}























finish_test







>
>
>

>







 







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




14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
..
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
source $testdir/tester.tcl

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

set ::testprefix fts3corrupt3

#-------------------------------------------------------------------------
# Test that fts3 does not choke on an oversized varint.
#
do_execsql_test 1.0 {
  PRAGMA page_size = 512;
  CREATE VIRTUAL TABLE t1 USING fts3;
  BEGIN;
    INSERT INTO t1 VALUES('one');
    INSERT INTO t1 VALUES('one');
    INSERT INTO t1 VALUES('one');
  COMMIT;
}
................................................................................
do_execsql_test 1.2 {
  UPDATE t1_segdir SET root = X'00036F6E650EFFFFFFFFFFFFFFFFFFFFFFFF0200';
}
do_catchsql_test 1.3 {
  SELECT rowid FROM t1 WHERE t1 MATCH 'one'
} {0 -1}

#-------------------------------------------------------------------------
# Interior node with the prefix or suffix count of an entry set to a
# negative value.
#
set doc1 [string repeat "x " 600]
set doc2 [string repeat "y " 600]
set doc3 [string repeat "z " 600]

do_execsql_test 2.0 {
  CREATE VIRTUAL TABLE t2 USING fts3;
  BEGIN;
    INSERT INTO t2 VALUES($doc1);
    INSERT INTO t2 VALUES($doc2);
    INSERT INTO t2 VALUES($doc3);
  COMMIT;
}
do_execsql_test 2.1 {
  SELECT quote(root) from t2_segdir;
} {X'0101017900017A'}



finish_test

Changes to test/fts3fault2.test.

169
170
171
172
173
174
175
176
















177


  faultsim_restore_and_reopen
  db eval {SELECT * FROM sqlite_master}
} -body {
  execsql { SELECT docid FROM t6 WHERE t6 MATCH '"a* b"' }
} -test {
  faultsim_test_result {0 -1}
}

















finish_test










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

>
>
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
  faultsim_restore_and_reopen
  db eval {SELECT * FROM sqlite_master}
} -body {
  execsql { SELECT docid FROM t6 WHERE t6 MATCH '"a* b"' }
} -test {
  faultsim_test_result {0 -1}
}

#-------------------------------------------------------------------------
# Inject faults into a query for an N-byte prefix that uses a prefix=N+1
# index.
reset_db
do_execsql_test 7.0 {
  CREATE VIRTUAL TABLE t7 USING fts4(x,prefix=2);
  INSERT INTO t7 VALUES('the quick brown fox');
  INSERT INTO t7 VALUES('jumped over the');
  INSERT INTO t7 VALUES('lazy dog');
}
do_faultsim_test 7.1 -faults oom* -body {
  execsql { SELECT docid FROM t7 WHERE t7 MATCH 't*' }
} -test {
  faultsim_test_result {0 {1 2}}
}

finish_test


Added test/fts3misc.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
120
121
122
123
124
# 2017 March 22
#
# 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 of this script is testing the FTS3 module.
#

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

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

#-------------------------------------------------------------------------
# A self-join.
#
do_execsql_test 1.0 {
  CREATE VIRTUAL TABLE t1 USING fts3(a, b);
  INSERT INTO t1 VALUES('one', 'i');
  INSERT INTO t1 VALUES('one', 'ii');
  INSERT INTO t1 VALUES('two', 'i');
  INSERT INTO t1 VALUES('two', 'ii');
}

do_execsql_test 1.1 {
  SELECT a.a, b.b FROM t1 a, t1 b WHERE a.t1 MATCH 'two' AND b.t1 MATCH 'i'
} {two i two i two i two i}

#-------------------------------------------------------------------------
# FTS tables with 128 or more columns.
#
proc v1 {v} {
  set vector [list a b c d e f g h]
  set res [list]
  for {set i 0} {$i<8} {incr i} {
    if {$v & (1 << $i)} { lappend res [lindex $vector $i] }
  }
  set res
}
proc v2 {v} {
  set vector [list d e f g h i j k]
  set res [list]
  for {set i 0} {$i<8} {incr i} {
    if {$v & (1 << $i)} { lappend res [lindex $vector $i] }
  }
  set res
}
db func v1 v1
db func v2 v2

do_test 2.0 {
  set cols [list]
  for {set i 0} {$i<200} {incr i} {
    lappend cols "c$i"
  }
  execsql "CREATE VIRTUAL TABLE t2 USING fts3([join $cols ,])"
  execsql {
    WITH data(i) AS (
      SELECT 1 UNION ALL SELECT i+1 FROM data WHERE i<200
    )
    INSERT INTO t2(c198, c199) SELECT v1(i), v2(i) FROM data;
  }
} {}
do_execsql_test 2.1 {
  SELECT rowid FROM t2 WHERE t2 MATCH '"a b c"'
} {
  7 15 23 31 39 47 55 63 71 79 87 95 103 111 
  119 127 135 143 151 159 167 175 183 191 199
}
do_execsql_test 2.2 {
  SELECT rowid FROM t2 WHERE t2 MATCH '"g h i"'
} {
  56 57 58 59 60 61 62 63 120 121 122 123 124 
  125 126 127 184 185 186 187 188 189 190 191
}
do_execsql_test 2.3 {
  SELECT rowid FROM t2 WHERE t2 MATCH '"i h"'
} {
}
do_execsql_test 2.4 {
  SELECT rowid FROM t2 WHERE t2 MATCH '"f e"'
} {
}
do_execsql_test 2.5 {
  SELECT rowid FROM t2 WHERE t2 MATCH '"e f"'
} {
  6 7 14 15 22 23 30 31 38 39 46 47 48 49 50 51 52 53 54 55 56 
  57 58 59 60 61 62 63 70 71 78 79 86 87 94 95 102 103 110 
  111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  134 135 142 143 150 151 158 159 166 167 174 175 176 177 178 179 180 
  181 182 183 184 185 186 187 188 189 190 191 198 199
}

# Range constraints on the docid using non-integer values.
#
do_execsql_test 2.6 {
  SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN NULL AND 45;
} {}
do_execsql_test 2.7 {
  SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN 11.5 AND 48.2;
} {
  14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 
  29 30 31 34 35 38 39 42 43 46 47 48
}
do_execsql_test 2.8 {
  SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN '11.5' AND '48.2';
} {
  14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 
  29 30 31 34 35 38 39 42 43 46 47 48
}


finish_test

Changes to test/permutations.test.

262
263
264
265
266
267
268

269
270
271
272
273
274
275
  fts3shared.test fts3snippet.test fts3sort.test fts3tok1.test
  fts3tok_err.test fts3varint.test fts4aa.test fts4check.test
  fts4content.test fts4docid.test fts4growth2.test fts4growth.test
  fts4incr.test fts4langid.test fts4lastrowid.test fts4merge2.test
  fts4merge4.test fts4merge.test fts4noti.test fts4onepass.test 
  fts4opt.test fts4unicode.test
  fts3corrupt3.test

}

test_suite "fts5" -prefix "" -description {
  All FTS5 tests.
} -files [glob -nocomplain $::testdir/../ext/fts5/test/*.test]

test_suite "fts5-light" -prefix "" -description {







>







262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
  fts3shared.test fts3snippet.test fts3sort.test fts3tok1.test
  fts3tok_err.test fts3varint.test fts4aa.test fts4check.test
  fts4content.test fts4docid.test fts4growth2.test fts4growth.test
  fts4incr.test fts4langid.test fts4lastrowid.test fts4merge2.test
  fts4merge4.test fts4merge.test fts4noti.test fts4onepass.test 
  fts4opt.test fts4unicode.test
  fts3corrupt3.test
  fts3misc.test
}

test_suite "fts5" -prefix "" -description {
  All FTS5 tests.
} -files [glob -nocomplain $::testdir/../ext/fts5/test/*.test]

test_suite "fts5-light" -prefix "" -description {