/ Check-in [c31eeb3c]
Login

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

Overview
Comment:Merge latest wal2 changes into this branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | begin-concurrent-wal2
Files: files | file ages | folders
SHA3-256:c31eeb3c87f260fa192638b3610a4d3b84b2c26cfaefc97ed63910495403f8c9
User & Date: dan 2019-01-02 16:30:10
Wiki:begin-concurrent-wal2
Context
2019-01-02
17:08
Reinstate assert() statements in os_unix.c that were removed to allow wal-mode SHARED locks to be taken over more than one locking slot (this branch no longer does that, so the assert() statements can go back in). check-in: fcb7348b user: dan tags: begin-concurrent-wal2
16:30
Merge latest wal2 changes into this branch. check-in: c31eeb3c user: dan tags: begin-concurrent-wal2
16:15
Merge latest trunk changes into this branch. check-in: 87ef68f9 user: dan tags: wal2
2018-12-29
20:47
Merge latest begin-concurrent changes with this branch. check-in: 1625887c user: dan tags: begin-concurrent-wal2
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/expert/expert1.test.

   239    239     CREATE TABLE t7(a, b);
   240    240   } {
   241    241     SELECT * FROM t7 WHERE a=? OR b=?
   242    242   } {
   243    243     CREATE INDEX t7_idx_00000062 ON t7(b);
   244    244     CREATE INDEX t7_idx_00000061 ON t7(a);
   245    245     MULTI-INDEX OR
   246         -    SEARCH TABLE t7 USING INDEX t7_idx_00000061 (a=?) 
   247         -    SEARCH TABLE t7 USING INDEX t7_idx_00000062 (b=?)
          246  +    INDEX 1
          247  +      SEARCH TABLE t7 USING INDEX t7_idx_00000061 (a=?) 
          248  +    INDEX 2
          249  +      SEARCH TABLE t7 USING INDEX t7_idx_00000062 (b=?)
   248    250   }
   249    251   
   250    252   # rowid terms.
   251    253   #
   252    254   do_setup_rec_test $tn.13.1 {
   253    255     CREATE TABLE t8(a, b);
   254    256   } {

Changes to ext/fts3/fts3_unicode2.c.

   196    196       'f',       'g',       'h',       'h',       'i',       'i'|HIBIT, 
   197    197       'k',       'l',       'l'|HIBIT, 'l',       'm',       'n',       
   198    198       'o'|HIBIT, 'p',       'r',       'r'|HIBIT, 'r',       's',       
   199    199       's'|HIBIT, 't',       'u',       'u'|HIBIT, 'v',       'w',       
   200    200       'w',       'x',       'y',       'z',       'h',       't',       
   201    201       'w',       'y',       'a',       'a'|HIBIT, 'a'|HIBIT, 'a'|HIBIT, 
   202    202       'e',       'e'|HIBIT, 'e'|HIBIT, 'i',       'o',       'o'|HIBIT, 
   203         -    'o'|HIBIT, 'o'|HIBIT, 'u',       'u'|HIBIT, 'u'|HIBIT, 'y',  
          203  +    'o'|HIBIT, 'o'|HIBIT, 'u',       'u'|HIBIT, 'u'|HIBIT, 'y',       
   204    204     };
   205    205   
   206    206     unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
   207    207     int iRes = 0;
   208    208     int iHi = sizeof(aDia)/sizeof(aDia[0]) - 1;
   209    209     int iLo = 0;
   210    210     while( iHi>=iLo ){
................................................................................
   227    227   ** is a diacritical modifier character.
   228    228   */
   229    229   int sqlite3FtsUnicodeIsdiacritic(int c){
   230    230     unsigned int mask0 = 0x08029FDF;
   231    231     unsigned int mask1 = 0x000361F8;
   232    232     if( c<768 || c>817 ) return 0;
   233    233     return (c < 768+32) ?
   234         -      (mask0 & (1 << (c-768))) :
   235         -      (mask1 & (1 << (c-768-32)));
          234  +      (mask0 & ((unsigned int)1 << (c-768))) :
          235  +      (mask1 & ((unsigned int)1 << (c-768-32)));
   236    236   }
   237    237   
   238    238   
   239    239   /*
   240    240   ** Interpret the argument as a unicode codepoint. If the codepoint
   241    241   ** is an upper case character that has a lower case equivalent,
   242    242   ** return the codepoint corresponding to the lower case version.

Changes to ext/fts3/unicode/mkunicode.tcl.

    59     59       incr i
    60     60   
    61     61       puts -nonewline [format "%5d" [expr ($iCode<<3) + $nRange-1]]
    62     62       puts -nonewline ", "
    63     63     }
    64     64     puts ""
    65     65     puts "  \};"
           66  +  puts "#define HIBIT ((char)0x80)"
    66     67     puts "  char aChar\[\] = \{"
    67     68     puts -nonewline "    '\\0',      "
    68     69     set i 1
    69     70     foreach c $aChar f $aFlag {
    70     71       if { $f } {
    71         -      set str "'$c'|0x80,  "
           72  +      set str "'$c'|HIBIT, "
    72     73       } else {
    73         -      set str "'$c'|0x00,  "
           74  +      set str "'$c',       "
    74     75       }
    75     76       if {$c == ""} { set str "'\\0',      " }
    76     77   
    77     78       if {($i % 6)==0} {puts "" ; puts -nonewline "    " }
    78     79       incr i
    79     80       puts -nonewline "$str"
    80     81     }
................................................................................
   130    131     puts "*/"
   131    132     puts "int ${zFunc}\(int c)\{"
   132    133     puts "  unsigned int mask0 = [format "0x%08X" $i1];"
   133    134     puts "  unsigned int mask1 = [format "0x%08X" $i2];"
   134    135   
   135    136     puts "  if( c<$iFirst || c>$iLast ) return 0;"
   136    137     puts "  return (c < $iFirst+32) ?"
   137         -  puts "      (mask0 & (1 << (c-$iFirst))) :"
   138         -  puts "      (mask1 & (1 << (c-$iFirst-32)));"
          138  +  puts "      (mask0 & ((unsigned int)1 << (c-$iFirst))) :"
          139  +  puts "      (mask1 & ((unsigned int)1 << (c-$iFirst-32)));"
   139    140     puts "\}"
   140    141   }
   141    142   
   142    143   
   143    144   #-------------------------------------------------------------------------
   144    145   
   145    146   proc an_load_separator_ranges {} {
................................................................................
   695    696     set aMapArray [intarray $aMap]
   696    697     set aDataArray [intarray $aData]
   697    698     puts [code {
   698    699       static u16 aFts5UnicodeBlock[] = {$aBlockArray};
   699    700       static u16 aFts5UnicodeMap[] = {$aMapArray};
   700    701       static u16 aFts5UnicodeData[] = {$aDataArray};
   701    702   
   702         -    int sqlite3Fts5UnicodeCategory(int iCode) { 
          703  +    int sqlite3Fts5UnicodeCategory(u32 iCode) { 
   703    704         int iRes = -1;
   704    705         int iHi;
   705    706         int iLo;
   706    707         int ret;
   707    708         u16 iKey;
   708    709   
   709    710         if( iCode>=(1<<20) ){
................................................................................
   778    779           if( aCP[iCP].iCode==i ){
   779    780             sqlite3Fts5UnicodeCatParse(aCP[iCP].zCat, aArray);
   780    781             iCP++;
   781    782           }else{
   782    783             aArray[0] = 1;
   783    784           }
   784    785   
   785         -        c = sqlite3Fts5UnicodeCategory(i);
          786  +        c = sqlite3Fts5UnicodeCategory((u32)i);
   786    787           if( aArray[c]==0 ){
   787    788             *piCode = i;
   788    789             return 1;
   789    790           }
   790    791         }
   791    792   
   792    793         return 0;

Changes to ext/fts5/fts5Int.h.

   784    784   /**************************************************************************
   785    785   ** Interface to automatically generated code in fts5_unicode2.c. 
   786    786   */
   787    787   int sqlite3Fts5UnicodeIsdiacritic(int c);
   788    788   int sqlite3Fts5UnicodeFold(int c, int bRemoveDiacritic);
   789    789   
   790    790   int sqlite3Fts5UnicodeCatParse(const char*, u8*);
   791         -int sqlite3Fts5UnicodeCategory(int iCode);
          791  +int sqlite3Fts5UnicodeCategory(u32 iCode);
   792    792   void sqlite3Fts5UnicodeAscii(u8*, u8*);
   793    793   /*
   794    794   ** End of interface to code in fts5_unicode2.c.
   795    795   **************************************************************************/
   796    796   
   797    797   #endif

Changes to ext/fts5/fts5_expr.c.

  2549   2549       return;
  2550   2550     }
  2551   2551     memset(aArr, 0, sizeof(aArr));
  2552   2552     sqlite3Fts5UnicodeCatParse("L*", aArr);
  2553   2553     sqlite3Fts5UnicodeCatParse("N*", aArr);
  2554   2554     sqlite3Fts5UnicodeCatParse("Co", aArr);
  2555   2555     iCode = sqlite3_value_int(apVal[0]);
  2556         -  sqlite3_result_int(pCtx, aArr[sqlite3Fts5UnicodeCategory(iCode)]);
         2556  +  sqlite3_result_int(pCtx, aArr[sqlite3Fts5UnicodeCategory((u32)iCode)]);
  2557   2557   }
  2558   2558   
  2559   2559   static void fts5ExprFold(
  2560   2560     sqlite3_context *pCtx,          /* Function call context */
  2561   2561     int nArg,                       /* Number of args */
  2562   2562     sqlite3_value **apVal           /* Function arguments */
  2563   2563   ){

Changes to ext/fts5/fts5_index.c.

   856    856     if( piCookie ) *piCookie = sqlite3Fts5Get32(pData);
   857    857     i = 4;
   858    858   
   859    859     /* Read the total number of levels and segments from the start of the
   860    860     ** structure record.  */
   861    861     i += fts5GetVarint32(&pData[i], nLevel);
   862    862     i += fts5GetVarint32(&pData[i], nSegment);
          863  +  if( nLevel>FTS5_MAX_SEGMENT   || nLevel<0
          864  +   || nSegment>FTS5_MAX_SEGMENT || nSegment<0
          865  +  ){
          866  +    return FTS5_CORRUPT;
          867  +  }
   863    868     nByte = (
   864    869         sizeof(Fts5Structure) +                    /* Main structure */
   865    870         sizeof(Fts5StructureLevel) * (nLevel-1)    /* aLevel[] array */
   866    871     );
   867    872     pRet = (Fts5Structure*)sqlite3Fts5MallocZero(&rc, nByte);
   868    873   
   869    874     if( pRet ){
................................................................................
   888    893           );
   889    894           nSegment -= nTotal;
   890    895         }
   891    896   
   892    897         if( rc==SQLITE_OK ){
   893    898           pLvl->nSeg = nTotal;
   894    899           for(iSeg=0; iSeg<nTotal; iSeg++){
          900  +          Fts5StructureSegment *pSeg = &pLvl->aSeg[iSeg];
   895    901             if( i>=nData ){
   896    902               rc = FTS5_CORRUPT;
   897    903               break;
   898    904             }
   899         -          i += fts5GetVarint32(&pData[i], pLvl->aSeg[iSeg].iSegid);
   900         -          i += fts5GetVarint32(&pData[i], pLvl->aSeg[iSeg].pgnoFirst);
   901         -          i += fts5GetVarint32(&pData[i], pLvl->aSeg[iSeg].pgnoLast);
          905  +          i += fts5GetVarint32(&pData[i], pSeg->iSegid);
          906  +          i += fts5GetVarint32(&pData[i], pSeg->pgnoFirst);
          907  +          i += fts5GetVarint32(&pData[i], pSeg->pgnoLast);
          908  +          if( pSeg->pgnoLast<pSeg->pgnoFirst ){
          909  +            rc = FTS5_CORRUPT;
          910  +            break;
          911  +          }
   902    912           }
          913  +        if( iLvl>0 && pLvl[-1].nMerge && nTotal==0 ) rc = FTS5_CORRUPT;
          914  +        if( iLvl==nLevel-1 && pLvl->nMerge ) rc = FTS5_CORRUPT;
   903    915         }
   904    916       }
   905    917       if( nSegment!=0 && rc==SQLITE_OK ) rc = FTS5_CORRUPT;
   906    918   
   907    919       if( rc!=SQLITE_OK ){
   908    920         fts5StructureRelease(pRet);
   909    921         pRet = 0;
................................................................................
  1637   1649   */
  1638   1650   static void fts5SegIterLoadTerm(Fts5Index *p, Fts5SegIter *pIter, int nKeep){
  1639   1651     u8 *a = pIter->pLeaf->p;        /* Buffer to read data from */
  1640   1652     int iOff = pIter->iLeafOffset;  /* Offset to read at */
  1641   1653     int nNew;                       /* Bytes of new data */
  1642   1654   
  1643   1655     iOff += fts5GetVarint32(&a[iOff], nNew);
  1644         -  if( iOff+nNew>pIter->pLeaf->nn ){
         1656  +  if( iOff+nNew>pIter->pLeaf->nn || nKeep>pIter->term.n ){
  1645   1657       p->rc = FTS5_CORRUPT;
  1646   1658       return;
  1647   1659     }
  1648   1660     pIter->term.n = nKeep;
  1649   1661     fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
         1662  +  assert( pIter->term.n<=pIter->term.nSpace );
  1650   1663     iOff += nNew;
  1651   1664     pIter->iTermLeafOffset = iOff;
  1652   1665     pIter->iTermLeafPgno = pIter->iLeafPgno;
  1653   1666     pIter->iLeafOffset = iOff;
  1654   1667   
  1655   1668     if( pIter->iPgidxOff>=pIter->pLeaf->nn ){
  1656   1669       pIter->iEndofDoclist = pIter->pLeaf->nn+1;
................................................................................
  2296   2309         if( pIter->pLeaf==0 ) return;
  2297   2310         a = pIter->pLeaf->p;
  2298   2311         if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
  2299   2312           iPgidx = pIter->pLeaf->szLeaf;
  2300   2313           iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
  2301   2314           if( iOff<4 || iOff>=pIter->pLeaf->szLeaf ){
  2302   2315             p->rc = FTS5_CORRUPT;
         2316  +          return;
  2303   2317           }else{
  2304   2318             nKeep = 0;
  2305   2319             iTermOff = iOff;
  2306   2320             n = pIter->pLeaf->nn;
  2307   2321             iOff += fts5GetVarint32(&a[iOff], nNew);
  2308   2322             break;
  2309   2323           }
  2310   2324         }
  2311   2325       }while( 1 );
  2312   2326     }
  2313   2327   
  2314   2328    search_success:
  2315         -
  2316   2329     pIter->iLeafOffset = iOff + nNew;
         2330  +  if( pIter->iLeafOffset>n ){
         2331  +    p->rc = FTS5_CORRUPT;
         2332  +    return;
         2333  +  }
  2317   2334     pIter->iTermLeafOffset = pIter->iLeafOffset;
  2318   2335     pIter->iTermLeafPgno = pIter->iLeafPgno;
  2319   2336   
  2320   2337     fts5BufferSet(&p->rc, &pIter->term, nKeep, pTerm);
  2321   2338     fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
  2322   2339   
  2323   2340     if( iPgidx>=n ){
................................................................................
  3564   3581         int i;
  3565   3582         u32 mask;
  3566   3583         memset(aUsed, 0, sizeof(aUsed));
  3567   3584         for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
  3568   3585           for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
  3569   3586             int iId = pStruct->aLevel[iLvl].aSeg[iSeg].iSegid;
  3570   3587             if( iId<=FTS5_MAX_SEGMENT ){
  3571         -            aUsed[(iId-1) / 32] |= 1 << ((iId-1) % 32);
         3588  +            aUsed[(iId-1) / 32] |= (u32)1 << ((iId-1) % 32);
  3572   3589             }
  3573   3590           }
  3574   3591         }
  3575   3592   
  3576   3593         for(i=0; aUsed[i]==0xFFFFFFFF; i++);
  3577   3594         mask = aUsed[i];
  3578         -      for(iSegid=0; mask & (1 << iSegid); iSegid++);
         3595  +      for(iSegid=0; mask & ((u32)1 << iSegid); iSegid++);
  3579   3596         iSegid += 1 + i*32;
  3580   3597   
  3581   3598   #ifdef SQLITE_DEBUG
  3582   3599         for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
  3583   3600           for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
  3584   3601             assert_nc( iSegid!=pStruct->aLevel[iLvl].aSeg[iSeg].iSegid );
  3585   3602           }
................................................................................
  3889   3906     Fts5Index *p, 
  3890   3907     Fts5SegWriter *pWriter,
  3891   3908     int nTerm, const u8 *pTerm 
  3892   3909   ){
  3893   3910     int nPrefix;                    /* Bytes of prefix compression for term */
  3894   3911     Fts5PageWriter *pPage = &pWriter->writer;
  3895   3912     Fts5Buffer *pPgidx = &pWriter->writer.pgidx;
         3913  +  int nMin = MIN(pPage->term.n, nTerm);
  3896   3914   
  3897   3915     assert( p->rc==SQLITE_OK );
  3898   3916     assert( pPage->buf.n>=4 );
  3899   3917     assert( pPage->buf.n>4 || pWriter->bFirstTermInPage );
  3900   3918   
  3901   3919     /* If the current leaf page is full, flush it to disk. */
  3902   3920     if( (pPage->buf.n + pPgidx->n + nTerm + 2)>=p->pConfig->pgsz ){
................................................................................
  3930   3948         ** Usually, the previous term is available in pPage->term. The exception
  3931   3949         ** is if this is the first term written in an incremental-merge step.
  3932   3950         ** In this case the previous term is not available, so just write a
  3933   3951         ** copy of (pTerm/nTerm) into the parent node. This is slightly
  3934   3952         ** inefficient, but still correct.  */
  3935   3953         int n = nTerm;
  3936   3954         if( pPage->term.n ){
  3937         -        n = 1 + fts5PrefixCompress(pPage->term.n, pPage->term.p, pTerm);
         3955  +        n = 1 + fts5PrefixCompress(nMin, pPage->term.p, pTerm);
  3938   3956         }
  3939   3957         fts5WriteBtreeTerm(p, pWriter, n, pTerm);
  3940   3958         pPage = &pWriter->writer;
  3941   3959       }
  3942   3960     }else{
  3943         -    nPrefix = fts5PrefixCompress(pPage->term.n, pPage->term.p, pTerm);
         3961  +    nPrefix = fts5PrefixCompress(nMin, pPage->term.p, pTerm);
  3944   3962       fts5BufferAppendVarint(&p->rc, &pPage->buf, nPrefix);
  3945   3963     }
  3946   3964   
  3947   3965     /* Append the number of bytes of new data, then the term data itself
  3948   3966     ** to the page. */
  3949   3967     fts5BufferAppendVarint(&p->rc, &pPage->buf, nTerm - nPrefix);
  3950   3968     fts5BufferAppendBlob(&p->rc, &pPage->buf, nTerm - nPrefix, &pTerm[nPrefix]);
