/ Check-in [1d018c35]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Add test cases to cover fts5 integrity-check code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1d018c35b9e81982df036f5e62a4a42219b54e02
User & Date: dan 2015-09-15 14:39:17
Context
2015-09-16
12:31
Fix typo in fts5.h. check-in: 07721c6c user: dan tags: trunk
2015-09-15
19:16
Merge enhancements from trunk. check-in: fc4d1de8 user: drh tags: begin-concurrent
17:31
Merge enhancements from trunk. check-in: 66fe0683 user: drh tags: cursor-hints
17:20
Merge trunk enhancements into the apple-osx branch. check-in: f12b8a0f user: drh tags: apple-osx
15:55
Merge the latest trunk enhancements with this branch. check-in: b7469c44 user: dan tags: sessions
14:39
Add test cases to cover fts5 integrity-check code. check-in: 1d018c35 user: dan tags: trunk
13:42
Reformat some code to make it easier to merge with sessions. No logic changes. check-in: eade355f user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5_index.c.

  4850   4850     for(i=iFirst; p->rc==SQLITE_OK && i<=iLast; i++){
  4851   4851       Fts5Data *pLeaf = fts5DataRead(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
  4852   4852       if( pLeaf ){
  4853   4853         if( !fts5LeafIsTermless(pLeaf) ) p->rc = FTS5_CORRUPT;
  4854   4854         if( i>=iNoRowid && 0!=fts5LeafFirstRowidOff(pLeaf) ) p->rc = FTS5_CORRUPT;
  4855   4855       }
  4856   4856       fts5DataRelease(pLeaf);
  4857         -    if( p->rc ) break;
  4858   4857     }
  4859   4858   }
  4860   4859   
  4861   4860   static void fts5IntegrityCheckPgidx(Fts5Index *p, Fts5Data *pLeaf){
  4862   4861     int iTermOff = 0;
  4863   4862     int ii;
  4864   4863   
................................................................................
  4917   4916     int rc2;
  4918   4917     int iIdxPrevLeaf = pSeg->pgnoFirst-1;
  4919   4918     int iDlidxPrevLeaf = pSeg->pgnoLast;
  4920   4919   
  4921   4920     if( pSeg->pgnoFirst==0 ) return;
  4922   4921   
  4923   4922     fts5IndexPrepareStmt(p, &pStmt, sqlite3_mprintf(
  4924         -      "SELECT segid, term, (pgno>>1), (pgno & 1) FROM '%q'.'%q_idx' WHERE segid=%d",
         4923  +      "SELECT segid, term, (pgno>>1), (pgno&1) FROM %Q.'%q_idx' WHERE segid=%d",
  4925   4924         pConfig->zDb, pConfig->zName, pSeg->iSegid
  4926   4925     ));
  4927   4926   
  4928   4927     /* Iterate through the b-tree hierarchy.  */
  4929   4928     while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
  4930   4929       i64 iRow;                     /* Rowid for this leaf */
  4931   4930       Fts5Data *pLeaf;              /* Data for this leaf */

Changes to ext/fts5/test/fts5corrupt3.test.

   150    150       set doc "x[string repeat $rnd 20]"
   151    151       execsql { INSERT INTO t1(rowid, x) VALUES($i, $doc) }
   152    152     }
   153    153   } {}
   154    154   
   155    155   do_3_test 3.10
   156    156   
   157         -}
   158         -
   159    157   #-------------------------------------------------------------------------
   160    158   # Test that segments that end unexpectedly are identified as corruption.
   161    159   #
   162    160   reset_db
   163    161   do_test 4.0 {
   164    162     execsql { 
   165    163       CREATE VIRTUAL TABLE t1 USING fts5(x);
................................................................................
   248    246         }
   249    247         set {} {}
   250    248       } {}
   251    249       catch { db eval ROLLBACK }
   252    250     }
   253    251   }
   254    252   
          253  +}
          254  +
          255  +#------------------------------------------------------------------------
          256  +#
          257  +reset_db
          258  +do_execsql_test 6.1.0 {
          259  +  CREATE VIRTUAL TABLE t1 USING fts5(a);
          260  +  INSERT INTO t1 VALUES('bbbbb ccccc');
          261  +  SELECT quote(block) FROM t1_data WHERE rowid>100;
          262  +} {X'000000180630626262626201020201056363636363010203040A'}
          263  +do_execsql_test 6.1.1 {
          264  +  UPDATE t1_data SET block = 
          265  +  X'000000180630626262626201020201056161616161010203040A'
          266  +  WHERE rowid>100;
          267  +}
          268  +do_catchsql_test 6.1.2 {
          269  +  INSERT INTO t1(t1) VALUES('integrity-check');
          270  +} {1 {database disk image is malformed}}
          271  +
          272  +#-------
          273  +reset_db
          274  +do_execsql_test 6.2.0 {
          275  +  CREATE VIRTUAL TABLE t1 USING fts5(a);
          276  +  INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
          277  +  INSERT INTO t1 VALUES('aa bb cc dd ee');
          278  +  SELECT pgno, quote(term) FROM t1_idx;
          279  +} {2 X'' 4 X'3064'}
          280  +do_execsql_test 6.2.1 {
          281  +  UPDATE t1_idx SET term = X'3065' WHERE pgno=4;
          282  +}
          283  +do_catchsql_test 6.2.2 {
          284  +  INSERT INTO t1(t1) VALUES('integrity-check');
          285  +} {1 {database disk image is malformed}}
          286  +
          287  +#-------
          288  +reset_db
          289  +do_execsql_test 6.3.0 {
          290  +  CREATE VIRTUAL TABLE t1 USING fts5(a);
          291  +  INSERT INTO t1 VALUES('abc abcdef abcdefghi');
          292  +  SELECT quote(block) FROM t1_data WHERE id>100;
          293  +}    {X'0000001C043061626301020204036465660102030703676869010204040808'}
          294  +do_execsql_test 6.3.1 {
          295  +  BEGIN;
          296  +    UPDATE t1_data SET block = 
          297  +      X'0000001C043061626301020204036465660102035003676869010204040808'
          298  +      ------------------------------------------^^---------------------
          299  +    WHERE id>100;
          300  +}
          301  +do_catchsql_test 6.3.2 {
          302  +  INSERT INTO t1(t1) VALUES('integrity-check');
          303  +} {1 {database disk image is malformed}}
          304  +do_execsql_test 6.3.3 {
          305  +  ROLLBACK;
          306  +  BEGIN;
          307  +    UPDATE t1_data SET block = 
          308  +      X'0000001C043061626301020204036465660102030750676869010204040808'
          309  +      --------------------------------------------^^-------------------
          310  +    WHERE id>100;
          311  +}
          312  +do_catchsql_test 6.3.3 {
          313  +  INSERT INTO t1(t1) VALUES('integrity-check');
          314  +} {1 {database disk image is malformed}}
          315  +do_execsql_test 6.3.4 {
          316  +  ROLLBACK;
          317  +  BEGIN;
          318  +    UPDATE t1_data SET block = 
          319  +      X'0000001C043061626301020204036465660102030707676869010204040850'
          320  +      --------------------------------------------------------------^^-
          321  +    WHERE id>100;
          322  +}
          323  +do_catchsql_test 6.3.5 {
          324  +  INSERT INTO t1(t1) VALUES('integrity-check');
          325  +} {1 {database disk image is malformed}}
          326  +do_execsql_test 6.3.6 {
          327  +  ROLLBACK;
          328  +  BEGIN;
          329  +    UPDATE t1_data SET block = 
          330  +      X'0000001C503061626301020204036465660102030707676869010204040808'
          331  +      ----------^^-----------------------------------------------------
          332  +    WHERE id>100;
          333  +}
          334  +do_catchsql_test 6.3.5 {
          335  +  INSERT INTO t1(t1) VALUES('integrity-check');
          336  +} {1 {database disk image is malformed}}
   255    337   
   256    338   sqlite3_fts5_may_be_corrupt 0
   257    339   finish_test
   258    340