/ Check-in [a21d60cb]
Login

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

Overview
Comment:Fix a problem in fts5fault1.test.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fts5
Files: files | file ages | folders
SHA1:a21d60cb2ac6463c012d82d1970d90da5da2a14a
User & Date: dan 2015-04-21 20:13:38
Context
2015-04-22
09:40
Update this branch with latest trunk changes. check-in: 9797482d user: dan tags: fts5
2015-04-21
20:13
Fix a problem in fts5fault1.test. check-in: a21d60cb user: dan tags: fts5
19:07
Fix an fts5 problem with large deletes. check-in: e50e8031 user: dan tags: fts5
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5_index.c.

  1469   1469       }
  1470   1470       pIter->iOff = iOff;
  1471   1471     }
  1472   1472   
  1473   1473     return pIter->bEof;
  1474   1474   }
  1475   1475   
  1476         -static void fts5DlidxIterInitFromData(
  1477         -  Fts5Index *p,                   /* Fts5 Backend to iterate within */
  1478         -  int bRev,                       /* True for ORDER BY ASC */
  1479         -  int iLeafPgno,                  /* Leaf page number dlidx is for */
  1480         -  Fts5Data *pDlidx,               /* Leaf index data */
  1481         -  Fts5DlidxIter **ppIter          /* OUT: Populated iterator */
  1482         -){
  1483         -  Fts5DlidxIter *pIter = *ppIter;
  1484         -
  1485         -  if( pIter==0 ){
  1486         -    *ppIter = pIter = (Fts5DlidxIter*)fts5IdxMalloc(p, sizeof(Fts5DlidxIter));
  1487         -    if( pIter==0 ){ 
  1488         -      fts5DataRelease(pDlidx);
  1489         -      return;
  1490         -    }
  1491         -  }else{
  1492         -    memset(pIter, 0, sizeof(Fts5DlidxIter));
  1493         -  }
  1494         -
  1495         -  pIter->pData = pDlidx;
  1496         -  pIter->iLeafPgno = iLeafPgno;
  1497         -  if( bRev==0 ){
  1498         -    fts5DlidxIterFirst(pIter);
  1499         -  }else{
  1500         -    fts5DlidxIterLast(pIter);
  1501         -  }
  1502         -}
  1503         -
  1504         -static void fts5DlidxIterInit(
         1476  +static Fts5DlidxIter *fts5DlidxIterInit(
  1505   1477     Fts5Index *p,                   /* Fts5 Backend to iterate within */
  1506   1478     int bRev,                       /* True for ORDER BY ASC */
  1507   1479     int iIdx, int iSegid,           /* Segment iSegid within index iIdx */
  1508         -  int iLeafPgno,                  /* Leaf page number to load dlidx for */
  1509         -  Fts5DlidxIter **ppIter          /* OUT: Populated iterator */
         1480  +  int iLeafPg                     /* Leaf page number to load dlidx for */
  1510   1481   ){
  1511         -  Fts5Data *pDlidx;
  1512         -  pDlidx = fts5DataRead(p, FTS5_DOCLIST_IDX_ROWID(iIdx, iSegid, iLeafPgno));
  1513         -  if( pDlidx==0 ) return;
  1514         -  fts5DlidxIterInitFromData(p, bRev, iLeafPgno, pDlidx, ppIter);
         1482  +  Fts5DlidxIter *pIter;
         1483  +
         1484  +  pIter = (Fts5DlidxIter*)fts5IdxMalloc(p, sizeof(Fts5DlidxIter));
         1485  +  if( pIter==0 ) return 0;
         1486  +
         1487  +  pIter->pData = fts5DataRead(p, FTS5_DOCLIST_IDX_ROWID(iIdx, iSegid, iLeafPg));
         1488  +  if( pIter->pData==0 ){
         1489  +    sqlite3_free(pIter);
         1490  +    pIter = 0;
         1491  +  }else{
         1492  +    pIter->iLeafPgno = iLeafPg;
         1493  +    if( bRev==0 ){
         1494  +      fts5DlidxIterFirst(pIter);
         1495  +    }else{
         1496  +      fts5DlidxIterLast(pIter);
         1497  +    }
         1498  +  }
         1499  +
         1500  +  return pIter;
  1515   1501   }
  1516   1502   
  1517   1503   /*
  1518   1504   ** Free a doclist-index iterator object allocated by fts5DlidxIterInit().
  1519   1505   */
  1520   1506   static void fts5DlidxIterFree(Fts5DlidxIter *pIter){
  1521   1507     if( pIter ){
................................................................................
  2026   2012           int nPos;
  2027   2013           iOff += fts5GetPoslistSize(&pLeaf->p[iOff], &nPos, &bDummy);
  2028   2014           iOff += nPos;
  2029   2015         }
  2030   2016       }
  2031   2017     }
  2032   2018   
  2033         -  fts5DlidxIterInit(p, bRev, iIdx, iSeg, pIter->iTermLeafPgno, &pIter->pDlidx);
         2019  +  pIter->pDlidx = fts5DlidxIterInit(p, bRev, iIdx, iSeg, pIter->iTermLeafPgno);
  2034   2020   }
  2035   2021   
  2036   2022   /*
  2037   2023   ** Initialize the object pIter to point to term pTerm/nTerm within segment
  2038   2024   ** pSeg, index iIdx. If there is no such term in the index, the iterator
  2039   2025   ** is set to EOF.
  2040   2026   **
................................................................................
  3971   3957     int iSegid,                     /* Segment id to load from */
  3972   3958     int iLeaf                       /* Load doclist-index for this leaf */
  3973   3959   ){
  3974   3960     Fts5DlidxIter *pDlidx = 0;
  3975   3961     i64 cksum1 = 13;
  3976   3962     i64 cksum2 = 13;
  3977   3963   
  3978         -  for(fts5DlidxIterInit(p, 0, iIdx, iSegid, iLeaf, &pDlidx);
         3964  +  for(pDlidx=fts5DlidxIterInit(p, 0, iIdx, iSegid, iLeaf);
  3979   3965         fts5DlidxIterEof(p, pDlidx)==0;
  3980   3966         fts5DlidxIterNext(pDlidx)
  3981   3967     ){
  3982   3968       assert( pDlidx->iLeafPgno>iLeaf );
  3983   3969       cksum1 = (cksum1 ^ ( (i64)(pDlidx->iLeafPgno) << 32 ));
  3984   3970       cksum1 = (cksum1 ^ pDlidx->iRowid);
  3985   3971     }
  3986   3972     fts5DlidxIterFree(pDlidx);
  3987   3973     pDlidx = 0;
  3988   3974   
  3989         -  for(fts5DlidxIterInit(p, 1, iIdx, iSegid, iLeaf, &pDlidx);
         3975  +  for(pDlidx=fts5DlidxIterInit(p, 1, iIdx, iSegid, iLeaf);
  3990   3976         fts5DlidxIterEof(p, pDlidx)==0;
  3991   3977         fts5DlidxIterPrev(pDlidx)
  3992   3978     ){
  3993   3979       assert( pDlidx->iLeafPgno>iLeaf );
  3994   3980       cksum2 = (cksum2 ^ ( (i64)(pDlidx->iLeafPgno) << 32 ));
  3995   3981       cksum2 = (cksum2 ^ pDlidx->iRowid);
  3996   3982     }
................................................................................
  4059   4045       if( iter.bDlidx ){
  4060   4046         Fts5DlidxIter *pDlidx = 0;  /* For iterating through doclist index */
  4061   4047         int iPrevLeaf = iter.iLeaf;
  4062   4048         int iSegid = pSeg->iSegid;
  4063   4049         int iPg;
  4064   4050         i64 iKey;
  4065   4051   
  4066         -      for(fts5DlidxIterInit(p, 0, iIdx, iSegid, iter.iLeaf, &pDlidx);
         4052  +      for(pDlidx=fts5DlidxIterInit(p, 0, iIdx, iSegid, iter.iLeaf);
  4067   4053             fts5DlidxIterEof(p, pDlidx)==0;
  4068   4054             fts5DlidxIterNext(pDlidx)
  4069   4055         ){
  4070   4056   
  4071   4057           /* Check any rowid-less pages that occur before the current leaf. */
  4072   4058           for(iPg=iPrevLeaf+1; iPg<pDlidx->iLeafPgno; iPg++){
  4073   4059             iKey = FTS5_SEGMENT_ROWID(iIdx, iSegid, 0, iPg);

Changes to ext/fts5/test/fts5fault1.test.

    27     27   #   1: CREATE VIRTUAL TABLE
    28     28   #   2: INSERT statement
    29     29   #   3: DELETE statement
    30     30   #   4: MATCH expressions
    31     31   #
    32     32   #
    33     33   
    34         -if 1 {
    35         -
    36     34   faultsim_save_and_close
    37     35   do_faultsim_test 1 -prep {
    38     36     faultsim_restore_and_reopen
    39     37   } -body {
    40     38     execsql { CREATE VIRTUAL TABLE t1 USING fts5(a, b, prefix='1, 2, 3') }
    41     39   } -test {
    42     40     faultsim_test_result {0 {}} 
................................................................................
   313    311     execsql { 
   314    312       SELECT rowid FROM x1 WHERE x1 MATCH 'x*'
   315    313     }
   316    314   } -test {
   317    315     faultsim_test_result [list 0 $::res]
   318    316   }
   319    317   
   320         -}
   321         -
   322    318   #-------------------------------------------------------------------------
   323    319   # Segment promotion.
   324    320   #
   325    321   do_test 9.0 {
   326    322     reset_db
   327    323     db func rnddoc fts5_rnddoc
   328    324     execsql {
................................................................................
   332    328     }
   333    329   
   334    330     for {set i 1} {$i <= 16} {incr i} {
   335    331       execsql { INSERT INTO s2 VALUES(rnddoc(5)) }
   336    332     }
   337    333     fts5_level_segs s2
   338    334   } {0 1}
          335  +set insert_doc [db one {SELECT rnddoc(160)}]
   339    336   faultsim_save_and_close
   340    337   
   341    338   do_faultsim_test 9.1 -faults oom-* -prep {
   342    339     faultsim_restore_and_reopen
   343         -  db func rnddoc fts5_rnddoc
   344    340   } -body {
   345         -  execsql { INSERT INTO s2 VALUES(rnddoc(160)) }
          341  +  execsql { INSERT INTO s2 VALUES($::insert_doc) }
   346    342   } -test {
   347    343     faultsim_test_result {0 {}}
   348    344     if {$testrc==0} {
   349    345       set ls [fts5_level_segs s2]
   350    346       if {$ls != "2 0"} { error "fts5_level_segs says {$ls}" }
   351    347     }
   352    348   }
   353    349   
   354    350   
   355    351   
   356    352   finish_test
   357    353