................................................................................
  6269   6287     ** copy is followed by FTS5_DATA_ZERO_PADDING 0x00 bytes, which prevents
  6270   6288     ** buffer overreads even if the record is corrupt.  */
  6271   6289     n = sqlite3_value_bytes(apVal[1]);
  6272   6290     aBlob = sqlite3_value_blob(apVal[1]);
  6273   6291     nSpace = n + FTS5_DATA_ZERO_PADDING;
  6274   6292     a = (u8*)sqlite3Fts5MallocZero(&rc, nSpace);
  6275   6293     if( a==0 ) goto decode_out;
  6276         -  memcpy(a, aBlob, n);
  6277         -
         6294  +  if( n>0 ) memcpy(a, aBlob, n);
  6278   6295   
  6279   6296     fts5DecodeRowid(iRowid, &iSegid, &bDlidx, &iHeight, &iPgno);
  6280   6297   
  6281   6298     fts5DebugRowid(&rc, &s, iRowid);
  6282   6299     if( bDlidx ){
  6283   6300       Fts5Data dlidx;
  6284   6301       Fts5DlidxLvl lvl;

Changes to ext/fts5/fts5_test_tok.c.

   374    374     if( idxNum==1 ){
   375    375       const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
   376    376       int nByte = sqlite3_value_bytes(apVal[0]);
   377    377       pCsr->zInput = sqlite3_malloc(nByte+1);
   378    378       if( pCsr->zInput==0 ){
   379    379         rc = SQLITE_NOMEM;
   380    380       }else{
   381         -      memcpy(pCsr->zInput, zByte, nByte);
          381  +      if( nByte>0 ) memcpy(pCsr->zInput, zByte, nByte);
   382    382         pCsr->zInput[nByte] = 0;
   383    383         rc = pTab->tok.xTokenize(
   384    384             pTab->pTok, (void*)pCsr, 0, zByte, nByte, fts5tokCb
   385    385         );
   386    386       }
   387    387     }
   388    388   

Changes to ext/fts5/fts5_tokenize.c.

   258    258     if( n>0 ){
   259    259       aNew = (int*)sqlite3_realloc(p->aiException, (n+p->nException)*sizeof(int));
   260    260       if( aNew ){
   261    261         int nNew = p->nException;
   262    262         const unsigned char *zCsr = (const unsigned char*)z;
   263    263         const unsigned char *zTerm = (const unsigned char*)&z[n];
   264    264         while( zCsr<zTerm ){
   265         -        int iCode;
          265  +        u32 iCode;
   266    266           int bToken;
   267    267           READ_UTF8(zCsr, zTerm, iCode);
   268    268           if( iCode<128 ){
   269    269             p->aTokenChar[iCode] = (unsigned char)bTokenChars;
   270    270           }else{
   271    271             bToken = p->aCategory[sqlite3Fts5UnicodeCategory(iCode)];
   272    272             assert( (bToken==0 || bToken==1) ); 
   273    273             assert( (bTokenChars==0 || bTokenChars==1) );
   274    274             if( bToken!=bTokenChars && sqlite3Fts5UnicodeIsdiacritic(iCode)==0 ){
   275    275               int i;
   276    276               for(i=0; i<nNew; i++){
   277         -              if( aNew[i]>iCode ) break;
          277  +              if( (u32)aNew[i]>iCode ) break;
   278    278               }
   279    279               memmove(&aNew[i+1], &aNew[i], (nNew-i)*sizeof(int));
   280    280               aNew[i] = iCode;
   281    281               nNew++;
   282    282             }
   283    283           }
   284    284         }
................................................................................
   425    425   /*
   426    426   ** Return true if, for the purposes of tokenizing with the tokenizer
   427    427   ** passed as the first argument, codepoint iCode is considered a token 
   428    428   ** character (not a separator).
   429    429   */
   430    430   static int fts5UnicodeIsAlnum(Unicode61Tokenizer *p, int iCode){
   431    431     return (
   432         -    p->aCategory[sqlite3Fts5UnicodeCategory(iCode)]
          432  +    p->aCategory[sqlite3Fts5UnicodeCategory((u32)iCode)]
   433    433       ^ fts5UnicodeIsException(p, iCode)
   434    434     );
   435    435   }
   436    436   
   437    437   static int fts5UnicodeTokenize(
   438    438     Fts5Tokenizer *pTokenizer,
   439    439     void *pCtx,
................................................................................
   454    454     const char *pEnd = &aFold[nFold-6];
   455    455   
   456    456     UNUSED_PARAM(iUnused);
   457    457   
   458    458     /* Each iteration of this loop gobbles up a contiguous run of separators,
   459    459     ** then the next token.  */
   460    460     while( rc==SQLITE_OK ){
   461         -    int iCode;                    /* non-ASCII codepoint read from input */
          461  +    u32 iCode;                    /* non-ASCII codepoint read from input */
   462    462       char *zOut = aFold;
   463    463       int is;
   464    464       int ie;
   465    465   
   466    466       /* Skip any separator characters. */
   467    467       while( 1 ){
   468    468         if( zCsr>=zTerm ) goto tokenize_done;
................................................................................
  1280   1280           &aBuiltin[i].x,
  1281   1281           0
  1282   1282       );
  1283   1283     }
  1284   1284   
  1285   1285     return rc;
  1286   1286   }
  1287         -
  1288         -

Changes to ext/fts5/fts5_unicode2.c.

    65     65       'f',       'g',       'h',       'h',       'i',       'i'|HIBIT, 
    66     66       'k',       'l',       'l'|HIBIT, 'l',       'm',       'n',       
    67     67       'o'|HIBIT, 'p',       'r',       'r'|HIBIT, 'r',       's',       
    68     68       's'|HIBIT, 't',       'u',       'u'|HIBIT, 'v',       'w',       
    69     69       'w',       'x',       'y',       'z',       'h',       't',       
    70     70       'w',       'y',       'a',       'a'|HIBIT, 'a'|HIBIT, 'a'|HIBIT, 
    71     71       'e',       'e'|HIBIT, 'e'|HIBIT, 'i',       'o',       'o'|HIBIT, 
    72         -    'o'|HIBIT, 'o'|HIBIT, 'u',       'u'|HIBIT, 'u'|HIBIT, 'y',  
           72  +    'o'|HIBIT, 'o'|HIBIT, 'u',       'u'|HIBIT, 'u'|HIBIT, 'y',       
    73     73     };
    74     74   
    75     75     unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
    76     76     int iRes = 0;
    77     77     int iHi = sizeof(aDia)/sizeof(aDia[0]) - 1;
    78     78     int iLo = 0;
    79     79     while( iHi>=iLo ){
................................................................................
    96     96   ** is a diacritical modifier character.
    97     97   */
    98     98   int sqlite3Fts5UnicodeIsdiacritic(int c){
    99     99     unsigned int mask0 = 0x08029FDF;
   100    100     unsigned int mask1 = 0x000361F8;
   101    101     if( c<768 || c>817 ) return 0;
   102    102     return (c < 768+32) ?
   103         -      (mask0 & (1 << (c-768))) :
   104         -      (mask1 & (1 << (c-768-32)));
          103  +      (mask0 & ((unsigned int)1 << (c-768))) :
          104  +      (mask1 & ((unsigned int)1 << (c-768-32)));
   105    105   }
   106    106   
   107    107   
   108    108   /*
   109    109   ** Interpret the argument as a unicode codepoint. If the codepoint
   110    110   ** is an upper case character that has a lower case equivalent,
   111    111   ** return the codepoint corresponding to the lower case version.
................................................................................
   244    244     
   245    245     else if( c>=66560 && c<66600 ){
   246    246       ret = c + 40;
   247    247     }
   248    248   
   249    249     return ret;
   250    250   }
          251  +
   251    252   
   252    253   int sqlite3Fts5UnicodeCatParse(const char *zCat, u8 *aArray){ 
   253    254     aArray[0] = 1;
   254    255     switch( zCat[0] ){
   255    256       case 'C':
   256    257             switch( zCat[1] ){
   257    258               case 'c': aArray[1] = 1; break;
................................................................................
   726    727       89,    1434,  3226,  506,   474,   506,   506,   367,   1018,  1946,  
   727    728       1402,  954,   1402,  314,   90,    1082,  218,   2266,  666,   1210,  
   728    729       186,   570,   2042,  58,    5850,  154,   2010,  154,   794,   2266,  
   729    730       378,   2266,  3738,  39,    39,    39,    39,    39,    39,    17351, 
   730    731       34,    3074,  7692,  63,    63,    
   731    732     };
   732    733   
   733         -int sqlite3Fts5UnicodeCategory(int iCode) { 
          734  +int sqlite3Fts5UnicodeCategory(u32 iCode) { 
   734    735     int iRes = -1;
   735    736     int iHi;
   736    737     int iLo;
   737    738     int ret;
   738    739     u16 iKey;
   739    740   
   740    741     if( iCode>=(1<<20) ){
................................................................................
   769    770       int n = (aFts5UnicodeData[iTbl] >> 5) + i;
   770    771       for(; i<128 && i<n; i++){
   771    772         aAscii[i] = bToken;
   772    773       }
   773    774       iTbl++;
   774    775     }
   775    776   }
          777  +

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

    31     31       CREATE VIRTUAL TABLE t1 USING fts5(x);
    32     32       INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
    33     33       WITH ii(i) AS (SELECT 1 UNION SELECT i+1 FROM ii WHERE i<100)
    34     34         INSERT INTO t1 SELECT rnddoc(10) FROM ii;
    35     35     }
    36     36   }
    37     37   
    38         -if 1 {
    39         -
    40     38   # Create a simple FTS5 table containing 100 documents. Each document 
    41     39   # contains 10 terms, each of which start with the character "x".
    42     40   #
    43     41   do_test 1.0 { create_t1 } {}
    44     42   
    45     43   do_test 1.1 {
    46     44     # Pick out the rowid of the right-most b-tree leaf in the new segment.
................................................................................
   376    374       db eval {DELETE FROM t5_data WHERE rowid = $i}
   377    375       set r [catchsql { INSERT INTO t5(t5) VALUES('integrity-check')} ]
   378    376       if {$r != "1 {database disk image is malformed}"} { error $r }
   379    377       db eval ROLLBACK  
   380    378     }
   381    379   } {}
   382    380   
   383         -}
   384         -
   385    381   #------------------------------------------------------------------------
   386    382   # Corruption within the structure record.
   387    383   #
   388    384   reset_db
   389    385   do_execsql_test 8.1 {
   390    386     CREATE VIRTUAL TABLE t1 USING fts5(x, y);
   391    387     INSERT INTO t1 VALUES('one', 'two');
................................................................................
   958    954   |     64: 70 00 00 00 00 00 00 00 00 00 00 00 70 00 00 00   p...........p...
   959    955   | end c16.db
   960    956   }]} {}
   961    957   
   962    958   do_catchsql_test 15.1 {
   963    959     INSERT INTO t1(t1) VALUES('integrity-check');
   964    960   } {1 {database disk image is malformed}}
          961  +
          962  +#---------------------------------------------------------------------------
          963  +#
          964  +reset_db
          965  +do_test 16.0 {
          966  +  sqlite3 db {}
          967  +  db deserialize [decode_hexdb {
          968  +| size 28672 pagesize 4096 filename c17.db
          969  +| page 1 offset 0
          970  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          971  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
          972  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00   ................
          973  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
          974  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
          975  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          976  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          977  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          978  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          979  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          980  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          981  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          982  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          983  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          984  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
          985  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
          986  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          987  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          988  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          989  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          990  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          991  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          992  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          993  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          994  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          995  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          996  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          997  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
          998  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
          999  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1000  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1001  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1002  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1003  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1004  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1005  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1006  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1007  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1008  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1009  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1010  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1011  +| page 2 offset 4096
         1012  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
         1013  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
         1014  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1015  +|   4048: 63 6b 01 02 02 04 02 66 74 00 02 22 04 04 6e 64   ck.....ft.....nd
         1016  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
         1017  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 41 01   ...$..........A.
         1018  +| page 3 offset 8192
         1019  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
         1020  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         1021  +| page 4 offset 12288
         1022  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
         1023  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1024  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         1025  +| page 5 offset 16384
         1026  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f4 0f ee 00 00   ................
         1027  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
         1028  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1029  +| page 6 offset 20480
         1030  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1031  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1032  +| page 7 offset 24576
         1033  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1034  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1035  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1036  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         1037  +| end c17.db
         1038  +}]} {}
         1039  +
         1040  +do_catchsql_test 16.1 {
         1041  +INSERT INTO t1(t1) VALUES('integrity-check');
         1042  +} {1 {vtable constructor failed: t1}}
         1043  +
         1044  +#--------------------------------------------------------------------------
         1045  +reset_db
         1046  +do_test 17.0 {
         1047  +  sqlite3 db {}
         1048  +  db deserialize [decode_hexdb {
         1049  +| size 28672 pagesize 4096 filename c18.db
         1050  +| page 1 offset 0
         1051  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1052  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
         1053  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00   ................
         1054  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1055  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
         1056  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1057  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1058  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1059  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1060  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1061  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1062  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1063  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1064  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1065  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         1066  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1067  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1068  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1069  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1070  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1071  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1072  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1073  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1074  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1075  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1076  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1077  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1078  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1079  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1080  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1081  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1082  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1083  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1084  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1085  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1086  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1087  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1088  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1089  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1090  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1091  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1092  +| page 2 offset 4096
         1093  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
         1094  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
         1095  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1096  +|   4048: 63 6b 01 02 02 04 02 66 74 00 02 22 04 04 6e 64   ck.....ft.....nd
         1097  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
         1098  +|   4080: 0a 03 00 24 00 00 0a aa aa aa aa aa aa aa aa aa   ...$............
         1099  +| page 3 offset 8192
         1100  +|      0: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa   ................
         1101  +|     16: aa aa aa aa aa aa aa aa 00 00 10 10 10 00 10 10   ................
         1102  +|     32: 10 10 a0 00 00 00 10 ff a0 00 ff 52 05 64 95 25   ...........R.d.%
         1103  +|     48: 45 54 14 c2 05 44 14 24 c4 52 07 43 12 05 55 34   ET...D.$.R.C..U4
         1104  +|     64: 94 e4 72 06 67 47 33 52 86 36 f6 e7 46 56 e7 42   ..r.gG3R.6..FV.B
         1105  +|     80: 90 d0 00 00 00 30 fb d0 00 fe 80 fe f0 fb 00 00   .....0..........
         1106  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         1107  +| page 4 offset 12288
         1108  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
         1109  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1110  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         1111  +| page 5 offset 16384
         1112  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f4 0f ee 00 00   ................
         1113  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
         1114  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1115  +| page 6 offset 20480
         1116  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1117  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1118  +| page 7 offset 24576
         1119  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1120  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1121  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1122  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         1123  +| end c18.db
         1124  +}]} {}
         1125  +
         1126  +do_catchsql_test 17.1 {
         1127  +  SELECT * FROM t1 WHERE t1 MATCH 'abandon';
         1128  +} {1 {vtable constructor failed: t1}}
         1129  +
         1130  +#--------------------------------------------------------------------------
         1131  +reset_db
         1132  +do_test 18.0 {
         1133  +  sqlite3 db {}
         1134  +  db deserialize [decode_hexdb {
         1135  +| size 28672 pagesize 4096 filename c19b.db
         1136  +| page 1 offset 0
         1137  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1138  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
         1139  +|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         1140  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1141  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
         1142  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
         1143  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1144  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1145  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1146  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1147  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1148  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1149  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1150  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1151  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1152  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         1153  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1154  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1155  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1156  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1157  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1158  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1159  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1160  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1161  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1162  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1163  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1164  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1165  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1166  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1167  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1168  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1169  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1170  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1171  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1172  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1173  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1174  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1175  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1176  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1177  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1178  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1179  +| page 2 offset 4096
         1180  +|      0: 0d 09 a6 00 06 09 22 00 0f e8 09 22 0f bd 0f 2c   ...............,
         1181  +|     16: 09 bd 09 3c 00 00 00 00 00 00 00 00 00 00 00 00   ...<............
         1182  +|   2336: 00 00 18 0a 03 00 36 00 00 00 00 01 04 04 00 04   ......6.........
         1183  +|   2352: 01 01 01 02 01 01 03 01 01 04 01 01 63 90 80 80   ............c...
         1184  +|   2368: 80 80 01 04 00 81 4a 00 00 00 56 06 30 61 62 61   ......J...V.0aba
         1185  +|   2384: 63 6b 08 01 04 04 6e 64 6f 6e 03 01 05 01 02 05   ck....ndon......
         1186  +|   2400: 63 74 69 76 65 08 01 02 04 6c 70 68 61 08 01 02   ctive....lpha...
         1187  +|   2416: 03 74 6f 6d 08 01 01 06 62 61 63 6b 75 70 08 01   .tom....backup..
         1188  +|   2432: 01 0c 63 68 61 6e 6e 65 62 6f 6f 6d 65 72 08 01   ..channeboomer..
         1189  +|   2448: 07 01 6c 08 01 01 04 74 65 73 74 08 01 04 09 0a   ..l....test.....
         1190  +|   2464: 09 08 07 0a 10 05 0f 18 00 17 30 00 00 00 00 01   ..........0.....
         1191  +|   2480: 03 03 00 03 01 01 01 02 01 01 03 01 01 8a 53 8c   ..............S.
         1192  +|   2496: 80 80 80 80 01 04 00 95 2a 00 00 05 35 0d 30 30   ........*...5.00
         1193  +|   2512: 31 30 66 66 61 30 30 30 66 66 61 05 02 1c 02 49   10ffa000ffa....I
         1194  +|   2528: 33 34 33 35 32 34 35 34 31 35 34 34 35 32 30 35   3435245415445205
         1195  +|   2544: 34 34 31 34 32 34 63 34 35 32 30 32 37 37 34 33   441424c452027743
         1196  +|   2560: 31 35 66 36 39 36 34 37 38 32 37 32 38 37 33 36   15f6964782728736
         1197  +|   2576: 35 36 37 36 39 36 34 32 63 32 30 37 34 36 35 37   56769642c2074657
         1198  +|   2592: 32 36 64 32 63 32 30 37 30 05 02 12 02 3b 36 31   26d2c2070....;61
         1199  +|   2608: 37 32 31 32 31 30 31 37 37 37 34 36 31 36 32 35   7212101777461625
         1200  +|   2624: 63 36 35 37 34 33 31 35 66 36 33 36 66 36 65 37   c6574315f636f6e7
         1201  +|   2640: 34 36 35 36 65 37 34 37 34 33 31 35 66 36 33 36   4656e7474315f636
         1202  +|   2656: 66 36 65 37 34 36 35 36 65 05 04 07 07 01 04 31   f6e74656e......1
         1203  +|   2672: 66 62 64 05 02 19 01 44 32 34 38 34 38 30 38 30   fbd....D24848080
         1204  +|   2688: 38 30 38 30 30 31 30 33 30 30 34 65 30 30 30 30   80800103004e0000
         1205  +|   2704: 30 30 31 65 30 36 33 30 36 31 36 32 36 31 36 33   001e063061626163
         1206  +|   2720: 36 62 30 31 30 32 30 32 30 34 30 32 36 36 37 34   6b01020204026674
         1207  +|   2736: 30 32 30 32 30 32 30 34 30 34 36 65 05 02 1a 02   02020204046e....
         1208  +|   2752: 03 66 65 72 05 02 1d 01 28 33 65 37 34 36 35 36   .fer....(3e74656
         1209  +|   2768: 65 37 34 32 39 30 64 30 30 30 30 30 30 30 33 30   e74290d000000030
         1210  +|   2784: 66 62 64 30 30 30 66 65 38 30 66 65 66 30 66 62   fbd000fe80fef0fb
         1211  +|   2800: 64 05 02 18 01 4a 34 31 35 32 35 39 32 30 34 62   d....J415259204b
         1212  +|   2816: 34 35 35 39 32 63 32 30 36 32 36 63 36 66 36 33   45592c20626c6f63
         1213  +|   2832: 36 62 32 30 34 32 34 63 34 66 34 32 32 39 33 61   6b20424c4f42293a
         1214  +|   2848: 30 31 30 36 31 37 31 31 31 31 30 38 36 33 37 34   0106171111086374
         1215  +|   2864: 36 31 36 32 36 63 36 35 37 34 33 31 37 34 33 31   61626c6574317431
         1216  +|   2880: 05 02 16 02 49 33 35 32 34 35 34 31 35 34 34 35   ....I35245415445
         1217  +|   2896: 32 30 35 36 34 39 35 32 35 34 35 35 34 31 34 63   205649525455414c
         1218  +|   2912: 32 30 35 34 34 31 34 32 34 63 34 35 32 30 37 34   205441424c452074
         1219  +|   2928: 33 31 6f 30 35 35 35 33 34 39 34 65 34 37 32 30   31o05553494e4720
         1220  +|   2944: 36 36 37 34 37 33 33 35 32 38 36 33 36 66 05 02   6674733528636f..
         1221  +|   2960: 17 02 49 35 32 30 35 34 34 31 34 32 34 63 34 35   ..I5205441424c45
         1222  +|   2976: 32 30 32 37 37 34 33 31 35 66 36 33 36 66 36 65   202774315f636f6e
         1223  +|   2992: 37 34 36 35 36 65 37 34 32 37 32 38 36 39 36 34   74656e7427286964
         1224  +|   3008: 32 30 34 39 34 65 35 34 34 35 34 37 34 35 35 32   20494e5445474552
         1225  +|   3024: 32 30 35 30 35 32 34 39 34 64 34 31 05 02 0e 44   205052494d41...D
         1226  +|   3040: 29 62 30 35 30 37 31 37 32 31 32 31 30 31 38 31   )b05071721210181
         1227  +|   3056: 30 31 37 34 36 31 36 32 36 63 36 35 37 34 33 31   017461626c657431
         1228  +|   3072: 35 66 36 34 36 66 36 33 37 33 05 02 09 01 4a 35   5f646f6373....J5
         1229  +|   3088: 32 34 35 34 31 35 34 34 35 32 30 35 34 34 31 34   2454154452054414
         1230  +|   3104: 32 34 63 34 35 32 30 32 37 37 34 33 31 35 66 36   24c45202774315f6
         1231  +|   3120: 34 36 31 37 34 36 31 32 37 32 38 36 39 36 34 32   4617461272869642
         1232  +|   3136: 30 34 39 34 65 35 34 34 35 34 37 34 35 35 32 32   0494e54454745522
         1233  +|   3152: 30 35 30 35 32 34 39 34 64 05 02 15 03 3a 35 39   05052494d....:59
         1234  +|   3168: 32 30 34 62 34 35 35 39 32 63 32 30 36 33 33 30   204b45592c206330
         1235  +|   3184: 32 39 36 39 30 33 30 37 31 37 31 39 31 39 30 31   2969030717191901
         1236  +|   3200: 38 31 32 64 37 34 36 31 36 32 36 63 36 35 37 34   812d7461626c6574
         1237  +|   3216: 33 31 35 66 36 39 79 79 05 02 0f 02 49 34 32 30   315f69yy....I420
         1238  +|   3232: 35 32 34 66 35 37 34 39 34 34 35 35 30 32 30 37   524f574944550207
         1239  +|   3248: 31 37 31 62 31 62 30 31 38 31 30 31 37 34 36 31   171b1b0181017461
         1240  +|   3264: 36 32 36 63 36 37 37 34 33 31 35 66 36 34 36 31   626c6774315f6461
         1241  +|   3280: 37 34 36 31 37 34 33 31 35 66 36 34 36 31 37 34   746174315f646174
         1242  +|   3296: 36 31 30 32 34 33 05 02 14 02 07 66 36 39 36 34   610243.....f6964
         1243  +|   3312: 37 38 05 02 11 01 4a 36 34 36 66 36 65 30 33 30   78....J646f6e030
         1244  +|   3328: 32 30 32 30 34 30 61 30 37 30 35 30 31 30 33 30   202040a070501030
         1245  +|   3344: 30 31 30 30 33 30 33 30 66 30 61 30 33 30 30 32   01003030f0a03002
         1246  +|   3360: 34 30 30 30 30 30 30 30 30 30 31 30 31 30 31 30   4000000000101010
         1247  +|   3376: 30 30 31 30 31 30 31 30 31 30 61 30 30 30 30 30   0010101010a00000
         1248  +|   3392: 30 05 02 1b 02 49 35 32 37 32 38 36 39 36 34 32   0....I5272869642
         1249  +|   3408: 30 34 39 34 65 35 34 34 35 34 37 34 35 35 32 32   0494e54454745522
         1250  +|   3424: 30 35 30 35 32 34 39 34 64 34 31 35 32 35 39 32   05052494d4152592
         1251  +|   3440: 30 34 62 34 35 35 39 32 63 32 30 37 33 37 61 32   04b45592c20737a2
         1252  +|   3456: 30 34 32 34 63 34 66 34 32 32 39 35 35 30 34 05   0424c4f42295504.
         1253  +|   3472: 04 06 07 02 49 37 36 65 36 66 32 63 32 30 35 30   ....I76e6f2c2050
         1254  +|   3488: 35 32 34 39 34 64 34 31 35 32 35 39 32 30 34 62   52494d415259204b
         1255  +|   3504: 34 35 35 39 32 38 37 33 36 35 36 37 36 39 36 34   4559287365676964
         1256  +|   3520: 32 63 32 30 37 34 36 35 37 32 36 64 32 39 32 39   2c207465726d2929
         1257  +|   3536: 32 30 35 37 34 39 35 34 34 38 34 66 35 35 05 02   20574954484f55..
         1258  +|   3552: 13 02 49 39 37 61 36 35 37 34 33 31 35 66 36 34   ..I97a6574315f64
         1259  +|   3568: 36 66 36 33 37 33 36 39 37 61 36 35 30 35 34 33   6f6373697a650543
         1260  +|   3584: 35 32 34 35 34 31 35 34 34 35 32 30 35 34 34 31   5245415445205441
         1261  +|   3600: 34 32 34 63 34 35 32 30 32 37 37 34 33 31 35 66   424c45202774315f
         1262  +|   3616: 36 34 36 66 36 33 37 33 36 39 37 61 05 04 05 07   646f6373697a....
         1263  +|   3632: 01 0e 37 34 30 34 34 33 35 32 34 35 34 31 35 34   ..74044352454154
         1264  +|   3648: 05 04 08 07 02 49 36 32 39 32 30 35 37 34 39 35   .....I6292057495
         1265  +|   3664: 34 34 38 34 66 35 35 35 34 32 30 35 32 34 66 35   4484f555420524f5
         1266  +|   3680: 37 34 39 34 34 35 62 30 35 30 37 31 37 32 31 32   749445b050717212
         1267  +|   3696: 31 30 31 38 31 30 31 37 34 36 31 36 32 36 63 36   10181017461626c6
         1268  +|   3712: 35 37 34 33 31 35 66 36 34 36 66 36 33 37 33 05   574315f646f6373.
         1269  +|   3728: 02 04 01 06 62 61 63 6b 75 70 05 02 1e 02 05 65   ....backup.....e
         1270  +|   3744: 61 6d 65 72 05 02 02 02 05 6f 6f 6d 65 72 05 01   amer.....oomer..
         1271  +|   3760: 02 40 75 6d 6d 32 34 63 34 35 32 30 32 37 37 34   .@umm24c45202774
         1272  +|   3776: 33 31 35 66 36 33 36 66 36 65 36 36 36 39 36 37   315f636f6e666967
         1273  +|   3792: 32 37 32 38 36 62 32 30 35 30 35 32 34 39 34 64   27286b205052494d
         1274  +|   3808: 34 31 35 32 35 39 32 30 34 62 34 35 35 39 32 63   415259204b45592c
         1275  +|   3824: 32 30 05 02 03 01 04 79 65 6b 72 05 02 10 04 11   20.....yekr.....
         1276  +|   3840: 4e 41 09 49 08 2d 4f 4e 4e 2e 4f 3f 4e 0c 4f 4f   NA.I.-ONN.O?N.OO
         1277  +|   3856: 4e 4f 14 4e 0b 0a 09 45 0f ef 00 14 2a 00 00 00   NO.N...E....*...
         1278  +|   3872: 00 01 02 02 00 02 01 01 01 02 01 01 81 09 88 80   ................
         1279  +|   3888: 80 80 80 01 04 00 82 16 00 00 00 79 06 30 61 62   ...........y.0ab
         1280  +|   3904: 61 63 6b 08 02 07 04 04 6e 64 6f 6e 08 02 05 02   ack.....ndon....
         1281  +|   3920: 05 63 74 69 76 65 04 02 02 04 02 0b 02 04 6c 70   .ctive........lp
         1282  +|   3936: 68 61 08 04 02 0a 02 03 74 6b 6d 06 02 02 03 02   ha......tkm.....
         1283  +|   3952: 6f 6d 08 02 09 05 02 69 63 07 02 02 01 06 62 61   om.....ic.....ba
         1284  +|   3968: 63 6b 75 70 08 02 04 02 05 6f 6f 6d 65 72 05 02   ckup.....oomer..
         1285  +|   3984: 02 01 0c 63 68 61 6e 6e 65 62 6f 6f 6d 65 72 08   ...channeboomer.
         1286  +|   4000: 02 08 07 01 6c 08 02 03 01 04 74 65 73 74 08 02   ....l.....test..
         1287  +|   4016: 06 04 0a 09 0d 0a 08 07 07 0b 0a 11 06 24 84 80   .............$..
         1288  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1289  +|   4048: 63 6b 01 08 02 04 02 66 74 00 02 22 04 04 6e 64   ck.....ft.....nd
         1290  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 06 22 00   on..............
         1291  +|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         1292  +| page 3 offset 8192
         1293  +|      0: 0a 00 00 00 04 0f e5 00 0f fa 0f f3 0f ec 0f e5   ................
         1294  +|   4064: 00 00 00 00 00 06 04 01 0c 01 04 02 06 04 01 0c   ................
         1295  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         1296  +| page 4 offset 12288
         1297  +|      0: 0d 0f 68 00 06 08 98 00 0f f6 0f ec 0f d5 08 98   ..h.............
         1298  +|     16: 0f c1 0f b6 0f 68 0f 68 00 00 00 00 00 00 00 00   .....h.h........
         1299  +|   2192: 00 00 00 00 00 00 00 00 8d 4d 05 04 00 9b 1f 62   .........M.....b
         1300  +|   2208: 65 61 6d 65 72 20 62 75 6d 6d 32 34 63 34 35 32   eamer bumm24c452
         1301  +|   2224: 30 32 37 37 34 33 31 35 66 36 33 36 66 36 65 36   02774315f636f6e6
         1302  +|   2240: 36 36 39 36 37 32 37 32 38 36 62 32 30 35 30 35   6696727286b20505
         1303  +|   2256: 32 34 39 34 64 34 31 35 32 35 39 32 30 34 62 34   2494d415259204b4
         1304  +|   2272: 35 35 39 32 63 32 30 0a 37 36 32 39 32 30 35 37   5592c20.76292057
         1305  +|   2288: 34 39 35 34 34 38 34 66 35 35 35 34 32 30 35 32   4954484f55542052
         1306  +|   2304: 34 66 35 37 34 39 34 34 35 62 30 35 30 37 31 37   4f5749445b050717
         1307  +|   2320: 32 31 32 31 30 31 38 31 30 31 37 34 36 31 36 32   2121018101746162
         1308  +|   2336: 36 63 36 35 37 34 33 31 35 66 36 34 36 66 36 33   6c6574315f646f63
         1309  +|   2352: 37 33 0a 36 39 37 61 36 35 37 34 33 31 35 66 36   73.697a6574315f6
         1310  +|   2368: 34 36 66 36 33 37 33 36 39 37 61 36 35 30 35 34   46f6373697a65054
         1311  +|   2384: 33 35 32 34 35 34 31 35 34 34 35 32 30 35 34 34   3524541544520544
         1312  +|   2400: 31 34 32 34 63 34 35 32 30 32 37 37 34 33 31 35   1424c45202774315
         1313  +|   2416: 66 36 34 36 66 36 33 37 33 36 39 37 61 0a 36 35   f646f6373697a.65
         1314  +|   2432: 32 37 32 38 36 39 36 34 32 30 34 39 34 65 35 34   2728696420494e54
         1315  +|   2448: 34 35 34 37 34 35 35 32 32 30 35 30 35 32 34 39   4547455220505249
         1316  +|   2464: 34 64 34 31 35 32 35 39 32 30 34 62 34 35 35 39   4d415259204b4559
         1317  +|   2480: 32 63 32 30 37 33 37 61 32 30 34 32 34 63 34 66   2c20737a20424c4f
         1318  +|   2496: 34 32 32 39 35 35 30 34 0a 30 36 31 37 32 31 32   42295504.0617212
         1319  +|   2512: 31 30 31 37 37 37 34 36 31 36 32 35 63 36 35 37   101777461625c657
         1320  +|   2528: 34 33 31 35 66 36 33 36 66 36 65 37 34 36 35 36   4315f636f6e74656
         1321  +|   2544: 65 37 34 37 34 33 31 35 66 36 33 36 66 36 65 37   e7474315f636f6e7
         1322  +|   2560: 34 36 35 36 65 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   4656e...........
         1323  +|   2576: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1324  +|   2592: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1325  +|   2608: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1326  +|   2624: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1327  +|   2640: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1328  +|   2656: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 37 34 30   .............740
         1329  +|   2672: 34 34 33 35 32 34 35 34 31 35 34 0a 34 35 32 30   44352454154.4520
         1330  +|   2688: 35 34 34 31 34 32 34 63 34 35 32 30 32 37 37 34   5441424c45202774
         1331  +|   2704: 33 31 35 66 36 33 36 66 36 65 37 34 36 35 36 65   315f636f6e74656e
         1332  +|   2720: 37 34 32 37 32 38 36 39 36 34 32 30 34 39 34 65   742728696420494e
         1333  +|   2736: 35 34 34 35 34 37 34 35 35 32 32 30 35 30 35 62   544547455220505b
         1334  +|   2752: 30 35 30 37 31 37 32 31 32 31 30 31 38 31 30 31   0507172121018101
         1335  +|   2768: 37 34 36 31 36 32 36 63 36 35 37 34 33 31 35 66   7461626c6574315f
         1336  +|   2784: 36 34 36 66 36 33 37 33 0a 36 39 37 61 36 35 37   646f6373.697a657
         1337  +|   2800: 34 33 31 35 66 36 34 36 66 36 33 37 33 36 39 37   4315f646f6373697
         1338  +|   2816: 61 36 35 30 35 34 33 35 32 34 35 34 31 35 34 34   a650543524541544
         1339  +|   2832: 35 32 30 35 34 34 31 34 32 34 63 34 35 32 30 32   5205441424c45202
         1340  +|   2848: 37 37 34 33 31 35 66 36 34 36 66 36 33 37 33 36   774315f646f63736
         1341  +|   2864: 39 37 61 0a 36 35 32 37 32 38 36 39 36 34 32 30   97a.652728696420
         1342  +|   2880: 34 39 34 65 35 34 34 35 34 37 34 35 35 32 32 30   494e544547455220
         1343  +|   2896: 35 30 35 32 34 39 34 64 34 31 35 32 35 39 32 30   5052494d41525920
         1344  +|   2912: 34 62 34 35 35 39 32 63 32 30 37 33 37 61 32 30   4b45592c20737a20
         1345  +|   2928: 34 32 34 63 34 66 34 32 32 39 35 35 30 34 0a 30   424c4f42295504.0
         1346  +|   2944: 36 31 37 32 31 32 31 30 31 37 37 37 34 36 31 36   6172121017774616
         1347  +|   2960: 32 35 63 36 35 37 34 33 31 35 66 36 33 36 66 36   25c6574315f636f6
         1348  +|   2976: 65 37 34 36 35 36 65 37 34 37 34 33 31 35 66 36   e74656e7474315f6
         1349  +|   2992: 33 36 66 36 65 37 34 36 35 36 65 0b 0b 0b 0b 0b   36f6e74656e.....
         1350  +|   3008: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1351  +|   3024: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1352  +|   3040: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1353  +|   3056: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1354  +|   3072: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1355  +|   3088: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1356  +|   3104: 0b 0b 0b 37 34 30 34 34 33 35 32 34 35 34 31 35   ...7404435245415
         1357  +|   3120: 34 0a 34 35 32 30 35 34 34 31 34 32 34 63 34 35   4.45205441424c45
         1358  +|   3136: 32 30 32 37 37 34 33 31 35 66 36 33 36 66 36 65   202774315f636f6e
         1359  +|   3152: 37 34 36 35 36 65 37 34 32 37 32 38 36 39 36 34   74656e7427286964
         1360  +|   3168: 32 30 34 39 34 65 35 34 34 35 34 37 34 35 35 32   20494e5445474552
         1361  +|   3184: 32 30 35 30 35 32 34 39 34 64 34 31 0a 35 32 35   205052494d41.525
         1362  +|   3200: 39 32 30 34 62 34 35 35 39 32 63 32 30 36 33 33   9204b45592c20633
         1363  +|   3216: 30 32 39 36 39 30 33 30 37 31 37 31 39 31 39 30   0296903071719190
         1364  +|   3232: 31 38 31 32 64 37 34 36 31 36 32 36 63 36 35 37   1812d7461626c657
         1365  +|   3248: 34 33 31 35 66 36 39 c3 bf c3 bf 7e c3 bf c3 89   4315f69....~....
         1366  +|   3264: 4b 52 c2 81 35 66 36 39 36 34 37 38 0a 30 33 34   KR..5f696478.034
         1367  +|   3280: 33 35 32 34 35 34 31 35 34 34 35 32 30 35 34 34   3524541544520544
         1368  +|   3296: 31 34 32 34 63 34 35 32 30 32 37 37 34 33 31 35   1424c45202774315
         1369  +|   3312: 66 36 39 36 34 37 38 32 37 32 38 37 33 36 35 36   f696478272873656
         1370  +|   3328: 37 36 39 36 34 32 63 32 30 37 34 36 35 37 32 36   769642c207465726
         1371  +|   3344: 64 32 63 32 30 37 30 0a 36 37 36 65 36 66 32 63   d2c2070.676e6f2c
         1372  +|   3360: 32 30 35 30 35 32 34 39 34 64 34 31 35 32 35 39   205052494d415259
         1373  +|   3376: 32 30 34 62 34 35 35 39 32 38 37 33 36 35 36 37   204b455928736567
         1374  +|   3392: 36 39 36 34 32 63 32 30 37 34 36 35 37 32 36 64   69642c207465726d
         1375  +|   3408: 32 39 32 39 32 30 35 37 34 39 35 34 34 38 34 66   292920574954484f
         1376  +|   3424: 35 35 0a 35 34 32 30 35 32 34 66 35 37 34 39 34   55.5420524f57494
         1377  +|   3440: 34 35 35 30 32 30 37 31 37 31 62 31 62 30 31 38   4550207171b1b018
         1378  +|   3456: 31 30 31 37 34 36 31 36 32 36 63 36 37 37 34 33   1017461626c67743
         1379  +|   3472: 31 35 66 36 34 36 31 37 34 36 31 37 34 33 31 35   15f6461746174315
         1380  +|   3488: 66 36 34 36 31 37 34 36 31 30 32 34 33 0a 35 32   f646174610243.52
         1381  +|   3504: 34 35 34 31 35 34 34 35 32 30 35 34 34 31 34 32   4541544520544142
         1382  +|   3520: 34 63 34 35 32 30 32 37 37 34 33 31 35 66 36 34   4c45202774315f64
         1383  +|   3536: 36 31 37 34 36 31 32 37 32 38 36 39 36 34 32 30   6174612728696420
         1384  +|   3552: 34 39 34 65 35 34 34 35 34 37 34 35 35 32 32 30   494e544547455220
         1385  +|   3568: 35 30 35 32 34 39 34 64 0a 34 31 35 32 35 39 32   5052494d.4152592
         1386  +|   3584: 30 34 62 34 35 35 39 32 63 32 30 36 32 36 63 36   04b45592c20626c6
         1387  +|   3600: 66 36 33 36 62 32 30 34 32 34 63 34 66 34 32 32   f636b20424c4f422
         1388  +|   3616: 39 33 61 30 31 30 36 31 37 31 31 31 31 30 38 36   93a0106171111086
         1389  +|   3632: 33 37 34 36 31 36 32 36 63 36 35 37 34 33 31 37   37461626c6574317
         1390  +|   3648: 34 33 31 0a 34 33 35 32 34 35 34 31 35 34 34 35   431.435245415445
         1391  +|   3664: 32 30 35 36 34 39 35 32 35 34 35 35 34 31 34 63   205649525455414c
         1392  +|   3680: 32 30 35 34 34 31 34 32 34 63 34 35 32 30 37 34   205441424c452074
         1393  +|   3696: 33 31 c3 94 30 35 35 35 33 34 39 34 65 34 37 32   31..05553494e472
         1394  +|   3712: 30 36 36 37 34 37 33 33 35 32 38 36 33 36 66 0a   06674733528636f.
         1395  +|   3728: 33 65 37 34 36 35 36 65 37 34 32 39 30 64 30 30   3e74656e74290d00
         1396  +|   3744: 30 30 30 30 30 33 30 66 62 64 30 30 30 66 65 38   0000030fbd000fe8
         1397  +|   3760: 30 66 65 66 30 66 62 64 0a 5b 31 66 62 64 5d 32   0fef0fbd.[1fbd]2
         1398  +|   3776: 34 38 34 38 30 38 30 38 30 38 30 30 31 30 33 30   4848080808001030
         1399  +|   3792: 30 34 65 30 30 30 30 30 30 31 65 30 36 33 30 36   04e0000001e06306
         1400  +|   3808: 31 36 32 36 31 36 33 36 62 30 31 30 32 30 32 30   16261636b0102020
         1401  +|   3824: 34 30 32 36 36 37 34 30 32 30 32 30 32 30 34 30   4026674020202040
         1402  +|   3840: 34 36 65 0a 36 34 36 66 36 65 30 33 30 32 30 32   46e.646f6e030202
         1403  +|   3856: 30 34 30 61 30 37 30 35 30 31 30 33 30 30 31 30   040a070501030010
         1404  +|   3872: 30 33 30 33 30 66 30 61 30 33 30 30 32 34 30 30   03030f0a03002400
         1405  +|   3888: 30 30 30 30 30 30 30 31 30 31 30 31 30 30 30 31   0000000101010001
         1406  +|   3904: 30 31 30 31 30 31 30 61 30 30 30 30 30 30 0a 30   0101010a000000.0
         1407  +|   3920: 31 30 66 66 61 30 30 30 66 66 61 0a 5b 32 66 65   10ffa000ffa.[2fe
         1408  +|   3936: 72 20 62 61 63 6b 75 70 0f ca 00 4e 81 1d 61 6c   r backup...N..al
         1409  +|   3952: 70 68 61 20 63 68 61 6e 6e 65 6c 20 c2 af 62 61   pha channel ..ba
         1410  +|   3968: 63 6b 75 70 20 61 62 61 6e 64 6f 6e 20 74 65 73   ckup abandon tes
         1411  +|   3984: 74 20 61 62 61 63 6b 20 63 68 61 6e 6e 65 62 6f   t aback channebo
         1412  +|   4000: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         1413  +|   4016: 61 63 74 69 76 65 09 07 03 00 19 61 74 6f 6d 69   active.....atomi
         1414  +|   4032: 63 07 06 03 00 15 61 74 6b 6d 0f e0 00 0b 19 62   c.....atkm.....b
         1415  +|   4048: 6f 6f 6d 65 72 09 04 03 00 19 61 63 74 69 76 65   oomer.....active
         1416  +|   4064: 00 00 00 0c 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1417  +|   4080: 17 61 66 21 66 74 08 01 03 00 17 61 62 61 63 6b   .af!ft.....aback
         1418  +| page 5 offset 16384
         1419  +|      0: 0d 0f ee 00 06 0f d6 00 0f fa 0f f4 0f e8 0f e2   ................
         1420  +|     16: 0f dc 0f d6 0f d0 0f d0 00 00 00 00 00 00 00 00   ................
         1421  +|   4048: 0f ee 00 06 0e 0a 04 07 03 00 0e 01 04 06 03 00   ................
         1422  +|   4064: 0e 01 04 05 03 00 0e 1d 04 04 03 00 0e 01 00 00   ................
         1423  +|   4080: 00 06 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1424  +| page 6 offset 20480
         1425  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1426  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1427  +| page 7 offset 24576
         1428  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1429  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1430  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1431  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         1432  +| end c19b.db
         1433  +}]} {}
         1434  +
         1435  +do_catchsql_test 18.1 {
         1436  +  INSERT INTO t1(t1) VALUES('optimize');
         1437  +} {1 {database disk image is malformed}}
         1438  +
         1439  +#--------------------------------------------------------------------------
         1440  +reset_db
         1441  +do_test 19.0 {
         1442  +  sqlite3 db {}
         1443  +  db deserialize [decode_hexdb {
         1444  +| size 28672 pagesize 4096 filename c20b.db
         1445  +| page 1 offset 0
         1446  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1447  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
         1448  +|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         1449  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1450  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
         1451  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
         1452  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1453  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1454  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1455  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1456  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1457  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1458  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1459  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1460  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1461  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         1462  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1463  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1464  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1465  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1466  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1467  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1468  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1469  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1470  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1471  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1472  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1473  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1474  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1475  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1476  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1477  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1478  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1479  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1480  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1481  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1482  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1483  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1484  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1485  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1486  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1487  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1488  +| page 2 offset 4096
         1489  +|      0: 0d 0f 20 00 05 0e a0 00 0f e8 0e a0 0f bd 0f 34   .. ............4
         1490  +|     16: 0e b7 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         1491  +|   3744: 15 0a 03 00 30 00 00 00 00 01 03 03 00 03 01 01   ....0...........
         1492  +|   3760: 01 02 01 01 03 01 01 62 8c 80 80 80 80 01 04 00   .......b........
         1493  +|   3776: 81 48 00 00 00 55 06 30 61 62 61 63 6b 08 01 04   .H...U.0aback...
         1494  +|   3792: 04 6e 64 6f 6e 03 01 05 01 02 05 63 74 69 76 65   .ndon......ctive
         1495  +|   3808: 08 01 02 04 6c 70 68 61 08 01 02 03 74 6f 6d 08   ....lpha....tom.
         1496  +|   3824: 01 01 06 62 61 63 6b 75 70 08 01 02 05 6f 6f 6d   ...backup....oom
         1497  +|   3840: 65 72 08 01 01 07 63 68 61 6e 6e 65 6c 08 01 01   er....channel...
         1498  +|   3856: 04 74 65 73 74 08 01 04 09 0a 09 08 07 0a 09 0b   .test...........
         1499  +|   3872: 0f ef 00 14 2a 00 00 00 00 01 02 02 00 02 01 01   ....*...........
         1500  +|   3888: 01 02 01 01 81 01 88 80 80 80 80 01 04 00 82 06   ................
         1501  +|   3904: 00 00 00 72 06 30 61 62 61 63 6b 08 02 07 04 04   ...r.0aback.....
         1502  +|   3920: 6e 64 6f 6e 08 02 05 02 05 63 74 69 76 65 04 02   ndon.....ctive..
         1503  +|   3936: 02 04 02 0b 02 04 6c 70 68 61 08 04 02 0a 02 03   ......lpha......
         1504  +|   3952: 74 6f 6d 06 02 02 02 02 09 05 02 69 63 07 02 02   tom........ic...
         1505  +|   3968: 01 06 62 61 63 6b 75 70 08 02 04 02 05 6f 6f 66   ..backup.....oof
         1506  +|   3984: 65 72 05 02 02 04 03 6d 65 72 08 02 08 01 07 63   er.....mer.....c
         1507  +|   4000: 68 61 6e 6e 65 6c 08 02 03 01 04 74 65 73 74 08   hannel.....test.
         1508  +|   4016: 02 06 04 0a 09 0d 0a 0b 07 0b 0a 08 0c 24 84 80   .............$..
         1509  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1510  +|   4048: 63 6b 01 02 66 04 00 22 74 00 02 22 04 04 6e 64   ck..f...t.....nd
         1511  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 06 06 00   on..............
         1512  +|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         1513  +| page 3 offset 8192
         1514  +|      0: 0a 00 00 00 03 0f ec 00 0f fa 0f f3 0f ec 00 00   ................
         1515  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 06 04 01 0c   ................
         1516  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         1517  +| page 4 offset 12288
         1518  +|      0: 0d 0f e0 00 06 0f b6 00 0f f6 0f ec 0f d5 0f ca   ................
         1519  +|     16: 0f c1 0f b6 0f 70 0f 70 00 00 00 00 00 00 00 00   .....p.p........
         1520  +|   3952: 0f e0 00 46 81 0d 61 6c 70 68 61 20 63 68 61 6e   ...F..alpha chan
         1521  +|   3968: 6e 65 6c 20 62 61 63 6b 75 70 20 61 62 61 6e 64   nel backup aband
         1522  +|   3984: 6f 6e 20 74 65 73 74 20 61 62 61 63 6b 20 62 6f   on test aback bo
         1523  +|   4000: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         1524  +|   4016: 61 63 74 69 76 65 09 07 03 00 19 61 74 6f 6d 69   active.....atomi
         1525  +|   4032: 63 07 06 03 00 15 61 74 6f 6d 09 05 03 00 19 62   c.....atom.....b
         1526  +|   4048: 6f 6f 66 65 72 09 04 03 00 19 61 63 74 69 76 65   oofer.....active
         1527  +|   4064: 00 00 00 0c 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1528  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         1529  +| page 5 offset 16384
         1530  +|      0: 0d 0f ee 00 06 0f d6 00 0f fa 0f f4 0f e8 0f e2   ................
         1531  +|     16: 0f dc 0f d6 0f d0 0f d0 00 00 00 00 00 00 00 00   ................
         1532  +|   4048: 0f ee 00 06 0e 0a 04 07 03 00 0e 01 04 06 03 00   ................
         1533  +|   4064: 0e 01 04 05 03 00 0e 01 04 04 03 00 0e 01 00 00   ................
         1534  +|   4080: 00 06 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1535  +| page 6 offset 20480
         1536  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1537  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1538  +| page 7 offset 24576
         1539  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1540  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1541  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1542  +|   4080: 86 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   .eck....optimize
         1543  +| end c20b.db
         1544  +}]} {}
         1545  +
         1546  +do_catchsql_test 19.1 {
         1547  +  INSERT INTO t1(t1) VALUES('optimize');
         1548  +} {1 {database disk image is malformed}}
         1549  +
         1550  +#--------------------------------------------------------------------------
         1551  +reset_db
         1552  +do_test 20.0 {
         1553  +  sqlite3 db {}
         1554  +  db deserialize [decode_hexdb {
         1555  +| size 28672 pagesize 4096 filename crash-cf347c523f793c.db
         1556  +| page 1 offset 0
         1557  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1558  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
         1559  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00   ................
         1560  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1561  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
         1562  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1563  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1564  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1565  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1566  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1567  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1568  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1569  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1570  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1571  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         1572  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1573  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1574  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1575  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1576  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1577  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1578  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1579  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1580  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1581  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1582  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1583  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1584  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1585  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1586  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1587  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1588  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1589  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1590  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1591  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1592  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1593  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1594  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1595  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1596  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1597  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1598  +| page 2 offset 4096
         1599  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
         1600  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
         1601  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1602  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
         1603  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
         1604  +|   4080: 0a 03 00 24 00 00 00 0e ee ee ee ee ee ee ee ee   ...$............
         1605  +| page 3 offset 8192
         1606  +|      0: ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee   ................
         1607  +|     16: ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee   ................
         1608  +|     32: ee ee ee ee ee ee ee ee ee ee ee ee 00 10 10 10   ................
         1609  +|     48: 00 10 10 10 10 a0 00 00 00 10 ff a0 00 ff 00 00   ................
         1610  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         1611  +| page 4 offset 12288
         1612  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
         1613  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1614  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         1615  +| page 5 offset 16384
         1616  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f4 0f ee 00 00   ................
         1617  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
         1618  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1619  +| page 6 offset 20480
         1620  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1621  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1622  +| page 7 offset 24576
         1623  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1624  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1625  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1626  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         1627  +| end crash-cf347c523f793c.db
         1628  +}]} {}
         1629  +
         1630  +do_catchsql_test 20.1 {
         1631  +  SELECT * FROM t1 WHERE t1 MATCH 'abandon';
         1632  +} {1 {vtable constructor failed: t1}}
         1633  +
         1634  +#-------------------------------------------------------------------------
         1635  +reset_db
         1636  +do_test 21.0 {
         1637  +  sqlite3 db {}
         1638  +  db deserialize [decode_hexdb {
         1639  +| size 28672 pagesize 4096 filename c22b.db
         1640  +| page 1 offset 0
         1641  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1642  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
         1643  +|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         1644  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1645  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
         1646  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
         1647  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1648  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1649  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1650  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1651  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1652  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1653  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1654  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1655  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1656  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         1657  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1658  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1659  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1660  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1661  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1662  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1663  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1664  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1665  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1666  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1667  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1668  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1669  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1670  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1671  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1672  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1673  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1674  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1675  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1676  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1677  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1678  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1679  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1680  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1681  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1682  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1683  +| page 2 offset 4096
         1684  +|      0: 0d 0e 8e 00 06 0e 2f 00 0f e8 0e 2f 0f bd 0f 3b   ....../..../...;
         1685  +|     16: 0e a5 0e 49 00 00 00 00 00 00 00 00 00 00 00 00   ...I............
         1686  +|   3616: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 18   ................
         1687  +|   3632: 0a 03 00 36 00 00 00 00 01 04 04 00 04 01 01 01   ...6............
         1688  +|   3648: 02 01 01 03 01 01 04 01 01 3e 90 80 80 80 80 01   .........>......
         1689  +|   3664: 04 00 81 00 00 00 00 36 06 30 62 61 63 6b 75 05   .......6.0backu.
         1690  +|   3680: 02 04 05 02 04 02 05 65 61 6d 65 72 05 02 02 05   .......eamer....
         1691  +|   3696: 02 02 02 05 6f 6f 6d 65 72 05 01 05 01 02 05 75   ....oomer......u
         1692  +|   3712: 6d 6d 65 72 05 02 03 05 02 03 04 0d 0d 0b 0f 27   mmer...........'
         1693  +|   3728: 00 17 30 00 00 00 00 01 03 03 00 03 01 01 01 02   ..0.............
         1694  +|   3744: 01 01 03 01 01 7b 8c 80 80 80 80 01 04 00 81 7a   ...............z
         1695  +|   3760: 00 00 00 6d 06 30 61 62 61 63 6b 0d 02 07 04 04   ...m.0aback.....
         1696  +|   3776: 6e 64 6f 6e 0d 02 05 02 05 63 74 69 76 65 09 02   ndon.....ctive..
         1697  +|   3792: 02 04 02 0b 02 04 6c 70 68 61 0d 04 02 0a 02 03   ......lpha......
         1698  +|   3808: 74 6f 6d 0b 02 02 02 02 09 05 02 69 63 0c 02 02   tom........ic...
         1699  +|   3824: 01 06 62 61 63 6b 75 70 0d 02 04 02 05 6f 6f 6d   ..backup.....oom
         1700  +|   3840: 65 72 0a 02 02 03 02 08 01 07 63 68 61 6e 6e 65   er........channe
         1701  +|   3856: 6c 0d 02 03 01 04 74 65 73 74 0d 02 06 04 0a 09   l.....test......
         1702  +|   3872: 0d 0a 0b 07 0b 0d 0c 0f ef 00 14 2a 00 00 00 00   ...........*....
         1703  +|   3888: 01 02 02 00 02 01 01 01 02 01 01 7b 88 80 80 80   ................
         1704  +|   3904: 80 01 04 00 81 7a 00 00 00 6d 06 30 61 62 61 63   .....z...m.0abac
         1705  +|   3920: 6b 08 02 07 04 04 6e 64 6f 6e 08 02 05 02 05 63   k.....ndon.....c
         1706  +|   3936: 74 69 76 65 04 02 02 04 02 0b 02 04 6c 70 68 61   tive........lpha
         1707  +|   3952: 08 04 02 0a 02 03 74 6f 6d 06 02 02 02 02 09 05   ......tom.......
         1708  +|   3968: 02 69 63 07 02 02 01 06 62 61 63 6b 75 70 08 02   .ic.....backup..
         1709  +|   3984: 04 02 05 6f 6f 6d 65 72 05 02 02 03 02 08 01 07   ...oomer........
         1710  +|   4000: 63 68 61 6e 6e 65 6c 08 02 03 01 04 74 65 73 74   channel.....test
         1711  +|   4016: 08 02 06 04 0a 09 0d 0a 0b 07 0b 0d 0c 24 84 80   .............$..
         1712  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1713  +|   4048: 63 6b 01 02 02 04 02 66 74 00 02 22 04 04 6e 64   ck.....ft.....nd
         1714  +|   4064: 6f 6e 03 02 02 08 0a 07 05 01 03 00 10 0d 23 00   on............#.
         1715  +|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         1716  +| page 3 offset 8192
         1717  +|      0: 0a 00 00 00 04 0f e5 00 0f fa 0f f3 0f ec 0f e5   ................
         1718  +|   4064: 00 00 00 00 00 06 04 01 0c 01 04 02 06 04 01 0c   ................
         1719  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         1720  +| page 4 offset 12288
         1721  +|      0: 0d 0f 5a 00 0d 0e ce 00 0f f6 0f ec 0f e0 0f d5   ..Z.............
         1722  +|     16: 0e e7 0f c1 0f b6 0f 70 0f 65 0e ce 0f 51 0f 46   .......p.e...Q.F
         1723  +|     32: 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         1724  +|   3776: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17 0a   ................
         1725  +|   3792: 03 00 35 62 65 61 6d 65 72 20 62 75 6d 6d 65 72   ..5beamer bummer
         1726  +|   3808: 20 62 61 63 6b 75 29 17 05 03 00 35 62 65 61 6d    backu)....5beam
         1727  +|   3824: 65 72 20 62 75 6d 6d 65 72 20 62 61 63 6b 75 29   er bummer backu)
         1728  +|   3840: 44 0d 04 00 81 0d 61 6c 70 68 61 20 63 68 61 6e   D.....alpha chan
         1729  +|   3856: 6e 65 6c 20 62 61 63 6b 75 70 20 61 62 61 6e 64   nel backup aband
         1730  +|   3872: 6f 6e 20 74 65 73 74 20 61 62 61 63 6b 20 62 6f   on test aback bo
         1731  +|   3888: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         1732  +|   3904: 61 63 74 69 76 65 09 0c 03 00 19 61 74 6f 6d 69   active.....atomi
         1733  +|   3920: 63 07 0b 03 00 15 61 74 6f 6d 0f ca 00 0b 19 62   c.....atom.....b
         1734  +|   3936: 6f 6f 6d 65 72 09 09 03 00 19 61 63 74 69 76 65   oomer.....active
         1735  +|   3952: 44 08 04 00 81 0d 61 6c 70 68 61 20 63 68 61 6e   D.....alpha chan
         1736  +|   3968: 6e 65 6c 20 62 61 63 6b 75 70 20 61 62 61 6e 64   nel backup aband
         1737  +|   3984: 6f 6e 20 74 65 73 74 20 61 62 61 63 6b 20 62 6f   on test aback bo
         1738  +|   4000: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         1739  +|   4016: 61 63 74 69 76 65 09 07 03 00 19 61 74 6f 6d 69   active.....atomi
         1740  +|   4032: 63 07 06 03 00 15 61 74 6f 6d 00 00 00 0b 19 62   c.....atom.....b
         1741  +|   4048: 6f 6f 6d 65 72 09 04 03 00 19 61 63 74 69 76 65   oomer.....active
         1742  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1743  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         1744  +| page 5 offset 16384
         1745  +|      0: 0d 00 00 00 0d 0f b2 00 0f fa 0f f4 0f ee 0f e8   ................
         1746  +|     16: 0f e2 0f dc 0f d6 0f d0 0f ca 0f c4 0f be 0f b8   ................
         1747  +|     32: 0f b2 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         1748  +|   4016: 00 00 04 0d 03 00 0e 0a 04 0c 03 00 0e 01 04 0b   ................
         1749  +|   4032: 03 00 0e 01 04 0a 03 00 0e 03 04 09 03 00 0e 01   ................
         1750  +|   4048: 04 08 03 00 0e 0a 04 07 03 00 0e 01 04 06 03 00   ................
         1751  +|   4064: 0e 01 04 05 03 00 0e 03 04 04 03 00 0e 01 04 03   ................
         1752  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1753  +| page 6 offset 20480
         1754  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1755  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1756  +| page 7 offset 24576
         1757  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1758  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1759  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1760  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         1761  +| end c22b.db
         1762  +}]} {}
         1763  +
         1764  +do_catchsql_test 21.1 {
         1765  +  DELETE FROM t1 WHERE t1 MATCH 'ab*ndon';
         1766  +} {1 {database disk image is malformed}}
         1767  +
         1768  +#-------------------------------------------------------------------------
         1769  +#
         1770  +reset_db
         1771  +do_test 22.0 {
         1772  +  sqlite3 db {}
         1773  +  db deserialize [decode_hexdb {
         1774  +| size 28672 pagesize 4096 filename c22b.db
         1775  +| page 1 offset 0
         1776  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1777  +|     16: 10 00 01 01 00 40 20 20 00 00 00 02 00 00 00 07   .....@  ........
         1778  +|     32: 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00   ................
         1779  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1780  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02   ................
         1781  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
         1782  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1783  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1784  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1785  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1786  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1787  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1788  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1789  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1790  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1791  +|   3664: 07 17 21 21 01 81 01 74 41 62 6c 65 74 31 5f 64   ..!!...tAblet1_d
         1792  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1793  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1794  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1795  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1796  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1797  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1798  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1799  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1800  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1801  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1802  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1803  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1804  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1805  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1806  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1807  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1808  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1809  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1810  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1811  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1812  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1813  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1814  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1815  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1816  +|   4064: 75 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   uAL TABLE t1 USI
         1817  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1818  +| page 2 offset 4096
         1819  +|      0: 0d 0f 15 00 05 08 4e 00 0f e8 08 4e 0f bd 0f 29   ......N....N...)
         1820  +|     16: 08 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00   .e..............
         1821  +|   2112: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 0a   ................
         1822  +|   2128: 03 00 30 00 00 00 00 01 03 02 01 03 01 01 01 02   ..0.............
         1823  +|   2144: 01 01 03 01 01 8d 28 8c 80 80 80 80 01 04 00 9a   ......(.........
         1824  +|   2160: 54 00 00 06 77 19 30 30 30 30 30 30 33 30 66 65   T...w.00000030fe
         1825  +|   2176: 65 30 30 30 66 66 61 30 66 66 34 30 66 65 65 05   e000ffa0ff40fee.
         1826  +|   2192: 02 19 02 0b 31 30 66 66 61 30 30 30 66 66 61 05   ....10ffa000ffa.
         1827  +|   2208: 06 13 18 09 02 25 33 34 33 35 32 34 35 34 31 35   .....%3435245415
         1828  +|   2224: 34 34 35 32 30 35 34 34 31 34 32 34 63 34 35 32   445205441424c452
         1829  +|   2240: 30 32 37 37 34 33 31 35 66 36 39 05 02 07 02 37   02774315f69....7
         1830  +|   2256: 34 30 33 30 33 30 30 30 65 30 31 30 34 30 32 30   40303000e0104020
         1831  +|   2272: 33 30 30 30 65 30 31 30 34 30 31 30 33 30 30 30   3000e01040103000
         1832  +|   2288: 65 30 31 30 61 30 30 30 30 30 30 30 31 30 66 66   e010a000000010ff
         1833  +|   2304: 34 30 30 30 66 66 34 05 02 1b 02 27 35 30 34 30   4000ff4....'5040
         1834  +|   2320: 39 30 63 30 31 30 32 30 64 30 30 30 30 30 30 30   90c01020d0000000
         1835  +|   2336: 33 30 66 65 30 30 30 30 66 66 36 30 66 65 63 30   30fe0000ff60fec0
         1836  +|   2352: 66 65 30 05 02 2c 27 02 66 30 05 02 16 02 1d 36   fe0..,'.f0.....6
         1837  +|   2368: 31 37 31 31 31 31 30 38 36 33 37 34 36 31 36 32   1711110863746162
         1838  +|   2384: 36 63 36 35 37 34 33 31 37 34 33 31 05 02 0d 02   6c6574317431....
         1839  +|   2400: 29 39 30 33 30 32 31 62 37 32 36 35 36 32 37 35   )903021b72656275
         1840  +|   2416: 36 34 36 31 37 34 36 31 37 34 33 31 35 66 36 34   6461746174315f64
         1841  +|   2432: 36 31 37 34 36 31 30 32 34 33 05 02 1f 02 43 61   6174610243....Ca
         1842  +|   2448: 30 33 30 33 30 30 31 62 36 31 36 32 36 31 36 65   0303001b6162616e
         1843  +|   2464: 36 34 36 66 36 65 30 38 30 32 30 33 30 30 31 37   646f6e0802030017
         1844  +|   2480: 36 31 36 32 36 31 36 36 37 34 30 38 30 31 30 33   6162616674080103
         1845  +|   2496: 30 30 31 37 36 31 36 32 36 31 36 33 36 62 30 64   0017616261636b0d
         1846  +|   2512: 30 30 05 02 18 34 1d 33 36 62 30 31 30 32 30 32   00...4.36b010202
         1847  +|   2528: 30 34 30 32 36 36 37 34 30 32 30 32 30 32 30 34   0402667402020204
         1848  +|   2544: 30 34 36 65 05 02 2e 02 33 62 30 33 31 62 30 31   046e....3b031b01
         1849  +|   2560: 37 36 36 35 37 32 37 33 36 39 36 66 36 65 30 34   76657273696f6e04
         1850  +|   2576: 30 64 30 30 30 30 30 30 30 33 30 66 64 36 30 30   0d000000030fd600
         1851  +|   2592: 30 66 66 34 30 66 65 31 30 66 64 36 05 02 1d 01   0ff40fe10fd6....
         1852  +|   2608: 04 31 66 62 64 05 04 10 18 01 01 32 05 02 14 02   .1fbd......2....
         1853  +|   2624: 43 34 38 34 38 30 38 30 38 30 38 30 30 31 30 33   C484808080800103
         1854  +|   2640: 30 30 34 65 30 30 30 30 30 30 31 65 30 36 33 30   004e0000001e0630
         1855  +|   2656: 36 31 36 32 36 31 36 33 36 62 30 31 30 32 30 32   616261636b010202
         1856  +|   2672: 30 34 30 32 36 36 37 34 30 32 30 32 30 32 30 34   0402667402020204
         1857  +|   2688: 30 34 36 65 05 04 11 18 02 01 66 05 02 2a 03 02   046e......f..*..
         1858  +|   2704: 65 72 05 02 31 01 08 33 35 32 38 36 33 36 66 05   er..1..3528636f.
         1859  +|   2720: 02 24 02 03 66 65 30 05 04 17 18 01 2b 34 31 35   .$..fe0.....+415
         1860  +|   2736: 32 35 39 32 30 34 62 34 35 35 39 32 63 32 30 36   259204b45592c206
         1861  +|   2752: 32 36 63 36 66 36 33 36 62 32 30 34 32 34 63 34   26c6f636b20424c4
         1862  +|   2768: 66 34 32 32 39 33 61 30 05 02 0c 2c 1f 31 30 36   f42293a0...,.106
         1863  +|   2784: 31 37 31 31 31 31 30 38 36 33 37 34 36 31 36 32   1711110863746162
         1864  +|   2800: 36 63 36 35 37 34 33 31 37 34 33 31 05 02 22 02   6c6574317431....
         1865  +|   2816: 40 33 35 32 34 35 34 31 35 34 34 35 32 30 35 36   @352454154452056
         1866  +|   2832: 34 39 35 32 35 34 37 35 34 31 34 63 32 30 35 34   49525475414c2054
         1867  +|   2848: 34 31 34 32 34 63 34 35 32 30 37 34 33 31 32 30   41424c4520743120
         1868  +|   2864: 35 35 35 33 34 39 34 65 34 37 32 30 36 36 37 34   5553494e47206674
         1869  +|   2880: 37 05 02 23 42 09 33 33 35 32 38 36 33 36 66 05   7..#B.33528636f.
         1870  +|   2896: 02 0e 02 03 66 65 65 05 02 1a 01 34 35 32 34 35   ....fee....45245
         1871  +|   2912: 34 31 35 34 34 35 32 30 35 34 34 31 34 32 34 63   415445205441424c
         1872  +|   2928: 34 35 32 30 32 37 37 34 33 31 35 66 36 34 36 31   45202774315f6461
         1873  +|   2944: 37 34 36 31 32 37 32 38 36 39 36 34 32 30 34 39   7461272869642049
         1874  +|   2960: 05 02 20 16 37 c3 b0 35 32 30 32 37 37 34 33 31   .. .7..520277431
         1875  +|   2976: 35 66 36 34 36 31 37 34 36 31 32 37 32 38 36 39   5f64617461272869
         1876  +|   2992: 36 34 32 30 34 39 34 65 35 34 34 35 34 37 34 35   6420494e54454745
         1877  +|   3008: 35 32 32 30 35 30 35 32 34 39 34 64 05 02 0b 03   52205052494d....
         1878  +|   3024: 48 35 39 32 30 34 62 34 35 35 39 32 63 32 30 36   H59204b45592c206
         1879  +|   3040: 33 33 30 32 39 36 39 30 33 30 30 30 31 35 37 35   3302969030001575
         1880  +|   3056: 33 31 31 39 32 36 64 37 34 36 31 36 32 36 63 36   311926d7461626c6
         1881  +|   3072: 35 37 34 33 31 35 66 36 39 36 34 37 38 37 34 33   574315f696478743
         1882  +|   3088: 31 35 66 36 39 36 34 37 38 05 02 06 02 38 34 32   15f696478....842
         1883  +|   3104: 30 35 32 34 66 35 37 34 39 34 34 35 35 30 32 30   0524f57494455020
         1884  +|   3120: 37 31 37 31 62 31 62 30 31 38 31 30 31 37 34 36   7171b1b018101746
         1885  +|   3136: 31 36 32 36 63 36 35 37 34 33 31 35 66 31 37 34   1626c6574315f174
         1886  +|   3152: 36 31 30 32 34 33 05 02 0a 02 03 66 66 34 05 02   610243.....ff4..
         1887  +|   3168: 1c 01 4a 36 34 36 66 36 65 30 33 30 32 30 32 30   ..J646f6e0302020
         1888  +|   3184: 34 30 61 30 37 30 35 30 31 30 33 30 30 31 30 30   40a0705010300100
         1889  +|   3200: 33 30 33 30 66 30 61 30 33 30 30 32 34 30 30 30   3030f0a030024000
         1890  +|   3216: 30 30 30 30 30 30 31 30 31 30 31 30 30 30 31 30   0000001010100010
         1891  +|   3232: 31 30 31 30 30 39 61 30 30 30 30 30 30 05 02 2f   101009a000000../
         1892  +|   3248: 42 09 31 30 61 30 30 30 30 30 30 05 02 28 08 43   B.10a000000..(.C
         1893  +|   3264: 74 30 32 30 32 30 34 30 61 30 37 30 35 30 31 30   t0202040a0705010
         1894  +|   3280: 33 30 30 31 30 30 33 30 33 30 66 30 61 30 33 30   3001003030f0a030
         1895  +|   3296: 30 32 34 30 30 30 30 30 30 30 30 30 31 30 31 30   0240000000001010
         1896  +|   3312: 31 30 30 30 31 30 31 30 31 30 31 30 61 30 30 30   100010101010a000
         1897  +|   3328: 30 30 30 05 02 12 02 49 37 36 65 36 66 32 63 32   000....I76e6f2c2
         1898  +|   3344: 30 35 30 35 32 34 39 34 64 34 31 35 32 35 39 32   05052494d4152592
         1899  +|   3360: 30 34 62 34 35 35 39 32 38 37 33 36 35 36 37 36   04b4559287365676
         1900  +|   3376: 39 36 34 32 63 32 30 37 34 36 35 37 32 36 64 32   9642c207465726d2
         1901  +|   3392: 39 32 39 32 30 35 37 34 39 35 34 34 38 34 66 35   92920574954484f5
         1902  +|   3408: 35 05 02 09 02 4c 39 37 61 36 35 37 34 33 31 35   5....L97a6574315
         1903  +|   3424: 66 36 34 36 66 36 33 37 33 36 39 37 61 36 35 30   f646f6373697a650
         1904  +|   3440: 35 34 33 35 32 34 35 34 31 35 34 34 35 32 30 35   5435245415445205
         1905  +|   3456: 34 38 36 39 36 34 32 30 34 39 34 65 35 34 34 35   48696420494e5445
         1906  +|   3472: 34 37 34 35 35 32 32 30 35 30 35 32 34 39 34 34   4745522050524944
         1907  +|   3488: 64 31 05 02 05 02 27 65 37 34 36 35 36 65 37 34   d1....'e74656e74
         1908  +|   3504: 32 39 30 64 30 30 30 30 30 30 30 33 30 66 62 64   290d000000030fbd
         1909  +|   3520: 30 30 30 62 65 38 30 66 65 66 30 66 62 64 05 02   000be80fef0fbd..
         1910  +|   3536: 0f 1e 0b 66 65 38 30 66 65 66 30 66 62 64 05 02   ...fe80fef0fbd..
         1911  +|   3552: 25 02 03 66 64 36 05 02 1e 01 4a 37 36 32 39 32   %..fd6....J76292
         1912  +|   3568: 30 35 37 34 39 35 34 34 38 34 66 35 35 35 34 32   0574954484f55542
         1913  +|   3584: 30 35 32 34 66 35 37 34 39 34 34 35 62 30 35 30   0524f5749445b050
         1914  +|   3600: 37 31 37 32 31 32 31 30 31 38 31 30 31 37 34 36   7172121018101746
         1915  +|   3616: 31 36 32 36 63 36 35 37 34 33 31 35 66 36 34 36   1626c6574315f646
         1916  +|   3632: 66 36 33 37 33 05 02 04 02 21 38 32 37 32 38 37   f6373....!827287
         1917  +|   3648: 33 36 35 36 37 36 39 36 34 32 63 32 30 37 34 36   3656769642c20746
         1918  +|   3664: 35 37 32 36 64 32 63 32 30 37 30 05 02 08 01 01   5726d2c2070.....
         1919  +|   3680: 61 05 02 2b 01 06 62 61 63 6b 75 70 05 02 32 02   a..+..backup..2.
         1920  +|   3696: 05 65 61 6d 65 72 05 02 02 02 05 6f 6f 6d 65 72   .eamer.....oomer
         1921  +|   3712: 05 01 02 40 75 6d 6d 32 34 63 34 35 32 30 32 37   ...@umm24c452027
         1922  +|   3728: 37 34 33 31 35 66 36 33 36 66 36 65 36 36 36 39   74315f636f6e6669
         1923  +|   3744: 36 37 32 37 32 38 36 62 32 30 35 30 35 32 34 39   6727286b20505249
         1924  +|   3760: 34 64 34 31 35 32 35 39 32 30 34 62 34 35 35 39   4d415259204b4559
         1925  +|   3776: 32 63 32 30 05 02 03 01 15 65 35 34 34 35 34 37   2c20.....e544547
         1926  +|   3792: 34 35 35 32 32 30 35 30 35 32 34 39 34 64 05 02   4552205052494d..
         1927  +|   3808: 21 01 02 66 61 05 02 15 04 1d 12 2a 3c 2c 07 22   !..fa......*<,..
         1928  +|   3824: 2e 48 22 38 0a 06 49 06 07 0d 09 30 24 45 0e 08   .H.8..I....0$E..
         1929  +|   3840: 39 3c 4d 3d 08 4f 0e 48 4e 51 2c 10 08 4f 26 06   9<M=.O.HNQ,..O&.
         1930  +|   3856: 0b 0a 09 45 1a 0f ef 00 14 2a 00 00 00 00 01 02   ...E.....*......
         1931  +|   3872: 01 01 02 01 01 01 02 01 01 81 0c 88 80 80 80 80   ................
         1932  +|   3888: 01 04 00 82 1c 00 00 00 7c 08 30 61 62 61 6e 64   ........|.0aband
         1933  +|   3904: 6f 6e 08 02 05 02 05 63 74 69 76 65 04 02 02 04   on.....ctive....
         1934  +|   3920: 02 0b 02 04 6c 70 68 61 08 04 02 0a 02 03 74 6b   ....lpha......tk
         1935  +|   3936: 6d 06 02 02 03 02 6f 6d 08 02 09 05 02 69 63 07   m.....om.....ic.
         1936  +|   3952: 02 02 01 06 62 61 63 6b 75 70 08 02 04 02 05 6f   ....backup.....o
         1937  +|   3968: 6f 6d 65 72 05 02 02 01 0c 63 68 61 6e 6e 65 62   omer.....channeb
         1938  +|   3984: 6f 6f 6d 65 72 08 02 08 07 01 6c 08 02 03 01 06   oomer.....l.....
         1939  +|   4000: 73 74 61 61 63 6b 08 02 07 01 03 74 65 62 08 02   staack.....teb..
         1940  +|   4016: 06 04 0c 0d 0a 08 07 07 0b 0a 11 06 0b 24 84 80   .............$..
         1941  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1942  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
         1943  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 08 41 00   on............A.
         1944  +|   4080: 00 00 11 24 00 00 00 00 01 01 00 01 01 01 01 01   ...$............
         1945  +| page 3 offset 8192
         1946  +|      0: 0a 00 00 00 03 0f ec 00 ff 00 0f f3 0f ec 00 00   ................
         1947  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 06 04 01 0c   ................
         1948  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         1949  +| page 4 offset 12288
         1950  +|      0: 0d 0f ca 00 08 07 e1 00 0f f6 0f ec 0f e0 0f d5   ................
         1951  +|     16: 07 e1 0f c1 0f b6 0f 6a 00 00 00 00 00 00 00 00   .......j........
         1952  +|   2016: 00 8f 06 05 04 00 9e 11 62 65 61 6d 65 72 20 62   ........beamer b
         1953  +|   2032: 75 6d 6d 32 34 63 34 35 32 30 32 37 37 34 33 31   umm24c4520277431
         1954  +|   2048: 35 66 36 33 36 66 36 65 36 36 36 39 36 37 32 37   5f636f6e66696727
         1955  +|   2064: 32 38 36 62 32 30 35 30 35 32 34 39 34 64 34 31   286b205052494d41
         1956  +|   2080: 35 32 35 39 32 30 34 62 34 35 35 39 32 63 32 30   5259204b45592c20
         1957  +|   2096: 0a 37 36 32 39 32 30 35 37 34 39 35 34 34 38 34   .762920574954484
         1958  +|   2112: 66 35 35 35 34 32 30 35 32 34 66 35 37 34 39 34   f555420524f57494
         1959  +|   2128: 34 35 62 30 35 30 37 31 37 32 31 32 31 30 31 38   45b0507172121018
         1960  +|   2144: 31 30 31 37 34 36 31 36 32 36 63 36 35 37 34 33   1017461626c65743
         1961  +|   2160: 31 35 66 36 34 36 66 36 33 37 33 0a 36 39 37 61   15f646f6373.697a
         1962  +|   2176: 36 35 37 34 33 31 35 66 36 34 36 66 36 33 37 33   6574315f646f6373
         1963  +|   2192: 36 39 37 61 36 35 30 35 34 33 35 32 34 35 34 31   697a650543524541
         1964  +|   2208: 35 34 34 35 32 30 35 34 38 36 39 36 34 32 30 34   5445205486964204
         1965  +|   2224: 39 34 65 35 34 34 35 34 37 34 35 35 32 32 30 35   94e5445474552205
         1966  +|   2240: 30 35 32 34 39 34 34 64 31 0a 35 32 35 39 32 30   0524944d1.525920
         1967  +|   2256: 34 62 34 35 35 39 32 63 32 30 36 33 33 30 32 39   4b45592c20633029
         1968  +|   2272: 36 39 30 33 30 30 30 31 35 37 35 33 31 31 39 32   6903000157531192
         1969  +|   2288: 36 64 37 34 36 31 36 32 36 63 36 35 37 34 33 31   6d7461626c657431
         1970  +|   2304: 35 66 36 39 36 34 37 38 37 34 33 31 35 66 36 39   5f69647874315f69
         1971  +|   2320: 36 34 37 38 0a 30 33 34 33 35 32 34 35 34 31 35   6478.03435245415
         1972  +|   2336: 34 34 35 32 30 35 34 34 31 34 32 34 63 34 35 32   445205441424c452
         1973  +|   2352: 30 32 37 37 34 33 31 35 66 36 39 01 0e 37 38 32   02774315f69..782
         1974  +|   2368: 37 32 38 37 33 36 35 36 37 36 39 36 34 32 63 32   72873656769642c2
         1975  +|   2384: 30 37 34 36 35 37 32 36 64 32 63 32 30 37 30 0a   07465726d2c2070.
         1976  +|   2400: 36 37 36 65 36 66 32 63 32 30 35 30 35 32 34 39   676e6f2c20505249
         1977  +|   2416: 34 64 34 31 35 32 35 39 32 30 34 62 34 35 35 39   4d415259204b4559
         1978  +|   2432: 32 38 37 33 36 35 36 37 36 39 36 34 32 63 32 30   2873656769642c20
         1979  +|   2448: 37 34 36 35 37 32 36 64 32 39 32 39 32 30 35 37   7465726d29292057
         1980  +|   2464: 34 39 35 34 34 38 34 66 35 35 0a 35 34 32 30 35   4954484f55.54205
         1981  +|   2480: 32 34 66 35 37 34 39 34 34 35 35 30 32 30 37 31   24f5749445502071
         1982  +|   2496: 37 31 62 31 62 30 31 38 31 30 31 37 34 36 31 36   71b1b01810174616
         1983  +|   2512: 32 36 63 36 35 37 34 33 31 35 66 31 37 34 36 31   26c6574315f17461
         1984  +|   2528: 30 32 34 33 0a 35 32 34 35 34 31 35 34 34 35 32   0243.52454154452
         1985  +|   2544: 30 35 34 34 31 34 32 34 63 34 c3 b0 35 32 30 32   05441424c4..5202
         1986  +|   2560: 37 37 34 33 31 35 66 36 34 36 31 37 34 36 31 32   774315f646174612
         1987  +|   2576: 37 32 38 36 39 36 34 32 30 34 39 34 65 35 34 34   728696420494e544
         1988  +|   2592: 35 34 37 34 35 35 32 32 30 35 30 35 32 34 39 34   5474552205052494
         1989  +|   2608: 64 0a 34 31 35 32 35 39 32 30 34 62 34 35 35 39   d.415259204b4559
         1990  +|   2624: 32 63 32 30 36 32 36 63 36 66 36 33 36 62 32 30   2c20626c6f636b20
         1991  +|   2640: 34 32 34 63 34 66 34 32 32 39 33 61 30 21 30 36   424c4f42293a0!06
         1992  +|   2656: 31 37 31 31 31 31 30 38 36 33 37 34 36 31 36 32   1711110863746162
         1993  +|   2672: 36 63 36 35 37 34 33 31 37 34 33 31 0a 34 33 35   6c6574317431.435
         1994  +|   2688: 32 34 35 34 31 35 34 34 35 32 30 35 36 34 39 35   2454154452056495
         1995  +|   2704: 32 35 34 37 35 34 31 34 63 32 30 35 34 34 31 34   25475414c2054414
         1996  +|   2720: 32 34 63 34 35 32 30 37 34 33 31 32 30 35 35 35   24c4520743120555
         1997  +|   2736: 33 34 39 34 65 34 37 32 30 36 36 37 34 37 33 33   3494e47206674733
         1998  +|   2752: 35 32 38 36 33 36 66 0a 36 65 37 34 36 35 36 65   528636f.6e74656e
         1999  +|   2768: 37 34 32 39 30 64 30 30 30 30 30 30 30 33 30 66   74290d000000030f
         2000  +|   2784: 62 64 30 30 30 62 65 38 30 66 65 66 30 66 62 64   bd000be80fef0fbd
         2001  +|   2800: 0a 5b 31 66 62 64 5d 32 34 38 34 38 30 38 30 38   .[1fbd]248480808
         2002  +|   2816: 30 38 30 30 31 30 33 30 30 34 65 30 30 30 30 30   0800103004e00000
         2003  +|   2832: 30 31 65 30 36 33 30 36 31 36 32 36 31 36 33 36   01e0630616261636
         2004  +|   2848: 62 30 31 30 32 30 32 30 34 30 32 36 36 37 34 30   b010202040266740
         2005  +|   2864: 32 30 32 30 32 30 34 30 34 36 65 0a 36 34 36 66   2020204046e.646f
         2006  +|   2880: 36 65 30 54 30 32 30 32 30 34 30 61 30 37 30 35   6e0T0202040a0705
         2007  +|   2896: 30 31 30 33 30 30 31 30 30 33 30 33 30 66 30 61   0103001003030f0a
         2008  +|   2912: 30 33 30 30 32 34 30 30 30 30 30 30 30 30 30 31   0300240000000001
         2009  +|   2928: 30 31 30 31 30 30 30 31 30 31 30 31 30 31 30 61   010100010101010a
         2010  +|   2944: 30 30 30 30 30 30 0a 30 31 30 66 66 61 30 30 30   000000.010ffa000
         2011  +|   2960: 66 66 61 0a 5b 32 21 66 61 5d 30 35 30 34 30 39   ffa.[2!fa]050409
         2012  +|   2976: 30 63 30 31 30 32 30 64 30 30 30 30 30 30 30 33   0c01020d00000003
         2013  +|   2992: 30 66 65 30 30 30 30 66 66 36 30 66 65 63 30 66   0fe0000ff60fec0f
         2014  +|   3008: 66 30 0a 5b 33 66 65 30 5d 30 61 30 33 30 33 30   f0.[3fe0]0a03030
         2015  +|   3024: 30 31 62 36 31 36 32 36 31 36 65 36 34 36 66 36   01b6162616e646f6
         2016  +|   3040: 65 30 38 30 32 30 33 30 30 31 37 36 31 36 32 36   e080203001761626
         2017  +|   3056: 31 36 36 37 34 30 38 30 31 30 33 30 30 31 37 36   1667408010300176
         2018  +|   3072: 31 36 32 36 31 36 33 36 62 30 64 30 30 0a 30 30   16261636b0d00.00
         2019  +|   3088: 30 30 30 33 30 66 65 65 30 30 30 66 66 61 30 66   00030fee000ffa0f
         2020  +|   3104: 66 34 30 66 65 65 0a 5b 34 66 65 65 5d 30 34 30   f40fee.[4fee]040
         2021  +|   3120: 33 30 33 30 30 30 65 30 31 30 34 30 32 30 33 30   303000e010402030
         2022  +|   3136: 30 30 65 30 31 30 34 30 31 30 33 30 30 30 65 30   00e01040103000e0
         2023  +|   3152: 31 30 61 30 30 30 30 30 30 30 31 30 66 66 34 30   10a000000010ff40
         2024  +|   3168: 30 30 66 66 34 0a 5b 35 66 66 34 5d 30 62 30 33   00ff4.[5ff4]0b03
         2025  +|   3184: 31 62 30 31 37 36 36 35 37 32 37 33 36 39 36 66   1b0176657273696f
         2026  +|   3200: 36 65 30 34 30 64 30 30 30 30 30 30 30 33 30 66   6e040d000000030f
         2027  +|   3216: 64 36 30 30 30 66 66 34 30 66 65 31 30 66 64 36   d6000ff40fe10fd6
         2028  +|   3232: 0a 5b 36 66 64 36 5d 30 39 30 33 30 32 31 62 37   .[6fd6]0903021b7
         2029  +|   3248: 32 36 35 36 32 37 35 36 34 36 31 37 34 36 31 37   2656275646174617
         2030  +|   3264: 34 33 31 35 66 36 34 36 31 37 34 36 31 30 32 34   4315f64617461024
         2031  +|   3280: 33 0a 35 32 34 35 34 31 35 34 34 35 32 30 35 34   3.52454154452054
         2032  +|   3296: 34 31 34 32 34 63 34 35 32 30 32 37 37 34 33 31   41424c4520277431
         2033  +|   3312: 35 66 36 34 36 31 37 34 36 31 32 37 32 38 36 39   5f64617461272869
         2034  +|   3328: 36 34 32 30 34 39 c2 81 65 35 34 34 35 34 37 34   642049..e5445474
         2035  +|   3344: 35 35 32 32 30 35 30 35 32 34 39 34 64 0a 34 31   552205052494d.41
         2036  +|   3360: 35 32 35 39 32 30 34 62 34 35 35 39 32 63 32 30   5259204b45592c20
         2037  +|   3376: 36 32 36 63 36 66 36 33 36 62 32 30 34 32 34 63   626c6f636b20424c
         2038  +|   3392: 34 66 34 32 32 39 33 61 30 31 30 36 31 37 31 31   4f42293a01061711
         2039  +|   3408: 31 31 30 38 36 33 37 34 36 31 36 32 36 63 36 35   1108637461626c65
         2040  +|   3424: 37 34 33 31 37 34 33 31 0a 34 33 35 32 34 35 34   74317431.4352454
         2041  +|   3440: 31 35 34 34 35 32 30 35 36 34 39 35 32 35 34 37   1544520564952547
         2042  +|   3456: 35 34 31 34 63 32 30 35 34 34 31 34 32 34 63 34   5414c205441424c4
         2043  +|   3472: 35 32 30 37 34 33 31 32 30 35 35 35 33 34 39 34   5207431205553494
         2044  +|   3488: 65 34 37 32 30 36 36 37 34 37 3b 33 35 32 38 36   e472066747;35286
         2045  +|   3504: 33 36 66 0a 36 65 37 34 36 35 36 65 37 34 32 39   36f.6e74656e7429
         2046  +|   3520: 30 64 30 30 30 30 30 30 30 33 30 66 62 64 30 30   0d000000030fbd00
         2047  +|   3536: 30 66 65 38 30 66 65 66 30 66 62 64 0a 5b 31 66   0fe80fef0fbd.[1f
         2048  +|   3552: 62 64 5d 32 34 38 34 38 30 38 30 38 30 38 30 30   bd]2484808080800
         2049  +|   3568: 31 30 33 30 30 34 65 30 30 30 30 30 30 31 65 30   103004e0000001e0
         2050  +|   3584: 36 33 30 36 31 36 32 36 31 36 33 36 62 30 31 30   630616261636b010
         2051  +|   3600: 32 30 32 30 34 30 32 36 36 37 34 30 32 30 32 30   2020402667402020
         2052  +|   3616: 32 30 34 30 34 36 65 0a 36 34 36 66 36 65 30 33   204046e.646f6e03
         2053  +|   3632: 30 32 30 32 30 34 30 61 30 37 30 35 30 31 30 33   0202040a07050103
         2054  +|   3648: 30 30 31 30 30 33 30 33 30 66 30 61 30 33 30 30   001003030f0a0300
         2055  +|   3664: 32 34 30 30 30 30 30 30 30 30 30 31 30 31 30 31   2400000000010101
         2056  +|   3680: 30 30 30 31 30 31 30 31 30 31 30 61 30 30 30 30   00010101010a0000
         2057  +|   3696: 30 30 0a 30 31 30 66 66 61 30 30 30 66 66 61 0a   00.010ffa000ffa.
         2058  +|   3712: 5b 32 66 29 61 5d 30 35 30 34 30 39 30 63 30 31   [2f)a]0504090c01
         2059  +|   3728: 30 32 30 64 30 30 30 30 30 30 30 33 30 66 65 30   020d000000030fe0
         2060  +|   3744: 30 30 30 66 66 36 30 66 65 63 30 66 65 30 0a 5b   000ff60fec0fe0.[
         2061  +|   3760: 33 66 65 30 5d 30 61 30 33 30 33 30 30 31 62 36   3fe0]0a0303001b6
         2062  +|   3776: 31 36 32 36 31 36 65 36 34 36 66 36 65 30 38 30   162616e646f6e080
         2063  +|   3792: 32 30 33 30 30 31 37 36 31 36 32 36 31 36 36 37   2030017616261667
         2064  +|   3808: 34 30 38 30 31 30 33 30 33 36 62 30 31 30 32 30   4080103036b01020
         2065  +|   3824: 32 30 34 30 32 36 36 37 34 30 32 30 32 30 32 30   2040266740202020
         2066  +|   3840: 34 30 34 36 65 0a 36 34 36 66 36 65 30 33 30 32   4046e.646f6e0302
         2067  +|   3856: 30 32 30 34 30 61 30 37 30 35 30 31 30 33 30 30   02040a0705010300
         2068  +|   3872: 31 30 30 33 30 33 30 66 30 61 30 33 30 30 32 34   1003030f0a030024
         2069  +|   3888: 30 30 30 30 30 30 30 30 30 31 30 31 30 31 30 30   0000000001010100
         2070  +|   3904: 30 31 30 31 30 31 30 30 39 61 30 30 30 30 30 30   010101009a000000
         2071  +|   3920: 0a 30 31 30 66 66 61 30 30 30 66 66 61 0a 5b 32   .010ffa000ffa.[2
         2072  +|   3936: 66 65 72 20 62 61 63 6b 75 70 4a 08 04 00 81 19   fer backupJ.....
         2073  +|   3952: 61 6c 70 68 61 20 63 68 61 6e 6e 65 6c 20 62 61   alpha channel ba
         2074  +|   3968: 63 6b 75 70 20 61 62 61 6e 64 6f 6e 20 74 65 62   ckup abandon teb
         2075  +|   3984: 20 73 74 61 61 63 6b 20 63 68 61 6e 6e 65 62 6f    staack channebo
         2076  +|   4000: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         2077  +|   4016: 61 63 74 69 76 65 09 07 03 00 19 61 74 6f 6d 69   active.....atomi
         2078  +|   4032: 63 07 06 03 00 15 61 74 6b 6d 00 00 00 0b 19 62   c.....atkm.....b
         2079  +|   4048: 6f 6f 6d 65 72 09 04 03 00 19 61 63 74 69 76 65   oomer.....active
         2080  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         2081  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         2082  +| page 5 offset 16384
         2083  +|      0: 0d 00 00 00 08 0f d0 00 0f fa 0f f4 0f ee 0f e8   ................
         2084  +|     16: 0f e2 0f dc 0f d6 0f d0 00 00 00 00 00 00 00 00   ................
         2085  +|   4048: 04 08 03 00 0e 0a 04 07 03 00 0e 01 04 06 03 00   ................
         2086  +|   4064: 0e 01 04 05 03 00 0e 31 04 04 03 00 0e 01 04 03   .......1........
         2087  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         2088  +| page 6 offset 20480
         2089  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         2090  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         2091  +| page 7 offset 24576
         2092  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         2093  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         2094  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         2095  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         2096  +| end c22b.db
         2097  +}]} {}
         2098  +
         2099  +
         2100  +do_catchsql_test 22.1 {
         2101  +  INSERT INTO t1(t1) VALUES('optimize');
         2102  +} {1 {vtable constructor failed: t1}}
   965   2103   
   966   2104   sqlite3_fts5_may_be_corrupt 0
   967   2105   finish_test
   968   2106   

Changes to ext/fts5/test/fts5unicode3.test.

    17     17   # If SQLITE_ENABLE_FTS5 is defined, omit this file.
    18     18   ifcapable !fts5 {
    19     19     finish_test
    20     20     return
    21     21   }
    22     22   
    23     23   proc fts3_unicode_path {file} {
    24         -  file join [file dirname [info script]] .. .. fts3 unicode $file
           24  +  file join .. [file dirname [info script]] .. .. fts3 unicode $file
    25     25   }
    26     26   
    27     27   source [fts3_unicode_path parseunicode.tcl]
    28     28   set testprefix fts5unicode3
    29     29   
    30     30   set CF [fts3_unicode_path CaseFolding.txt]
    31     31   set UD [fts3_unicode_path UnicodeData.txt]

Changes to src/analyze.c.

  1152   1152       */
  1153   1153       addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
  1154   1154       VdbeCoverage(v);
  1155   1155       sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
  1156   1156       addrNextRow = sqlite3VdbeCurrentAddr(v);
  1157   1157   
  1158   1158       if( nColTest>0 ){
  1159         -      int endDistinctTest = sqlite3VdbeMakeLabel(v);
         1159  +      int endDistinctTest = sqlite3VdbeMakeLabel(pParse);
  1160   1160         int *aGotoChng;               /* Array of jump instruction addresses */
  1161   1161         aGotoChng = sqlite3DbMallocRawNN(db, sizeof(int)*nColTest);
  1162   1162         if( aGotoChng==0 ) continue;
  1163   1163   
  1164   1164         /*
  1165   1165         **  next_row:
  1166   1166         **   regChng = 0

Changes to src/btree.c.

  4863   4863         }while( ALWAYS(pPrev) );
  4864   4864       }
  4865   4865       btreeReleaseAllCursorPages(pCur);
  4866   4866       unlockBtreeIfUnused(pBt);
  4867   4867       sqlite3_free(pCur->aOverflow);
  4868   4868       sqlite3_free(pCur->pKey);
  4869   4869       sqlite3BtreeLeave(pBtree);
         4870  +    pCur->pBtree = 0;
  4870   4871     }
  4871   4872     return SQLITE_OK;
  4872   4873   }
  4873   4874   
  4874   4875   /*
  4875   4876   ** Make sure the BtCursor* given in the argument has a valid
  4876   4877   ** BtCursor.info structure.  If it is not already valid, call

Changes to src/build.c.

  2636   2636     }
  2637   2637   
  2638   2638     /* Remove the table entry from SQLite's internal schema and modify
  2639   2639     ** the schema cookie.
  2640   2640     */
  2641   2641     if( IsVirtual(pTab) ){
  2642   2642       sqlite3VdbeAddOp4(v, OP_VDestroy, iDb, 0, 0, pTab->zName, 0);
         2643  +    sqlite3MayAbort(pParse);
  2643   2644     }
  2644   2645     sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);
  2645   2646     sqlite3ChangeCookie(pParse, iDb);
  2646   2647     sqliteViewResetAll(db, iDb);
  2647   2648   }
  2648   2649   
  2649   2650   /*

Changes to src/delete.c.

   513    513           sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
   514    514         }
   515    515       }
   516    516     
   517    517       /* If this DELETE cannot use the ONEPASS strategy, this is the 
   518    518       ** end of the WHERE loop */
   519    519       if( eOnePass!=ONEPASS_OFF ){
   520         -      addrBypass = sqlite3VdbeMakeLabel(v);
          520  +      addrBypass = sqlite3VdbeMakeLabel(pParse);
   521    521       }else{
   522    522         sqlite3WhereEnd(pWInfo);
   523    523       }
   524    524     
   525    525       /* Unless this is a view, open cursors for the table we are 
   526    526       ** deleting from and all its indices. If this is a view, then the
   527    527       ** only effect this statement has is to fire the INSTEAD OF 
................................................................................
   702    702     assert( v );
   703    703     VdbeModuleComment((v, "BEGIN: GenRowDel(%d,%d,%d,%d)",
   704    704                            iDataCur, iIdxCur, iPk, (int)nPk));
   705    705   
   706    706     /* Seek cursor iCur to the row to delete. If this row no longer exists 
   707    707     ** (this can happen if a trigger program has already deleted it), do
   708    708     ** not attempt to delete it or fire any DELETE triggers.  */
   709         -  iLabel = sqlite3VdbeMakeLabel(v);
          709  +  iLabel = sqlite3VdbeMakeLabel(pParse);
   710    710     opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
   711    711     if( eMode==ONEPASS_OFF ){
   712    712       sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
   713    713       VdbeCoverageIf(v, opSeek==OP_NotExists);
   714    714       VdbeCoverageIf(v, opSeek==OP_NotFound);
   715    715     }
   716    716    
................................................................................
   908    908     Vdbe *v = pParse->pVdbe;
   909    909     int j;
   910    910     int regBase;
   911    911     int nCol;
   912    912   
   913    913     if( piPartIdxLabel ){
   914    914       if( pIdx->pPartIdxWhere ){
   915         -      *piPartIdxLabel = sqlite3VdbeMakeLabel(v);
          915  +      *piPartIdxLabel = sqlite3VdbeMakeLabel(pParse);
   916    916         pParse->iSelfTab = iDataCur + 1;
   917    917         sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel, 
   918    918                               SQLITE_JUMPIFNULL);
   919    919         pParse->iSelfTab = 0;
   920    920       }else{
   921    921         *piPartIdxLabel = 0;
   922    922       }

Changes to src/expr.c.

   549    549     Expr *pLeft = pExpr->pLeft;
   550    550     Expr *pRight = pExpr->pRight;
   551    551     int nLeft = sqlite3ExprVectorSize(pLeft);
   552    552     int i;
   553    553     int regLeft = 0;
   554    554     int regRight = 0;
   555    555     u8 opx = op;
   556         -  int addrDone = sqlite3VdbeMakeLabel(v);
          556  +  int addrDone = sqlite3VdbeMakeLabel(pParse);
   557    557   
   558    558     if( nLeft!=sqlite3ExprVectorSize(pRight) ){
   559    559       sqlite3ErrorMsg(pParse, "row value misused");
   560    560       return;
   561    561     }
   562    562     assert( pExpr->op==TK_EQ || pExpr->op==TK_NE 
   563    563          || pExpr->op==TK_IS || pExpr->op==TK_ISNOT 
................................................................................
  2346   2346   */
  2347   2347   #ifndef SQLITE_OMIT_SUBQUERY
  2348   2348   int sqlite3FindInIndex(
  2349   2349     Parse *pParse,             /* Parsing context */
  2350   2350     Expr *pX,                  /* The right-hand side (RHS) of the IN operator */
  2351   2351     u32 inFlags,               /* IN_INDEX_LOOP, _MEMBERSHIP, and/or _NOOP_OK */
  2352   2352     int *prRhsHasNull,         /* Register holding NULL status.  See notes */
  2353         -  int *aiMap                 /* Mapping from Index fields to RHS fields */
         2353  +  int *aiMap,                /* Mapping from Index fields to RHS fields */
         2354  +  int *piTab                 /* OUT: index to use */
  2354   2355   ){
  2355   2356     Select *p;                            /* SELECT to the right of IN operator */
  2356   2357     int eType = 0;                        /* Type of RHS table. IN_INDEX_* */
  2357   2358     int iTab = pParse->nTab++;            /* Cursor of the RHS table */
  2358   2359     int mustBeUnique;                     /* True if RHS must be unique */
  2359   2360     Vdbe *v = sqlite3GetVdbe(pParse);     /* Virtual machine being coded */
  2360   2361   
................................................................................
  2539   2540         if( pX->pLeft->iColumn<0 && !ExprHasProperty(pX, EP_xIsSelect) ){
  2540   2541           eType = IN_INDEX_ROWID;
  2541   2542         }
  2542   2543       }else if( prRhsHasNull ){
  2543   2544         *prRhsHasNull = rMayHaveNull = ++pParse->nMem;
  2544   2545       }
  2545   2546       assert( pX->op==TK_IN );
  2546         -    sqlite3CodeRhsOfIN(pParse, pX, eType==IN_INDEX_ROWID);
         2547  +    sqlite3CodeRhsOfIN(pParse, pX, iTab, eType==IN_INDEX_ROWID);
  2547   2548       if( rMayHaveNull ){
  2548         -      sqlite3SetHasNullFlag(v, pX->iTable, rMayHaveNull);
         2549  +      sqlite3SetHasNullFlag(v, iTab, rMayHaveNull);
  2549   2550       }
  2550   2551       pParse->nQueryLoop = savedNQueryLoop;
  2551         -  }else{
  2552         -    pX->iTable = iTab;
  2553   2552     }
  2554   2553   
  2555   2554     if( aiMap && eType!=IN_INDEX_INDEX_ASC && eType!=IN_INDEX_INDEX_DESC ){
  2556   2555       int i, n;
  2557   2556       n = sqlite3ExprVectorSize(pX->pLeft);
  2558   2557       for(i=0; i<n; i++) aiMap[i] = i;
  2559   2558     }
         2559  +  *piTab = iTab;
  2560   2560     return eType;
  2561   2561   }
  2562   2562   #endif
  2563   2563   
  2564   2564   #ifndef SQLITE_OMIT_SUBQUERY
  2565   2565   /*
  2566   2566   ** Argument pExpr is an (?, ?...) IN(...) expression. This 
................................................................................
  2635   2635   ** Generate code that will construct an ephemeral table containing all terms
  2636   2636   ** in the RHS of an IN operator.  The IN operator can be in either of two
  2637   2637   ** forms:
  2638   2638   **
  2639   2639   **     x IN (4,5,11)              -- IN operator with list on right-hand side
  2640   2640   **     x IN (SELECT a FROM b)     -- IN operator with subquery on the right
  2641   2641   **
  2642         -** The pExpr parameter is the IN operator.
         2642  +** The pExpr parameter is the IN operator.  The cursor number for the
         2643  +** constructed ephermeral table is returned.  The first time the ephemeral
         2644  +** table is computed, the cursor number is also stored in pExpr->iTable,
         2645  +** however the cursor number returned might not be the same, as it might
         2646  +** have been duplicated using OP_OpenDup.
  2643   2647   **
  2644   2648   ** If parameter isRowid is non-zero, then LHS of the IN operator is guaranteed
  2645   2649   ** to be a non-null integer. In this case, the ephemeral table can be an
  2646   2650   ** table B-Tree that keyed by only integers.  The more general cases uses
  2647   2651   ** an index B-Tree which can have arbitrary keys, but is slower to both
  2648   2652   ** read and write.
  2649   2653   **
................................................................................
  2654   2658   ** if either column has NUMERIC or INTEGER affinity. If neither
  2655   2659   ** 'x' nor the SELECT... statement are columns, then numeric affinity
  2656   2660   ** is used.
  2657   2661   */
  2658   2662   void sqlite3CodeRhsOfIN(
  2659   2663     Parse *pParse,          /* Parsing context */
  2660   2664     Expr *pExpr,            /* The IN operator */
         2665  +  int iTab,               /* Use this cursor number */
  2661   2666     int isRowid             /* If true, LHS is a rowid */
  2662   2667   ){
  2663         -  int jmpIfDynamic = -1;      /* One-time test address */
         2668  +  int addrOnce = 0;           /* Address of the OP_Once instruction at top */
  2664   2669     int addr;                   /* Address of OP_OpenEphemeral instruction */
  2665   2670     Expr *pLeft;                /* the LHS of the IN operator */
  2666   2671     KeyInfo *pKeyInfo = 0;      /* Key information */
  2667   2672     int nVal;                   /* Size of vector pLeft */
  2668   2673     Vdbe *v;                    /* The prepared statement under construction */
  2669   2674   
  2670         -  v = sqlite3GetVdbe(pParse);
         2675  +  v = pParse->pVdbe;
  2671   2676     assert( v!=0 );
  2672   2677   
  2673         -  /* The evaluation of the RHS of IN operator must be repeated every time it
         2678  +  /* The evaluation of the IN must be repeated every time it
  2674   2679     ** is encountered if any of the following is true:
  2675   2680     **
  2676   2681     **    *  The right-hand side is a correlated subquery
  2677   2682     **    *  The right-hand side is an expression list containing variables
  2678   2683     **    *  We are inside a trigger
  2679   2684     **
  2680         -  ** If all of the above are false, then we can run this code just once
  2681         -  ** save the results, and reuse the same result on subsequent invocations.
         2685  +  ** If all of the above are false, then we can compute the RHS just once
         2686  +  ** and reuse it many names.
  2682   2687     */
  2683         -  if( !ExprHasProperty(pExpr, EP_VarSelect) ){
  2684         -    jmpIfDynamic = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
         2688  +  if( !ExprHasProperty(pExpr, EP_VarSelect) && pParse->iSelfTab==0 ){
         2689  +    /* Reuse of the RHS is allowed */
         2690  +    /* If this routine has already been coded, but the previous code
         2691  +    ** might not have been invoked yet, so invoke it now as a subroutine. 
         2692  +    */
         2693  +    if( ExprHasProperty(pExpr, EP_Subrtn) ){
         2694  +      addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
         2695  +      if( ExprHasProperty(pExpr, EP_xIsSelect) ){
         2696  +        ExplainQueryPlan((pParse, 0, "REUSE LIST SUBQUERY %d",
         2697  +              pExpr->x.pSelect->selId));
         2698  +      }
         2699  +      sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
         2700  +                        pExpr->y.sub.iAddr);
         2701  +      sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
         2702  +      sqlite3VdbeJumpHere(v, addrOnce);
         2703  +      return;
         2704  +    }
         2705  +
         2706  +    /* Begin coding the subroutine */
         2707  +    ExprSetProperty(pExpr, EP_Subrtn);
         2708  +    pExpr->y.sub.regReturn = ++pParse->nMem;
         2709  +    pExpr->y.sub.iAddr =
         2710  +      sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
         2711  +    VdbeComment((v, "return address"));
         2712  +
         2713  +    addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
  2685   2714     }
  2686   2715   
  2687   2716     /* Check to see if this is a vector IN operator */
  2688   2717     pLeft = pExpr->pLeft;
  2689   2718     nVal = sqlite3ExprVectorSize(pLeft);
  2690   2719     assert( !isRowid || nVal==1 );
  2691   2720   
  2692   2721     /* Construct the ephemeral table that will contain the content of
  2693   2722     ** RHS of the IN operator.
  2694   2723     */
  2695         -  pExpr->iTable = pParse->nTab++;
         2724  +  pExpr->iTable = iTab;
  2696   2725     addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, 
  2697   2726         pExpr->iTable, (isRowid?0:nVal));
         2727  +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
         2728  +  if( ExprHasProperty(pExpr, EP_xIsSelect) ){
         2729  +    VdbeComment((v, "Result of SELECT %u", pExpr->x.pSelect->selId));
         2730  +  }else{
         2731  +    VdbeComment((v, "RHS of IN operator"));
         2732  +  }
         2733  +#endif
  2698   2734     pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
  2699   2735   
  2700   2736     if( ExprHasProperty(pExpr, EP_xIsSelect) ){
  2701   2737       /* Case 1:     expr IN (SELECT ...)
  2702   2738       **
  2703   2739       ** Generate code to write the results of the select into the temporary
  2704   2740       ** table allocated and opened above.
  2705   2741       */
  2706   2742       Select *pSelect = pExpr->x.pSelect;
  2707   2743       ExprList *pEList = pSelect->pEList;
  2708   2744   
  2709         -    ExplainQueryPlan((pParse, 1, "%sLIST SUBQUERY",
  2710         -        jmpIfDynamic>=0?"":"CORRELATED "
         2745  +    ExplainQueryPlan((pParse, 1, "%sLIST SUBQUERY %d",
         2746  +        addrOnce?"":"CORRELATED ", pSelect->selId
  2711   2747       ));
  2712   2748       assert( !isRowid );
  2713   2749       /* If the LHS and RHS of the IN operator do not match, that
  2714   2750       ** error will have been caught long before we reach this point. */
  2715   2751       if( ALWAYS(pEList->nExpr==nVal) ){
  2716   2752         SelectDest dest;
  2717   2753         int i;
  2718         -      sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
         2754  +      sqlite3SelectDestInit(&dest, SRT_Set, iTab);
  2719   2755         dest.zAffSdst = exprINAffinity(pParse, pExpr);
  2720   2756         pSelect->iLimit = 0;
  2721   2757         testcase( pSelect->selFlags & SF_Distinct );
  2722   2758         testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
  2723   2759         if( sqlite3Select(pParse, pSelect, &dest) ){
  2724   2760           sqlite3DbFree(pParse->db, dest.zAffSdst);
  2725   2761           sqlite3KeyInfoUnref(pKeyInfo);
................................................................................
  2768   2804         int iValToIns;
  2769   2805   
  2770   2806         /* If the expression is not constant then we will need to
  2771   2807         ** disable the test that was generated above that makes sure
  2772   2808         ** this code only executes once.  Because for a non-constant
  2773   2809         ** expression we need to rerun this code each time.
  2774   2810         */
  2775         -      if( jmpIfDynamic>=0 && !sqlite3ExprIsConstant(pE2) ){
  2776         -        sqlite3VdbeChangeToNoop(v, jmpIfDynamic);
  2777         -        jmpIfDynamic = -1;
         2811  +      if( addrOnce && !sqlite3ExprIsConstant(pE2) ){
         2812  +        sqlite3VdbeChangeToNoop(v, addrOnce);
         2813  +        addrOnce = 0;
  2778   2814         }
  2779   2815   
  2780   2816         /* Evaluate the expression and insert it into the temp table */
  2781   2817         if( isRowid && sqlite3ExprIsInteger(pE2, &iValToIns) ){
  2782         -        sqlite3VdbeAddOp3(v, OP_InsertInt, pExpr->iTable, r2, iValToIns);
         2818  +        sqlite3VdbeAddOp3(v, OP_InsertInt, iTab, r2, iValToIns);
  2783   2819         }else{
  2784   2820           r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
  2785   2821           if( isRowid ){
  2786   2822             sqlite3VdbeAddOp2(v, OP_MustBeInt, r3,
  2787   2823                               sqlite3VdbeCurrentAddr(v)+2);
  2788   2824             VdbeCoverage(v);
  2789         -          sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3);
         2825  +          sqlite3VdbeAddOp3(v, OP_Insert, iTab, r2, r3);
  2790   2826           }else{
  2791   2827             sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
  2792         -          sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pExpr->iTable, r2, r3, 1);
         2828  +          sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r2, r3, 1);
  2793   2829           }
  2794   2830         }
  2795   2831       }
  2796   2832       sqlite3ReleaseTempReg(pParse, r1);
  2797   2833       sqlite3ReleaseTempReg(pParse, r2);
  2798   2834     }
  2799   2835     if( pKeyInfo ){
  2800   2836       sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
  2801   2837     }
  2802         -  if( jmpIfDynamic>=0 ){
  2803         -    sqlite3VdbeJumpHere(v, jmpIfDynamic);
         2838  +  if( addrOnce ){
         2839  +    sqlite3VdbeJumpHere(v, addrOnce);
         2840  +    /* Subroutine return */
         2841  +    sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
         2842  +    sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
  2804   2843     }
  2805   2844   }
  2806   2845   #endif /* SQLITE_OMIT_SUBQUERY */
  2807   2846   
  2808   2847   /*
  2809   2848   ** Generate code for scalar subqueries used as a subquery expression
  2810   2849   ** or EXISTS operator:
................................................................................
  2817   2856   ** The register that holds the result.  For a multi-column SELECT, 
  2818   2857   ** the result is stored in a contiguous array of registers and the
  2819   2858   ** return value is the register of the left-most result column.
  2820   2859   ** Return 0 if an error occurs.
  2821   2860   */
  2822   2861   #ifndef SQLITE_OMIT_SUBQUERY
  2823   2862   int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
  2824         -  int jmpIfDynamic = -1;      /* One-time test address */
         2863  +  int addrOnce = 0;           /* Address of OP_Once at top of subroutine */
  2825   2864     int rReg = 0;               /* Register storing resulting */
  2826   2865     Select *pSel;               /* SELECT statement to encode */
  2827   2866     SelectDest dest;            /* How to deal with SELECT result */
  2828   2867     int nReg;                   /* Registers to allocate */
  2829   2868     Expr *pLimit;               /* New limit expression */
  2830         -  Vdbe *v = sqlite3GetVdbe(pParse);
         2869  +
         2870  +  Vdbe *v = pParse->pVdbe;
  2831   2871     assert( v!=0 );
         2872  +  testcase( pExpr->op==TK_EXISTS );
         2873  +  testcase( pExpr->op==TK_SELECT );
         2874  +  assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
         2875  +  assert( ExprHasProperty(pExpr, EP_xIsSelect) );
         2876  +  pSel = pExpr->x.pSelect;
  2832   2877   
  2833   2878     /* The evaluation of the EXISTS/SELECT must be repeated every time it
  2834   2879     ** is encountered if any of the following is true:
  2835   2880     **
  2836   2881     **    *  The right-hand side is a correlated subquery
  2837   2882     **    *  The right-hand side is an expression list containing variables
  2838   2883     **    *  We are inside a trigger
  2839   2884     **
  2840   2885     ** If all of the above are false, then we can run this code just once
  2841   2886     ** save the results, and reuse the same result on subsequent invocations.
  2842   2887     */
  2843   2888     if( !ExprHasProperty(pExpr, EP_VarSelect) ){
  2844         -    jmpIfDynamic = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
         2889  +    /* If this routine has already been coded, then invoke it as a
         2890  +    ** subroutine. */
         2891  +    if( ExprHasProperty(pExpr, EP_Subrtn) ){
         2892  +      ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId));
         2893  +      sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
         2894  +                        pExpr->y.sub.iAddr);
         2895  +      return pExpr->iTable;
         2896  +    }
         2897  +
         2898  +    /* Begin coding the subroutine */
         2899  +    ExprSetProperty(pExpr, EP_Subrtn);
         2900  +    pExpr->y.sub.regReturn = ++pParse->nMem;
         2901  +    pExpr->y.sub.iAddr =
         2902  +      sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
         2903  +    VdbeComment((v, "return address"));
         2904  +
         2905  +    addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
  2845   2906     }
  2846   2907     
  2847   2908     /* For a SELECT, generate code to put the values for all columns of
  2848   2909     ** the first row into an array of registers and return the index of
  2849   2910     ** the first register.
  2850   2911     **
  2851   2912     ** If this is an EXISTS, write an integer 0 (not exists) or 1 (exists)
  2852   2913     ** into a register and return that register number.
  2853   2914     **
  2854   2915     ** In both cases, the query is augmented with "LIMIT 1".  Any 
  2855   2916     ** preexisting limit is discarded in place of the new LIMIT 1.
  2856   2917     */
  2857         -  testcase( pExpr->op==TK_EXISTS );
  2858         -  testcase( pExpr->op==TK_SELECT );
  2859         -  assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
  2860         -  assert( ExprHasProperty(pExpr, EP_xIsSelect) );
  2861         -
  2862         -  pSel = pExpr->x.pSelect;
  2863         -  ExplainQueryPlan((pParse, 1, "%sSCALAR SUBQUERY",
  2864         -        jmpIfDynamic>=0?"":"CORRELATED "));
         2918  +  ExplainQueryPlan((pParse, 1, "%sSCALAR SUBQUERY %d",
         2919  +        addrOnce?"":"CORRELATED ", pSel->selId));
  2865   2920     nReg = pExpr->op==TK_SELECT ? pSel->pEList->nExpr : 1;
  2866   2921     sqlite3SelectDestInit(&dest, 0, pParse->nMem+1);
  2867   2922     pParse->nMem += nReg;
  2868   2923     if( pExpr->op==TK_SELECT ){
  2869   2924       dest.eDest = SRT_Mem;
  2870   2925       dest.iSdst = dest.iSDParm;
  2871   2926       dest.nSdst = nReg;
................................................................................
  2883   2938     }else{
  2884   2939       pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
  2885   2940     }
  2886   2941     pSel->iLimit = 0;
  2887   2942     if( sqlite3Select(pParse, pSel, &dest) ){
  2888   2943       return 0;
  2889   2944     }
  2890         -  rReg = dest.iSDParm;
         2945  +  pExpr->iTable = rReg = dest.iSDParm;
  2891   2946     ExprSetVVAProperty(pExpr, EP_NoReduce);
         2947  +  if( addrOnce ){
         2948  +    sqlite3VdbeJumpHere(v, addrOnce);
  2892   2949   
  2893         -  if( jmpIfDynamic>=0 ){
  2894         -    sqlite3VdbeJumpHere(v, jmpIfDynamic);
         2950  +    /* Subroutine return */
         2951  +    sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
         2952  +    sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
  2895   2953     }
  2896   2954   
  2897   2955     return rReg;
  2898   2956   }
  2899   2957   #endif /* SQLITE_OMIT_SUBQUERY */
  2900   2958   
  2901   2959   #ifndef SQLITE_OMIT_SUBQUERY
