/ 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 Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3.c.

   368    368       if( (c & 0x80)==0 ) break;
   369    369     }
   370    370     *v = b;
   371    371     return (int)(p - pStart);
   372    372   }
   373    373   
   374    374   /*
   375         -** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to a
   376         -** 32-bit integer before it is returned.
          375  +** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to 
          376  +** a non-negative 32-bit integer before it is returned.
   377    377   */
   378    378   int sqlite3Fts3GetVarint32(const char *p, int *pi){
   379    379     u32 a;
   380    380   
   381    381   #ifndef fts3GetVarint32
   382    382     GETVARINT_INIT(a, p, 0,  0x00,     0x80, *pi, 1);
   383    383   #else
................................................................................
   385    385     assert( a & 0x80 );
   386    386   #endif
   387    387   
   388    388     GETVARINT_STEP(a, p, 7,  0x7F,     0x4000, *pi, 2);
   389    389     GETVARINT_STEP(a, p, 14, 0x3FFF,   0x200000, *pi, 3);
   390    390     GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
   391    391     a = (a & 0x0FFFFFFF );
   392         -  *pi = (int)(a | ((u32)(*p & 0x0F) << 28));
          392  +  *pi = (int)(a | ((u32)(*p & 0x07) << 28));
          393  +  assert( 0==(a & 0x80000000) );
          394  +  assert( *pi>=0 );
   393    395     return 5;
   394    396   }
   395    397   
   396    398   /*
   397    399   ** Return the number of bytes required to encode v as a varint
   398    400   */
   399    401   int sqlite3Fts3VarintLen(sqlite3_uint64 v){
................................................................................
  1843   1845       ** the size of zBuffer if required.  */
  1844   1846       if( !isFirstTerm ){
  1845   1847         zCsr += fts3GetVarint32(zCsr, &nPrefix);
  1846   1848       }
  1847   1849       isFirstTerm = 0;
  1848   1850       zCsr += fts3GetVarint32(zCsr, &nSuffix);
  1849   1851       
  1850         -    if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
         1852  +    assert( nPrefix>=0 && nSuffix>=0 );
         1853  +    if( &zCsr[nSuffix]>zEnd ){
  1851   1854         rc = FTS_CORRUPT_VTAB;
  1852   1855         goto finish_scan;
  1853   1856       }
  1854   1857       if( nPrefix+nSuffix>nAlloc ){
  1855   1858         char *zNew;
  1856   1859         nAlloc = (nPrefix+nSuffix) * 2;
  1857   1860         zNew = (char *)sqlite3_realloc(zBuffer, nAlloc);
................................................................................
  2653   2656         nOut += sqlite3Fts3PutVarint(&pOut[nOut], iDelta);
  2654   2657         pOut[nOut++] = 0x02;
  2655   2658         bWritten = 1;
  2656   2659       }
  2657   2660       fts3ColumnlistCopy(0, &p);
  2658   2661     }
  2659   2662   
  2660         -  while( p<pEnd && *p==0x01 ){
         2663  +  while( p<pEnd ){
  2661   2664       sqlite3_int64 iCol;
  2662   2665       p++;
  2663   2666       p += sqlite3Fts3GetVarint(p, &iCol);
  2664   2667       if( *p==0x02 ){
  2665   2668         if( bWritten==0 ){
  2666   2669           nOut += sqlite3Fts3PutVarint(&pOut[nOut], iDelta);
  2667   2670           bWritten = 1;

Changes to test/fts3aa.test.

   238    238   do_execsql_test 8.3 { COMMIT }
   239    239   do_execsql_test 8.4 {
   240    240     SELECT docid FROM t0 WHERE t0 MATCH 'abc';
   241    241   } {6 5}
   242    242   do_execsql_test 8.5 {
   243    243     SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"';
   244    244   } {}
   245         -
   246    245   
   247    246   do_execsql_test 9.1 {
   248    247     CREATE VIRTUAL TABLE t9 USING fts4(a, "", '---');
   249    248   }
   250    249   do_execsql_test 9.2 {
   251    250     CREATE VIRTUAL TABLE t10 USING fts3(<, b, c);
   252    251   }
   253    252   
   254    253   finish_test

Changes to test/fts3corrupt3.test.

    14     14   source $testdir/tester.tcl
    15     15   
    16     16   # If SQLITE_ENABLE_FTS3 is not defined, omit this file.
    17     17   ifcapable !fts3 { finish_test ; return }
    18     18   
    19     19   set ::testprefix fts3corrupt3
    20     20   
           21  +#-------------------------------------------------------------------------
           22  +# Test that fts3 does not choke on an oversized varint.
           23  +#
    21     24   do_execsql_test 1.0 {
           25  +  PRAGMA page_size = 512;
    22     26     CREATE VIRTUAL TABLE t1 USING fts3;
    23     27     BEGIN;
    24     28       INSERT INTO t1 VALUES('one');
    25     29       INSERT INTO t1 VALUES('one');
    26     30       INSERT INTO t1 VALUES('one');
    27     31     COMMIT;
    28     32   }
................................................................................
    32     36   do_execsql_test 1.2 {
    33     37     UPDATE t1_segdir SET root = X'00036F6E650EFFFFFFFFFFFFFFFFFFFFFFFF0200';
    34     38   }
    35     39   do_catchsql_test 1.3 {
    36     40     SELECT rowid FROM t1 WHERE t1 MATCH 'one'
    37     41   } {0 -1}
    38     42   
           43  +#-------------------------------------------------------------------------
           44  +# Interior node with the prefix or suffix count of an entry set to a
           45  +# negative value.
           46  +#
           47  +set doc1 [string repeat "x " 600]
           48  +set doc2 [string repeat "y " 600]
           49  +set doc3 [string repeat "z " 600]
           50  +
           51  +do_execsql_test 2.0 {
           52  +  CREATE VIRTUAL TABLE t2 USING fts3;
           53  +  BEGIN;
           54  +    INSERT INTO t2 VALUES($doc1);
           55  +    INSERT INTO t2 VALUES($doc2);
           56  +    INSERT INTO t2 VALUES($doc3);
           57  +  COMMIT;
           58  +}
           59  +do_execsql_test 2.1 {
           60  +  SELECT quote(root) from t2_segdir;
           61  +} {X'0101017900017A'}
    39     62   
    40     63   
    41     64   
    42     65   finish_test

Changes to test/fts3fault2.test.

   169    169     faultsim_restore_and_reopen
   170    170     db eval {SELECT * FROM sqlite_master}
   171    171   } -body {
   172    172     execsql { SELECT docid FROM t6 WHERE t6 MATCH '"a* b"' }
   173    173   } -test {
   174    174     faultsim_test_result {0 -1}
   175    175   }
          176  +
          177  +#-------------------------------------------------------------------------
          178  +# Inject faults into a query for an N-byte prefix that uses a prefix=N+1
          179  +# index.
          180  +reset_db
          181  +do_execsql_test 7.0 {
          182  +  CREATE VIRTUAL TABLE t7 USING fts4(x,prefix=2);
          183  +  INSERT INTO t7 VALUES('the quick brown fox');
          184  +  INSERT INTO t7 VALUES('jumped over the');
          185  +  INSERT INTO t7 VALUES('lazy dog');
          186  +}
          187  +do_faultsim_test 7.1 -faults oom* -body {
          188  +  execsql { SELECT docid FROM t7 WHERE t7 MATCH 't*' }
          189  +} -test {
          190  +  faultsim_test_result {0 {1 2}}
          191  +}
   176    192   
   177    193   finish_test
          194  +
          195  +

Added test/fts3misc.test.

            1  +# 2017 March 22
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#*************************************************************************
           11  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this script is testing the FTS3 module.
           13  +#
           14  +
           15  +set testdir [file dirname $argv0]
           16  +source $testdir/tester.tcl
           17  +set testprefix fts3misc
           18  +
           19  +# If SQLITE_ENABLE_FTS3 is defined, omit this file.
           20  +ifcapable !fts3 {
           21  +  finish_test
           22  +  return
           23  +}
           24  +
           25  +#-------------------------------------------------------------------------
           26  +# A self-join.
           27  +#
           28  +do_execsql_test 1.0 {
           29  +  CREATE VIRTUAL TABLE t1 USING fts3(a, b);
           30  +  INSERT INTO t1 VALUES('one', 'i');
           31  +  INSERT INTO t1 VALUES('one', 'ii');
           32  +  INSERT INTO t1 VALUES('two', 'i');
           33  +  INSERT INTO t1 VALUES('two', 'ii');
           34  +}
           35  +
           36  +do_execsql_test 1.1 {
           37  +  SELECT a.a, b.b FROM t1 a, t1 b WHERE a.t1 MATCH 'two' AND b.t1 MATCH 'i'
           38  +} {two i two i two i two i}
           39  +
           40  +#-------------------------------------------------------------------------
           41  +# FTS tables with 128 or more columns.
           42  +#
           43  +proc v1 {v} {
           44  +  set vector [list a b c d e f g h]
           45  +  set res [list]
           46  +  for {set i 0} {$i<8} {incr i} {
           47  +    if {$v & (1 << $i)} { lappend res [lindex $vector $i] }
           48  +  }
           49  +  set res
           50  +}
           51  +proc v2 {v} {
           52  +  set vector [list d e f g h i j k]
           53  +  set res [list]
           54  +  for {set i 0} {$i<8} {incr i} {
           55  +    if {$v & (1 << $i)} { lappend res [lindex $vector $i] }
           56  +  }
           57  +  set res
           58  +}
           59  +db func v1 v1
           60  +db func v2 v2
           61  +
           62  +do_test 2.0 {
           63  +  set cols [list]
           64  +  for {set i 0} {$i<200} {incr i} {
           65  +    lappend cols "c$i"
           66  +  }
           67  +  execsql "CREATE VIRTUAL TABLE t2 USING fts3([join $cols ,])"
           68  +  execsql {
           69  +    WITH data(i) AS (
           70  +      SELECT 1 UNION ALL SELECT i+1 FROM data WHERE i<200
           71  +    )
           72  +    INSERT INTO t2(c198, c199) SELECT v1(i), v2(i) FROM data;
           73  +  }
           74  +} {}
           75  +do_execsql_test 2.1 {
           76  +  SELECT rowid FROM t2 WHERE t2 MATCH '"a b c"'
           77  +} {
           78  +  7 15 23 31 39 47 55 63 71 79 87 95 103 111 
           79  +  119 127 135 143 151 159 167 175 183 191 199
           80  +}
           81  +do_execsql_test 2.2 {
           82  +  SELECT rowid FROM t2 WHERE t2 MATCH '"g h i"'
           83  +} {
           84  +  56 57 58 59 60 61 62 63 120 121 122 123 124 
           85  +  125 126 127 184 185 186 187 188 189 190 191
           86  +}
           87  +do_execsql_test 2.3 {
           88  +  SELECT rowid FROM t2 WHERE t2 MATCH '"i h"'
           89  +} {
           90  +}
           91  +do_execsql_test 2.4 {
           92  +  SELECT rowid FROM t2 WHERE t2 MATCH '"f e"'
           93  +} {
           94  +}
           95  +do_execsql_test 2.5 {
           96  +  SELECT rowid FROM t2 WHERE t2 MATCH '"e f"'
           97  +} {
           98  +  6 7 14 15 22 23 30 31 38 39 46 47 48 49 50 51 52 53 54 55 56 
           99  +  57 58 59 60 61 62 63 70 71 78 79 86 87 94 95 102 103 110 
          100  +  111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
          101  +  134 135 142 143 150 151 158 159 166 167 174 175 176 177 178 179 180 
          102  +  181 182 183 184 185 186 187 188 189 190 191 198 199
          103  +}
          104  +
          105  +# Range constraints on the docid using non-integer values.
          106  +#
          107  +do_execsql_test 2.6 {
          108  +  SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN NULL AND 45;
          109  +} {}
          110  +do_execsql_test 2.7 {
          111  +  SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN 11.5 AND 48.2;
          112  +} {
          113  +  14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 
          114  +  29 30 31 34 35 38 39 42 43 46 47 48
          115  +}
          116  +do_execsql_test 2.8 {
          117  +  SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN '11.5' AND '48.2';
          118  +} {
          119  +  14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 
          120  +  29 30 31 34 35 38 39 42 43 46 47 48
          121  +}
          122  +
          123  +
          124  +finish_test

Changes to test/permutations.test.

   262    262     fts3shared.test fts3snippet.test fts3sort.test fts3tok1.test
   263    263     fts3tok_err.test fts3varint.test fts4aa.test fts4check.test
   264    264     fts4content.test fts4docid.test fts4growth2.test fts4growth.test
   265    265     fts4incr.test fts4langid.test fts4lastrowid.test fts4merge2.test
   266    266     fts4merge4.test fts4merge.test fts4noti.test fts4onepass.test 
   267    267     fts4opt.test fts4unicode.test
   268    268     fts3corrupt3.test
          269  +  fts3misc.test
   269    270   }
   270    271   
   271    272   test_suite "fts5" -prefix "" -description {
   272    273     All FTS5 tests.
   273    274   } -files [glob -nocomplain $::testdir/../ext/fts5/test/*.test]
   274    275   
   275    276   test_suite "fts5-light" -prefix "" -description {