................................................................................
  2964   3022     Expr *pLeft;          /* The LHS of the IN operator */
  2965   3023     int i;                /* loop counter */
  2966   3024     int destStep2;        /* Where to jump when NULLs seen in step 2 */
  2967   3025     int destStep6 = 0;    /* Start of code for Step 6 */
  2968   3026     int addrTruthOp;      /* Address of opcode that determines the IN is true */
  2969   3027     int destNotNull;      /* Jump here if a comparison is not true in step 6 */
  2970   3028     int addrTop;          /* Top of the step-6 loop */ 
         3029  +  int iTab = 0;         /* Index to use */
  2971   3030   
  2972   3031     pLeft = pExpr->pLeft;
  2973   3032     if( sqlite3ExprCheckIN(pParse, pExpr) ) return;
  2974   3033     zAff = exprINAffinity(pParse, pExpr);
  2975   3034     nVector = sqlite3ExprVectorSize(pExpr->pLeft);
  2976   3035     aiMap = (int*)sqlite3DbMallocZero(
  2977   3036         pParse->db, nVector*(sizeof(int) + sizeof(char)) + 1
  2978   3037     );
  2979   3038     if( pParse->db->mallocFailed ) goto sqlite3ExprCodeIN_oom_error;
  2980   3039   
  2981   3040     /* Attempt to compute the RHS. After this step, if anything other than
  2982         -  ** IN_INDEX_NOOP is returned, the table opened ith cursor pExpr->iTable 
         3041  +  ** IN_INDEX_NOOP is returned, the table opened with cursor iTab
  2983   3042     ** contains the values that make up the RHS. If IN_INDEX_NOOP is returned,
  2984   3043     ** the RHS has not yet been coded.  */
  2985   3044     v = pParse->pVdbe;
  2986   3045     assert( v!=0 );       /* OOM detected prior to this routine */
  2987   3046     VdbeNoopComment((v, "begin IN expr"));
  2988   3047     eType = sqlite3FindInIndex(pParse, pExpr,
  2989   3048                                IN_INDEX_MEMBERSHIP | IN_INDEX_NOOP_OK,
  2990         -                             destIfFalse==destIfNull ? 0 : &rRhsHasNull, aiMap);
         3049  +                             destIfFalse==destIfNull ? 0 : &rRhsHasNull,
         3050  +                             aiMap, &iTab);
  2991   3051   
  2992   3052     assert( pParse->nErr || nVector==1 || eType==IN_INDEX_EPH
  2993   3053          || eType==IN_INDEX_INDEX_ASC || eType==IN_INDEX_INDEX_DESC 
  2994   3054     );
  2995   3055   #ifdef SQLITE_DEBUG
  2996   3056     /* Confirm that aiMap[] contains nVector integer values between 0 and
  2997   3057     ** nVector-1. */
................................................................................
  3029   3089     ** sequence of comparisons.
  3030   3090     **
  3031   3091     ** This is step (1) in the in-operator.md optimized algorithm.
  3032   3092     */
  3033   3093     if( eType==IN_INDEX_NOOP ){
  3034   3094       ExprList *pList = pExpr->x.pList;
  3035   3095       CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
  3036         -    int labelOk = sqlite3VdbeMakeLabel(v);
         3096  +    int labelOk = sqlite3VdbeMakeLabel(pParse);
  3037   3097       int r2, regToFree;
  3038   3098       int regCkNull = 0;
  3039   3099       int ii;
  3040   3100       assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
  3041   3101       if( destIfNull!=destIfFalse ){
  3042   3102         regCkNull = sqlite3GetTempReg(pParse);
  3043   3103         sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull);
................................................................................
  3073   3133     /* Step 2: Check to see if the LHS contains any NULL columns.  If the
  3074   3134     ** LHS does contain NULLs then the result must be either FALSE or NULL.
  3075   3135     ** We will then skip the binary search of the RHS.
  3076   3136     */
  3077   3137     if( destIfNull==destIfFalse ){
  3078   3138       destStep2 = destIfFalse;
  3079   3139     }else{
  3080         -    destStep2 = destStep6 = sqlite3VdbeMakeLabel(v);
         3140  +    destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
  3081   3141     }
  3082   3142     for(i=0; i<nVector; i++){
  3083   3143       Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
  3084   3144       if( sqlite3ExprCanBeNull(p) ){
  3085   3145         sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
  3086   3146         VdbeCoverage(v);
  3087   3147       }
................................................................................
  3091   3151     ** of the RHS using the LHS as a probe.  If found, the result is
  3092   3152     ** true.
  3093   3153     */
  3094   3154     if( eType==IN_INDEX_ROWID ){
  3095   3155       /* In this case, the RHS is the ROWID of table b-tree and so we also
  3096   3156       ** know that the RHS is non-NULL.  Hence, we combine steps 3 and 4
  3097   3157       ** into a single opcode. */
  3098         -    sqlite3VdbeAddOp3(v, OP_SeekRowid, pExpr->iTable, destIfFalse, rLhs);
         3158  +    sqlite3VdbeAddOp3(v, OP_SeekRowid, iTab, destIfFalse, rLhs);
  3099   3159       VdbeCoverage(v);
  3100   3160       addrTruthOp = sqlite3VdbeAddOp0(v, OP_Goto);  /* Return True */
  3101   3161     }else{
  3102   3162       sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector);
  3103   3163       if( destIfFalse==destIfNull ){
  3104   3164         /* Combine Step 3 and Step 5 into a single opcode */
  3105         -      sqlite3VdbeAddOp4Int(v, OP_NotFound, pExpr->iTable, destIfFalse,
         3165  +      sqlite3VdbeAddOp4Int(v, OP_NotFound, iTab, destIfFalse,
  3106   3166                              rLhs, nVector); VdbeCoverage(v);
  3107   3167         goto sqlite3ExprCodeIN_finished;
  3108   3168       }
  3109   3169       /* Ordinary Step 3, for the case where FALSE and NULL are distinct */
  3110         -    addrTruthOp = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0,
         3170  +    addrTruthOp = sqlite3VdbeAddOp4Int(v, OP_Found, iTab, 0,
  3111   3171                                         rLhs, nVector); VdbeCoverage(v);
  3112   3172     }
  3113   3173   
  3114   3174     /* Step 4.  If the RHS is known to be non-NULL and we did not find
  3115   3175     ** an match on the search above, then the result must be FALSE.
  3116   3176     */
  3117   3177     if( rRhsHasNull && nVector==1 ){
................................................................................
  3128   3188     ** If any comparison is NULL, then the result is NULL.  If all
  3129   3189     ** comparisons are FALSE then the final result is FALSE.
  3130   3190     **
  3131   3191     ** For a scalar LHS, it is sufficient to check just the first row
  3132   3192     ** of the RHS.
  3133   3193     */
  3134   3194     if( destStep6 ) sqlite3VdbeResolveLabel(v, destStep6);
  3135         -  addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse);
         3195  +  addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, destIfFalse);
  3136   3196     VdbeCoverage(v);
  3137   3197     if( nVector>1 ){
  3138         -    destNotNull = sqlite3VdbeMakeLabel(v);
         3198  +    destNotNull = sqlite3VdbeMakeLabel(pParse);
  3139   3199     }else{
  3140   3200       /* For nVector==1, combine steps 6 and 7 by immediately returning
  3141   3201       ** FALSE if the first comparison is not NULL */
  3142   3202       destNotNull = destIfFalse;
  3143   3203     }
  3144   3204     for(i=0; i<nVector; i++){
  3145   3205       Expr *p;
  3146   3206       CollSeq *pColl;
  3147   3207       int r3 = sqlite3GetTempReg(pParse);
  3148   3208       p = sqlite3VectorFieldSubexpr(pLeft, i);
  3149   3209       pColl = sqlite3ExprCollSeq(pParse, p);
  3150         -    sqlite3VdbeAddOp3(v, OP_Column, pExpr->iTable, i, r3);
         3210  +    sqlite3VdbeAddOp3(v, OP_Column, iTab, i, r3);
  3151   3211       sqlite3VdbeAddOp4(v, OP_Ne, rLhs+i, destNotNull, r3,
  3152   3212                         (void*)pColl, P4_COLLSEQ);
  3153   3213       VdbeCoverage(v);
  3154   3214       sqlite3ReleaseTempReg(pParse, r3);
  3155   3215     }
  3156   3216     sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
  3157   3217     if( nVector>1 ){
  3158   3218       sqlite3VdbeResolveLabel(v, destNotNull);
  3159         -    sqlite3VdbeAddOp2(v, OP_Next, pExpr->iTable, addrTop+1);
         3219  +    sqlite3VdbeAddOp2(v, OP_Next, iTab, addrTop+1);
  3160   3220       VdbeCoverage(v);
  3161   3221   
  3162   3222       /* Step 7:  If we reach this point, we know that the result must
  3163   3223       ** be false. */
  3164   3224       sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
  3165   3225     }
  3166   3226   
................................................................................
  3696   3756         }
  3697   3757   
  3698   3758         /* Attempt a direct implementation of the built-in COALESCE() and
  3699   3759         ** IFNULL() functions.  This avoids unnecessary evaluation of
  3700   3760         ** arguments past the first non-NULL argument.
  3701   3761         */
  3702   3762         if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
  3703         -        int endCoalesce = sqlite3VdbeMakeLabel(v);
         3763  +        int endCoalesce = sqlite3VdbeMakeLabel(pParse);
  3704   3764           assert( nFarg>=2 );
  3705   3765           sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
  3706   3766           for(i=1; i<nFarg; i++){
  3707   3767             sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
  3708   3768             VdbeCoverage(v);
  3709   3769             sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
  3710   3770           }
................................................................................
  3844   3904         ){
  3845   3905           sqlite3ErrorMsg(pParse, "%d columns assigned %d values",
  3846   3906                                   pExpr->iTable, n);
  3847   3907         }
  3848   3908         return pExpr->pLeft->iTable + pExpr->iColumn;
  3849   3909       }
  3850   3910       case TK_IN: {
  3851         -      int destIfFalse = sqlite3VdbeMakeLabel(v);
  3852         -      int destIfNull = sqlite3VdbeMakeLabel(v);
         3911  +      int destIfFalse = sqlite3VdbeMakeLabel(pParse);
         3912  +      int destIfNull = sqlite3VdbeMakeLabel(pParse);
  3853   3913         sqlite3VdbeAddOp2(v, OP_Null, 0, target);
  3854   3914         sqlite3ExprCodeIN(pParse, pExpr, destIfFalse, destIfNull);
  3855   3915         sqlite3VdbeAddOp2(v, OP_Integer, 1, target);
  3856   3916         sqlite3VdbeResolveLabel(v, destIfFalse);
  3857   3917         sqlite3VdbeAddOp2(v, OP_AddImm, target, 0);
  3858   3918         sqlite3VdbeResolveLabel(v, destIfNull);
  3859   3919         return target;
................................................................................
  3985   4045         Expr *pTest = 0;                  /* X==Ei (form A) or just Ei (form B) */
  3986   4046   
  3987   4047         assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
  3988   4048         assert(pExpr->x.pList->nExpr > 0);
  3989   4049         pEList = pExpr->x.pList;
  3990   4050         aListelem = pEList->a;
  3991   4051         nExpr = pEList->nExpr;
  3992         -      endLabel = sqlite3VdbeMakeLabel(v);
         4052  +      endLabel = sqlite3VdbeMakeLabel(pParse);
  3993   4053         if( (pX = pExpr->pLeft)!=0 ){
  3994   4054           tempX = *pX;
  3995   4055           testcase( pX->op==TK_COLUMN );
  3996   4056           exprToRegister(&tempX, exprCodeVector(pParse, &tempX, &regFree1));
  3997   4057           testcase( regFree1==0 );
  3998   4058           memset(&opCompare, 0, sizeof(opCompare));
  3999   4059           opCompare.op = TK_EQ;
................................................................................
  4008   4068         for(i=0; i<nExpr-1; i=i+2){
  4009   4069           if( pX ){
  4010   4070             assert( pTest!=0 );
  4011   4071             opCompare.pRight = aListelem[i].pExpr;
  4012   4072           }else{
  4013   4073             pTest = aListelem[i].pExpr;
  4014   4074           }
  4015         -        nextCase = sqlite3VdbeMakeLabel(v);
         4075  +        nextCase = sqlite3VdbeMakeLabel(pParse);
  4016   4076           testcase( pTest->op==TK_COLUMN );
  4017   4077           sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
  4018   4078           testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
  4019   4079           sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
  4020   4080           sqlite3VdbeGoto(v, endLabel);
  4021   4081           sqlite3VdbeResolveLabel(v, nextCase);
  4022   4082         }
................................................................................
  4377   4437   
  4378   4438     assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
  4379   4439     if( NEVER(v==0) )     return;  /* Existence of VDBE checked by caller */
  4380   4440     if( NEVER(pExpr==0) ) return;  /* No way this can happen */
  4381   4441     op = pExpr->op;
  4382   4442     switch( op ){
  4383   4443       case TK_AND: {
  4384         -      int d2 = sqlite3VdbeMakeLabel(v);
         4444  +      int d2 = sqlite3VdbeMakeLabel(pParse);
  4385   4445         testcase( jumpIfNull==0 );
  4386   4446         sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL);
  4387   4447         sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
  4388   4448         sqlite3VdbeResolveLabel(v, d2);
  4389   4449         break;
  4390   4450       }
  4391   4451       case TK_OR: {
................................................................................
  4463   4523       case TK_BETWEEN: {
  4464   4524         testcase( jumpIfNull==0 );
  4465   4525         exprCodeBetween(pParse, pExpr, dest, sqlite3ExprIfTrue, jumpIfNull);
  4466   4526         break;
  4467   4527       }
  4468   4528   #ifndef SQLITE_OMIT_SUBQUERY
  4469   4529       case TK_IN: {
  4470         -      int destIfFalse = sqlite3VdbeMakeLabel(v);
         4530  +      int destIfFalse = sqlite3VdbeMakeLabel(pParse);
  4471   4531         int destIfNull = jumpIfNull ? dest : destIfFalse;
  4472   4532         sqlite3ExprCodeIN(pParse, pExpr, destIfFalse, destIfNull);
  4473   4533         sqlite3VdbeGoto(v, dest);
  4474   4534         sqlite3VdbeResolveLabel(v, destIfFalse);
  4475   4535         break;
  4476   4536       }
  4477   4537   #endif
................................................................................
  4550   4610       case TK_AND: {
  4551   4611         testcase( jumpIfNull==0 );
  4552   4612         sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
  4553   4613         sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
  4554   4614         break;
  4555   4615       }
  4556   4616       case TK_OR: {
  4557         -      int d2 = sqlite3VdbeMakeLabel(v);
         4617  +      int d2 = sqlite3VdbeMakeLabel(pParse);
  4558   4618         testcase( jumpIfNull==0 );
  4559   4619         sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL);
  4560   4620         sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
  4561   4621         sqlite3VdbeResolveLabel(v, d2);
  4562   4622         break;
  4563   4623       }
  4564   4624       case TK_NOT: {
................................................................................
  4634   4694         break;
  4635   4695       }
  4636   4696   #ifndef SQLITE_OMIT_SUBQUERY
  4637   4697       case TK_IN: {
  4638   4698         if( jumpIfNull ){
  4639   4699           sqlite3ExprCodeIN(pParse, pExpr, dest, dest);
  4640   4700         }else{
  4641         -        int destIfNull = sqlite3VdbeMakeLabel(v);
         4701  +        int destIfNull = sqlite3VdbeMakeLabel(pParse);
  4642   4702           sqlite3ExprCodeIN(pParse, pExpr, dest, destIfNull);
  4643   4703           sqlite3VdbeResolveLabel(v, destIfNull);
  4644   4704         }
  4645   4705         break;
  4646   4706       }
  4647   4707   #endif
  4648   4708       default: {

Changes to src/fkey.c.

   325    325     int regData,          /* Address of array containing child table row */
   326    326     int nIncr,            /* Increment constraint counter by this */
   327    327     int isIgnore          /* If true, pretend pTab contains all NULL values */
   328    328   ){
   329    329     int i;                                    /* Iterator variable */
   330    330     Vdbe *v = sqlite3GetVdbe(pParse);         /* Vdbe to add code to */
   331    331     int iCur = pParse->nTab - 1;              /* Cursor number to use */
   332         -  int iOk = sqlite3VdbeMakeLabel(v);        /* jump here if parent key found */
          332  +  int iOk = sqlite3VdbeMakeLabel(pParse);   /* jump here if parent key found */
   333    333   
   334    334     sqlite3VdbeVerifyAbortable(v,
   335    335       (!pFKey->isDeferred
   336    336         && !(pParse->db->flags & SQLITE_DeferFKs)
   337    337         && !pParse->pToplevel 
   338    338         && !pParse->isMultiWrite) ? OE_Abort : OE_Ignore);
   339    339   
................................................................................
   725    725         ** the entire DELETE if there are no outstanding deferred constraints
   726    726         ** when this statement is run.  */
   727    727         FKey *p;
   728    728         for(p=pTab->pFKey; p; p=p->pNextFrom){
   729    729           if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
   730    730         }
   731    731         if( !p ) return;
   732         -      iSkip = sqlite3VdbeMakeLabel(v);
          732  +      iSkip = sqlite3VdbeMakeLabel(pParse);
   733    733         sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
   734    734       }
   735    735   
   736    736       pParse->disableTriggers = 1;
   737    737       sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0);
   738    738       pParse->disableTriggers = 0;
   739    739   

Changes to src/insert.c.

   862    862       */
   863    863       addrInsTop = addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
   864    864       VdbeCoverage(v);
   865    865     }
   866    866   
   867    867     /* Run the BEFORE and INSTEAD OF triggers, if there are any
   868    868     */
   869         -  endOfLoop = sqlite3VdbeMakeLabel(v);
          869  +  endOfLoop = sqlite3VdbeMakeLabel(pParse);
   870    870     if( tmask & TRIGGER_BEFORE ){
   871    871       int regCols = sqlite3GetTempRange(pParse, pTab->nCol+1);
   872    872   
   873    873       /* build the NEW.* reference row.  Note that if there is an INTEGER
   874    874       ** PRIMARY KEY into which a NULL is being inserted, that NULL will be
   875    875       ** translated into a unique ID for the row.  But on a BEFORE trigger,
   876    876       ** we do not know what the unique ID will be (because the insert has
................................................................................
  1352   1352       }
  1353   1353       assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
  1354   1354           || onError==OE_Ignore || onError==OE_Replace );
  1355   1355       addr1 = 0;
  1356   1356       switch( onError ){
  1357   1357         case OE_Replace: {
  1358   1358           assert( onError==OE_Replace );
  1359         -        addr1 = sqlite3VdbeMakeLabel(v);
         1359  +        addr1 = sqlite3VdbeMakeLabel(pParse);
  1360   1360           sqlite3VdbeAddOp2(v, OP_NotNull, regNewData+1+i, addr1);
  1361   1361             VdbeCoverage(v);
  1362   1362           sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
  1363   1363           sqlite3VdbeAddOp2(v, OP_NotNull, regNewData+1+i, addr1);
  1364   1364             VdbeCoverage(v);
  1365   1365           onError = OE_Abort;
  1366   1366           /* Fall through into the OE_Abort case to generate code that runs
................................................................................
  1403   1403         if( aiChng
  1404   1404          && !sqlite3ExprReferencesUpdatedColumn(pExpr, aiChng, pkChng)
  1405   1405         ){
  1406   1406           /* The check constraints do not reference any of the columns being
  1407   1407           ** updated so there is no point it verifying the check constraint */
  1408   1408           continue;
  1409   1409         }
  1410         -      allOk = sqlite3VdbeMakeLabel(v);
         1410  +      allOk = sqlite3VdbeMakeLabel(pParse);
  1411   1411         sqlite3VdbeVerifyAbortable(v, onError);
  1412   1412         sqlite3ExprIfTrue(pParse, pExpr, allOk, SQLITE_JUMPIFNULL);
  1413   1413         if( onError==OE_Ignore ){
  1414   1414           sqlite3VdbeGoto(v, ignoreDest);
  1415   1415         }else{
  1416   1416           char *zName = pCheck->a[i].zName;
  1417   1417           if( zName==0 ) zName = pTab->zName;
................................................................................
  1470   1470       }
  1471   1471     }
  1472   1472   
  1473   1473     /* If rowid is changing, make sure the new rowid does not previously
  1474   1474     ** exist in the table.
  1475   1475     */
  1476   1476     if( pkChng && pPk==0 ){
  1477         -    int addrRowidOk = sqlite3VdbeMakeLabel(v);
         1477  +    int addrRowidOk = sqlite3VdbeMakeLabel(pParse);
  1478   1478   
  1479   1479       /* Figure out what action to take in case of a rowid collision */
  1480   1480       onError = pTab->keyConf;
  1481   1481       if( overrideError!=OE_Default ){
  1482   1482         onError = overrideError;
  1483   1483       }else if( onError==OE_Default ){
  1484   1484         onError = OE_Abort;
................................................................................
  1620   1620       if( aRegIdx[ix]==0 ) continue;  /* Skip indices that do not change */
  1621   1621       if( pUpIdx==pIdx ){
  1622   1622         addrUniqueOk = upsertJump+1;
  1623   1623         upsertBypass = sqlite3VdbeGoto(v, 0);
  1624   1624         VdbeComment((v, "Skip upsert subroutine"));
  1625   1625         sqlite3VdbeJumpHere(v, upsertJump);
  1626   1626       }else{
  1627         -      addrUniqueOk = sqlite3VdbeMakeLabel(v);
         1627  +      addrUniqueOk = sqlite3VdbeMakeLabel(pParse);
  1628   1628       }
  1629   1629       if( bAffinityDone==0 && (pUpIdx==0 || pUpIdx==pIdx) ){
  1630   1630         sqlite3TableAffinity(v, pTab, regNewData+1);
  1631   1631         bAffinityDone = 1;
  1632   1632       }
  1633   1633       VdbeNoopComment((v, "uniqueness check for %s", pIdx->zName));
  1634   1634       iThisCur = iIdxCur+ix;

Changes to src/pragma.c.

  1373   1373           pParent = sqlite3FindTable(db, pFK->zTo, zDb);
  1374   1374           pIdx = 0;
  1375   1375           aiCols = 0;
  1376   1376           if( pParent ){
  1377   1377             x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
  1378   1378             assert( x==0 );
  1379   1379           }
  1380         -        addrOk = sqlite3VdbeMakeLabel(v);
         1380  +        addrOk = sqlite3VdbeMakeLabel(pParse);
  1381   1381   
  1382   1382           /* Generate code to read the child key values into registers
  1383   1383           ** regRow..regRow+n. If any of the child key values are NULL, this 
  1384   1384           ** row cannot cause an FK violation. Jump directly to addrOk in 
  1385   1385           ** this case. */
  1386   1386           for(j=0; j<pFK->nCol; j++){
  1387   1387             int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom;
................................................................................
  1593   1593             integrityCheckResultRow(v);
  1594   1594             sqlite3VdbeJumpHere(v, jmp2);
  1595   1595           }
  1596   1596           /* Verify CHECK constraints */
  1597   1597           if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
  1598   1598             ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
  1599   1599             if( db->mallocFailed==0 ){
  1600         -            int addrCkFault = sqlite3VdbeMakeLabel(v);
  1601         -            int addrCkOk = sqlite3VdbeMakeLabel(v);
         1600  +            int addrCkFault = sqlite3VdbeMakeLabel(pParse);
         1601  +            int addrCkOk = sqlite3VdbeMakeLabel(pParse);
  1602   1602               char *zErr;
  1603   1603               int k;
  1604   1604               pParse->iSelfTab = iDataCur + 1;
  1605   1605               for(k=pCheck->nExpr-1; k>0; k--){
  1606   1606                 sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
  1607   1607               }
  1608   1608               sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk, 
................................................................................
  1617   1617             }
  1618   1618             sqlite3ExprListDelete(db, pCheck);
  1619   1619           }
  1620   1620           if( !isQuick ){ /* Omit the remaining tests for quick_check */
  1621   1621             /* Validate index entries for the current row */
  1622   1622             for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
  1623   1623               int jmp2, jmp3, jmp4, jmp5;
  1624         -            int ckUniq = sqlite3VdbeMakeLabel(v);
         1624  +            int ckUniq = sqlite3VdbeMakeLabel(pParse);
  1625   1625               if( pPk==pIdx ) continue;
  1626   1626               r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
  1627   1627                                            pPrior, r1);
  1628   1628               pPrior = pIdx;
  1629   1629               sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1);/* increment entry count */
  1630   1630               /* Verify that an index entry exists for the current table row */
  1631   1631               jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
................................................................................
  1638   1638               sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
  1639   1639               jmp4 = integrityCheckResultRow(v);
  1640   1640               sqlite3VdbeJumpHere(v, jmp2);
  1641   1641               /* For UNIQUE indexes, verify that only one entry exists with the
  1642   1642               ** current key.  The entry is unique if (1) any column is NULL
  1643   1643               ** or (2) the next entry has a different key */
  1644   1644               if( IsUniqueIndex(pIdx) ){
  1645         -              int uniqOk = sqlite3VdbeMakeLabel(v);
         1645  +              int uniqOk = sqlite3VdbeMakeLabel(pParse);
  1646   1646                 int jmp6;
  1647   1647                 int kk;
  1648   1648                 for(kk=0; kk<pIdx->nKeyCol; kk++){
  1649   1649                   int iCol = pIdx->aiColumn[kk];
  1650   1650                   assert( iCol!=XN_ROWID && iCol<pTab->nCol );
  1651   1651                   if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
  1652   1652                   sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);

Changes to src/resolve.c.

  1658   1658     w.xSelectCallback2 = 0;
  1659   1659     w.pParse = pParse;
  1660   1660     w.u.pNC = pOuterNC;
  1661   1661     sqlite3WalkSelect(&w, p);
  1662   1662   }
  1663   1663   
  1664   1664   /*
  1665         -** Resolve names in expressions that can only reference a single table:
         1665  +** Resolve names in expressions that can only reference a single table
         1666  +** or which cannot reference any tables at all.  Examples:
  1666   1667   **
  1667         -**    *   CHECK constraints
  1668         -**    *   WHERE clauses on partial indices
         1668  +**    (1)   CHECK constraints
         1669  +**    (2)   WHERE clauses on partial indices
         1670  +**    (3)   Expressions in indexes on expressions
         1671  +**    (4)   Expression arguments to VACUUM INTO.
  1669   1672   **
  1670         -** The Expr.iTable value for Expr.op==TK_COLUMN nodes of the expression
  1671         -** is set to -1 and the Expr.iColumn value is set to the column number.
         1673  +** In all cases except (4), the Expr.iTable value for Expr.op==TK_COLUMN
         1674  +** nodes of the expression is set to -1 and the Expr.iColumn value is
         1675  +** set to the column number.  In case (4), TK_COLUMN nodes cause an error.
  1672   1676   **
  1673   1677   ** Any errors cause an error message to be set in pParse.
  1674   1678   */
  1675         -void sqlite3ResolveSelfReference(
         1679  +int sqlite3ResolveSelfReference(
  1676   1680     Parse *pParse,      /* Parsing context */
  1677         -  Table *pTab,        /* The table being referenced */
  1678         -  int type,           /* NC_IsCheck or NC_PartIdx or NC_IdxExpr */
         1681  +  Table *pTab,        /* The table being referenced, or NULL */
         1682  +  int type,           /* NC_IsCheck or NC_PartIdx or NC_IdxExpr, or 0 */
  1679   1683     Expr *pExpr,        /* Expression to resolve.  May be NULL. */
  1680   1684     ExprList *pList     /* Expression list to resolve.  May be NULL. */
  1681   1685   ){
  1682   1686     SrcList sSrc;                   /* Fake SrcList for pParse->pNewTable */
  1683   1687     NameContext sNC;                /* Name context for pParse->pNewTable */
         1688  +  int rc;
  1684   1689   
  1685         -  assert( type==NC_IsCheck || type==NC_PartIdx || type==NC_IdxExpr );
         1690  +  assert( type==0 || pTab!=0 );
         1691  +  assert( type==NC_IsCheck || type==NC_PartIdx || type==NC_IdxExpr || pTab==0 );
  1686   1692     memset(&sNC, 0, sizeof(sNC));
  1687   1693     memset(&sSrc, 0, sizeof(sSrc));
  1688         -  sSrc.nSrc = 1;
  1689         -  sSrc.a[0].zName = pTab->zName;
  1690         -  sSrc.a[0].pTab = pTab;
  1691         -  sSrc.a[0].iCursor = -1;
         1694  +  if( pTab ){
         1695  +    sSrc.nSrc = 1;
         1696  +    sSrc.a[0].zName = pTab->zName;
         1697  +    sSrc.a[0].pTab = pTab;
         1698  +    sSrc.a[0].iCursor = -1;
         1699  +  }
  1692   1700     sNC.pParse = pParse;
  1693   1701     sNC.pSrcList = &sSrc;
  1694   1702     sNC.ncFlags = type;
  1695         -  if( sqlite3ResolveExprNames(&sNC, pExpr) ) return;
  1696         -  if( pList ) sqlite3ResolveExprListNames(&sNC, pList);
         1703  +  if( (rc = sqlite3ResolveExprNames(&sNC, pExpr))!=SQLITE_OK ) return rc;
         1704  +  if( pList ) rc = sqlite3ResolveExprListNames(&sNC, pList);
         1705  +  return rc;
  1697   1706   }

Changes to src/select.c.

   627    627       regBase = regData - nPrefixReg;
   628    628     }else{
   629    629       regBase = pParse->nMem + 1;
   630    630       pParse->nMem += nBase;
   631    631     }
   632    632     assert( pSelect->iOffset==0 || pSelect->iLimit!=0 );
   633    633     iLimit = pSelect->iOffset ? pSelect->iOffset+1 : pSelect->iLimit;
   634         -  pSort->labelDone = sqlite3VdbeMakeLabel(v);
          634  +  pSort->labelDone = sqlite3VdbeMakeLabel(pParse);
   635    635     sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, regOrigData,
   636    636                             SQLITE_ECEL_DUP | (regOrigData? SQLITE_ECEL_REF : 0));
   637    637     if( bSeq ){
   638    638       sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
   639    639     }
   640    640     if( nPrefixReg==0 && nData>0 ){
   641    641       sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
................................................................................
   666    666       memset(pKI->aSortOrder, 0, pKI->nKeyField); /* Makes OP_Jump testable */
   667    667       sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
   668    668       testcase( pKI->nAllField > pKI->nKeyField+2 );
   669    669       pOp->p4.pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pSort->pOrderBy,nOBSat,
   670    670                                              pKI->nAllField-pKI->nKeyField-1);
   671    671       addrJmp = sqlite3VdbeCurrentAddr(v);
   672    672       sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
   673         -    pSort->labelBkOut = sqlite3VdbeMakeLabel(v);
          673  +    pSort->labelBkOut = sqlite3VdbeMakeLabel(pParse);
   674    674       pSort->regReturn = ++pParse->nMem;
   675    675       sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
   676    676       sqlite3VdbeAddOp1(v, OP_ResetSorter, pSort->iECursor);
   677    677       if( iLimit ){
   678    678         sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, pSort->labelDone);
   679    679         VdbeCoverage(v);
   680    680       }
................................................................................
  1413   1413     Select *p,        /* The SELECT statement */
  1414   1414     SortCtx *pSort,   /* Information on the ORDER BY clause */
  1415   1415     int nColumn,      /* Number of columns of data */
  1416   1416     SelectDest *pDest /* Write the sorted results here */
  1417   1417   ){
  1418   1418     Vdbe *v = pParse->pVdbe;                     /* The prepared statement */
  1419   1419     int addrBreak = pSort->labelDone;            /* Jump here to exit loop */
  1420         -  int addrContinue = sqlite3VdbeMakeLabel(v);  /* Jump here for next cycle */
         1420  +  int addrContinue = sqlite3VdbeMakeLabel(pParse);/* Jump here for next cycle */
  1421   1421     int addr;                       /* Top of output loop. Jump for Next. */
  1422   1422     int addrOnce = 0;
  1423   1423     int iTab;
  1424   1424     ExprList *pOrderBy = pSort->pOrderBy;
  1425   1425     int eDest = pDest->eDest;
  1426   1426     int iParm = pDest->iSDParm;
  1427   1427     int regRow;
................................................................................
  2325   2325     }
  2326   2326   #endif
  2327   2327   
  2328   2328     /* Obtain authorization to do a recursive query */
  2329   2329     if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return;
  2330   2330   
  2331   2331     /* Process the LIMIT and OFFSET clauses, if they exist */
  2332         -  addrBreak = sqlite3VdbeMakeLabel(v);
         2332  +  addrBreak = sqlite3VdbeMakeLabel(pParse);
  2333   2333     p->nSelectRow = 320;  /* 4 billion rows */
  2334   2334     computeLimitRegisters(pParse, p, addrBreak);
  2335   2335     pLimit = p->pLimit;
  2336   2336     regLimit = p->iLimit;
  2337   2337     regOffset = p->iOffset;
  2338   2338     p->pLimit = 0;
  2339   2339     p->iLimit = p->iOffset = 0;
................................................................................
  2395   2395       sqlite3VdbeAddOp3(v, OP_Column, iQueue, pOrderBy->nExpr+1, regCurrent);
  2396   2396     }else{
  2397   2397       sqlite3VdbeAddOp2(v, OP_RowData, iQueue, regCurrent);
  2398   2398     }
  2399   2399     sqlite3VdbeAddOp1(v, OP_Delete, iQueue);
  2400   2400   
  2401   2401     /* Output the single row in Current */
  2402         -  addrCont = sqlite3VdbeMakeLabel(v);
         2402  +  addrCont = sqlite3VdbeMakeLabel(pParse);
  2403   2403     codeOffset(v, regOffset, addrCont);
  2404   2404     selectInnerLoop(pParse, p, iCurrent,
  2405   2405         0, 0, pDest, addrCont, addrBreak);
  2406   2406     if( regLimit ){
  2407   2407       sqlite3VdbeAddOp2(v, OP_DecrJumpZero, regLimit, addrBreak);
  2408   2408       VdbeCoverage(v);
  2409   2409     }
................................................................................
  2703   2703           /* Convert the data in the temporary table into whatever form
  2704   2704           ** it is that we currently need.
  2705   2705           */
  2706   2706           assert( unionTab==dest.iSDParm || dest.eDest!=priorOp );
  2707   2707           if( dest.eDest!=priorOp ){
  2708   2708             int iCont, iBreak, iStart;
  2709   2709             assert( p->pEList );
  2710         -          iBreak = sqlite3VdbeMakeLabel(v);
  2711         -          iCont = sqlite3VdbeMakeLabel(v);
         2710  +          iBreak = sqlite3VdbeMakeLabel(pParse);
         2711  +          iCont = sqlite3VdbeMakeLabel(pParse);
  2712   2712             computeLimitRegisters(pParse, p, iBreak);
  2713   2713             sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
  2714   2714             iStart = sqlite3VdbeCurrentAddr(v);
  2715   2715             selectInnerLoop(pParse, p, unionTab,
  2716   2716                             0, 0, &dest, iCont, iBreak);
  2717   2717             sqlite3VdbeResolveLabel(v, iCont);
  2718   2718             sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); VdbeCoverage(v);
................................................................................
  2772   2772           sqlite3ExprDelete(db, p->pLimit);
  2773   2773           p->pLimit = pLimit;
  2774   2774     
  2775   2775           /* Generate code to take the intersection of the two temporary
  2776   2776           ** tables.
  2777   2777           */
  2778   2778           assert( p->pEList );
  2779         -        iBreak = sqlite3VdbeMakeLabel(v);
  2780         -        iCont = sqlite3VdbeMakeLabel(v);
         2779  +        iBreak = sqlite3VdbeMakeLabel(pParse);
         2780  +        iCont = sqlite3VdbeMakeLabel(pParse);
  2781   2781           computeLimitRegisters(pParse, p, iBreak);
  2782   2782           sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
  2783   2783           r1 = sqlite3GetTempReg(pParse);
  2784   2784           iStart = sqlite3VdbeAddOp2(v, OP_RowData, tab1, r1);
  2785   2785           sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
  2786   2786           VdbeCoverage(v);
  2787   2787           sqlite3ReleaseTempReg(pParse, r1);
................................................................................
  2903   2903     int iBreak              /* Jump here if we hit the LIMIT */
  2904   2904   ){
  2905   2905     Vdbe *v = pParse->pVdbe;
  2906   2906     int iContinue;
  2907   2907     int addr;
  2908   2908   
  2909   2909     addr = sqlite3VdbeCurrentAddr(v);
  2910         -  iContinue = sqlite3VdbeMakeLabel(v);
         2910  +  iContinue = sqlite3VdbeMakeLabel(pParse);
  2911   2911   
  2912   2912     /* Suppress duplicates for UNION, EXCEPT, and INTERSECT 
  2913   2913     */
  2914   2914     if( regPrev ){
  2915   2915       int addr1, addr2;
  2916   2916       addr1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev); VdbeCoverage(v);
  2917   2917       addr2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
................................................................................
  3140   3140     int *aPermute;        /* Mapping from ORDER BY terms to result set columns */
  3141   3141   
  3142   3142     assert( p->pOrderBy!=0 );
  3143   3143     assert( pKeyDup==0 ); /* "Managed" code needs this.  Ticket #3382. */
  3144   3144     db = pParse->db;
  3145   3145     v = pParse->pVdbe;
  3146   3146     assert( v!=0 );       /* Already thrown the error if VDBE alloc failed */
  3147         -  labelEnd = sqlite3VdbeMakeLabel(v);
  3148         -  labelCmpr = sqlite3VdbeMakeLabel(v);
         3147  +  labelEnd = sqlite3VdbeMakeLabel(pParse);
         3148  +  labelCmpr = sqlite3VdbeMakeLabel(pParse);
  3149   3149   
  3150   3150   
  3151   3151     /* Patch up the ORDER BY clause
  3152   3152     */
  3153   3153     op = p->op;  
  3154   3154     pPrior = p->pPrior;
  3155   3155     assert( pPrior->pOrderBy==0 );
................................................................................
  5326   5326         regAgg = sqlite3GetTempRange(pParse, nArg);
  5327   5327         sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
  5328   5328       }else{
  5329   5329         nArg = 0;
  5330   5330         regAgg = 0;
  5331   5331       }
  5332   5332       if( pF->iDistinct>=0 ){
  5333         -      addrNext = sqlite3VdbeMakeLabel(v);
         5333  +      addrNext = sqlite3VdbeMakeLabel(pParse);
  5334   5334         testcase( nArg==0 );  /* Error condition */
  5335   5335         testcase( nArg>1 );   /* Also an error */
  5336   5336         codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
  5337   5337       }
  5338   5338       if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
  5339   5339         CollSeq *pColl = 0;
  5340   5340         struct ExprList_item *pItem;
................................................................................
  5462   5462   */
  5463   5463   static struct SrcList_item *isSelfJoinView(
  5464   5464     SrcList *pTabList,           /* Search for self-joins in this FROM clause */
  5465   5465     struct SrcList_item *pThis   /* Search for prior reference to this subquery */
  5466   5466   ){
  5467   5467     struct SrcList_item *pItem;
  5468   5468     for(pItem = pTabList->a; pItem<pThis; pItem++){
         5469  +    Select *pS1;
  5469   5470       if( pItem->pSelect==0 ) continue;
  5470   5471       if( pItem->fg.viaCoroutine ) continue;
  5471   5472       if( pItem->zName==0 ) continue;
  5472   5473       if( sqlite3_stricmp(pItem->zDatabase, pThis->zDatabase)!=0 ) continue;
  5473   5474       if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue;
  5474         -    if( sqlite3ExprCompare(0, 
  5475         -          pThis->pSelect->pWhere, pItem->pSelect->pWhere, -1) 
  5476         -    ){
         5475  +    pS1 = pItem->pSelect;
         5476  +    if( pThis->pSelect->selId!=pS1->selId ){
         5477  +      /* The query flattener left two different CTE tables with identical
         5478  +      ** names in the same FROM clause. */
         5479  +      continue;
         5480  +    }
         5481  +    if( sqlite3ExprCompare(0, pThis->pSelect->pWhere, pS1->pWhere, -1) ){
  5477   5482         /* The view was modified by some other optimization such as
  5478   5483         ** pushDownWhereTerms() */
  5479   5484         continue;
  5480   5485       }
  5481   5486       return pItem;
  5482   5487     }
  5483   5488     return 0;
................................................................................
  5826   5831   
  5827   5832   #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
  5828   5833       /* Generate code for all sub-queries in the FROM clause
  5829   5834       */
  5830   5835       pSub = pItem->pSelect;
  5831   5836       if( pSub==0 ) continue;
  5832   5837   
  5833         -    /* Sometimes the code for a subquery will be generated more than
  5834         -    ** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
  5835         -    ** for example.  In that case, do not regenerate the code to manifest
  5836         -    ** a view or the co-routine to implement a view.  The first instance
  5837         -    ** is sufficient, though the subroutine to manifest the view does need
  5838         -    ** to be invoked again. */
  5839         -    if( pItem->addrFillSub ){
  5840         -      if( pItem->fg.viaCoroutine==0 ){
  5841         -        /* The subroutine that manifests the view might be a one-time routine,
  5842         -        ** or it might need to be rerun on each iteration because it
  5843         -        ** encodes a correlated subquery. */
  5844         -        testcase( sqlite3VdbeGetOp(v, pItem->addrFillSub)->opcode==OP_Once );
  5845         -        sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
  5846         -      }
  5847         -      continue;
  5848         -    }
         5838  +    /* The code for a subquery should only be generated once, though it is
         5839  +    ** technically harmless for it to be generated multiple times. The
         5840  +    ** following assert() will detect if something changes to cause
         5841  +    ** the same subquery to be coded multiple times, as a signal to the
         5842  +    ** developers to try to optimize the situation. */
         5843  +    assert( pItem->addrFillSub==0 );
  5849   5844   
  5850   5845       /* Increment Parse.nHeight by the height of the largest expression
  5851   5846       ** tree referred to by this, the parent select. The child select
  5852   5847       ** may contain expression trees of at most
  5853   5848       ** (SQLITE_MAX_EXPR_DEPTH-Parse.nHeight) height. This is a bit
  5854   5849       ** more conservative than necessary, but much easier than enforcing
  5855   5850       ** an exact limit.
................................................................................
  6029   6024     */
  6030   6025     if( pDest->eDest==SRT_EphemTab ){
  6031   6026       sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
  6032   6027     }
  6033   6028   
  6034   6029     /* Set the limiter.
  6035   6030     */
  6036         -  iEnd = sqlite3VdbeMakeLabel(v);
         6031  +  iEnd = sqlite3VdbeMakeLabel(pParse);
  6037   6032     if( (p->selFlags & SF_FixedLimit)==0 ){
  6038   6033       p->nSelectRow = 320;  /* 4 billion rows */
  6039   6034     }
  6040   6035     computeLimitRegisters(pParse, p, iEnd);
  6041   6036     if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
  6042   6037       sqlite3VdbeChangeOpcode(v, sSort.addrSortIndex, OP_SorterOpen);
  6043   6038       sSort.sortFlags |= SORTFLAG_UseSorter;
................................................................................
  6096   6091       if( sSort.addrSortIndex>=0 && sSort.pOrderBy==0 ){
  6097   6092         sqlite3VdbeChangeToNoop(v, sSort.addrSortIndex);
  6098   6093       }
  6099   6094   
  6100   6095       assert( p->pEList==pEList );
  6101   6096   #ifndef SQLITE_OMIT_WINDOWFUNC
  6102   6097       if( pWin ){
  6103         -      int addrGosub = sqlite3VdbeMakeLabel(v);
  6104         -      int iCont = sqlite3VdbeMakeLabel(v);
  6105         -      int iBreak = sqlite3VdbeMakeLabel(v);
         6098  +      int addrGosub = sqlite3VdbeMakeLabel(pParse);
         6099  +      int iCont = sqlite3VdbeMakeLabel(pParse);
         6100  +      int iBreak = sqlite3VdbeMakeLabel(pParse);
  6106   6101         int regGosub = ++pParse->nMem;
  6107   6102   
  6108   6103         sqlite3WindowCodeStep(pParse, p, pWInfo, regGosub, addrGosub);
  6109   6104   
  6110   6105         sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
  6111   6106         sqlite3VdbeResolveLabel(v, addrGosub);
  6112   6107         VdbeNoopComment((v, "inner-loop subroutine"));
................................................................................
  6173   6168       ** ORDER BY and GROUP BY clauses are the same by setting the orderByGrp
  6174   6169       ** variable.  */
  6175   6170       if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
  6176   6171         orderByGrp = 1;
  6177   6172       }
  6178   6173    
  6179   6174       /* Create a label to jump to when we want to abort the query */
  6180         -    addrEnd = sqlite3VdbeMakeLabel(v);
         6175  +    addrEnd = sqlite3VdbeMakeLabel(pParse);
  6181   6176   
  6182   6177       /* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in
  6183   6178       ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
  6184   6179       ** SELECT statement.
  6185   6180       */
  6186   6181       memset(&sNC, 0, sizeof(sNC));
  6187   6182       sNC.pParse = pParse;
................................................................................
  6262   6257             0, (char*)pKeyInfo, P4_KEYINFO);
  6263   6258   
  6264   6259         /* Initialize memory locations used by GROUP BY aggregate processing
  6265   6260         */
  6266   6261         iUseFlag = ++pParse->nMem;
  6267   6262         iAbortFlag = ++pParse->nMem;
  6268   6263         regOutputRow = ++pParse->nMem;
  6269         -      addrOutputRow = sqlite3VdbeMakeLabel(v);
         6264  +      addrOutputRow = sqlite3VdbeMakeLabel(pParse);
  6270   6265         regReset = ++pParse->nMem;
  6271         -      addrReset = sqlite3VdbeMakeLabel(v);
         6266  +      addrReset = sqlite3VdbeMakeLabel(pParse);
  6272   6267         iAMem = pParse->nMem + 1;
  6273   6268         pParse->nMem += pGroupBy->nExpr;
  6274   6269         iBMem = pParse->nMem + 1;
  6275   6270         pParse->nMem += pGroupBy->nExpr;
  6276   6271         sqlite3VdbeAddOp2(v, OP_Integer, 0, iAbortFlag);
  6277   6272         VdbeComment((v, "clear abort flag"));
  6278   6273         sqlite3VdbeAddOp3(v, OP_Null, 0, iAMem, iAMem+pGroupBy->nExpr-1);

Changes to src/sqliteInt.h.

  2482   2482                            ** TK_COLUMN: the value of p5 for OP_Column
  2483   2483                            ** TK_AGG_FUNCTION: nesting depth */
  2484   2484     AggInfo *pAggInfo;     /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
  2485   2485     union {
  2486   2486       Table *pTab;           /* TK_COLUMN: Table containing column. Can be NULL
  2487   2487                              ** for a column of an index on an expression */
  2488   2488       Window *pWin;          /* TK_FUNCTION: Window definition for the func */
         2489  +    struct {               /* TK_IN, TK_SELECT, and TK_EXISTS */
         2490  +      int iAddr;             /* Subroutine entry address */
         2491  +      int regReturn;         /* Register used to hold return address */
         2492  +    } sub;
  2489   2493     } y;
  2490   2494   };
  2491   2495   
  2492   2496   /*
  2493   2497   ** The following are the meanings of bits in the Expr.flags field.
  2494   2498   */
  2495   2499   #define EP_FromJoin  0x000001 /* Originates in ON/USING clause of outer join */
................................................................................
  2513   2517   #define EP_Unlikely  0x040000 /* unlikely() or likelihood() function */
  2514   2518   #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
  2515   2519   #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
  2516   2520   #define EP_Subquery  0x200000 /* Tree contains a TK_SELECT operator */
  2517   2521   #define EP_Alias     0x400000 /* Is an alias for a result set column */
  2518   2522   #define EP_Leaf      0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
  2519   2523   #define EP_WinFunc  0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
         2524  +#define EP_Subrtn   0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
  2520   2525   
  2521   2526   /*
  2522   2527   ** The EP_Propagate mask is a set of properties that automatically propagate
  2523   2528   ** upwards into parent nodes.
  2524   2529   */
  2525   2530   #define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc)
  2526   2531   
................................................................................
  3062   3067     u8 disableLookaside; /* Number of times lookaside has been disabled */
  3063   3068     u8 disableVtab;      /* Disable all virtual tables for this parse */
  3064   3069     int nRangeReg;       /* Size of the temporary register block */
  3065   3070     int iRangeReg;       /* First register in temporary register block */
  3066   3071     int nErr;            /* Number of errors seen */
  3067   3072     int nTab;            /* Number of previously allocated VDBE cursors */
  3068   3073     int nMem;            /* Number of memory cells used so far */
  3069         -  int nOpAlloc;        /* Number of slots allocated for Vdbe.aOp[] */
  3070   3074     int szOpAlloc;       /* Bytes of memory space allocated for Vdbe.aOp[] */
  3071   3075     int iSelfTab;        /* Table associated with an index on expr, or negative
  3072   3076                          ** of the base register during check-constraint eval */
  3073         -  int nLabel;          /* Number of labels used */
         3077  +  int nLabel;          /* The *negative* of the number of labels used */
         3078  +  int nLabelAlloc;     /* Number of slots in aLabel */
  3074   3079     int *aLabel;         /* Space to hold the labels */
  3075   3080     ExprList *pConstExpr;/* Constant expressions */
  3076   3081     Token constraintName;/* Name of the constraint currently being parsed */
  3077   3082     yDbMask writeMask;   /* Start a write transaction on these databases */
  3078   3083     yDbMask cookieMask;  /* Bitmask of schema verified databases */
  3079   3084     int regRowid;        /* Register holding rowid of CREATE TABLE entry */
  3080   3085     int regRoot;         /* Register holding root page number for new objects */
................................................................................
  4255   4260   void sqlite3Reindex(Parse*, Token*, Token*);
  4256   4261   void sqlite3AlterFunctions(void);
  4257   4262   void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
  4258   4263   void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*);
  4259   4264   int sqlite3GetToken(const unsigned char *, int *);
  4260   4265   void sqlite3NestedParse(Parse*, const char*, ...);
  4261   4266   void sqlite3ExpirePreparedStatements(sqlite3*, int);
  4262         -void sqlite3CodeRhsOfIN(Parse*, Expr*, int);
         4267  +void sqlite3CodeRhsOfIN(Parse*, Expr*, int, int);
  4263   4268   int sqlite3CodeSubselect(Parse*, Expr*);
  4264   4269   void sqlite3SelectPrep(Parse*, Select*, NameContext*);
  4265   4270   void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
  4266   4271   int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
  4267   4272   int sqlite3ResolveExprNames(NameContext*, Expr*);
  4268   4273   int sqlite3ResolveExprListNames(NameContext*, ExprList*);
  4269   4274   void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
  4270         -void sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
         4275  +int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
  4271   4276   int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
  4272   4277   void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
  4273   4278   void sqlite3AlterFinishAddColumn(Parse *, Token *);
  4274   4279   void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
  4275   4280   void *sqlite3RenameTokenMap(Parse*, void*, Token*);
  4276   4281   void sqlite3RenameTokenRemap(Parse*, void *pTo, void *pFrom);
  4277   4282   void sqlite3RenameExprUnmap(Parse*, Expr*);
................................................................................
  4508   4513   #define IN_INDEX_NOOP         5   /* No table available. Use comparisons */
  4509   4514   /*
  4510   4515   ** Allowed flags for the 3rd parameter to sqlite3FindInIndex().
  4511   4516   */
  4512   4517   #define IN_INDEX_NOOP_OK     0x0001  /* OK to return IN_INDEX_NOOP */
  4513   4518   #define IN_INDEX_MEMBERSHIP  0x0002  /* IN operator used for membership test */
  4514   4519   #define IN_INDEX_LOOP        0x0004  /* IN operator used as a loop */
  4515         -int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*);
         4520  +int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*, int*);
  4516   4521   
  4517   4522   int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
  4518   4523   int sqlite3JournalSize(sqlite3_vfs *);
  4519   4524   #if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
  4520   4525    || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
  4521   4526     int sqlite3JournalCreate(sqlite3_file *);
  4522   4527   #endif

Changes to src/treeview.c.

   134    134       sqlite3_str_appendf(&x, "{%d,*}", pItem->iCursor);
   135    135       if( pItem->zDatabase ){
   136    136         sqlite3_str_appendf(&x, " %s.%s", pItem->zDatabase, pItem->zName);
   137    137       }else if( pItem->zName ){
   138    138         sqlite3_str_appendf(&x, " %s", pItem->zName);
   139    139       }
   140    140       if( pItem->pTab ){
   141         -      sqlite3_str_appendf(&x, " tabname=%Q", pItem->pTab->zName);
          141  +      sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p",
          142  +           pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab);
   142    143       }
   143    144       if( pItem->zAlias ){
   144    145         sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias);
   145    146       }
   146    147       if( pItem->fg.jointype & JT_LEFT ){
   147    148         sqlite3_str_appendf(&x, " LEFT-JOIN");
   148    149       }

Changes to src/trigger.c.

   940    940       ** (or NULL) the sub-vdbe is immediately halted by jumping to the 
   941    941       ** OP_Halt inserted at the end of the program.  */
   942    942       if( pTrigger->pWhen ){
   943    943         pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
   944    944         if( SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen) 
   945    945          && db->mallocFailed==0 
   946    946         ){
   947         -        iEndTrigger = sqlite3VdbeMakeLabel(v);
          947  +        iEndTrigger = sqlite3VdbeMakeLabel(pSubParse);
   948    948           sqlite3ExprIfFalse(pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
   949    949         }
   950    950         sqlite3ExprDelete(db, pWhen);
   951    951       }
   952    952   
   953    953       /* Code the trigger program into the sub-vdbe. */
   954    954       codeTriggerProgram(pSubParse, pTrigger->step_list, orconf);

Changes to src/update.c.

   437    437       updateVirtualTable(pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef,
   438    438                          pWhere, onError);
   439    439       goto update_cleanup;
   440    440     }
   441    441   #endif
   442    442   
   443    443     /* Jump to labelBreak to abandon further processing of this UPDATE */
   444         -  labelContinue = labelBreak = sqlite3VdbeMakeLabel(v);
          444  +  labelContinue = labelBreak = sqlite3VdbeMakeLabel(pParse);
   445    445   
   446    446     /* Not an UPSERT.  Normal processing.  Begin by
   447    447     ** initialize the count of updated rows */
   448    448     if( (db->flags&SQLITE_CountRows)!=0
   449    449      && !pParse->pTriggerTab
   450    450      && !pParse->nested
   451    451      && pUpsert==0
................................................................................
   572    572       if( eOnePass!=ONEPASS_OFF ){
   573    573         if( !isView && aiCurOnePass[0]!=iDataCur && aiCurOnePass[1]!=iDataCur ){
   574    574           assert( pPk );
   575    575           sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey,nKey);
   576    576           VdbeCoverage(v);
   577    577         }
   578    578         if( eOnePass!=ONEPASS_SINGLE ){
   579         -        labelContinue = sqlite3VdbeMakeLabel(v);
          579  +        labelContinue = sqlite3VdbeMakeLabel(pParse);
   580    580         }
   581    581         sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
   582    582         VdbeCoverageIf(v, pPk==0);
   583    583         VdbeCoverageIf(v, pPk!=0);
   584    584       }else if( pPk ){
   585         -      labelContinue = sqlite3VdbeMakeLabel(v);
          585  +      labelContinue = sqlite3VdbeMakeLabel(pParse);
   586    586         sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v);
   587    587         addrTop = sqlite3VdbeAddOp2(v, OP_RowData, iEph, regKey);
   588    588         sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0);
   589    589         VdbeCoverage(v);
   590    590       }else{
   591    591         labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet,labelBreak,
   592    592                                  regOldRowid);

Changes to src/vacuum.c.

   120    120       ** legacy applications. */
   121    121       iDb = sqlite3FindDb(pParse->db, pNm);
   122    122       if( iDb<0 ) iDb = 0;
   123    123   #endif
   124    124     }
   125    125     if( iDb!=1 ){
   126    126       int iIntoReg = 0;
   127         -    if( pInto ){
          127  +    if( pInto && sqlite3ResolveSelfReference(pParse,0,0,pInto,0)==0 ){
   128    128         iIntoReg = ++pParse->nMem;
   129    129         sqlite3ExprCode(pParse, pInto, iIntoReg);
   130    130       }
   131    131       sqlite3VdbeAddOp2(v, OP_Vacuum, iDb, iIntoReg);
   132    132       sqlite3VdbeUsesBtree(v, iDb);
   133    133     }
   134    134   build_vacuum_end:

Changes to src/vdbe.c.

   236    236     VdbeCursor *pCx = 0;
   237    237     nByte = 
   238    238         ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField + 
   239    239         (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0);
   240    240   
   241    241     assert( iCur>=0 && iCur<p->nCursor );
   242    242     if( p->apCsr[iCur] ){ /*OPTIMIZATION-IF-FALSE*/
          243  +    /* Before calling sqlite3VdbeFreeCursor(), ensure the isEphemeral flag
          244  +    ** is clear. Otherwise, if this is an ephemeral cursor created by 
          245  +    ** OP_OpenDup, the cursor will not be closed and will still be part
          246  +    ** of a BtShared.pCursor list.  */
          247  +    p->apCsr[iCur]->isEphemeral = 0;
   243    248       sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
   244    249       p->apCsr[iCur] = 0;
   245    250     }
   246    251     if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
   247    252       p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
   248    253       memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
   249    254       pCx->eCurType = eCurType;
................................................................................
  3637   3642   
  3638   3643     pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
  3639   3644     if( pCx==0 ) goto no_mem;
  3640   3645     pCx->nullRow = 1;
  3641   3646     pCx->isEphemeral = 1;
  3642   3647     pCx->pKeyInfo = pOrig->pKeyInfo;
  3643   3648     pCx->isTable = pOrig->isTable;
  3644         -  rc = sqlite3BtreeCursor(pOrig->pBtx, MASTER_ROOT, BTREE_WRCSR,
         3649  +  pCx->pgnoRoot = pOrig->pgnoRoot;
         3650  +  rc = sqlite3BtreeCursor(pOrig->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
  3645   3651                             pCx->pKeyInfo, pCx->uc.pCursor);
  3646   3652     /* The sqlite3BtreeCursor() routine can only fail for the first cursor
  3647   3653     ** opened for a database.  Since there is already an open cursor when this
  3648   3654     ** opcode is run, the sqlite3BtreeCursor() cannot fail */
  3649   3655     assert( rc==SQLITE_OK );
  3650   3656     break;
  3651   3657   }
................................................................................
  3654   3660   /* Opcode: OpenEphemeral P1 P2 * P4 P5
  3655   3661   ** Synopsis: nColumn=P2
  3656   3662   **
  3657   3663   ** Open a new cursor P1 to a transient table.
  3658   3664   ** The cursor is always opened read/write even if 
  3659   3665   ** the main database is read-only.  The ephemeral
  3660   3666   ** table is deleted automatically when the cursor is closed.
         3667  +**
         3668  +** If the cursor P1 is already opened on an ephermal table, the table
         3669  +** is cleared (all content is erased).
  3661   3670   **
  3662   3671   ** P2 is the number of columns in the ephemeral table.
  3663   3672   ** The cursor points to a BTree table if P4==0 and to a BTree index
  3664   3673   ** if P4 is not 0.  If P4 is not NULL, it points to a KeyInfo structure
  3665   3674   ** that defines the format of keys in the index.
  3666   3675   **
  3667   3676   ** The P5 parameter can be a mask of the BTREE_* flags defined
................................................................................
  3686   3695         SQLITE_OPEN_READWRITE |
  3687   3696         SQLITE_OPEN_CREATE |
  3688   3697         SQLITE_OPEN_EXCLUSIVE |
  3689   3698         SQLITE_OPEN_DELETEONCLOSE |
  3690   3699         SQLITE_OPEN_TRANSIENT_DB;
  3691   3700     assert( pOp->p1>=0 );
  3692   3701     assert( pOp->p2>=0 );
  3693         -  pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
  3694         -  if( pCx==0 ) goto no_mem;
  3695         -  pCx->nullRow = 1;
  3696         -  pCx->isEphemeral = 1;
  3697         -  rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx, 
  3698         -                        BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
  3699         -  if( rc==SQLITE_OK ){
  3700         -    rc = sqlite3BtreeBeginTrans(pCx->pBtx, 1, 0);
  3701         -  }
  3702         -  if( rc==SQLITE_OK ){
  3703         -    /* If a transient index is required, create it by calling
  3704         -    ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
  3705         -    ** opening it. If a transient table is required, just use the
  3706         -    ** automatically created table with root-page 1 (an BLOB_INTKEY table).
  3707         -    */
  3708         -    if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
  3709         -      int pgno;
  3710         -      assert( pOp->p4type==P4_KEYINFO );
  3711         -      rc = sqlite3BtreeCreateTable(pCx->pBtx, &pgno, BTREE_BLOBKEY | pOp->p5); 
  3712         -      if( rc==SQLITE_OK ){
  3713         -        assert( pgno==MASTER_ROOT+1 );
  3714         -        assert( pKeyInfo->db==db );
  3715         -        assert( pKeyInfo->enc==ENC(db) );
  3716         -        rc = sqlite3BtreeCursor(pCx->pBtx, pgno, BTREE_WRCSR,
  3717         -                                pKeyInfo, pCx->uc.pCursor);
  3718         -      }
  3719         -      pCx->isTable = 0;
  3720         -    }else{
  3721         -      rc = sqlite3BtreeCursor(pCx->pBtx, MASTER_ROOT, BTREE_WRCSR,
  3722         -                              0, pCx->uc.pCursor);
  3723         -      pCx->isTable = 1;
  3724         -    }
  3725         -  }
  3726         -  if( rc ) goto abort_due_to_error;
  3727         -  pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
         3702  +  pCx = p->apCsr[pOp->p1];
         3703  +  if( pCx ){
         3704  +    /* If the ephermeral table is already open, erase all existing content
         3705  +    ** so that the table is empty again, rather than creating a new table. */
         3706  +    rc = sqlite3BtreeClearTable(pCx->pBtx, pCx->pgnoRoot, 0);
         3707  +  }else{
         3708  +    pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
         3709  +    if( pCx==0 ) goto no_mem;
         3710  +    pCx->nullRow = 1;
         3711  +    pCx->isEphemeral = 1;
         3712  +    rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx, 
         3713  +                          BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5,
         3714  +                          vfsFlags);
         3715  +    if( rc==SQLITE_OK ){
         3716  +      rc = sqlite3BtreeBeginTrans(pCx->pBtx, 1, 0);
         3717  +    }
         3718  +    if( rc==SQLITE_OK ){
         3719  +      /* If a transient index is required, create it by calling
         3720  +      ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
         3721  +      ** opening it. If a transient table is required, just use the
         3722  +      ** automatically created table with root-page 1 (an BLOB_INTKEY table).
         3723  +      */
         3724  +      if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
         3725  +        assert( pOp->p4type==P4_KEYINFO );
         3726  +        rc = sqlite3BtreeCreateTable(pCx->pBtx, (int*)&pCx->pgnoRoot,
         3727  +                                     BTREE_BLOBKEY | pOp->p5); 
         3728  +        if( rc==SQLITE_OK ){
         3729  +          assert( pCx->pgnoRoot==MASTER_ROOT+1 );
         3730  +          assert( pKeyInfo->db==db );
         3731  +          assert( pKeyInfo->enc==ENC(db) );
         3732  +          rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
         3733  +                                  pKeyInfo, pCx->uc.pCursor);
         3734  +        }
         3735  +        pCx->isTable = 0;
         3736  +      }else{
         3737  +        pCx->pgnoRoot = MASTER_ROOT;
         3738  +        rc = sqlite3BtreeCursor(pCx->pBtx, MASTER_ROOT, BTREE_WRCSR,
         3739  +                                0, pCx->uc.pCursor);
         3740  +        pCx->isTable = 1;
         3741  +      }
         3742  +    }
         3743  +    pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
         3744  +  }
         3745  +  if( rc ) goto abort_due_to_error;
  3728   3746     break;
  3729   3747   }
  3730   3748   
  3731   3749   /* Opcode: SorterOpen P1 P2 P3 P4 *
  3732   3750   **
  3733   3751   ** This opcode works like OP_OpenEphemeral except that it opens
  3734   3752   ** a transient index that is specifically designed to sort large
................................................................................
  6896   6914   ** P4 is the name of a virtual table in database P1.  Call the xDestroy method
  6897   6915   ** of that table.
  6898   6916   */
  6899   6917   case OP_VDestroy: {
  6900   6918     db->nVDestroy++;
  6901   6919     rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z);
  6902   6920     db->nVDestroy--;
         6921  +  assert( p->errorAction==OE_Abort && p->usesStmtJournal );
  6903   6922     if( rc ) goto abort_due_to_error;
  6904   6923     break;
  6905   6924   }
  6906   6925   #endif /* SQLITE_OMIT_VIRTUALTABLE */
  6907   6926   
  6908   6927   #ifndef SQLITE_OMIT_VIRTUALTABLE
  6909   6928   /* Opcode: VOpen P1 * * P4 *

Changes to src/vdbe.h.

   152    152   #   define COLNAME_N      1      /* Store only the name */
   153    153   # else
   154    154   #   define COLNAME_N      2      /* Store the name and decltype */
   155    155   # endif
   156    156   #endif
   157    157   
   158    158   /*
   159         -** The following macro converts a relative address in the p2 field
   160         -** of a VdbeOp structure into a negative number so that 
   161         -** sqlite3VdbeAddOpList() knows that the address is relative.  Calling
   162         -** the macro again restores the address.
          159  +** The following macro converts a label returned by sqlite3VdbeMakeLabel()
          160  +** into an index into the Parse.aLabel[] array that contains the resolved
          161  +** address of that label.
   163    162   */
   164         -#define ADDR(X)  (-1-(X))
          163  +#define ADDR(X)  (~(X))
   165    164   
   166    165   /*
   167    166   ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
   168    167   ** header file that defines a number for each opcode used by the VDBE.
   169    168   */
   170    169   #include "opcodes.h"
   171    170   
................................................................................
   211    210   # define ExplainQueryPlan(P)        sqlite3VdbeExplain P
   212    211   # define ExplainQueryPlanPop(P)     sqlite3VdbeExplainPop(P)
   213    212   # define ExplainQueryPlanParent(P)  sqlite3VdbeExplainParent(P)
   214    213   #else
   215    214   # define ExplainQueryPlan(P)
   216    215   # define ExplainQueryPlanPop(P)
   217    216   # define ExplainQueryPlanParent(P) 0
          217  +# define sqlite3ExplainBreakpoint(A,B) /*no-op*/
          218  +#endif
          219  +#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_EXPLAIN)
          220  +  void sqlite3ExplainBreakpoint(const char*,const char*);
          221  +#else
          222  +# define sqlite3ExplainBreakpoint(A,B) /*no-op*/
   218    223   #endif
   219    224   void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
   220    225   void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8);
   221    226   void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
   222    227   void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
   223    228   void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
   224    229   void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
................................................................................
   226    231   int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
   227    232   int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
   228    233   void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
   229    234   void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
   230    235   void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
   231    236   void sqlite3VdbeUsesBtree(Vdbe*, int);
   232    237   VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
   233         -int sqlite3VdbeMakeLabel(Vdbe*);
          238  +int sqlite3VdbeMakeLabel(Parse*);
   234    239   void sqlite3VdbeRunOnlyOnce(Vdbe*);
   235    240   void sqlite3VdbeReusable(Vdbe*);
   236    241   void sqlite3VdbeDelete(Vdbe*);
   237    242   void sqlite3VdbeClearObject(sqlite3*,Vdbe*);
   238    243   void sqlite3VdbeMakeReady(Vdbe*,Parse*);
   239    244   int sqlite3VdbeFinalize(Vdbe*);
   240    245   void sqlite3VdbeResolveLabel(Vdbe*, int);

Changes to src/vdbeInt.h.

   381    381     int rc;                 /* Value to return */
   382    382     int nChange;            /* Number of db changes made since last reset */
   383    383     int iStatement;         /* Statement number (or 0 if has no opened stmt) */
   384    384     i64 iCurrentTime;       /* Value of julianday('now') for this statement */
   385    385     i64 nFkConstraint;      /* Number of imm. FK constraints this VM */
   386    386     i64 nStmtDefCons;       /* Number of def. constraints when stmt started */
   387    387     i64 nStmtDefImmCons;    /* Number of def. imm constraints when stmt started */
          388  +  Mem *aMem;              /* The memory locations */
          389  +  Mem **apArg;            /* Arguments to currently executing user function */
          390  +  VdbeCursor **apCsr;     /* One element of this array for each open cursor */
          391  +  Mem *aVar;              /* Values for the OP_Variable opcode. */
   388    392   
   389    393     /* When allocating a new Vdbe object, all of the fields below should be
   390    394     ** initialized to zero or NULL */
   391    395   
   392    396     Op *aOp;                /* Space to hold the virtual machine's program */
   393         -  Mem *aMem;              /* The memory locations */
   394         -  Mem **apArg;            /* Arguments to currently executing user function */
          397  +  int nOp;                /* Number of instructions in the program */
          398  +  int nOpAlloc;           /* Slots allocated for aOp[] */
   395    399     Mem *aColName;          /* Column names to return */
   396    400     Mem *pResultSet;        /* Pointer to an array of results */
   397    401     char *zErrMsg;          /* Error message written here */
   398         -  VdbeCursor **apCsr;     /* One element of this array for each open cursor */
   399         -  Mem *aVar;              /* Values for the OP_Variable opcode. */
   400    402     VList *pVList;          /* Name of variables */
   401    403   #ifndef SQLITE_OMIT_TRACE
   402    404     i64 startTime;          /* Time when query started - used for profiling */
   403    405   #endif
   404         -  int nOp;                /* Number of instructions in the program */
   405    406   #ifdef SQLITE_DEBUG
   406    407     int rcApp;              /* errcode set by sqlite3_result_error_code() */
   407    408     u32 nWrite;             /* Number of write operations that have occurred */
   408    409   #endif
   409    410     u16 nResColumn;         /* Number of columns in one row of the result set */
   410    411     u8 errorAction;         /* Recovery action to do in case of an error */
   411    412     u8 minWriteFileFormat;  /* Minimum file format for writable database files */

Changes to src/vdbeaux.c.

    32     32     p->pPrev = 0;
    33     33     db->pVdbe = p;
    34     34     p->magic = VDBE_MAGIC_INIT;
    35     35     p->pParse = pParse;
    36     36     pParse->pVdbe = p;
    37     37     assert( pParse->aLabel==0 );
    38     38     assert( pParse->nLabel==0 );
    39         -  assert( pParse->nOpAlloc==0 );
           39  +  assert( p->nOpAlloc==0 );
    40     40     assert( pParse->szOpAlloc==0 );
    41     41     sqlite3VdbeAddOp2(p, OP_Init, 0, 1);
    42     42     return p;
    43     43   }
    44     44   
    45     45   /*
    46     46   ** Change the error string stored in Vdbe.zErrMsg
................................................................................
   135    135   
   136    136   /*
   137    137   ** Resize the Vdbe.aOp array so that it is at least nOp elements larger 
   138    138   ** than its current size. nOp is guaranteed to be less than or equal
   139    139   ** to 1024/sizeof(Op).
   140    140   **
   141    141   ** If an out-of-memory error occurs while resizing the array, return
   142         -** SQLITE_NOMEM. In this case Vdbe.aOp and Parse.nOpAlloc remain 
          142  +** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain 
   143    143   ** unchanged (this is so that any opcodes already allocated can be 
   144    144   ** correctly deallocated along with the rest of the Vdbe).
   145    145   */
   146    146   static int growOpArray(Vdbe *v, int nOp){
   147    147     VdbeOp *pNew;
   148    148     Parse *p = v->pParse;
   149    149   
................................................................................
   151    151     ** more frequent reallocs and hence provide more opportunities for 
   152    152     ** simulated OOM faults.  SQLITE_TEST_REALLOC_STRESS is generally used
   153    153     ** during testing only.  With SQLITE_TEST_REALLOC_STRESS grow the op array
   154    154     ** by the minimum* amount required until the size reaches 512.  Normal
   155    155     ** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current
   156    156     ** size of the op array or add 1KB of space, whichever is smaller. */
   157    157   #ifdef SQLITE_TEST_REALLOC_STRESS
   158         -  int nNew = (p->nOpAlloc>=512 ? p->nOpAlloc*2 : p->nOpAlloc+nOp);
          158  +  int nNew = (v->nOpAlloc>=512 ? v->nOpAlloc*2 : v->nOpAlloc+nOp);
   159    159   #else
   160         -  int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
          160  +  int nNew = (v->nOpAlloc ? v->nOpAlloc*2 : (int)(1024/sizeof(Op)));
   161    161     UNUSED_PARAMETER(nOp);
   162    162   #endif
   163    163   
   164    164     /* Ensure that the size of a VDBE does not grow too large */
   165    165     if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){
   166    166       sqlite3OomFault(p->db);
   167    167       return SQLITE_NOMEM;
   168    168     }
   169    169   
   170    170     assert( nOp<=(1024/sizeof(Op)) );
   171         -  assert( nNew>=(p->nOpAlloc+nOp) );
          171  +  assert( nNew>=(v->nOpAlloc+nOp) );
   172    172     pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
   173    173     if( pNew ){
   174    174       p->szOpAlloc = sqlite3DbMallocSize(p->db, pNew);
   175         -    p->nOpAlloc = p->szOpAlloc/sizeof(Op);
          175  +    v->nOpAlloc = p->szOpAlloc/sizeof(Op);
   176    176       v->aOp = pNew;
   177    177     }
   178    178     return (pNew ? SQLITE_OK : SQLITE_NOMEM_BKPT);
   179    179   }
   180    180   
   181    181   #ifdef SQLITE_DEBUG
   182    182   /* This routine is just a convenient place to set a breakpoint that will
................................................................................
   202    202   **    p1, p2, p3      Operands
   203    203   **
   204    204   ** Use the sqlite3VdbeResolveLabel() function to fix an address and
   205    205   ** the sqlite3VdbeChangeP4() function to change the value of the P4
   206    206   ** operand.
   207    207   */
   208    208   static SQLITE_NOINLINE int growOp3(Vdbe *p, int op, int p1, int p2, int p3){
   209         -  assert( p->pParse->nOpAlloc<=p->nOp );
          209  +  assert( p->nOpAlloc<=p->nOp );
   210    210     if( growOpArray(p, 1) ) return 1;
   211         -  assert( p->pParse->nOpAlloc>p->nOp );
          211  +  assert( p->nOpAlloc>p->nOp );
   212    212     return sqlite3VdbeAddOp3(p, op, p1, p2, p3);
   213    213   }
   214    214   int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
   215    215     int i;
   216    216     VdbeOp *pOp;
   217    217   
   218    218     i = p->nOp;
   219    219     assert( p->magic==VDBE_MAGIC_INIT );
   220    220     assert( op>=0 && op<0xff );
   221         -  if( p->pParse->nOpAlloc<=i ){
          221  +  if( p->nOpAlloc<=i ){
   222    222       return growOp3(p, op, p1, p2, p3);
   223    223     }
   224    224     p->nOp++;
   225    225     pOp = &p->aOp[i];
   226    226     pOp->opcode = (u8)op;
   227    227     pOp->p5 = 0;
   228    228     pOp->p1 = p1;
................................................................................
   346    346     VdbeOp *pOp;
   347    347     if( pParse->addrExplain==0 ) return 0;
   348    348     pOp = sqlite3VdbeGetOp(pParse->pVdbe, pParse->addrExplain);
   349    349     return pOp->p2;
   350    350   }
   351    351   
   352    352   /*
   353         -** Add a new OP_Explain opcode.
          353  +** Set a debugger breakpoint on the following routine in order to
          354  +** monitor the EXPLAIN QUERY PLAN code generation.
          355  +*/
          356  +#if defined(SQLITE_DEBUG)
          357  +void sqlite3ExplainBreakpoint(const char *z1, const char *z2){
          358  +  (void)z1;
          359  +  (void)z2;
          360  +}
          361  +#endif
          362  +
          363  +/*
          364  +** Add a new OP_ opcode.
   354    365   **
   355    366   ** If the bPush flag is true, then make this opcode the parent for
   356    367   ** subsequent Explains until sqlite3VdbeExplainPop() is called.
   357    368   */
   358    369   void sqlite3VdbeExplain(Parse *pParse, u8 bPush, const char *zFmt, ...){
   359    370   #ifndef SQLITE_DEBUG
   360    371     /* Always include the OP_Explain opcodes if SQLITE_DEBUG is defined.
................................................................................
   369    380       va_start(ap, zFmt);
   370    381       zMsg = sqlite3VMPrintf(pParse->db, zFmt, ap);
   371    382       va_end(ap);
   372    383       v = pParse->pVdbe;
   373    384       iThis = v->nOp;
   374    385       sqlite3VdbeAddOp4(v, OP_Explain, iThis, pParse->addrExplain, 0,
   375    386                         zMsg, P4_DYNAMIC);
   376         -    if( bPush) pParse->addrExplain = iThis;
          387  +    sqlite3ExplainBreakpoint(bPush?"PUSH":"", sqlite3VdbeGetOp(v,-1)->p4.z);
          388  +    if( bPush){
          389  +      pParse->addrExplain = iThis;
          390  +    }
   377    391     }
   378    392   }
   379    393   
   380    394   /*
   381    395   ** Pop the EXPLAIN QUERY PLAN stack one level.
   382    396   */
   383    397   void sqlite3VdbeExplainPop(Parse *pParse){
          398  +  sqlite3ExplainBreakpoint("POP", 0);
   384    399     pParse->addrExplain = sqlite3VdbeExplainParent(pParse);
   385    400   }
   386    401   #endif /* SQLITE_OMIT_EXPLAIN */
   387    402   
   388    403   /*
   389    404   ** Add an OP_ParseSchema opcode.  This routine is broken out from
   390    405   ** sqlite3VdbeAddOp4() since it needs to also needs to mark all btrees
................................................................................
   441    456   ** the label is resolved to a specific address, the VDBE will scan
   442    457   ** through its operation list and change all values of P2 which match
   443    458   ** the label into the resolved address.
   444    459   **
   445    460   ** The VDBE knows that a P2 value is a label because labels are
   446    461   ** always negative and P2 values are suppose to be non-negative.
   447    462   ** Hence, a negative P2 value is a label that has yet to be resolved.
          463  +** (Later:) This is only true for opcodes that have the OPFLG_JUMP
          464  +** property.
   448    465   **
   449         -** Zero is returned if a malloc() fails.
          466  +** Variable usage notes:
          467  +**
          468  +**     Parse.aLabel[x]     Stores the address that the x-th label resolves
          469  +**                         into.  For testing (SQLITE_DEBUG), unresolved
          470  +**                         labels stores -1, but that is not required.
          471  +**     Parse.nLabelAlloc   Number of slots allocated to Parse.aLabel[]
          472  +**     Parse.nLabel        The *negative* of the number of labels that have
          473  +**                         been issued.  The negative is stored because
          474  +**                         that gives a performance improvement over storing
          475  +**                         the equivalent positive value.
   450    476   */
   451         -int sqlite3VdbeMakeLabel(Vdbe *v){
   452         -  Parse *p = v->pParse;
   453         -  int i = p->nLabel++;
   454         -  assert( v->magic==VDBE_MAGIC_INIT );
   455         -  if( (i & (i-1))==0 ){
   456         -    p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel, 
   457         -                                       (i*2+1)*sizeof(p->aLabel[0]));
   458         -  }
   459         -  if( p->aLabel ){
   460         -    p->aLabel[i] = -1;
   461         -  }
   462         -  return ADDR(i);
          477  +int sqlite3VdbeMakeLabel(Parse *pParse){
          478  +  return --pParse->nLabel;
   463    479   }
   464    480   
   465    481   /*
   466    482   ** Resolve label "x" to be the address of the next instruction to
   467    483   ** be inserted.  The parameter "x" must have been obtained from
   468    484   ** a prior call to sqlite3VdbeMakeLabel().
   469    485   */
          486  +static SQLITE_NOINLINE void resizeResolveLabel(Parse *p, Vdbe *v, int j){
          487  +  int nNewSize = 10 - p->nLabel;
          488  +  p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
          489  +                     nNewSize*sizeof(p->aLabel[0]));
          490  +  if( p->aLabel==0 ){
          491  +    p->nLabelAlloc = 0;
          492  +  }else{
          493  +#ifdef SQLITE_DEBUG
          494  +    int i;
          495  +    for(i=p->nLabelAlloc; i<nNewSize; i++) p->aLabel[i] = -1;
          496  +#endif
          497  +    p->nLabelAlloc = nNewSize;
          498  +    p->aLabel[j] = v->nOp;
          499  +  }
          500  +}
   470    501   void sqlite3VdbeResolveLabel(Vdbe *v, int x){
   471    502     Parse *p = v->pParse;
   472    503     int j = ADDR(x);
   473    504     assert( v->magic==VDBE_MAGIC_INIT );
   474         -  assert( j<p->nLabel );
          505  +  assert( j<-p->nLabel );
   475    506     assert( j>=0 );
   476         -  if( p->aLabel ){
   477    507   #ifdef SQLITE_DEBUG
   478         -    if( p->db->flags & SQLITE_VdbeAddopTrace ){
   479         -      printf("RESOLVE LABEL %d to %d\n", x, v->nOp);
   480         -    }
          508  +  if( p->db->flags & SQLITE_VdbeAddopTrace ){
          509  +    printf("RESOLVE LABEL %d to %d\n", x, v->nOp);
          510  +  }
   481    511   #endif
          512  +  if( p->nLabelAlloc + p->nLabel < 0 ){
          513  +    resizeResolveLabel(p,v,j);
          514  +  }else{
   482    515       assert( p->aLabel[j]==(-1) ); /* Labels may only be resolved once */
   483    516       p->aLabel[j] = v->nOp;
   484    517     }
   485    518   }
   486    519   
   487    520   /*
   488    521   ** Mark the VDBE as one that can only be run one time.
................................................................................
   599    632     VdbeOpIter sIter;
   600    633     memset(&sIter, 0, sizeof(sIter));
   601    634     sIter.v = v;
   602    635   
   603    636     while( (pOp = opIterNext(&sIter))!=0 ){
   604    637       int opcode = pOp->opcode;
   605    638       if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename 
          639  +     || opcode==OP_VDestroy
   606    640        || ((opcode==OP_Halt || opcode==OP_HaltIfNull) 
   607    641         && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
   608    642       ){
   609    643         hasAbort = 1;
   610    644         break;
   611    645       }
   612    646       if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;
................................................................................
   749    783   #endif
   750    784           default: {
   751    785             if( pOp->p2<0 ){
   752    786               /* The mkopcodeh.tcl script has so arranged things that the only
   753    787               ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
   754    788               ** have non-negative values for P2. */
   755    789               assert( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 );
   756         -            assert( ADDR(pOp->p2)<pParse->nLabel );
          790  +            assert( ADDR(pOp->p2)<-pParse->nLabel );
   757    791               pOp->p2 = aLabel[ADDR(pOp->p2)];
   758    792             }
   759    793             break;
   760    794           }
   761    795         }
   762    796         /* The mkopcodeh.tcl script has so arranged things that the only
   763    797         ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
................................................................................
   788    822   ** SQLITE_TEST_REALLOC_STRESS).  This interface is used during testing
   789    823   ** to verify that certain calls to sqlite3VdbeAddOpList() can never
   790    824   ** fail due to a OOM fault and hence that the return value from
   791    825   ** sqlite3VdbeAddOpList() will always be non-NULL.
   792    826   */
   793    827   #if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS)
   794    828   void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N){
   795         -  assert( p->nOp + N <= p->pParse->nOpAlloc );
          829  +  assert( p->nOp + N <= p->nOpAlloc );
   796    830   }
   797    831   #endif
   798    832   
   799    833   /*
   800    834   ** Verify that the VM passed as the only argument does not contain
   801    835   ** an OP_ResultRow opcode. Fail an assert() if it does. This is used
   802    836   ** by code in pragma.c to ensure that the implementation of certain
................................................................................
   860    894     VdbeOpList const *aOp,       /* The opcodes to be added */
   861    895     int iLineno                  /* Source-file line number of first opcode */
   862    896   ){
   863    897     int i;
   864    898     VdbeOp *pOut, *pFirst;
   865    899     assert( nOp>0 );
   866    900     assert( p->magic==VDBE_MAGIC_INIT );
   867         -  if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p, nOp) ){
          901  +  if( p->nOp + nOp > p->nOpAlloc && growOpArray(p, nOp) ){
   868    902       return 0;
   869    903     }
   870    904     pFirst = pOut = &p->aOp[p->nOp];
   871    905     for(i=0; i<nOp; i++, aOp++, pOut++){
   872    906       pOut->opcode = aOp->opcode;
   873    907       pOut->p1 = aOp->p1;
   874    908       pOut->p2 = aOp->p2;
................................................................................
  2182   2216     ** requirements by reusing the opcode array tail, then the second
  2183   2217     ** pass will fill in the remainder using a fresh memory allocation.  
  2184   2218     **
  2185   2219     ** This two-pass approach that reuses as much memory as possible from
  2186   2220     ** the leftover memory at the end of the opcode array.  This can significantly
  2187   2221     ** reduce the amount of memory held by a prepared statement.
  2188   2222     */
  2189         -  do {
  2190         -    x.nNeeded = 0;
  2191         -    p->aMem = allocSpace(&x, p->aMem, nMem*sizeof(Mem));
  2192         -    p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
  2193         -    p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
  2194         -    p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
         2223  +  x.nNeeded = 0;
         2224  +  p->aMem = allocSpace(&x, 0, nMem*sizeof(Mem));
         2225  +  p->aVar = allocSpace(&x, 0, nVar*sizeof(Mem));
         2226  +  p->apArg = allocSpace(&x, 0, nArg*sizeof(Mem*));
         2227  +  p->apCsr = allocSpace(&x, 0, nCursor*sizeof(VdbeCursor*));
  2195   2228   #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
  2196         -    p->anExec = allocSpace(&x, p->anExec, p->nOp*sizeof(i64));
         2229  +  p->anExec = allocSpace(&x, 0, p->nOp*sizeof(i64));
  2197   2230   #endif
  2198         -    if( x.nNeeded==0 ) break;
         2231  +  if( x.nNeeded ){
  2199   2232       x.pSpace = p->pFree = sqlite3DbMallocRawNN(db, x.nNeeded);
  2200   2233       x.nFree = x.nNeeded;
  2201         -  }while( !db->mallocFailed );
         2234  +    if( !db->mallocFailed ){
         2235  +      p->aMem = allocSpace(&x, p->aMem, nMem*sizeof(Mem));
         2236  +      p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
         2237  +      p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
         2238  +      p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
         2239  +#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
         2240  +      p->anExec = allocSpace(&x, p->anExec, p->nOp*sizeof(i64));
         2241  +#endif
         2242  +    }
         2243  +  }
  2202   2244   
  2203   2245     p->pVList = pParse->pVList;
  2204   2246     pParse->pVList =  0;
  2205   2247     p->explain = pParse->explain;
  2206   2248     if( db->mallocFailed ){
  2207   2249       p->nVar = 0;
  2208   2250       p->nCursor = 0;

Changes to src/where.c.

   833    833       addrTop =  sqlite3VdbeAddOp1(v, OP_Yield, regYield);
   834    834       VdbeCoverage(v);
   835    835       VdbeComment((v, "next row of %s", pTabItem->pTab->zName));
   836    836     }else{
   837    837       addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
   838    838     }
   839    839     if( pPartial ){
   840         -    iContinue = sqlite3VdbeMakeLabel(v);
          840  +    iContinue = sqlite3VdbeMakeLabel(pParse);
   841    841       sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL);
   842    842       pLoop->wsFlags |= WHERE_PARTIALIDX;
   843    843     }
   844    844     regRecord = sqlite3GetTempReg(pParse);
   845    845     regBase = sqlite3GenerateIndexKey(
   846    846         pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0
   847    847     );
................................................................................
   850    850     if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
   851    851     if( pTabItem->fg.viaCoroutine ){
   852    852       sqlite3VdbeChangeP2(v, addrCounter, regBase+n);
   853    853       testcase( pParse->db->mallocFailed );
   854    854       translateColumnToCopy(pParse, addrTop, pLevel->iTabCur,
   855    855                             pTabItem->regResult, 1);
   856    856       sqlite3VdbeGoto(v, addrTop);
          857  +    pTabItem->fg.viaCoroutine = 0;
   857    858     }else{
   858    859       sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
   859    860     }
   860    861     sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
   861    862     sqlite3VdbeJumpHere(v, addrTop);
   862    863     sqlite3ReleaseTempReg(pParse, regRecord);
   863    864     
................................................................................
  4639   4640     pWInfo->pParse = pParse;
  4640   4641     pWInfo->pTabList = pTabList;
  4641   4642     pWInfo->pOrderBy = pOrderBy;
  4642   4643     pWInfo->pWhere = pWhere;
  4643   4644     pWInfo->pResultSet = pResultSet;
  4644   4645     pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
  4645   4646     pWInfo->nLevel = nTabList;
  4646         -  pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
         4647  +  pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(pParse);
  4647   4648     pWInfo->wctrlFlags = wctrlFlags;
  4648   4649     pWInfo->iLimit = iAuxArg;
  4649   4650     pWInfo->savedNQueryLoop = pParse->nQueryLoop;
  4650   4651     memset(&pWInfo->nOBSat, 0, 
  4651   4652            offsetof(WhereInfo,sWC) - offsetof(WhereInfo,nOBSat));
  4652   4653     memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel));
  4653   4654     assert( pWInfo->eOnePass==ONEPASS_OFF );  /* ONEPASS defaults to OFF */
................................................................................
  5070   5071         if( db->mallocFailed ) goto whereBeginError;
  5071   5072       }
  5072   5073   #endif
  5073   5074       addrExplain = sqlite3WhereExplainOneScan(
  5074   5075           pParse, pTabList, pLevel, wctrlFlags
  5075   5076       );
  5076   5077       pLevel->addrBody = sqlite3VdbeCurrentAddr(v);
  5077         -    notReady = sqlite3WhereCodeOneLoopStart(pWInfo, ii, notReady);
         5078  +    notReady = sqlite3WhereCodeOneLoopStart(pParse,v,pWInfo,ii,pLevel,notReady);
  5078   5079       pWInfo->iContinue = pLevel->addrCont;
  5079   5080       if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_OR_SUBCLAUSE)==0 ){
  5080   5081         sqlite3WhereAddScanStatus(v, pTabList, pLevel, addrExplain);
  5081   5082       }
  5082   5083     }
  5083   5084   
  5084   5085     /* Done. */

Changes to src/whereInt.h.

   503    503     WhereLevel *pLvl,               /* Level to add scanstatus() entry for */
   504    504     int addrExplain                 /* Address of OP_Explain (or 0) */
   505    505   );
   506    506   #else
   507    507   # define sqlite3WhereAddScanStatus(a, b, c, d) ((void)d)
   508    508   #endif
   509    509   Bitmask sqlite3WhereCodeOneLoopStart(
          510  +  Parse *pParse,       /* Parsing context */
          511  +  Vdbe *v,             /* Prepared statement under construction */
   510    512     WhereInfo *pWInfo,   /* Complete information about the WHERE clause */
   511    513     int iLevel,          /* Which level of pWInfo->a[] should be coded */
          514  +  WhereLevel *pLevel,  /* The current level pointer */
   512    515     Bitmask notReady     /* Which tables are currently available */
   513    516   );
   514    517   
   515    518   /* whereexpr.c: */
   516    519   void sqlite3WhereClauseInit(WhereClause*,WhereInfo*);
   517    520   void sqlite3WhereClauseClear(WhereClause*);
   518    521   void sqlite3WhereSplit(WhereClause*,Expr*,u8);

Changes to src/wherecode.c.

   209    209         sqlite3_str_appendf(&str, " (~%llu rows)",
   210    210                sqlite3LogEstToInt(pLoop->nOut));
   211    211       }else{
   212    212         sqlite3_str_append(&str, " (~1 row)", 9);
   213    213       }
   214    214   #endif
   215    215       zMsg = sqlite3StrAccumFinish(&str);
          216  +    sqlite3ExplainBreakpoint("",zMsg);
   216    217       ret = sqlite3VdbeAddOp4(v, OP_Explain, sqlite3VdbeCurrentAddr(v),
   217    218                               pParse->addrExplain, 0, zMsg,P4_DYNAMIC);
   218    219     }
   219    220     return ret;
   220    221   }
   221    222   #endif /* SQLITE_OMIT_EXPLAIN */
   222    223   
................................................................................
   534    535         }
   535    536       }
   536    537       for(i=iEq;i<pLoop->nLTerm; i++){
   537    538         assert( pLoop->aLTerm[i]!=0 );
   538    539         if( pLoop->aLTerm[i]->pExpr==pX ) nEq++;
   539    540       }
   540    541   
          542  +    iTab = 0;
   541    543       if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){
   542         -      eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0);
          544  +      eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
   543    545       }else{
   544    546         sqlite3 *db = pParse->db;
   545    547         pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
   546    548   
   547    549         if( !db->mallocFailed ){
   548    550           aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
   549         -        eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap);
   550         -        pTerm->pExpr->iTable = pX->iTable;
          551  +        eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
          552  +        pTerm->pExpr->iTable = iTab;
   551    553         }
   552    554         sqlite3ExprDelete(db, pX);
   553    555         pX = pTerm->pExpr;
   554    556       }
   555    557   
   556    558       if( eType==IN_INDEX_INDEX_DESC ){
   557    559         testcase( bRev );
   558    560         bRev = !bRev;
   559    561       }
   560         -    iTab = pX->iTable;
   561    562       sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
   562    563       VdbeCoverageIf(v, bRev);
   563    564       VdbeCoverageIf(v, !bRev);
   564    565       assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
   565    566   
   566    567       pLoop->wsFlags |= WHERE_IN_ABLE;
   567    568       if( pLevel->u.in.nIn==0 ){
   568         -      pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
          569  +      pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
   569    570       }
   570    571   
   571    572       i = pLevel->u.in.nIn;
   572    573       pLevel->u.in.nIn += nEq;
   573    574       pLevel->u.in.aInLoop =
   574    575          sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
   575    576                                 sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
................................................................................
  1160   1161   }
  1161   1162   
  1162   1163   /*
  1163   1164   ** Generate code for the start of the iLevel-th loop in the WHERE clause
  1164   1165   ** implementation described by pWInfo.
  1165   1166   */
  1166   1167   Bitmask sqlite3WhereCodeOneLoopStart(
         1168  +  Parse *pParse,       /* Parsing context */
         1169  +  Vdbe *v,             /* Prepared statement under construction */
  1167   1170     WhereInfo *pWInfo,   /* Complete information about the WHERE clause */
  1168   1171     int iLevel,          /* Which level of pWInfo->a[] should be coded */
         1172  +  WhereLevel *pLevel,  /* The current level pointer */
  1169   1173     Bitmask notReady     /* Which tables are currently available */
  1170   1174   ){
  1171   1175     int j, k;            /* Loop counters */
  1172   1176     int iCur;            /* The VDBE cursor for the table */
  1173   1177     int addrNxt;         /* Where to jump to continue with the next IN case */
  1174         -  int omitTable;       /* True if we use the index only */
  1175   1178     int bRev;            /* True if we need to scan in reverse order */
  1176         -  WhereLevel *pLevel;  /* The where level to be coded */
  1177   1179     WhereLoop *pLoop;    /* The WhereLoop object being coded */
  1178   1180     WhereClause *pWC;    /* Decomposition of the entire WHERE clause */
  1179   1181     WhereTerm *pTerm;               /* A WHERE clause term */
  1180         -  Parse *pParse;                  /* Parsing context */
  1181   1182     sqlite3 *db;                    /* Database connection */
  1182         -  Vdbe *v;                        /* The prepared stmt under constructions */
  1183   1183     struct SrcList_item *pTabItem;  /* FROM clause term being coded */
  1184   1184     int addrBrk;                    /* Jump here to break out of the loop */
  1185   1185     int addrHalt;                   /* addrBrk for the outermost loop */
  1186   1186     int addrCont;                   /* Jump here to continue with next cycle */
  1187   1187     int iRowidReg = 0;        /* Rowid is stored in this register, if not zero */
  1188   1188     int iReleaseReg = 0;      /* Temp register to free before returning */
  1189   1189     Index *pIdx = 0;          /* Index used by loop (if any) */
  1190   1190     int iLoop;                /* Iteration of constraint generator loop */
  1191   1191   
  1192         -  pParse = pWInfo->pParse;
  1193         -  v = pParse->pVdbe;
  1194   1192     pWC = &pWInfo->sWC;
  1195   1193     db = pParse->db;
  1196         -  pLevel = &pWInfo->a[iLevel];
  1197   1194     pLoop = pLevel->pWLoop;
  1198   1195     pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
  1199   1196     iCur = pTabItem->iCursor;
  1200   1197     pLevel->notReady = notReady & ~sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur);
  1201   1198     bRev = (pWInfo->revMask>>iLevel)&1;
  1202         -  omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0 
  1203         -           && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0;
  1204   1199     VdbeModuleComment((v, "Begin WHERE-loop%d: %s",iLevel,pTabItem->pTab->zName));
  1205   1200   
  1206   1201     /* Create labels for the "break" and "continue" instructions
  1207   1202     ** for the current loop.  Jump to addrBrk to break out of a loop.
  1208   1203     ** Jump to cont to go immediately to the next iteration of the
  1209   1204     ** loop.
  1210   1205     **
  1211   1206     ** When there is an IN operator, we also have a "addrNxt" label that
  1212   1207     ** means to continue with the next IN value combination.  When
  1213   1208     ** there are no IN operators in the constraints, the "addrNxt" label
  1214   1209     ** is the same as "addrBrk".
  1215   1210     */
  1216         -  addrBrk = pLevel->addrBrk = pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
  1217         -  addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(v);
         1211  +  addrBrk = pLevel->addrBrk = pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
         1212  +  addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(pParse);
  1218   1213   
  1219   1214     /* If this is the right table of a LEFT OUTER JOIN, allocate and
  1220   1215     ** initialize a memory cell that records if this table matches any
  1221   1216     ** row of the left table of the join.
  1222   1217     */
  1223   1218     assert( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)
  1224   1219          || pLevel->iFrom>0 || (pTabItem[0].fg.jointype & JT_LEFT)==0
................................................................................
  1337   1332       **          we reference multiple rows using a "rowid IN (...)"
  1338   1333       **          construct.
  1339   1334       */
  1340   1335       assert( pLoop->u.btree.nEq==1 );
  1341   1336       pTerm = pLoop->aLTerm[0];
  1342   1337       assert( pTerm!=0 );
  1343   1338       assert( pTerm->pExpr!=0 );
  1344         -    assert( omitTable==0 );
  1345   1339       testcase( pTerm->wtFlags & TERM_VIRTUAL );
  1346   1340       iReleaseReg = ++pParse->nMem;
  1347   1341       iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
  1348   1342       if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg);
  1349   1343       addrNxt = pLevel->addrNxt;
  1350   1344       sqlite3VdbeAddOp3(v, OP_SeekRowid, iCur, addrNxt, iRowidReg);
  1351   1345       VdbeCoverage(v);
................................................................................
  1356   1350       /* Case 3:  We have an inequality comparison against the ROWID field.
  1357   1351       */
  1358   1352       int testOp = OP_Noop;
  1359   1353       int start;
  1360   1354       int memEndValue = 0;
  1361   1355       WhereTerm *pStart, *pEnd;
  1362   1356   
  1363         -    assert( omitTable==0 );
  1364   1357       j = 0;
  1365   1358       pStart = pEnd = 0;
  1366   1359       if( pLoop->wsFlags & WHERE_BTM_LIMIT ) pStart = pLoop->aLTerm[j++];
  1367   1360       if( pLoop->wsFlags & WHERE_TOP_LIMIT ) pEnd = pLoop->aLTerm[j++];
  1368   1361       assert( pStart!=0 || pEnd!=0 );
  1369   1362       if( bRev ){
  1370   1363         pTerm = pStart;
................................................................................
  1520   1513       int iIdxCur;                 /* The VDBE cursor for the index */
  1521   1514       int nExtraReg = 0;           /* Number of extra registers needed */
  1522   1515       int op;                      /* Instruction opcode */
  1523   1516       char *zStartAff;             /* Affinity for start of range constraint */
  1524   1517       char *zEndAff = 0;           /* Affinity for end of range constraint */
  1525   1518       u8 bSeekPastNull = 0;        /* True to seek past initial nulls */
  1526   1519       u8 bStopAtNull = 0;          /* Add condition to terminate at NULLs */
         1520  +    int omitTable;               /* True if we use the index only */
         1521  +
  1527   1522   
  1528   1523       pIdx = pLoop->u.btree.pIndex;
  1529   1524       iIdxCur = pLevel->iIdxCur;
  1530   1525       assert( nEq>=pLoop->nSkip );
  1531   1526   
  1532   1527       /* If this loop satisfies a sort order (pOrderBy) request that 
  1533   1528       ** was passed to this function to implement a "SELECT min(x) ..." 
................................................................................
  1721   1716       }
  1722   1717   
  1723   1718       if( pLoop->wsFlags & WHERE_IN_EARLYOUT ){
  1724   1719         sqlite3VdbeAddOp2(v, OP_SeekHit, iIdxCur, 1);
  1725   1720       }
  1726   1721   
  1727   1722       /* Seek the table cursor, if required */
         1723  +    omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0 
         1724  +           && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0;
  1728   1725       if( omitTable ){
  1729   1726         /* pIdx is a covering index.  No need to access the main table. */
  1730   1727       }else if( HasRowid(pIdx->pTable) ){
  1731   1728         if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE) || (
  1732   1729             (pWInfo->wctrlFlags & WHERE_SEEK_UNIQ_TABLE) 
  1733   1730          && (pWInfo->eOnePass==ONEPASS_SINGLE)
  1734   1731         )){
................................................................................
  1831   1828       SrcList *pOrTab;       /* Shortened table list or OR-clause generation */
  1832   1829       Index *pCov = 0;             /* Potential covering index (or NULL) */
  1833   1830       int iCovCur = pParse->nTab++;  /* Cursor used for index scans (if any) */
  1834   1831   
  1835   1832       int regReturn = ++pParse->nMem;           /* Register used with OP_Gosub */
  1836   1833       int regRowset = 0;                        /* Register for RowSet object */
  1837   1834       int regRowid = 0;                         /* Register holding rowid */
  1838         -    int iLoopBody = sqlite3VdbeMakeLabel(v);  /* Start of loop body */
         1835  +    int iLoopBody = sqlite3VdbeMakeLabel(pParse);/* Start of loop body */
  1839   1836       int iRetInit;                             /* Address of regReturn init */
  1840   1837       int untestedTerms = 0;             /* Some terms not completely tested */
  1841   1838       int ii;                            /* Loop counter */
  1842   1839       u16 wctrlFlags;                    /* Flags for sub-WHERE clause */
  1843   1840       Expr *pAndExpr = 0;                /* An ".. AND (...)" expression */
  1844   1841       Table *pTab = pTabItem->pTab;
  1845   1842   
................................................................................
  1947   1944                || ExprHasProperty(pOrExpr, EP_FromJoin) 
  1948   1945           );
  1949   1946           if( pAndExpr ){
  1950   1947             pAndExpr->pLeft = pOrExpr;
  1951   1948             pOrExpr = pAndExpr;
  1952   1949           }
  1953   1950           /* Loop through table entries that match term pOrTerm. */
         1951  +        ExplainQueryPlan((pParse, 1, "INDEX %d", ii+1));
  1954   1952           WHERETRACE(0xffff, ("Subplan for OR-clause:\n"));
  1955   1953           pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
  1956   1954                                         wctrlFlags, iCovCur);
  1957   1955           assert( pSubWInfo || pParse->nErr || db->mallocFailed );
  1958   1956           if( pSubWInfo ){
  1959   1957             WhereLoop *pSubLoop;
  1960   1958             int addrExplain = sqlite3WhereExplainOneScan(
................................................................................
  2050   2048               pCov = pSubLoop->u.btree.pIndex;
  2051   2049             }else{
  2052   2050               pCov = 0;
  2053   2051             }
  2054   2052   
  2055   2053             /* Finish the loop through table entries that match term pOrTerm. */
  2056   2054             sqlite3WhereEnd(pSubWInfo);
         2055  +          ExplainQueryPlanPop(pParse);
  2057   2056           }
  2058   2057         }
  2059   2058       }
  2060   2059       ExplainQueryPlanPop(pParse);
  2061   2060       pLevel->u.pCovidx = pCov;
  2062   2061       if( pCov ) pLevel->iIdxCur = iCovCur;
  2063   2062       if( pAndExpr ){

Changes to src/window.c.

  1326   1326     Window *pWin;
  1327   1327     for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
  1328   1328       FuncDef *pFunc = pWin->pFunc;
  1329   1329       if( pFunc->zName==nth_valueName
  1330   1330        || pFunc->zName==first_valueName
  1331   1331       ){
  1332   1332         int csr = pWin->csrApp;
  1333         -      int lbl = sqlite3VdbeMakeLabel(v);
         1333  +      int lbl = sqlite3VdbeMakeLabel(pParse);
  1334   1334         int tmpReg = sqlite3GetTempReg(pParse);
  1335   1335         sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
  1336   1336   
  1337   1337         if( pFunc->zName==nth_valueName ){
  1338   1338           sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+1,tmpReg);
  1339   1339           windowCheckIntValue(pParse, tmpReg, 2);
  1340   1340         }else{
................................................................................
  1349   1349         sqlite3VdbeResolveLabel(v, lbl);
  1350   1350         sqlite3ReleaseTempReg(pParse, tmpReg);
  1351   1351       }
  1352   1352       else if( pFunc->zName==leadName || pFunc->zName==lagName ){
  1353   1353         int nArg = pWin->pOwner->x.pList->nExpr;
  1354   1354         int iEph = pMWin->iEphCsr;
  1355   1355         int csr = pWin->csrApp;
  1356         -      int lbl = sqlite3VdbeMakeLabel(v);
         1356  +      int lbl = sqlite3VdbeMakeLabel(pParse);
  1357   1357         int tmpReg = sqlite3GetTempReg(pParse);
  1358   1358   
  1359   1359         if( nArg<3 ){
  1360   1360           sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
  1361   1361         }else{
  1362   1362           sqlite3VdbeAddOp3(v, OP_Column, iEph, pWin->iArgCol+2, pWin->regResult);
  1363   1363         }
................................................................................
  1610   1610          || pMWin->eEnd==TK_CURRENT 
  1611   1611          || pMWin->eEnd==TK_UNBOUNDED 
  1612   1612          || pMWin->eEnd==TK_PRECEDING 
  1613   1613     );
  1614   1614   
  1615   1615     /* Allocate register and label for the "flush_partition" sub-routine. */
  1616   1616     regFlushPart = ++pParse->nMem;
  1617         -  lblFlushPart = sqlite3VdbeMakeLabel(v);
  1618         -  lblFlushDone = sqlite3VdbeMakeLabel(v);
         1617  +  lblFlushPart = sqlite3VdbeMakeLabel(pParse);
         1618  +  lblFlushDone = sqlite3VdbeMakeLabel(pParse);
  1619   1619   
  1620   1620     regStart = ++pParse->nMem;
  1621   1621     regEnd = ++pParse->nMem;
  1622   1622   
  1623   1623     windowPartitionCache(pParse, p, pWInfo, regFlushPart, lblFlushPart, &regSize);
  1624   1624   
  1625   1625     addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
................................................................................
  1721   1721       sqlite3VdbeJumpHere(v, addrIfPos2);
  1722   1722     }
  1723   1723   
  1724   1724     if( pMWin->eStart==TK_CURRENT 
  1725   1725      || pMWin->eStart==TK_PRECEDING 
  1726   1726      || pMWin->eStart==TK_FOLLOWING 
  1727   1727     ){
  1728         -    int lblSkipInverse = sqlite3VdbeMakeLabel(v);;
         1728  +    int lblSkipInverse = sqlite3VdbeMakeLabel(pParse);;
  1729   1729       if( pMWin->eStart==TK_PRECEDING ){
  1730   1730         sqlite3VdbeAddOp3(v, OP_IfPos, regStart, lblSkipInverse, 1);
  1731   1731         VdbeCoverage(v);
  1732   1732       }
  1733   1733       if( pMWin->eStart==TK_FOLLOWING ){
  1734   1734         sqlite3VdbeAddOp2(v, OP_Next, csrStart, sqlite3VdbeCurrentAddr(v)+2);
  1735   1735         VdbeCoverage(v);
................................................................................
  1886   1886   
  1887   1887     assert( (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_CURRENT) 
  1888   1888          || (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_UNBOUNDED) 
  1889   1889          || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_CURRENT) 
  1890   1890          || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_UNBOUNDED) 
  1891   1891     );
  1892   1892   
  1893         -  lblEmpty = sqlite3VdbeMakeLabel(v);
         1893  +  lblEmpty = sqlite3VdbeMakeLabel(pParse);
  1894   1894     regNewPeer = pParse->nMem+1;
  1895   1895     pParse->nMem += nPeer;
  1896   1896   
  1897   1897     /* Allocate register and label for the "flush_partition" sub-routine. */
  1898   1898     regFlushPart = ++pParse->nMem;
  1899         -  lblFlushPart = sqlite3VdbeMakeLabel(v);
         1899  +  lblFlushPart = sqlite3VdbeMakeLabel(pParse);
  1900   1900   
  1901   1901     csrLead = pParse->nTab++;
  1902   1902     regCtr = ++pParse->nMem;
  1903   1903   
  1904   1904     windowPartitionCache(pParse, p, pWInfo, regFlushPart, lblFlushPart, &regSize);
  1905   1905     addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
  1906   1906   

Changes to test/autoindex1.test.

   180    180   }
   181    181   do_eqp_test autoindex1-500.1 {
   182    182     SELECT b FROM t501
   183    183      WHERE t501.a IN (SELECT x FROM t502 WHERE y=?);
   184    184   } {
   185    185     QUERY PLAN
   186    186     |--SEARCH TABLE t501 USING INTEGER PRIMARY KEY (rowid=?)
   187         -  `--LIST SUBQUERY
          187  +  `--LIST SUBQUERY xxxxxx
   188    188        `--SCAN TABLE t502
   189    189   }
   190    190   do_eqp_test autoindex1-501 {
   191    191     SELECT b FROM t501
   192    192      WHERE t501.a IN (SELECT x FROM t502 WHERE y=t501.b);
   193    193   } {
   194    194     QUERY PLAN
   195    195     |--SCAN TABLE t501
   196         -  `--CORRELATED LIST SUBQUERY
          196  +  `--CORRELATED LIST SUBQUERY xxxxxx
   197    197        `--SEARCH TABLE t502 USING AUTOMATIC COVERING INDEX (y=?)
   198    198   }
   199    199   do_eqp_test autoindex1-502 {
   200    200     SELECT b FROM t501
   201    201      WHERE t501.a=123
   202    202        AND t501.a IN (SELECT x FROM t502 WHERE y=t501.b);
   203    203   } {
   204    204     QUERY PLAN
   205    205     |--SEARCH TABLE t501 USING INTEGER PRIMARY KEY (rowid=?)
   206         -  `--CORRELATED LIST SUBQUERY
          206  +  `--CORRELATED LIST SUBQUERY xxxxxx
   207    207        `--SCAN TABLE t502
   208    208   }
   209    209   
   210    210   # The following code checks a performance regression reported on the
   211    211   # mailing list on 2010-10-19.  The problem is that the nRowEst field
   212    212   # of ephermeral tables was not being initialized correctly and so no
   213    213   # automatic index was being created for the emphemeral table when it was
................................................................................
   276    276      WHERE y.sheep_no IS NULL
   277    277      ORDER BY x.registering_flock;
   278    278   } {
   279    279     QUERY PLAN
   280    280     |--MATERIALIZE xxxxxx
   281    281     |  |--SCAN TABLE sheep AS s
   282    282     |  |--SEARCH TABLE flock_owner AS prev USING INDEX sqlite_autoindex_flock_owner_1 (flock_no=? AND owner_change_date<?)
   283         -  |  `--CORRELATED SCALAR SUBQUERY
          283  +  |  `--CORRELATED SCALAR SUBQUERY xxxxxx
   284    284     |     `--SEARCH TABLE flock_owner AS later USING COVERING INDEX sqlite_autoindex_flock_owner_1 (flock_no=? AND owner_change_date>? AND owner_change_date<?)
   285    285     |--SCAN TABLE sheep AS x USING INDEX sheep_reg_flock_index
   286    286     `--SEARCH SUBQUERY xxxxxx AS y USING AUTOMATIC COVERING INDEX (sheep_no=?)
   287    287   }
   288    288   
   289    289   
   290    290   do_execsql_test autoindex1-700 {

Changes to test/bestindex3.test.

    86     86   } {SCAN TABLE t1 VIRTUAL TABLE INDEX 0:a EQ ?}
    87     87   
    88     88   do_eqp_test 1.3 {
    89     89     SELECT * FROM t1 WHERE a = 'abc' OR b = 'def';
    90     90   } {
    91     91     QUERY PLAN
    92     92     `--MULTI-INDEX OR
    93         -     |--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:a EQ ?
    94         -     `--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:b EQ ?
           93  +     |--INDEX 1
           94  +     |  `--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:a EQ ?
           95  +     `--INDEX 2
           96  +        `--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:b EQ ?
    95     97   }
    96     98   
    97     99   do_eqp_test 1.4 {
    98    100     SELECT * FROM t1 WHERE a LIKE 'abc%' OR b = 'def';
    99    101   } {
   100    102     QUERY PLAN
   101    103     `--MULTI-INDEX OR
   102         -     |--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:a LIKE ?
   103         -     `--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:b EQ ?
          104  +     |--INDEX 1
          105  +     |  `--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:a LIKE ?
          106  +     `--INDEX 2
          107  +        `--SCAN TABLE t1 VIRTUAL TABLE INDEX 0:b EQ ?
   104    108   }
   105    109   
   106    110   do_execsql_test 1.5 {
   107    111     CREATE TABLE ttt(a, b, c);
   108    112   
   109    113     INSERT INTO ttt VALUES(1, 'two',   'three');
   110    114     INSERT INTO ttt VALUES(2, 'one',   'two');
................................................................................
   146    150     }
   147    151   
   148    152     do_eqp_test 2.2 {
   149    153       SELECT * FROM t2 WHERE x LIKE 'abc%' OR y = 'def'
   150    154     } [string map {"\n  " \n} {
   151    155       QUERY PLAN
   152    156       `--MULTI-INDEX OR
   153         -       |--SEARCH TABLE t2 USING INDEX t2x (x>? AND x<?)
   154         -       `--SEARCH TABLE t2 USING INDEX t2y (y=?)
          157  +       |--INDEX 1
          158  +       |  `--SEARCH TABLE t2 USING INDEX t2x (x>? AND x<?)
          159  +       `--INDEX 2
          160  +          `--SEARCH TABLE t2 USING INDEX t2y (y=?)
   155    161     }]
   156    162   }
   157    163   
   158    164   #-------------------------------------------------------------------------
   159    165   # Test that any PRIMARY KEY within a sqlite3_decl_vtab() CREATE TABLE 
   160    166   # statement is currently ignored.
   161    167   #

Changes to test/btree02.test.

    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   load_static_extension db eval
    21     21   do_execsql_test btree02-100 {
    22     22     CREATE TABLE t1(a TEXT, ax INTEGER, b INT, PRIMARY KEY(a,ax)) WITHOUT ROWID;
    23     23     WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<10)
    24         -    INSERT INTO t1(a,ax,b) SELECT printf('%02x',i), random(), i FROM c;
           24  +    INSERT INTO t1(a,ax,b) SELECT printf('%02x',i+160), random(), i FROM c;
    25     25     CREATE INDEX t1a ON t1(a);
    26     26     CREATE TABLE t2(x,y);
    27     27     CREATE TABLE t3(cnt);
    28     28     WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<4)
    29     29       INSERT INTO t3(cnt) SELECT i FROM c;
    30     30     SELECT count(*) FROM t1;
    31     31   } {10}
           32  +
           33  +proc showt1 {} {
           34  +  puts -nonewline "t1: "
           35  +  puts [db eval {SELECT printf('(%s,%s)',quote(a),quote(b)) FROM t1}]
           36  +}
           37  +
    32     38   do_test btree02-110 {
    33     39     db eval BEGIN
    34     40     set i 0
           41  +  # showt1
    35     42     db eval {SELECT a, ax, b, cnt FROM t1 CROSS JOIN t3 WHERE b IS NOT NULL} {
    36         -    if {$a==""} {set a 0}
    37         -    if {$b==""} {set b 0}    
           43  +    if {$a==""} continue
    38     44       db eval {INSERT INTO t2(x,y) VALUES($b,$cnt)}
    39     45       # puts "a,b,cnt = ($a,$b,$cnt)"
    40     46       incr i
    41     47       if {$i%2==1} {
    42     48         set bx [expr {$b+1000}]
    43         -      # puts "INSERT ($a),$bx"
           49  +      #  puts "INSERT ($a),$bx"
    44     50         db eval {INSERT INTO t1(a,ax,b) VALUES(printf('(%s)',$a),random(),$bx)}
           51  +      # showt1
    45     52       } else {
    46     53         # puts "DELETE a=$a"
    47     54         db eval {DELETE FROM t1 WHERE a=$a}
           55  +      # showt1
    48     56       }
    49     57       db eval {COMMIT; BEGIN}
    50     58     }  
    51     59     db one {COMMIT; SELECT count(*) FROM t1;}
    52         -} {27}
           60  +} {10}
    53     61   
    54     62   finish_test

Changes to test/cost.test.

    54     54   do_eqp_test 3.2 {
    55     55     SELECT a FROM t5 
    56     56     WHERE b IS NULL OR c IS NULL OR d IS NULL 
    57     57     ORDER BY a;
    58     58   } {
    59     59     QUERY PLAN
    60     60     |--MULTI-INDEX OR
    61         -  |  |--SEARCH TABLE t5 USING INDEX t5b (b=?)
    62         -  |  |--SEARCH TABLE t5 USING INDEX t5c (c=?)
    63         -  |  `--SEARCH TABLE t5 USING INDEX t5d (d=?)
           61  +  |  |--INDEX 1
           62  +  |  |  `--SEARCH TABLE t5 USING INDEX t5b (b=?)
           63  +  |  |--INDEX 2
           64  +  |  |  `--SEARCH TABLE t5 USING INDEX t5c (c=?)
           65  +  |  `--INDEX 3
           66  +  |     `--SEARCH TABLE t5 USING INDEX t5d (d=?)
    64     67     `--USE TEMP B-TREE FOR ORDER BY
    65     68   }
    66     69   
    67     70   #-------------------------------------------------------------------------
    68     71   # If there is no likelihood() or stat3 data, SQLite assumes that a closed
    69     72   # range scan (e.g. one constrained by "col BETWEEN ? AND ?" constraint)
    70     73   # visits 1/64 of the rows in a table.
................................................................................
   120    123   }
   121    124   
   122    125   do_eqp_test 6.2 {
   123    126     SELECT a FROM t3 WHERE (b BETWEEN 2 AND 4) OR c=100 ORDER BY a
   124    127   } {
   125    128     QUERY PLAN
   126    129     |--MULTI-INDEX OR
   127         -  |  |--SEARCH TABLE t3 USING INDEX t3i1 (b>? AND b<?)
   128         -  |  `--SEARCH TABLE t3 USING INDEX t3i2 (c=?)
          130  +  |  |--INDEX 1
          131  +  |  |  `--SEARCH TABLE t3 USING INDEX t3i1 (b>? AND b<?)
          132  +  |  `--INDEX 2
          133  +  |     `--SEARCH TABLE t3 USING INDEX t3i2 (c=?)
   129    134     `--USE TEMP B-TREE FOR ORDER BY
   130    135   }
   131    136   
   132    137   #-------------------------------------------------------------------------
   133    138   #
   134    139   reset_db
   135    140   do_execsql_test 7.1 {
................................................................................
   145    150   do_eqp_test 7.2 {
   146    151     SELECT a FROM t1
   147    152        WHERE (b>=950 AND b<=1010) OR (b IS NULL AND c NOT NULL)
   148    153     ORDER BY a
   149    154   } {
   150    155     QUERY PLAN
   151    156     |--MULTI-INDEX OR
   152         -  |  |--SEARCH TABLE t1 USING INDEX t1b (b>? AND b<?)
   153         -  |  `--SEARCH TABLE t1 USING INDEX t1b (b=?)
          157  +  |  |--INDEX 1
          158  +  |  |  `--SEARCH TABLE t1 USING INDEX t1b (b>? AND b<?)
          159  +  |  `--INDEX 2
          160  +  |     `--SEARCH TABLE t1 USING INDEX t1b (b=?)
   154    161     `--USE TEMP B-TREE FOR ORDER BY
   155    162   }
   156    163   
   157    164   do_eqp_test 7.3 {
   158    165     SELECT rowid FROM t1
   159    166     WHERE (+b IS NULL AND c NOT NULL AND d NOT NULL)
   160    167           OR (b NOT NULL AND c IS NULL AND d NOT NULL)

Changes to test/eqp.test.

    41     41   }
    42     42   
    43     43   do_eqp_test 1.2 {
    44     44     SELECT * FROM t2, t1 WHERE t1.a=1 OR t1.b=2;
    45     45   } {
    46     46     QUERY PLAN
    47     47     |--MULTI-INDEX OR
    48         -  |  |--SEARCH TABLE t1 USING INDEX i1 (a=?)
    49         -  |  `--SEARCH TABLE t1 USING INDEX i2 (b=?)
           48  +  |  |--INDEX 1
           49  +  |  |  `--SEARCH TABLE t1 USING INDEX i1 (a=?)
           50  +  |  `--INDEX 2
           51  +  |     `--SEARCH TABLE t1 USING INDEX i2 (b=?)
    50     52     `--SCAN TABLE t2
    51     53   }
    52     54   do_eqp_test 1.3 {
    53     55     SELECT * FROM t2 CROSS JOIN t1 WHERE t1.a=1 OR t1.b=2;
    54     56   } {
    55     57     QUERY PLAN
    56     58     |--SCAN TABLE t2
    57     59     `--MULTI-INDEX OR
    58         -     |--SEARCH TABLE t1 USING INDEX i1 (a=?)
    59         -     `--SEARCH TABLE t1 USING INDEX i2 (b=?)
           60  +     |--INDEX 1
           61  +     |  `--SEARCH TABLE t1 USING INDEX i1 (a=?)
           62  +     `--INDEX 2
           63  +        `--SEARCH TABLE t1 USING INDEX i2 (b=?)
    60     64   }
    61     65   do_eqp_test 1.3 {
    62     66     SELECT a FROM t1 ORDER BY a
    63     67   } {
    64     68     QUERY PLAN
    65     69     `--SCAN TABLE t1 USING COVERING INDEX i1
    66     70   }
................................................................................
   221    225   # Test cases eqp-3.* - tests for select statements that use sub-selects.
   222    226   #
   223    227   do_eqp_test 3.1.1 {
   224    228     SELECT (SELECT x FROM t1 AS sub) FROM t1;
   225    229   } {
   226    230     QUERY PLAN
   227    231     |--SCAN TABLE t1
   228         -  `--SCALAR SUBQUERY
          232  +  `--SCALAR SUBQUERY xxxxxx
   229    233        `--SCAN TABLE t1 AS sub
   230    234   }
   231    235   do_eqp_test 3.1.2 {
   232    236     SELECT * FROM t1 WHERE (SELECT x FROM t1 AS sub);
   233    237   } {
   234    238     QUERY PLAN
   235    239     |--SCAN TABLE t1
   236         -  `--SCALAR SUBQUERY
          240  +  `--SCALAR SUBQUERY xxxxxx
   237    241        `--SCAN TABLE t1 AS sub
   238    242   }
   239    243   do_eqp_test 3.1.3 {
   240    244     SELECT * FROM t1 WHERE (SELECT x FROM t1 AS sub ORDER BY y);
   241    245   } {
   242    246     QUERY PLAN
   243    247     |--SCAN TABLE t1
   244         -  `--SCALAR SUBQUERY
          248  +  `--SCALAR SUBQUERY xxxxxx
   245    249        |--SCAN TABLE t1 AS sub
   246    250        `--USE TEMP B-TREE FOR ORDER BY
   247    251   }
   248    252   do_eqp_test 3.1.4 {
   249    253     SELECT * FROM t1 WHERE (SELECT x FROM t2 ORDER BY x);
   250    254   } {
   251    255     QUERY PLAN
   252    256     |--SCAN TABLE t1
   253         -  `--SCALAR SUBQUERY
          257  +  `--SCALAR SUBQUERY xxxxxx
   254    258        `--SCAN TABLE t2 USING COVERING INDEX t2i1
   255    259   }
   256    260   
   257    261   det 3.2.1 {
   258    262     SELECT * FROM (SELECT * FROM t1 ORDER BY x LIMIT 10) ORDER BY y LIMIT 5
   259    263   } {
   260    264     QUERY PLAN
................................................................................
   282    286   }
   283    287   
   284    288   det 3.3.1 {
   285    289     SELECT * FROM t1 WHERE y IN (SELECT y FROM t2)
   286    290   } {
   287    291     QUERY PLAN
   288    292     |--SCAN TABLE t1
   289         -  `--LIST SUBQUERY
          293  +  `--LIST SUBQUERY xxxxxx
   290    294        `--SCAN TABLE t2
   291    295   }
   292    296   det 3.3.2 {
   293    297     SELECT * FROM t1 WHERE y IN (SELECT y FROM t2 WHERE t1.x!=t2.x)
   294    298   } {
   295    299     QUERY PLAN
   296    300     |--SCAN TABLE t1
   297         -  `--CORRELATED LIST SUBQUERY
          301  +  `--CORRELATED LIST SUBQUERY xxxxxx
   298    302        `--SCAN TABLE t2
   299    303   }
   300    304   det 3.3.3 {
   301    305     SELECT * FROM t1 WHERE EXISTS (SELECT y FROM t2 WHERE t1.x!=t2.x)
   302    306   } {
   303    307     QUERY PLAN
   304    308     |--SCAN TABLE t1
   305         -  `--CORRELATED SCALAR SUBQUERY
          309  +  `--CORRELATED SCALAR SUBQUERY xxxxxx
   306    310        `--SCAN TABLE t2
   307    311   }
   308    312   
   309    313   #-------------------------------------------------------------------------
   310    314   # Test cases eqp-4.* - tests for composite select statements.
   311    315   #
   312    316   do_eqp_test 4.1.1 {
................................................................................
   809    813       AND event.objid=thread.last
   810    814     ORDER BY 1;
   811    815   } {
   812    816     QUERY PLAN
   813    817     |--MATERIALIZE xxxxxx
   814    818     |  |--SCAN TABLE forumpost AS x USING INDEX forumthread
   815    819     |  |--USING ROWID SEARCH ON TABLE private FOR IN-OPERATOR
   816         -  |  |--CORRELATED SCALAR SUBQUERY
          820  +  |  |--CORRELATED SCALAR SUBQUERY xxxxxx
   817    821     |  |  |--SEARCH TABLE forumpost USING COVERING INDEX forumthread (froot=?)
   818    822     |  |  `--USING ROWID SEARCH ON TABLE private FOR IN-OPERATOR
   819    823     |  `--USE TEMP B-TREE FOR ORDER BY
   820    824     |--SCAN SUBQUERY xxxxxx
   821    825     |--SEARCH TABLE blob USING INTEGER PRIMARY KEY (rowid=?)
   822    826     |--SEARCH TABLE event USING INTEGER PRIMARY KEY (rowid=?)
   823    827     `--USE TEMP B-TREE FOR ORDER BY
   824    828   }
   825    829   
   826    830   finish_test

Changes to test/join5.test.

   263    263     SELECT * FROM t1 LEFT JOIN t2 ON (
   264    264       t2.x = t1.x AND (t2.y=? OR (t2.y=? AND t2.z IS NOT NULL))
   265    265     );
   266    266   } {
   267    267     QUERY PLAN
   268    268     |--SCAN TABLE t1
   269    269     `--MULTI-INDEX OR
   270         -     |--SEARCH TABLE t2 USING INDEX t2xy (x=? AND y=?)
   271         -     `--SEARCH TABLE t2 USING INDEX t2xy (x=? AND y=?)
          270  +     |--INDEX 1
          271  +     |  `--SEARCH TABLE t2 USING INDEX t2xy (x=? AND y=?)
          272  +     `--INDEX 2
          273  +        `--SEARCH TABLE t2 USING INDEX t2xy (x=? AND y=?)
   272    274   }
   273    275   
   274    276   do_execsql_test 7.3 {
   275    277     CREATE TABLE t3(x);
   276    278   
   277    279     CREATE TABLE t4(x, y, z);
   278    280     CREATE INDEX t4xy ON t4(x, y);

Changes to test/rowvalue4.test.

   231    231   do_eqp_test 5.1 {
   232    232     SELECT * FROM d2 WHERE 
   233    233       (a, b) IN (SELECT x, y FROM d1) AND
   234    234       (c) IN (SELECT y FROM d1)
   235    235   } {
   236    236     QUERY PLAN
   237    237     |--SEARCH TABLE d2 USING INDEX d2ab (a=? AND b=?)
   238         -  |--LIST SUBQUERY
          238  +  |--LIST SUBQUERY xxxxxx
   239    239     |  `--SCAN TABLE d1
   240         -  `--LIST SUBQUERY
          240  +  `--LIST SUBQUERY xxxxxx
   241    241        `--SCAN TABLE d1
   242    242   }
   243    243   
   244    244   do_execsql_test 6.0 {
   245    245     CREATE TABLE e1(a, b, c, d, e);
   246    246     CREATE INDEX e1ab ON e1(a, b);
   247    247     CREATE INDEX e1cde ON e1(c, d, e);

Changes to test/tkt-80ba201079.test.

   106    106                AND entry_id IN (SELECT change_id
   107    107                                 FROM object_changes
   108    108                                  WHERE obj_context = 'exported_pools'));
   109    109     }
   110    110   } {300 object_change 2048}
   111    111   do_test tkt-80ba2-201 {
   112    112     db eval {
          113  +PRAGMA vdbe_debug=on;
          114  +PRAGMA vdbe_addoptrace=on;
   113    115       CREATE INDEX timeline_entry_id_idx on timeline(entry_id);
   114    116       SELECT entry_type,
   115    117              entry_types.name,
   116    118              entry_id
   117    119         FROM timeline JOIN entry_types ON entry_type = entry_types.id
   118    120        WHERE (entry_types.name = 'cli_command' AND entry_id=2114)
   119    121           OR (entry_types.name = 'object_change'

Changes to test/vacuum-into.test.

    61     61     CREATE TABLE t2(name TEXT);
    62     62     INSERT INTO t2 VALUES(':memory:');
    63     63     VACUUM main INTO (SELECT name FROM t2);
    64     64   } {}
    65     65   do_catchsql_test vacuum-into-310 {
    66     66     VACUUM INTO null;
    67     67   } {1 {non-text filename}}
           68  +do_catchsql_test vacuum-into-320 {
           69  +  VACUUM INTO x;
           70  +} {1 {no such column: x}}
           71  +do_catchsql_test vacuum-into-330 {
           72  +  VACUUM INTO t1.nosuchcol;
           73  +} {1 {no such column: t1.nosuchcol}}
           74  +do_catchsql_test vacuum-into-340 {
           75  +  VACUUM INTO main.t1.nosuchcol;
           76  +} {1 {no such column: main.t1.nosuchcol}}
           77  +
           78  +forcedelete test.db2
           79  +db func target target
           80  +proc target {} { return "test.db2" }
           81  +do_test vacuum-into-410 {
           82  +  execsql { VACUUM INTO target() }
           83  +  file exists test.db2
           84  +} 1
           85  +do_catchsql_test vacuum-into-420 {
           86  +  VACUUM INTO target2()
           87  +} {1 {no such function: target2}}
           88  +
    68     89   
    69     90   finish_test

Added test/vtabdrop.test.

            1  +# 2018 December 28
            2  +#
            3  +#    May you do good and not evil.
            4  +#    May you find forgiveness for yourself and forgive others.
            5  +#    May you share freely, never taking more than you give.
            6  +#
            7  +#***********************************************************************
            8  +#
            9  +# The tests in this file test edge cases surrounding DROP TABLE on 
           10  +# virtual tables.
           11  +#
           12  +
           13  +set testdir [file dirname $argv0]
           14  +source $testdir/tester.tcl
           15  +
           16  +ifcapable !vtab { finish_test ; return }
           17  +source $testdir/fts3_common.tcl
           18  +source $testdir/malloc_common.tcl
           19  +
           20  +set testprefix vtabdrop
           21  +
           22  +#-------------------------------------------------------------------------
           23  +# Test that if a DROP TABLE is executed against an rtree table, but the
           24  +# xDestroy() call fails, the rtree table is not dropped, the sqlite_master
           25  +# table is not modified and the internal schema remains intact.
           26  +# 
           27  +ifcapable rtree {
           28  +  do_execsql_test 1.0 {
           29  +    CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2);
           30  +    CREATE TABLE t1(x, y);
           31  +    INSERT INTO t1 VALUES(1, 2);
           32  +  }
           33  +  
           34  +  do_test 1.1 {
           35  +    execsql {
           36  +      BEGIN;
           37  +        INSERT INTO t1 VALUES(3, 4);
           38  +    }
           39  +    db eval { SELECT * FROM t1 } {
           40  +      catchsql { DROP TABLE rt }
           41  +    }
           42  +    execsql COMMIT
           43  +  } {}
           44  +  
           45  +  do_execsql_test 1.2 {
           46  +    SELECT name FROM sqlite_master ORDER BY 1;
           47  +    SELECT * FROM t1;
           48  +    SELECT * FROM rt;
           49  +  } {rt rt_node rt_parent rt_rowid t1 1 2 3 4}
           50  +  
           51  +  db close
           52  +  sqlite3 db test.db
           53  +  
           54  +  do_execsql_test 1.3 {
           55  +    SELECT name FROM sqlite_master ORDER BY 1;
           56  +  } {rt rt_node rt_parent rt_rowid t1}
           57  +}
           58  +
           59  +#-------------------------------------------------------------------------
           60  +# Same as tests 1.*, except with fts5 instead of rtree.
           61  +# 
           62  +ifcapable fts5 {
           63  +  reset_db
           64  +  do_execsql_test 2.0 {
           65  +    CREATE VIRTUAL TABLE ft USING fts5(x);
           66  +    CREATE TABLE t1(x, y);
           67  +    INSERT INTO t1 VALUES(1, 2);
           68  +  }
           69  +  
           70  +  do_test 2.1 {
           71  +    execsql {
           72  +      BEGIN;
           73  +        INSERT INTO t1 VALUES(3, 4);
           74  +    }
           75  +    db eval { SELECT * FROM t1 } {
           76  +      catchsql { DROP TABLE ft }
           77  +    }
           78  +    execsql COMMIT
           79  +  } {}
           80  +  
           81  +  do_execsql_test 2.2 {
           82  +    SELECT name FROM sqlite_master ORDER BY 1;
           83  +  } {ft ft_config ft_content ft_data ft_docsize ft_idx t1}
           84  +  
           85  +  db close
           86  +  sqlite3 db test.db
           87  +  
           88  +  do_execsql_test 2.3 {
           89  +    SELECT name FROM sqlite_master ORDER BY 1;
           90  +  } {ft ft_config ft_content ft_data ft_docsize ft_idx t1}
           91  +}
           92  +
           93  +#-------------------------------------------------------------------------
           94  +# Same as tests 1.*, except with fts3 instead of rtree.
           95  +# 
           96  +ifcapable fts3 {
           97  +  reset_db
           98  +  do_execsql_test 2.0 {
           99  +    CREATE VIRTUAL TABLE ft USING fts3(x);
          100  +    CREATE TABLE t1(x, y);
          101  +    INSERT INTO t1 VALUES(1, 2);
          102  +  }
          103  +  
          104  +  do_test 2.1 {
          105  +    execsql {
          106  +      BEGIN;
          107  +        INSERT INTO t1 VALUES(3, 4);
          108  +    }
          109  +    db eval { SELECT * FROM t1 } {
          110  +      catchsql { DROP TABLE ft }
          111  +    }
          112  +    execsql COMMIT
          113  +  } {}
          114  +  
          115  +  do_execsql_test 2.2 {
          116  +    SELECT name FROM sqlite_master ORDER BY 1;
          117  +  } {ft ft_content ft_segdir ft_segments sqlite_autoindex_ft_segdir_1 t1}
          118  +  
          119  +  db close
          120  +  sqlite3 db test.db
          121  +  
          122  +  do_execsql_test 2.3 {
          123  +    SELECT name FROM sqlite_master ORDER BY 1;
          124  +  } {ft ft_content ft_segdir ft_segments sqlite_autoindex_ft_segdir_1 t1}
          125  +}
          126  +
          127  +finish_test

Added test/wal2rollback.test.

            1  +# 2017 September 19
            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 file is testing the operation of the library in
           13  +# "PRAGMA journal_mode=WAL2" mode.
           14  +#
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +source $testdir/lock_common.tcl
           19  +source $testdir/malloc_common.tcl
           20  +source $testdir/wal_common.tcl
           21  +
           22  +set testprefix wal2rollback
           23  +ifcapable !wal {finish_test ; return }
           24  +
           25  +do_execsql_test 1.0 {
           26  +  CREATE TABLE t1(a, b, c);
           27  +  CREATE TABLE t2(a, b, c);
           28  +  CREATE INDEX i1 ON t1(a);
           29  +  CREATE INDEX i2 ON t1(b);
           30  +  PRAGMA journal_mode = wal2;
           31  +  PRAGMA cache_size = 5;
           32  +  PRAGMA journal_size_limit = 10000;
           33  +  WITH s(i) AS (
           34  +    SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 1000
           35  +  )
           36  +  INSERT INTO t1 SELECT i, i, randomblob(200) FROM s;
           37  +} {wal2 10000}
           38  +
           39  +do_test 1.1 {
           40  +  expr [file size test.db-wal] > 10000
           41  +} 1
           42  +
           43  +do_test 1.2 {
           44  +  execsql {
           45  +    BEGIN;
           46  +      UPDATE t1 SET b=b+1;
           47  +      INSERT INTO t2 VALUES(1,2,3);
           48  +  }
           49  +  expr [file size test.db-wal2] > 10000
           50  +} {1}
           51  +
           52  +breakpoint
           53  +do_execsql_test 1.3 {
           54  +  ROLLBACK;
           55  +  SELECT * FROM t2;
           56  +  SELECT count(*) FROM t1 WHERE a=b;
           57  +  PRAGMA integrity_check;
           58  +} {1000 ok}
           59  +
           60  +
           61  +
           62  +finish_test

Changes to test/where7.test.

 23349  23349         AND t302.c3 > 1287603136
 23350  23350         AND (t301.c4 = 1407449685622784
 23351  23351              OR t301.c8 = 1407424651264000)
 23352  23352      ORDER BY t302.c5 LIMIT 200;
 23353  23353   } {
 23354  23354     QUERY PLAN
 23355  23355     |--MULTI-INDEX OR
 23356         -  |  |--SEARCH TABLE t301 USING COVERING INDEX t301_c4 (c4=?)
 23357         -  |  `--SEARCH TABLE t301 USING INTEGER PRIMARY KEY (rowid=?)
        23356  +  |  |--INDEX 1
        23357  +  |  |  `--SEARCH TABLE t301 USING COVERING INDEX t301_c4 (c4=?)
        23358  +  |  `--INDEX 2
        23359  +  |     `--SEARCH TABLE t301 USING INTEGER PRIMARY KEY (rowid=?)
 23358  23360     |--SEARCH TABLE t302 USING INDEX t302_c8_c3 (c8=? AND c3>?)
 23359  23361     `--USE TEMP B-TREE FOR ORDER BY
 23360  23362   }
 23361  23363   
 23362  23364   finish_test

Changes to test/where9.test.

   360    360     do_eqp_test where9-3.1 {
   361    361       SELECT t2.a FROM t1, t2
   362    362       WHERE t1.a=80 AND ((t1.c=t2.c AND t1.d=t2.d) OR t1.f=t2.f)
   363    363     } [string map {"\n  " \n} {
   364    364       QUERY PLAN
   365    365       |--SEARCH TABLE t1 USING INTEGER PRIMARY KEY (rowid=?)
   366    366       `--MULTI-INDEX OR
   367         -       |--SEARCH TABLE t2 USING INDEX t2d (d=?)
   368         -       `--SEARCH TABLE t2 USING COVERING INDEX t2f (f=?)
          367  +       |--INDEX 1
          368  +       |  `--SEARCH TABLE t2 USING INDEX t2d (d=?)
          369  +       `--INDEX 3
          370  +          `--SEARCH TABLE t2 USING COVERING INDEX t2f (f=?)
   369    371     }]
   370    372     do_eqp_test where9-3.2 {
   371    373       SELECT coalesce(t2.a,9999)
   372    374       FROM t1 LEFT JOIN t2 ON (t1.c+1=t2.c AND t1.d=t2.d) OR (t1.f||'x')=t2.f
   373    375       WHERE t1.a=80
   374    376     } [string map {"\n  " \n} {
   375    377       QUERY PLAN
   376    378       |--SEARCH TABLE t1 USING INTEGER PRIMARY KEY (rowid=?)
   377    379       `--MULTI-INDEX OR
   378         -       |--SEARCH TABLE t2 USING INDEX t2d (d=?)
   379         -       `--SEARCH TABLE t2 USING COVERING INDEX t2f (f=?)
          380  +       |--INDEX 1
          381  +       |  `--SEARCH TABLE t2 USING INDEX t2d (d=?)
          382  +       `--INDEX 2
          383  +          `--SEARCH TABLE t2 USING COVERING INDEX t2f (f=?)
   380    384     }]
   381    385   } 
   382    386   
   383    387   # Make sure that INDEXED BY and multi-index OR clauses play well with
   384    388   # one another.
   385    389   #
   386    390   do_test where9-4.1 {
................................................................................
   452    456   # the former is an equality test which is expected to return fewer rows.
   453    457   #
   454    458   do_eqp_test where9-5.1 {
   455    459     SELECT a FROM t1 WHERE b>1000 AND (c=31031 OR d IS NULL)
   456    460   } {
   457    461     QUERY PLAN
   458    462     `--MULTI-INDEX OR
   459         -     |--SEARCH TABLE t1 USING INDEX t1c (c=?)
   460         -     `--SEARCH TABLE t1 USING INDEX t1d (d=?)
          463  +     |--INDEX 1
          464  +     |  `--SEARCH TABLE t1 USING INDEX t1c (c=?)
          465  +     `--INDEX 2
          466  +        `--SEARCH TABLE t1 USING INDEX t1d (d=?)
   461    467   }
   462    468   
   463    469   # In contrast, b=1000 is preferred over any OR-clause.
   464    470   #
   465    471   do_eqp_test where9-5.2 {
   466    472     SELECT a FROM t1 WHERE b=1000 AND (c=31031 OR d IS NULL)
   467    473   } {SEARCH TABLE t1 USING INDEX t1b (b=?)}

Changes to test/whereI.test.

    27     27   }
    28     28   
    29     29   do_eqp_test 1.1 {
    30     30     SELECT a FROM t1 WHERE b='b' OR c='x'
    31     31   } {
    32     32     QUERY PLAN
    33     33     `--MULTI-INDEX OR
    34         -     |--SEARCH TABLE t1 USING INDEX i1 (b=?)
    35         -     `--SEARCH TABLE t1 USING INDEX i2 (c=?)
           34  +     |--INDEX 1
           35  +     |  `--SEARCH TABLE t1 USING INDEX i1 (b=?)
           36  +     `--INDEX 2
           37  +        `--SEARCH TABLE t1 USING INDEX i2 (c=?)
    36     38   }
    37     39   
    38     40   do_execsql_test 1.2 {
    39     41     SELECT a FROM t1 WHERE b='b' OR c='x'
    40     42   } {2 3}
    41     43   
    42     44   do_execsql_test 1.3 {
................................................................................
    57     59   }
    58     60   
    59     61   do_eqp_test 2.1 {
    60     62     SELECT a FROM t2 WHERE b='b' OR c='x'
    61     63   } {
    62     64     QUERY PLAN
    63     65     `--MULTI-INDEX OR
    64         -     |--SEARCH TABLE t2 USING INDEX i3 (b=?)
    65         -     `--SEARCH TABLE t2 USING INDEX i4 (c=?)
           66  +     |--INDEX 1
           67  +     |  `--SEARCH TABLE t2 USING INDEX i3 (b=?)
           68  +     `--INDEX 2
           69  +        `--SEARCH TABLE t2 USING INDEX i4 (c=?)
    66     70   }
    67     71   
    68     72   do_execsql_test 2.2 {
    69     73     SELECT a FROM t2 WHERE b='b' OR c='x'
    70     74   } {ii iii}
    71     75   
    72     76   do_execsql_test 2.3 {

Changes to test/window1.test.

   615    615     CREATE TABLE t2(c); INSERT INTO t2(c) VALUES(1);
   616    616     SELECT y, y+1, y+2 FROM (
   617    617       SELECT c IN (
   618    618         SELECT (row_number() OVER()) FROM t1
   619    619       ) AS y FROM t2
   620    620     );
   621    621   } {1 2 3}
          622  +
          623  +# 2018-12-31
          624  +# https://www.sqlite.org/src/info/d0866b26f83e9c55
          625  +# Window function in correlated subquery causes assertion fault 
          626  +#
          627  +do_catchsql_test 15.0 {
          628  +  WITH t(id, parent) AS (
          629  +  SELECT CAST(1 AS INT), CAST(NULL AS INT)
          630  +  UNION ALL
          631  +  SELECT 2, NULL
          632  +  UNION ALL
          633  +  SELECT 3, 1
          634  +  UNION ALL
          635  +  SELECT 4, 1
          636  +  UNION ALL
          637  +  SELECT 5, 2
          638  +  UNION ALL
          639  +  SELECT 6, 2
          640  +  ), q AS (
          641  +  SELECT t.*, ROW_NUMBER() OVER (ORDER BY t.id) AS rn
          642  +    FROM t
          643  +   WHERE parent IS NULL
          644  +   UNION ALL
          645  +  SELECT t.*, ROW_NUMBER() OVER (ORDER BY t.id) AS rn
          646  +    FROM q
          647  +    JOIN t
          648  +      ON t.parent = q.id
          649  +  )
          650  +  SELECT *
          651  +    FROM q;
          652  +} {1 {cannot use window functions in recursive queries}}
          653  +do_execsql_test 15.1 {
          654  +  DROP TABLE IF EXISTS t1;
          655  +  DROP TABLE IF EXISTS t2;
          656  +  CREATE TABLE t1(x);
          657  +  INSERT INTO t1 VALUES('a'), ('b'), ('c');
          658  +  CREATE TABLE t2(a, b);
          659  +  INSERT INTO t2 VALUES('X', 1), ('X', 2), ('Y', 2), ('Y', 3);
          660  +  SELECT x, (
          661  +    SELECT sum(b)
          662  +      OVER (PARTITION BY a ROWS BETWEEN UNBOUNDED PRECEDING
          663  +                                    AND UNBOUNDED FOLLOWING)
          664  +    FROM t2 WHERE b<x
          665  +  ) FROM t1;
          666  +} {a 3 b 3 c 3}
          667  +
          668  +do_execsql_test 15.2 {
          669  +  SELECT(
          670  +    WITH c AS(
          671  +      VALUES(1)
          672  +    ) SELECT '' FROM c,c
          673  +  ) x WHERE x+x;
          674  +} {}
   622    675   
   623    676   finish_test

Changes to test/with1.test.

  1039   1039   #
  1040   1040   do_execsql_test 20.1 {
  1041   1041     WITH c(i)AS(VALUES(9)UNION SELECT~i FROM c)SELECT max(5)>i fROM c;
  1042   1042   } {0}
  1043   1043   do_execsql_test 20.2 {
  1044   1044     WITH c(i)AS(VALUES(5)UNIoN SELECT 0)SELECT min(1)-i fROM c;
  1045   1045   } {1}
         1046  +
         1047  +# 2018-12-26
         1048  +# Two different CTE tables with the same name appear in within a single FROM
         1049  +# clause due to the query-flattener optimization.  make sure this does not cause
         1050  +# problems.  This problem was discovered by Matt Denton.
         1051  +#
         1052  +do_execsql_test 21.1 {
         1053  +   WITH RECURSIVE t21(a,b) AS (
         1054  +    WITH t21(x) AS (VALUES(1))
         1055  +    SELECT x, x FROM t21 ORDER BY 1
         1056  +  )
         1057  +  SELECT * FROM t21 AS tA, t21 AS tB
         1058  +} {1 1 1 1}
         1059  +do_execsql_test 21.2 {
         1060  +  SELECT printf('',
         1061  +     EXISTS (WITH RECURSIVE Table0 AS (WITH Table0 AS (SELECT DISTINCT 1)
         1062  +                                       SELECT *, * FROM Table0 ORDER BY 1 DESC)
         1063  +             SELECT * FROM Table0  NATURAL JOIN  Table0));
         1064  +} {{}}
  1046   1065   
  1047   1066   finish_test

Changes to test/with3.test.

   116    116        SELECT * FROM c, w2, w1
   117    117        WHERE c.id=w2.pk AND c.id=w1.pk;
   118    118   } {
   119    119     QUERY PLAN
   120    120     |--MATERIALIZE xxxxxx
   121    121     |  |--SETUP
   122    122     |  |  |--SCAN CONSTANT ROW
   123         -  |  |  `--SCALAR SUBQUERY
          123  +  |  |  `--SCALAR SUBQUERY xxxxxx
   124    124     |  |     `--SCAN TABLE w2
   125    125     |  `--RECURSIVE STEP
   126    126     |     |--SCAN TABLE w1
   127    127     |     `--SCAN TABLE c
   128    128     |--SCAN SUBQUERY xxxxxx
   129    129     |--SEARCH TABLE w2 USING INTEGER PRIMARY KEY (rowid=?)
   130    130     `--SEARCH TABLE w1 USING INTEGER PRIMARY KEY (rowid=?)
   131    131   }
   132    132   
   133    133   finish_test

Changes to tool/dbtotxt.c.

   108    108       if( pgsz<512 || (pgsz&(pgsz-1))!=0 ){
   109    109         fprintf(stderr, "Invalid page size in header: %d\n", pgsz);
   110    110         exit(1);
   111    111       }
   112    112     }
   113    113     zBaseName = zInputFile;
   114    114     for(i=0; zInputFile[i]; i++){
   115         -    if( zInputFile[i]=='/' && zInputFile[i+1]!=0 ) zBaseName = zInputFile+1;
          115  +    if( zInputFile[i]=='/' && zInputFile[i+1]!=0 ) zBaseName = zInputFile+i+1;
   116    116     }
   117    117     printf("| size %d pagesize %d filename %s\n",(int)szFile,pgsz,zBaseName);
   118    118     for(i=0; i<szFile; i+=16){
   119    119       int got = (int)fread(aLine, 1, 16, in);
   120    120       if( got!=16 ){
   121    121         static int once = 1;
   122    122         if( once ){