/ Check-in [ce184c7b]
Login
Overview
Comment:Add logic to do test coverage measurements on the VDBE code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | insert-optimization
Files: files | file ages | folders
SHA1:ce184c7bb16988641d37c908d9b3042456d4be3d
User & Date: drh 2014-02-17 22:40:43
Context
2014-02-17
23:52
Merge in performance enhancements for INSERT operations, especially INSERTs on tables that have no affinity columns or that have many indices or INSERTs with content coming from a SELECT. Add the SQLITE_TESTCTRL_VDBE_COVERAGE test control and the SQLITE_VDBE_COVERAGE compile-time option used for measure coverage of branches in VDBE programs. check-in: a7268769 user: drh tags: trunk
22:40
Add logic to do test coverage measurements on the VDBE code. Closed-Leaf check-in: ce184c7b user: drh tags: insert-optimization
15:40
Add a test case for OP_SoftNull. check-in: f29d194e user: drh tags: insert-optimization
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

   600    600     if( ALWAYS(v) ){
   601    601       int r1 = sqlite3GetTempReg(pParse);
   602    602       int r2 = sqlite3GetTempReg(pParse);
   603    603       int j1;
   604    604       sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
   605    605       sqlite3VdbeUsesBtree(v, iDb);
   606    606       sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2);
   607         -    j1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1);
          607  +    j1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1); VdbeCoverage(v);
   608    608       sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, r2);
   609    609       sqlite3VdbeJumpHere(v, j1);
   610    610       sqlite3ReleaseTempReg(pParse, r1);
   611    611       sqlite3ReleaseTempReg(pParse, r2);
   612    612     }
   613    613   }
   614    614   

Changes to src/analyze.c.

  1073   1073       **   Rewind csr
  1074   1074       **   if eof(csr) goto end_of_scan;
  1075   1075       **   regChng = 0
  1076   1076       **   goto next_push_0;
  1077   1077       **
  1078   1078       */
  1079   1079       addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
         1080  +    VdbeCoverage(v);
  1080   1081       sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
  1081   1082       addrGotoChng0 = sqlite3VdbeAddOp0(v, OP_Goto);
  1082   1083   
  1083   1084       /*
  1084   1085       **  next_row:
  1085   1086       **   regChng = 0
  1086   1087       **   if( idx(0) != regPrev(0) ) goto chng_addr_0
................................................................................
  1094   1095       for(i=0; i<nCol; i++){
  1095   1096         char *pColl = (char*)sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
  1096   1097         sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
  1097   1098         sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
  1098   1099         aGotoChng[i] = 
  1099   1100         sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
  1100   1101         sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
         1102  +      VdbeCoverage(v);
  1101   1103       }
  1102   1104       sqlite3VdbeAddOp2(v, OP_Integer, nCol, regChng);
  1103   1105       aGotoChng[nCol] = sqlite3VdbeAddOp0(v, OP_Goto);
  1104   1106   
  1105   1107       /*
  1106   1108       **  chng_addr_0:
  1107   1109       **   regPrev(0) = idx(0)
................................................................................
  1140   1142         sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol);
  1141   1143       }
  1142   1144   #endif
  1143   1145       assert( regChng==(regStat4+1) );
  1144   1146       sqlite3VdbeAddOp3(v, OP_Function, 1, regStat4, regTemp);
  1145   1147       sqlite3VdbeChangeP4(v, -1, (char*)&statPushFuncdef, P4_FUNCDEF);
  1146   1148       sqlite3VdbeChangeP5(v, 2+IsStat34);
  1147         -    sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow);
         1149  +    sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
  1148   1150   
  1149   1151       /* Add the entry to the stat1 table. */
  1150   1152       callStatGet(v, regStat4, STAT_GET_STAT1, regStat1);
  1151   1153       sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
  1152   1154       sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
  1153   1155       sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
  1154   1156       sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
................................................................................
  1167   1169         u8 seekOp = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
  1168   1170   
  1169   1171         pParse->nMem = MAX(pParse->nMem, regCol+nCol+1);
  1170   1172   
  1171   1173         addrNext = sqlite3VdbeCurrentAddr(v);
  1172   1174         callStatGet(v, regStat4, STAT_GET_ROWID, regSampleRowid);
  1173   1175         addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid);
         1176  +      VdbeCoverage(v);
  1174   1177         callStatGet(v, regStat4, STAT_GET_NEQ, regEq);
  1175   1178         callStatGet(v, regStat4, STAT_GET_NLT, regLt);
  1176   1179         callStatGet(v, regStat4, STAT_GET_NDLT, regDLt);
  1177   1180         sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
         1181  +      VdbeCoverage(v);
  1178   1182   #ifdef SQLITE_ENABLE_STAT3
  1179   1183         sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, 
  1180   1184                                         pIdx->aiColumn[0], regSample);
  1181   1185   #else
  1182   1186         for(i=0; i<nCol; i++){
  1183   1187           i16 iCol = pIdx->aiColumn[i];
  1184   1188           sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i);
................................................................................
  1201   1205   
  1202   1206     /* Create a single sqlite_stat1 entry containing NULL as the index
  1203   1207     ** name and the row count as the content.
  1204   1208     */
  1205   1209     if( pOnlyIdx==0 && needTableCnt ){
  1206   1210       VdbeComment((v, "%s", pTab->zName));
  1207   1211       sqlite3VdbeAddOp2(v, OP_Count, iTabCur, regStat1);
  1208         -    jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1);
         1212  +    jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1); VdbeCoverage(v);
  1209   1213       sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
  1210   1214       sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
  1211   1215       sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
  1212   1216       sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
  1213   1217       sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
  1214   1218       sqlite3VdbeJumpHere(v, jZeroRows);
  1215   1219     }

Changes to src/build.c.

   944    944       ** set them now.
   945    945       */
   946    946       reg1 = pParse->regRowid = ++pParse->nMem;
   947    947       reg2 = pParse->regRoot = ++pParse->nMem;
   948    948       reg3 = ++pParse->nMem;
   949    949       sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT);
   950    950       sqlite3VdbeUsesBtree(v, iDb);
   951         -    j1 = sqlite3VdbeAddOp1(v, OP_If, reg3);
          951  +    j1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v);
   952    952       fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
   953    953                     1 : SQLITE_MAX_FILE_FORMAT;
   954    954       sqlite3VdbeAddOp2(v, OP_Integer, fileFormat, reg3);
   955    955       sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, reg3);
   956    956       sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
   957    957       sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_TEXT_ENCODING, reg3);
   958    958       sqlite3VdbeJumpHere(v, j1);
................................................................................
  2671   2671     iSorter = pParse->nTab++;
  2672   2672     sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (char*)
  2673   2673                       sqlite3KeyInfoRef(pKey), P4_KEYINFO);
  2674   2674   
  2675   2675     /* Open the table. Loop through all rows of the table, inserting index
  2676   2676     ** records into the sorter. */
  2677   2677     sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
  2678         -  addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
         2678  +  addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0); VdbeCoverage(v);
  2679   2679     regRecord = sqlite3GetTempReg(pParse);
  2680   2680   
  2681   2681     sqlite3GenerateIndexKey(pParse,pIndex,iTab,regRecord,0,&iPartIdxLabel,0,0);
  2682   2682     sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
  2683   2683     sqlite3VdbeResolveLabel(v, iPartIdxLabel);
  2684         -  sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
         2684  +  sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1); VdbeCoverage(v);
  2685   2685     sqlite3VdbeJumpHere(v, addr1);
  2686   2686     if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
  2687   2687     sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb, 
  2688   2688                       (char *)pKey, P4_KEYINFO);
  2689   2689     sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
  2690   2690   
  2691         -  addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
         2691  +  addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
  2692   2692     assert( pKey!=0 || db->mallocFailed || pParse->nErr );
  2693   2693     if( pIndex->onError!=OE_None && pKey!=0 ){
  2694   2694       int j2 = sqlite3VdbeCurrentAddr(v) + 3;
  2695   2695       sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
  2696   2696       addr2 = sqlite3VdbeCurrentAddr(v);
  2697   2697       sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
  2698         -                         pKey->nField - pIndex->nKeyCol);
         2698  +                         pKey->nField - pIndex->nKeyCol); VdbeCoverage(v);
  2699   2699       sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
  2700   2700     }else{
  2701   2701       addr2 = sqlite3VdbeCurrentAddr(v);
  2702   2702     }
  2703   2703     sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
  2704   2704     sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
  2705   2705     sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
  2706   2706     sqlite3ReleaseTempReg(pParse, regRecord);
  2707         -  sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2);
         2707  +  sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
  2708   2708     sqlite3VdbeJumpHere(v, addr1);
  2709   2709   
  2710   2710     sqlite3VdbeAddOp1(v, OP_Close, iTab);
  2711   2711     sqlite3VdbeAddOp1(v, OP_Close, iIdx);
  2712   2712     sqlite3VdbeAddOp1(v, OP_Close, iSorter);
  2713   2713   }
  2714   2714   

Changes to src/delete.c.

   477    477       */
   478    478       if( okOnePass ){
   479    479         /* Just one row.  Hence the top-of-loop is a no-op */
   480    480         assert( nKey==nPk ); /* OP_Found will use an unpacked key */
   481    481         if( aToOpen[iDataCur-iTabCur] ){
   482    482           assert( pPk!=0 );
   483    483           sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
          484  +        VdbeCoverage(v);
   484    485         }
   485    486       }else if( pPk ){
   486         -      addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur);
          487  +      addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);
   487    488         sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey);
   488    489         assert( nKey==0 );  /* OP_Found will use a composite key */
   489    490       }else{
   490    491         addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
          492  +      VdbeCoverage(v);
   491    493         assert( nKey==1 );
   492    494       }  
   493    495     
   494    496       /* Delete the row */
   495    497   #ifndef SQLITE_OMIT_VIRTUALTABLE
   496    498       if( IsVirtual(pTab) ){
   497    499         const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
................................................................................
   507    509                                  iKey, nKey, count, OE_Default, okOnePass);
   508    510       }
   509    511     
   510    512       /* End of the loop over all rowids/primary-keys. */
   511    513       if( okOnePass ){
   512    514         sqlite3VdbeResolveLabel(v, addrBypass);
   513    515       }else if( pPk ){
   514         -      sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1);
          516  +      sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v);
   515    517         sqlite3VdbeJumpHere(v, addrLoop);
   516    518       }else{
   517    519         sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop);
   518    520         sqlite3VdbeJumpHere(v, addrLoop);
   519    521       }     
   520    522     
   521    523       /* Close the cursors open on the table and its indexes. */
................................................................................
   605    607                            iDataCur, iIdxCur, iPk, (int)nPk));
   606    608   
   607    609     /* Seek cursor iCur to the row to delete. If this row no longer exists 
   608    610     ** (this can happen if a trigger program has already deleted it), do
   609    611     ** not attempt to delete it or fire any DELETE triggers.  */
   610    612     iLabel = sqlite3VdbeMakeLabel(v);
   611    613     opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
   612         -  if( !bNoSeek ) sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
          614  +  if( !bNoSeek ){
          615  +    sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
          616  +    VdbeCoverage(v);
          617  +  }
   613    618    
   614    619     /* If there are any triggers to fire, allocate a range of registers to
   615    620     ** use for the old.* references in the triggers.  */
   616    621     if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
   617    622       u32 mask;                     /* Mask of OLD.* columns in use */
   618    623       int iCol;                     /* Iterator used while populating OLD.* */
   619    624       int addrStart;                /* Start of BEFORE trigger programs */
................................................................................
   647    652       /* If any BEFORE triggers were coded, then seek the cursor to the 
   648    653       ** row to be deleted again. It may be that the BEFORE triggers moved
   649    654       ** the cursor or of already deleted the row that the cursor was
   650    655       ** pointing to.
   651    656       */
   652    657       if( addrStart<sqlite3VdbeCurrentAddr(v) ){
   653    658         sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
          659  +      VdbeCoverage(v);
   654    660       }
   655    661   
   656    662       /* Do FK processing. This call checks that any FK constraints that
   657    663       ** refer to this table (i.e. constraints attached to other tables) 
   658    664       ** are not violated by deleting this row.  */
   659    665       sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
   660    666     }

Changes to src/expr.c.

  1379   1379   void sqlite3ExprCodeIsNullJump(
  1380   1380     Vdbe *v,            /* The VDBE under construction */
  1381   1381     const Expr *pExpr,  /* Only generate OP_IsNull if this expr can be NULL */
  1382   1382     int iReg,           /* Test the value in this register for NULL */
  1383   1383     int iDest           /* Jump here if the value is null */
  1384   1384   ){
  1385   1385     if( sqlite3ExprCanBeNull(pExpr) ){
  1386         -    sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iDest);
         1386  +    sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iDest); VdbeCoverage(v);
  1387   1387     }
  1388   1388   }
  1389   1389   
  1390   1390   /*
  1391   1391   ** Return TRUE if the given expression is a constant which would be
  1392   1392   ** unchanged by OP_Affinity with the affinity given in the second
  1393   1393   ** argument.
................................................................................
  1482   1482   
  1483   1483   /*
  1484   1484   ** Code an OP_Once instruction and allocate space for its flag. Return the 
  1485   1485   ** address of the new instruction.
  1486   1486   */
  1487   1487   int sqlite3CodeOnce(Parse *pParse){
  1488   1488     Vdbe *v = sqlite3GetVdbe(pParse);      /* Virtual machine being coded */
  1489         -  return sqlite3VdbeAddOp1(v, OP_Once, pParse->nOnce++);
         1489  +  int addr = sqlite3VdbeAddOp1(v, OP_Once, pParse->nOnce++);
         1490  +  VdbeCoverage(v);
         1491  +  return addr;
  1490   1492   }
  1491   1493   
  1492   1494   /*
  1493   1495   ** This function is used by the implementation of the IN (...) operator.
  1494   1496   ** The pX parameter is the expression on the RHS of the IN operator, which
  1495   1497   ** might be either a list of expressions or a subquery.
  1496   1498   **
................................................................................
  1833   1835             if( isRowid && sqlite3ExprIsInteger(pE2, &iValToIns) ){
  1834   1836               sqlite3VdbeAddOp3(v, OP_InsertInt, pExpr->iTable, r2, iValToIns);
  1835   1837             }else{
  1836   1838               r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
  1837   1839               if( isRowid ){
  1838   1840                 sqlite3VdbeAddOp2(v, OP_MustBeInt, r3,
  1839   1841                                   sqlite3VdbeCurrentAddr(v)+2);
         1842  +              VdbeCoverage(v);
  1840   1843                 sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3);
  1841   1844               }else{
  1842   1845                 sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
  1843   1846                 sqlite3ExprCacheAffinityChange(pParse, r3, 1);
  1844   1847                 sqlite3VdbeAddOp2(v, OP_IdxInsert, pExpr->iTable, r2);
  1845   1848               }
  1846   1849             }
................................................................................
  1956   1959   
  1957   1960     /* If the LHS is NULL, then the result is either false or NULL depending
  1958   1961     ** on whether the RHS is empty or not, respectively.
  1959   1962     */
  1960   1963     if( destIfNull==destIfFalse ){
  1961   1964       /* Shortcut for the common case where the false and NULL outcomes are
  1962   1965       ** the same. */
  1963         -    sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull);
         1966  +    sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull); VdbeCoverage(v);
  1964   1967     }else{
  1965         -    int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1);
         1968  +    int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1); VdbeCoverage(v);
  1966   1969       sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse);
         1970  +    VdbeCoverage(v);
  1967   1971       sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
  1968   1972       sqlite3VdbeJumpHere(v, addr1);
  1969   1973     }
  1970   1974   
  1971   1975     if( eType==IN_INDEX_ROWID ){
  1972   1976       /* In this case, the RHS is the ROWID of table b-tree
  1973   1977       */
  1974         -    sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, destIfFalse);
         1978  +    sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, destIfFalse); VdbeCoverage(v);
  1975   1979       sqlite3VdbeAddOp3(v, OP_NotExists, pExpr->iTable, destIfFalse, r1);
         1980  +    VdbeCoverage(v);
  1976   1981     }else{
  1977   1982       /* In this case, the RHS is an index b-tree.
  1978   1983       */
  1979   1984       sqlite3VdbeAddOp4(v, OP_Affinity, r1, 1, 0, &affinity, 1);
  1980   1985   
  1981   1986       /* If the set membership test fails, then the result of the 
  1982   1987       ** "x IN (...)" expression must be either 0 or NULL. If the set
................................................................................
  1989   1994         ** cannot contain NULL values. This happens as the result
  1990   1995         ** of a "NOT NULL" constraint in the database schema.
  1991   1996         **
  1992   1997         ** Also run this branch if NULL is equivalent to FALSE
  1993   1998         ** for this particular IN operator.
  1994   1999         */
  1995   2000         sqlite3VdbeAddOp4Int(v, OP_NotFound, pExpr->iTable, destIfFalse, r1, 1);
  1996         -
         2001  +      VdbeCoverage(v);
  1997   2002       }else{
  1998   2003         /* In this branch, the RHS of the IN might contain a NULL and
  1999   2004         ** the presence of a NULL on the RHS makes a difference in the
  2000   2005         ** outcome.
  2001   2006         */
  2002   2007         int j1, j2, j3;
  2003   2008   
  2004   2009         /* First check to see if the LHS is contained in the RHS.  If so,
  2005   2010         ** then the presence of NULLs in the RHS does not matter, so jump
  2006   2011         ** over all of the code that follows.
  2007   2012         */
  2008   2013         j1 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, r1, 1);
         2014  +      VdbeCoverage(v);
  2009   2015   
  2010   2016         /* Here we begin generating code that runs if the LHS is not
  2011   2017         ** contained within the RHS.  Generate additional code that
  2012   2018         ** tests the RHS for NULLs.  If the RHS contains a NULL then
  2013   2019         ** jump to destIfNull.  If there are no NULLs in the RHS then
  2014   2020         ** jump to destIfFalse.
  2015   2021         */
  2016         -      j2 = sqlite3VdbeAddOp1(v, OP_NotNull, rRhsHasNull);
         2022  +      j2 = sqlite3VdbeAddOp1(v, OP_NotNull, rRhsHasNull); VdbeCoverage(v);
  2017   2023         j3 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, rRhsHasNull, 1);
         2024  +      VdbeCoverage(v);
  2018   2025         sqlite3VdbeAddOp2(v, OP_Integer, -1, rRhsHasNull);
  2019   2026         sqlite3VdbeJumpHere(v, j3);
  2020   2027         sqlite3VdbeAddOp2(v, OP_AddImm, rRhsHasNull, 1);
  2021   2028         sqlite3VdbeJumpHere(v, j2);
  2022   2029   
  2023   2030         /* Jump to the appropriate target depending on whether or not
  2024   2031         ** the RHS contains a NULL
  2025   2032         */
  2026         -      sqlite3VdbeAddOp2(v, OP_If, rRhsHasNull, destIfNull);
         2033  +      sqlite3VdbeAddOp2(v, OP_If, rRhsHasNull, destIfNull); VdbeCoverage(v);
  2027   2034         sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
  2028   2035   
  2029   2036         /* The OP_Found at the top of this branch jumps here when true, 
  2030   2037         ** causing the overall IN expression evaluation to fall through.
  2031   2038         */
  2032   2039         sqlite3VdbeJumpHere(v, j1);
  2033   2040       }
................................................................................
  2556   2563         testcase( op==TK_GT );
  2557   2564         testcase( op==TK_GE );
  2558   2565         testcase( op==TK_EQ );
  2559   2566         testcase( op==TK_NE );
  2560   2567         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  2561   2568         r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  2562   2569         codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  2563         -                  r1, r2, inReg, SQLITE_STOREP2);
         2570  +                  r1, r2, inReg, SQLITE_STOREP2); VdbeCoverage(v);
  2564   2571         testcase( regFree1==0 );
  2565   2572         testcase( regFree2==0 );
  2566   2573         break;
  2567   2574       }
  2568   2575       case TK_IS:
  2569   2576       case TK_ISNOT: {
  2570   2577         testcase( op==TK_IS );
  2571   2578         testcase( op==TK_ISNOT );
  2572   2579         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  2573   2580         r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  2574   2581         op = (op==TK_IS) ? TK_EQ : TK_NE;
  2575   2582         codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  2576   2583                     r1, r2, inReg, SQLITE_STOREP2 | SQLITE_NULLEQ);
         2584  +      VdbeCoverage(v);
  2577   2585         testcase( regFree1==0 );
  2578   2586         testcase( regFree2==0 );
  2579   2587         break;
  2580   2588       }
  2581   2589       case TK_AND:
  2582   2590       case TK_OR:
  2583   2591       case TK_PLUS:
................................................................................
  2659   2667         assert( TK_ISNULL==OP_IsNull );
  2660   2668         assert( TK_NOTNULL==OP_NotNull );
  2661   2669         testcase( op==TK_ISNULL );
  2662   2670         testcase( op==TK_NOTNULL );
  2663   2671         sqlite3VdbeAddOp2(v, OP_Integer, 1, target);
  2664   2672         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  2665   2673         testcase( regFree1==0 );
  2666         -      addr = sqlite3VdbeAddOp1(v, op, r1);
         2674  +      addr = sqlite3VdbeAddOp1(v, op, r1); VdbeCoverage(v);
  2667   2675         sqlite3VdbeAddOp2(v, OP_AddImm, target, -1);
  2668   2676         sqlite3VdbeJumpHere(v, addr);
  2669   2677         break;
  2670   2678       }
  2671   2679       case TK_AGG_FUNCTION: {
  2672   2680         AggInfo *pInfo = pExpr->pAggInfo;
  2673   2681         if( pInfo==0 ){
................................................................................
  2711   2719         */
  2712   2720         if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
  2713   2721           int endCoalesce = sqlite3VdbeMakeLabel(v);
  2714   2722           assert( nFarg>=2 );
  2715   2723           sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
  2716   2724           for(i=1; i<nFarg; i++){
  2717   2725             sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
         2726  +          VdbeCoverage(v);
  2718   2727             sqlite3ExprCacheRemove(pParse, target, 1);
  2719   2728             sqlite3ExprCachePush(pParse);
  2720   2729             sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
  2721   2730             sqlite3ExprCachePop(pParse, 1);
  2722   2731           }
  2723   2732           sqlite3VdbeResolveLabel(v, endCoalesce);
  2724   2733           break;
................................................................................
  2849   2858         r2 = sqlite3ExprCodeTemp(pParse, pRight, &regFree2);
  2850   2859         testcase( regFree1==0 );
  2851   2860         testcase( regFree2==0 );
  2852   2861         r3 = sqlite3GetTempReg(pParse);
  2853   2862         r4 = sqlite3GetTempReg(pParse);
  2854   2863         codeCompare(pParse, pLeft, pRight, OP_Ge,
  2855   2864                     r1, r2, r3, SQLITE_STOREP2);
         2865  +      VdbeCoverage(v);
  2856   2866         pLItem++;
  2857   2867         pRight = pLItem->pExpr;
  2858   2868         sqlite3ReleaseTempReg(pParse, regFree2);
  2859   2869         r2 = sqlite3ExprCodeTemp(pParse, pRight, &regFree2);
  2860   2870         testcase( regFree2==0 );
  2861   2871         codeCompare(pParse, pLeft, pRight, OP_Le, r1, r2, r4, SQLITE_STOREP2);
         2872  +      VdbeCoverage(v);
  2862   2873         sqlite3VdbeAddOp3(v, OP_And, r3, r4, target);
  2863   2874         sqlite3ReleaseTempReg(pParse, r3);
  2864   2875         sqlite3ReleaseTempReg(pParse, r4);
  2865   2876         break;
  2866   2877       }
  2867   2878       case TK_COLLATE: 
  2868   2879       case TK_UPLUS: {
................................................................................
  3021   3032         if( pExpr->affinity==OE_Abort ){
  3022   3033           sqlite3MayAbort(pParse);
  3023   3034         }
  3024   3035         assert( !ExprHasProperty(pExpr, EP_IntValue) );
  3025   3036         if( pExpr->affinity==OE_Ignore ){
  3026   3037           sqlite3VdbeAddOp4(
  3027   3038               v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
         3039  +        VdbeCoverage(v);
  3028   3040         }else{
  3029   3041           sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER,
  3030   3042                                 pExpr->affinity, pExpr->u.zToken, 0, 0);
  3031   3043         }
  3032   3044   
  3033   3045         break;
  3034   3046       }
................................................................................
  3609   3621         testcase( op==TK_GE );
  3610   3622         testcase( op==TK_EQ );
  3611   3623         testcase( op==TK_NE );
  3612   3624         testcase( jumpIfNull==0 );
  3613   3625         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  3614   3626         r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  3615   3627         codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  3616         -                  r1, r2, dest, jumpIfNull);
         3628  +                  r1, r2, dest, jumpIfNull);  VdbeCoverage(v);
  3617   3629         testcase( regFree1==0 );
  3618   3630         testcase( regFree2==0 );
  3619   3631         break;
  3620   3632       }
  3621   3633       case TK_IS:
  3622   3634       case TK_ISNOT: {
  3623   3635         testcase( op==TK_IS );
  3624   3636         testcase( op==TK_ISNOT );
  3625   3637         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  3626   3638         r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  3627   3639         op = (op==TK_IS) ? TK_EQ : TK_NE;
  3628   3640         codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  3629         -                  r1, r2, dest, SQLITE_NULLEQ);
         3641  +                  r1, r2, dest, SQLITE_NULLEQ);  VdbeCoverage(v);
  3630   3642         testcase( regFree1==0 );
  3631   3643         testcase( regFree2==0 );
  3632   3644         break;
  3633   3645       }
  3634   3646       case TK_ISNULL:
  3635   3647       case TK_NOTNULL: {
  3636   3648         assert( TK_ISNULL==OP_IsNull );
  3637   3649         assert( TK_NOTNULL==OP_NotNull );
  3638   3650         testcase( op==TK_ISNULL );
  3639   3651         testcase( op==TK_NOTNULL );
  3640   3652         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  3641         -      sqlite3VdbeAddOp2(v, op, r1, dest);
         3653  +      sqlite3VdbeAddOp2(v, op, r1, dest); VdbeCoverage(v);
  3642   3654         testcase( regFree1==0 );
  3643   3655         break;
  3644   3656       }
  3645   3657       case TK_BETWEEN: {
  3646   3658         testcase( jumpIfNull==0 );
  3647   3659         exprCodeBetween(pParse, pExpr, dest, 1, jumpIfNull);
  3648   3660         break;
................................................................................
  3661   3673         if( exprAlwaysTrue(pExpr) ){
  3662   3674           sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
  3663   3675         }else if( exprAlwaysFalse(pExpr) ){
  3664   3676           /* No-op */
  3665   3677         }else{
  3666   3678           r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
  3667   3679           sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
         3680  +        VdbeCoverage(v);
  3668   3681           testcase( regFree1==0 );
  3669   3682           testcase( jumpIfNull==0 );
  3670   3683         }
  3671   3684         break;
  3672   3685       }
  3673   3686     }
  3674   3687     sqlite3ReleaseTempReg(pParse, regFree1);
................................................................................
  3762   3775         testcase( op==TK_GE );
  3763   3776         testcase( op==TK_EQ );
  3764   3777         testcase( op==TK_NE );
  3765   3778         testcase( jumpIfNull==0 );
  3766   3779         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  3767   3780         r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  3768   3781         codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  3769         -                  r1, r2, dest, jumpIfNull);
         3782  +                  r1, r2, dest, jumpIfNull);  VdbeCoverage(v);
  3770   3783         testcase( regFree1==0 );
  3771   3784         testcase( regFree2==0 );
  3772   3785         break;
  3773   3786       }
  3774   3787       case TK_IS:
  3775   3788       case TK_ISNOT: {
  3776   3789         testcase( pExpr->op==TK_IS );
  3777   3790         testcase( pExpr->op==TK_ISNOT );
  3778   3791         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  3779   3792         r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  3780   3793         op = (pExpr->op==TK_IS) ? TK_NE : TK_EQ;
  3781   3794         codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  3782         -                  r1, r2, dest, SQLITE_NULLEQ);
         3795  +                  r1, r2, dest, SQLITE_NULLEQ);  VdbeCoverage(v);
  3783   3796         testcase( regFree1==0 );
  3784   3797         testcase( regFree2==0 );
  3785   3798         break;
  3786   3799       }
  3787   3800       case TK_ISNULL:
  3788   3801       case TK_NOTNULL: {
  3789   3802         testcase( op==TK_ISNULL );
  3790   3803         testcase( op==TK_NOTNULL );
  3791   3804         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  3792         -      sqlite3VdbeAddOp2(v, op, r1, dest);
         3805  +      sqlite3VdbeAddOp2(v, op, r1, dest); VdbeCoverage(v);
  3793   3806         testcase( regFree1==0 );
  3794   3807         break;
  3795   3808       }
  3796   3809       case TK_BETWEEN: {
  3797   3810         testcase( jumpIfNull==0 );
  3798   3811         exprCodeBetween(pParse, pExpr, dest, 0, jumpIfNull);
  3799   3812         break;
................................................................................
  3814   3827         if( exprAlwaysFalse(pExpr) ){
  3815   3828           sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
  3816   3829         }else if( exprAlwaysTrue(pExpr) ){
  3817   3830           /* no-op */
  3818   3831         }else{
  3819   3832           r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
  3820   3833           sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
         3834  +        VdbeCoverage(v);
  3821   3835           testcase( regFree1==0 );
  3822   3836           testcase( jumpIfNull==0 );
  3823   3837         }
  3824   3838         break;
  3825   3839       }
  3826   3840     }
  3827   3841     sqlite3ReleaseTempReg(pParse, regFree1);

Changes to src/fkey.c.

   336    336     ** to check if deleting this row resolves any outstanding violations.
   337    337     **
   338    338     ** Check if any of the key columns in the child table row are NULL. If 
   339    339     ** any are, then the constraint is considered satisfied. No need to 
   340    340     ** search for a matching row in the parent table.  */
   341    341     if( nIncr<0 ){
   342    342       sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, iOk);
          343  +    VdbeCoverage(v);
   343    344     }
   344    345     for(i=0; i<pFKey->nCol; i++){
   345    346       int iReg = aiCol[i] + regData + 1;
   346         -    sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iOk);
          347  +    sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iOk); VdbeCoverage(v);
   347    348     }
   348    349   
   349    350     if( isIgnore==0 ){
   350    351       if( pIdx==0 ){
   351    352         /* If pIdx is NULL, then the parent key is the INTEGER PRIMARY KEY
   352    353         ** column of the parent table (table pTab).  */
   353    354         int iMustBeInt;               /* Address of MustBeInt instruction */
................................................................................
   356    357         /* Invoke MustBeInt to coerce the child key value to an integer (i.e. 
   357    358         ** apply the affinity of the parent key). If this fails, then there
   358    359         ** is no matching parent key. Before using MustBeInt, make a copy of
   359    360         ** the value. Otherwise, the value inserted into the child key column
   360    361         ** will have INTEGER affinity applied to it, which may not be correct.  */
   361    362         sqlite3VdbeAddOp2(v, OP_SCopy, aiCol[0]+1+regData, regTemp);
   362    363         iMustBeInt = sqlite3VdbeAddOp2(v, OP_MustBeInt, regTemp, 0);
          364  +      VdbeCoverage(v);
   363    365     
   364    366         /* If the parent table is the same as the child table, and we are about
   365    367         ** to increment the constraint-counter (i.e. this is an INSERT operation),
   366    368         ** then check if the row being inserted matches itself. If so, do not
   367    369         ** increment the constraint-counter.  */
   368    370         if( pTab==pFKey->pFrom && nIncr==1 ){
   369         -        sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp);
          371  +        sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp); VdbeCoverage(v);
   370    372         }
   371    373     
   372    374         sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
   373         -      sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp);
          375  +      sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
   374    376         sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
   375    377         sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
   376    378         sqlite3VdbeJumpHere(v, iMustBeInt);
   377    379         sqlite3ReleaseTempReg(pParse, regTemp);
   378    380       }else{
   379    381         int nCol = pFKey->nCol;
   380    382         int regTemp = sqlite3GetTempRange(pParse, nCol);
................................................................................
   402    404             int iChild = aiCol[i]+1+regData;
   403    405             int iParent = pIdx->aiColumn[i]+1+regData;
   404    406             assert( aiCol[i]!=pTab->iPKey );
   405    407             if( pIdx->aiColumn[i]==pTab->iPKey ){
   406    408               /* The parent key is a composite key that includes the IPK column */
   407    409               iParent = regData;
   408    410             }
   409         -          sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent);
          411  +          sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent); VdbeCoverage(v);
   410    412             sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
   411    413           }
   412    414           sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
   413    415         }
   414    416     
   415    417         sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec,
   416    418                           sqlite3IndexAffinityStr(v,pIdx), nCol);
   417         -      sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0);
          419  +      sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v);
   418    420     
   419    421         sqlite3ReleaseTempReg(pParse, regRec);
   420    422         sqlite3ReleaseTempRange(pParse, regTemp, nCol);
   421    423       }
   422    424     }
   423    425   
   424    426     if( !pFKey->isDeferred && !(pParse->db->flags & SQLITE_DeferFKs)
................................................................................
   548    550     assert( pIdx==0 || pIdx->pTable==pTab );
   549    551     assert( pIdx==0 || pIdx->nKeyCol==pFKey->nCol );
   550    552     assert( pIdx!=0 || pFKey->nCol==1 );
   551    553     assert( pIdx!=0 || HasRowid(pTab) );
   552    554   
   553    555     if( nIncr<0 ){
   554    556       iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
          557  +    VdbeCoverage(v);
   555    558     }
   556    559   
   557    560     /* Create an Expr object representing an SQL expression like:
   558    561     **
   559    562     **   <parent-key1> = <child-key1> AND <parent-key2> = <child-key2> ...
   560    563     **
   561    564     ** The collation sequence used for the comparison should be that of
................................................................................
   710    713         ** when this statement is run.  */
   711    714         FKey *p;
   712    715         for(p=pTab->pFKey; p; p=p->pNextFrom){
   713    716           if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
   714    717         }
   715    718         if( !p ) return;
   716    719         iSkip = sqlite3VdbeMakeLabel(v);
   717         -      sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip);
          720  +      sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
   718    721       }
   719    722   
   720    723       pParse->disableTriggers = 1;
   721    724       sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);
   722    725       pParse->disableTriggers = 0;
   723    726   
   724    727       /* If the DELETE has generated immediate foreign key constraint 
................................................................................
   728    731       **
   729    732       ** If the SQLITE_DeferFKs flag is set, then this is not required, as
   730    733       ** the statement transaction will not be rolled back even if FK
   731    734       ** constraints are violated.
   732    735       */
   733    736       if( (db->flags & SQLITE_DeferFKs)==0 ){
   734    737         sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2);
          738  +      VdbeCoverage(v);
   735    739         sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
   736    740             OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
   737    741       }
   738    742   
   739    743       if( iSkip ){
   740    744         sqlite3VdbeResolveLabel(v, iSkip);
   741    745       }
................................................................................
   887    891           ** missing, behave as if it is empty. i.e. decrement the relevant
   888    892           ** FK counter for each row of the current table with non-NULL keys.
   889    893           */
   890    894           Vdbe *v = sqlite3GetVdbe(pParse);
   891    895           int iJump = sqlite3VdbeCurrentAddr(v) + pFKey->nCol + 1;
   892    896           for(i=0; i<pFKey->nCol; i++){
   893    897             int iReg = pFKey->aCol[i].iFrom + regOld + 1;
   894         -          sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iJump);
          898  +          sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iJump); VdbeCoverage(v);
   895    899           }
   896    900           sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, -1);
   897    901         }
   898    902         continue;
   899    903       }
   900    904       assert( pFKey->nCol==1 || (aiFree && pIdx) );
   901    905   

Changes to src/insert.c.

   258    258       pDb = &db->aDb[p->iDb];
   259    259       memId = p->regCtr;
   260    260       assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
   261    261       sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
   262    262       sqlite3VdbeAddOp3(v, OP_Null, 0, memId, memId+1);
   263    263       addr = sqlite3VdbeCurrentAddr(v);
   264    264       sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0);
   265         -    sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9);
          265  +    sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9); VdbeCoverage(v);
   266    266       sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId);
   267         -    sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId);
          267  +    sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId); VdbeCoverage(v);
   268    268       sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
   269    269       sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
   270    270       sqlite3VdbeAddOp3(v, OP_Column, 0, 1, memId);
   271    271       sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+9);
   272         -    sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2);
          272  +    sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2); VdbeCoverage(v);
   273    273       sqlite3VdbeAddOp2(v, OP_Integer, 0, memId);
   274    274       sqlite3VdbeAddOp0(v, OP_Close);
   275    275     }
   276    276   }
   277    277   
   278    278   /*
   279    279   ** Update the maximum rowid for an autoincrement calculation.
................................................................................
   307    307       int j1, j2, j3, j4, j5;
   308    308       int iRec;
   309    309       int memId = p->regCtr;
   310    310   
   311    311       iRec = sqlite3GetTempReg(pParse);
   312    312       assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
   313    313       sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
   314         -    j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1);
   315         -    j2 = sqlite3VdbeAddOp0(v, OP_Rewind);
          314  +    j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1); VdbeCoverage(v);
          315  +    j2 = sqlite3VdbeAddOp0(v, OP_Rewind); VdbeCoverage(v);
   316    316       j3 = sqlite3VdbeAddOp3(v, OP_Column, 0, 0, iRec);
   317         -    j4 = sqlite3VdbeAddOp3(v, OP_Eq, memId-1, 0, iRec);
   318         -    sqlite3VdbeAddOp2(v, OP_Next, 0, j3);
          317  +    j4 = sqlite3VdbeAddOp3(v, OP_Eq, memId-1, 0, iRec); VdbeCoverage(v);
          318  +    sqlite3VdbeAddOp2(v, OP_Next, 0, j3); VdbeCoverage(v);
   319    319       sqlite3VdbeJumpHere(v, j2);
   320    320       sqlite3VdbeAddOp2(v, OP_NewRowid, 0, memId+1);
   321    321       j5 = sqlite3VdbeAddOp0(v, OP_Goto);
   322    322       sqlite3VdbeJumpHere(v, j4);
   323    323       sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
   324    324       sqlite3VdbeJumpHere(v, j1);
   325    325       sqlite3VdbeJumpHere(v, j5);
................................................................................
   688    688         int regTempRowid;    /* Register to hold temp table ROWID */
   689    689         int addrTop;         /* Label "L" */
   690    690   
   691    691         srcTab = pParse->nTab++;
   692    692         regRec = sqlite3GetTempReg(pParse);
   693    693         regTempRowid = sqlite3GetTempReg(pParse);
   694    694         sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn);
   695         -      addrTop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
          695  +      addrTop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); VdbeCoverage(v);
   696    696         sqlite3VdbeAddOp3(v, OP_MakeRecord, regFromSelect, nColumn, regRec);
   697    697         sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, regTempRowid);
   698    698         sqlite3VdbeAddOp3(v, OP_Insert, srcTab, regRec, regTempRowid);
   699    699         sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
   700    700         sqlite3VdbeJumpHere(v, addrTop);
   701    701         sqlite3ReleaseTempReg(pParse, regRec);
   702    702         sqlite3ReleaseTempReg(pParse, regTempRowid);
................................................................................
   773    773       **
   774    774       **         rewind temp table, if empty goto D
   775    775       **      C: loop over rows of intermediate table
   776    776       **           transfer values form intermediate table into <table>
   777    777       **         end loop
   778    778       **      D: ...
   779    779       */
   780         -    addrInsTop = sqlite3VdbeAddOp1(v, OP_Rewind, srcTab);
          780  +    addrInsTop = sqlite3VdbeAddOp1(v, OP_Rewind, srcTab); VdbeCoverage(v);
   781    781       addrCont = sqlite3VdbeCurrentAddr(v);
   782    782     }else if( pSelect ){
   783    783       /* This block codes the top of loop only.  The complete loop is the
   784    784       ** following pseudocode (template 3):
   785    785       **
   786    786       **      C: yield X, at EOF goto D
   787    787       **         insert the select result into <table> from R..R+n
   788    788       **         goto C
   789    789       **      D: ...
   790    790       */
   791    791       addrInsTop = addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
          792  +    VdbeCoverage(v);
   792    793     }
   793    794   
   794    795     /* Run the BEFORE and INSTEAD OF triggers, if there are any
   795    796     */
   796    797     endOfLoop = sqlite3VdbeMakeLabel(v);
   797    798     if( tmask & TRIGGER_BEFORE ){
   798    799       int regCols = sqlite3GetTempRange(pParse, pTab->nCol+1);
................................................................................
   810    811         assert( !withoutRowid );
   811    812         if( useTempTable ){
   812    813           sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regCols);
   813    814         }else{
   814    815           assert( pSelect==0 );  /* Otherwise useTempTable is true */
   815    816           sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regCols);
   816    817         }
   817         -      j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols);
          818  +      j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols); VdbeCoverage(v);
   818    819         sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
   819    820         sqlite3VdbeJumpHere(v, j1);
   820         -      sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols);
          821  +      sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols); VdbeCoverage(v);
   821    822       }
   822    823   
   823    824       /* Cannot have triggers on a virtual table. If it were possible,
   824    825       ** this block would have to account for hidden column.
   825    826       */
   826    827       assert( !IsVirtual(pTab) );
   827    828   
................................................................................
   888    889         }
   889    890         /* If the PRIMARY KEY expression is NULL, then use OP_NewRowid
   890    891         ** to generate a unique primary key value.
   891    892         */
   892    893         if( !appendFlag ){
   893    894           int j1;
   894    895           if( !IsVirtual(pTab) ){
   895         -          j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid);
          896  +          j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid); VdbeCoverage(v);
   896    897             sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
   897    898             sqlite3VdbeJumpHere(v, j1);
   898    899           }else{
   899    900             j1 = sqlite3VdbeCurrentAddr(v);
   900         -          sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2);
          901  +          sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2); VdbeCoverage(v);
   901    902           }
   902         -        sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid);
          903  +        sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid); VdbeCoverage(v);
   903    904         }
   904    905       }else if( IsVirtual(pTab) || withoutRowid ){
   905    906         sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
   906    907       }else{
   907    908         sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
   908    909         appendFlag = 1;
   909    910       }
................................................................................
   986    987     }
   987    988   
   988    989     /* The bottom of the main insertion loop, if the data source
   989    990     ** is a SELECT statement.
   990    991     */
   991    992     sqlite3VdbeResolveLabel(v, endOfLoop);
   992    993     if( useTempTable ){
   993         -    sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont);
          994  +    sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v);
   994    995       sqlite3VdbeJumpHere(v, addrInsTop);
   995    996       sqlite3VdbeAddOp1(v, OP_Close, srcTab);
   996    997     }else if( pSelect ){
   997    998       sqlite3VdbeAddOp2(v, OP_Goto, 0, addrCont);
   998    999       sqlite3VdbeJumpHere(v, addrInsTop);
   999   1000     }
  1000   1001   
................................................................................
  1208   1209         case OE_Rollback:
  1209   1210         case OE_Fail: {
  1210   1211           char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
  1211   1212                                       pTab->aCol[i].zName);
  1212   1213           sqlite3VdbeAddOp4(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError,
  1213   1214                             regNewData+1+i, zMsg, P4_DYNAMIC);
  1214   1215           sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
         1216  +        VdbeCoverage(v);
  1215   1217           break;
  1216   1218         }
  1217   1219         case OE_Ignore: {
  1218   1220           sqlite3VdbeAddOp2(v, OP_IsNull, regNewData+1+i, ignoreDest);
         1221  +        VdbeCoverage(v);
  1219   1222           break;
  1220   1223         }
  1221   1224         default: {
  1222   1225           assert( onError==OE_Replace );
  1223         -        j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regNewData+1+i);
         1226  +        j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regNewData+1+i); VdbeCoverage(v);
  1224   1227           sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
  1225   1228           sqlite3VdbeJumpHere(v, j1);
  1226   1229           break;
  1227   1230         }
  1228   1231       }
  1229   1232     }
  1230   1233   
................................................................................
  1268   1271       }
  1269   1272   
  1270   1273       if( isUpdate ){
  1271   1274         /* pkChng!=0 does not mean that the rowid has change, only that
  1272   1275         ** it might have changed.  Skip the conflict logic below if the rowid
  1273   1276         ** is unchanged. */
  1274   1277         sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
         1278  +      VdbeCoverage(v);
  1275   1279       }
  1276   1280   
  1277   1281       /* If the response to a rowid conflict is REPLACE but the response
  1278   1282       ** to some other UNIQUE constraint is FAIL or IGNORE, then we need
  1279   1283       ** to defer the running of the rowid conflict checking until after
  1280   1284       ** the UNIQUE constraints have run.
  1281   1285       */
................................................................................
  1287   1291           }
  1288   1292         }
  1289   1293       }
  1290   1294   
  1291   1295       /* Check to see if the new rowid already exists in the table.  Skip
  1292   1296       ** the following conflict logic if it does not. */
  1293   1297       sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData);
         1298  +    VdbeCoverage(v);
  1294   1299   
  1295   1300       /* Generate code that deals with a rowid collision */
  1296   1301       switch( onError ){
  1297   1302         default: {
  1298   1303           onError = OE_Abort;
  1299   1304           /* Fall thru into the next case */
  1300   1305         }
................................................................................
  1426   1431         onError = overrideError;
  1427   1432       }else if( onError==OE_Default ){
  1428   1433         onError = OE_Abort;
  1429   1434       }
  1430   1435       
  1431   1436       /* Check to see if the new index entry will be unique */
  1432   1437       sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
  1433         -                         regIdx, pIdx->nKeyCol);
         1438  +                         regIdx, pIdx->nKeyCol); VdbeCoverage(v);
  1434   1439   
  1435   1440       /* Generate code to handle collisions */
  1436   1441       regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
  1437   1442       if( isUpdate || onError==OE_Replace ){
  1438   1443         if( HasRowid(pTab) ){
  1439   1444           sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
  1440   1445           /* Conflict only if the rowid of the existing index entry
  1441   1446           ** is different from old-rowid */
  1442   1447           if( isUpdate ){
  1443   1448             sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
         1449  +          VdbeCoverage(v);
  1444   1450           }
  1445   1451         }else{
  1446   1452           int x;
  1447   1453           /* Extract the PRIMARY KEY from the end of the index entry and
  1448   1454           ** store it in registers regR..regR+nPk-1 */
  1449   1455           if( pIdx!=pPk ){
  1450   1456             for(i=0; i<pPk->nKeyCol; i++){
................................................................................
  1471   1477               x = pPk->aiColumn[i];
  1472   1478               if( i==(pPk->nKeyCol-1) ){
  1473   1479                 addrJump = addrUniqueOk;
  1474   1480                 op = OP_Eq;
  1475   1481               }
  1476   1482               sqlite3VdbeAddOp4(v, op, 
  1477   1483                   regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
  1478         -            );
         1484  +            );  VdbeCoverage(v);
  1479   1485             }
  1480   1486           }
  1481   1487         }
  1482   1488       }
  1483   1489   
  1484   1490       /* Generate code that executes if the new index entry is not unique */
  1485   1491       assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
................................................................................
  1553   1559     assert( v!=0 );
  1554   1560     assert( pTab->pSelect==0 );  /* This table is not a VIEW */
  1555   1561     for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
  1556   1562       if( aRegIdx[i]==0 ) continue;
  1557   1563       bAffinityDone = 1;
  1558   1564       if( pIdx->pPartIdxWhere ){
  1559   1565         sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
         1566  +      VdbeCoverage(v);
  1560   1567       }
  1561   1568       sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]);
  1562   1569       pik_flags = 0;
  1563   1570       if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
  1564   1571       if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
  1565   1572         assert( pParse->nested==0 );
  1566   1573         pik_flags |= OPFLAG_NCHANGE;
................................................................................
  1936   1943       **     of index entries might need to change.)
  1937   1944       **
  1938   1945       ** (2) The destination has a unique index.  (The xfer optimization 
  1939   1946       **     is unable to test uniqueness.)
  1940   1947       **
  1941   1948       ** (3) onError is something other than OE_Abort and OE_Rollback.
  1942   1949       */
  1943         -    addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0);
         1950  +    addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
  1944   1951       emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
  1945   1952       sqlite3VdbeJumpHere(v, addr1);
  1946   1953     }
  1947   1954     if( HasRowid(pSrc) ){
  1948   1955       sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
  1949         -    emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
         1956  +    emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
  1950   1957       if( pDest->iPKey>=0 ){
  1951   1958         addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
  1952   1959         addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
         1960  +      VdbeCoverage(v);
  1953   1961         sqlite3RowidConstraint(pParse, onError, pDest);
  1954   1962         sqlite3VdbeJumpHere(v, addr2);
  1955   1963         autoIncStep(pParse, regAutoinc, regRowid);
  1956   1964       }else if( pDest->pIndex==0 ){
  1957   1965         addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
  1958   1966       }else{
  1959   1967         addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
  1960   1968         assert( (pDest->tabFlags & TF_Autoincrement)==0 );
  1961   1969       }
  1962   1970       sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
  1963   1971       sqlite3VdbeAddOp3(v, OP_Insert, iDest, regData, regRowid);
  1964   1972       sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND);
  1965   1973       sqlite3VdbeChangeP4(v, -1, pDest->zName, 0);
  1966         -    sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1);
         1974  +    sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v);
  1967   1975       sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
  1968   1976       sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
  1969   1977     }else{
  1970   1978       sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
  1971   1979       sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
  1972   1980     }
  1973   1981     for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
................................................................................
  1978   1986       sqlite3VdbeAddOp3(v, OP_OpenRead, iSrc, pSrcIdx->tnum, iDbSrc);
  1979   1987       sqlite3VdbeSetP4KeyInfo(pParse, pSrcIdx);
  1980   1988       VdbeComment((v, "%s", pSrcIdx->zName));
  1981   1989       sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
  1982   1990       sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
  1983   1991       sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
  1984   1992       VdbeComment((v, "%s", pDestIdx->zName));
  1985         -    addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
         1993  +    addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
  1986   1994       sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
  1987   1995       sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
  1988         -    sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1);
         1996  +    sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
  1989   1997       sqlite3VdbeJumpHere(v, addr1);
  1990   1998       sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
  1991   1999       sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
  1992   2000     }
  1993   2001     if( emptySrcTest ) sqlite3VdbeJumpHere(v, emptySrcTest);
  1994   2002     sqlite3ReleaseTempReg(pParse, regRowid);
  1995   2003     sqlite3ReleaseTempReg(pParse, regData);

Changes to src/main.c.

  3303   3303       ** that demonstrat invariants on well-formed database files.
  3304   3304       */
  3305   3305       case SQLITE_TESTCTRL_NEVER_CORRUPT: {
  3306   3306         sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int);
  3307   3307         break;
  3308   3308       }
  3309   3309   
         3310  +
         3311  +    /*   sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, xCallback, ptr);
         3312  +    **
         3313  +    ** Set the VDBE coverage callback function to xCallback with context 
         3314  +    ** pointer ptr.
         3315  +    */
         3316  +    case SQLITE_TESTCTRL_VDBE_COVERAGE: {
         3317  +#ifdef SQLITE_VDBE_COVERAGE
         3318  +      typedef void (*branch_callback)(void*,int,u8,u8);
         3319  +      sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback);
         3320  +      sqlite3GlobalConfig.pVdbeBranchArg = va_arg(ap,void*);
         3321  +#endif
         3322  +      break;
         3323  +    }
         3324  +
  3310   3325     }
  3311   3326     va_end(ap);
  3312   3327   #endif /* SQLITE_OMIT_BUILTIN_TEST */
  3313   3328     return rc;
  3314   3329   }
  3315   3330   
  3316   3331   /*

Changes to src/pragma.c.

   820    820     ** Older versions of SQLite would set the default cache size to a
   821    821     ** negative number to indicate synchronous=OFF.  These days, synchronous
   822    822     ** is always on by default regardless of the sign of the default cache
   823    823     ** size.  But continue to take the absolute value of the default cache
   824    824     ** size of historical compatibility.
   825    825     */
   826    826     case PragTyp_DEFAULT_CACHE_SIZE: {
          827  +    static const int iLn = __LINE__+2;
   827    828       static const VdbeOpList getCacheSize[] = {
   828    829         { OP_Transaction, 0, 0,        0},                         /* 0 */
   829    830         { OP_ReadCookie,  0, 1,        BTREE_DEFAULT_CACHE_SIZE},  /* 1 */
   830    831         { OP_IfPos,       1, 8,        0},
   831    832         { OP_Integer,     0, 2,        0},
   832    833         { OP_Subtract,    1, 2,        1},
   833    834         { OP_IfPos,       1, 8,        0},
................................................................................
   837    838       };
   838    839       int addr;
   839    840       sqlite3VdbeUsesBtree(v, iDb);
   840    841       if( !zRight ){
   841    842         sqlite3VdbeSetNumCols(v, 1);
   842    843         sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
   843    844         pParse->nMem += 2;
   844         -      addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
          845  +      addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn);
   845    846         sqlite3VdbeChangeP1(v, addr, iDb);
   846    847         sqlite3VdbeChangeP1(v, addr+1, iDb);
   847    848         sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
   848    849       }else{
   849    850         int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
   850    851         sqlite3BeginWriteOperation(pParse, 0, iDb);
   851    852         sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
................................................................................
  1082   1083         rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto);
  1083   1084         if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){
  1084   1085           /* When setting the auto_vacuum mode to either "full" or 
  1085   1086           ** "incremental", write the value of meta[6] in the database
  1086   1087           ** file. Before writing to meta[6], check that meta[3] indicates
  1087   1088           ** that this really is an auto-vacuum capable database.
  1088   1089           */
         1090  +        static const int iLn = __LINE__+2;
  1089   1091           static const VdbeOpList setMeta6[] = {
  1090   1092             { OP_Transaction,    0,         1,                 0},    /* 0 */
  1091   1093             { OP_ReadCookie,     0,         1,         BTREE_LARGEST_ROOT_PAGE},
  1092   1094             { OP_If,             1,         0,                 0},    /* 2 */
  1093   1095             { OP_Halt,           SQLITE_OK, OE_Abort,          0},    /* 3 */
  1094   1096             { OP_Integer,        0,         1,                 0},    /* 4 */
  1095   1097             { OP_SetCookie,      0,         BTREE_INCR_VACUUM, 1},    /* 5 */
  1096   1098           };
  1097   1099           int iAddr;
  1098         -        iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6);
         1100  +        iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn);
  1099   1101           sqlite3VdbeChangeP1(v, iAddr, iDb);
  1100   1102           sqlite3VdbeChangeP1(v, iAddr+1, iDb);
  1101   1103           sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4);
  1102   1104           sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1);
  1103   1105           sqlite3VdbeChangeP1(v, iAddr+5, iDb);
  1104   1106           sqlite3VdbeUsesBtree(v, iDb);
  1105   1107         }
................................................................................
  1117   1119     case PragTyp_INCREMENTAL_VACUUM: {
  1118   1120       int iLimit, addr;
  1119   1121       if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
  1120   1122         iLimit = 0x7fffffff;
  1121   1123       }
  1122   1124       sqlite3BeginWriteOperation(pParse, 0, iDb);
  1123   1125       sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
  1124         -    addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb);
         1126  +    addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb); VdbeCoverage(v);
  1125   1127       sqlite3VdbeAddOp1(v, OP_ResultRow, 1);
  1126   1128       sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
  1127         -    sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr);
         1129  +    sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr); VdbeCoverage(v);
  1128   1130       sqlite3VdbeJumpHere(v, addr);
  1129   1131       break;
  1130   1132     }
  1131   1133   #endif
  1132   1134   
  1133   1135   #ifndef SQLITE_OMIT_PAGER_PRAGMAS
  1134   1136     /*
................................................................................
  1691   1693             k = 0;
  1692   1694             break;
  1693   1695           }
  1694   1696         }
  1695   1697         assert( pParse->nErr>0 || pFK==0 );
  1696   1698         if( pFK ) break;
  1697   1699         if( pParse->nTab<i ) pParse->nTab = i;
  1698         -      addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0);
         1700  +      addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
  1699   1701         for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
  1700   1702           pParent = sqlite3FindTable(db, pFK->zTo, zDb);
  1701   1703           pIdx = 0;
  1702   1704           aiCols = 0;
  1703   1705           if( pParent ){
  1704   1706             x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
  1705   1707             assert( x==0 );
................................................................................
  1707   1709           addrOk = sqlite3VdbeMakeLabel(v);
  1708   1710           if( pParent && pIdx==0 ){
  1709   1711             int iKey = pFK->aCol[0].iFrom;
  1710   1712             assert( iKey>=0 && iKey<pTab->nCol );
  1711   1713             if( iKey!=pTab->iPKey ){
  1712   1714               sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow);
  1713   1715               sqlite3ColumnDefault(v, pTab, iKey, regRow);
  1714         -            sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk);
  1715         -            sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow,
  1716         -               sqlite3VdbeCurrentAddr(v)+3);
         1716  +            sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v);
         1717  +            sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow, 
         1718  +               sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v);
  1717   1719             }else{
  1718   1720               sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
  1719   1721             }
  1720         -          sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow);
         1722  +          sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v);
  1721   1723             sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk);
  1722   1724             sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
  1723   1725           }else{
  1724   1726             for(j=0; j<pFK->nCol; j++){
  1725   1727               sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
  1726   1728                               aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
  1727         -            sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk);
         1729  +            sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
  1728   1730             }
  1729   1731             if( pParent ){
  1730   1732               sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
  1731   1733                                 sqlite3IndexAffinityStr(v,pIdx), pFK->nCol);
  1732   1734               sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
         1735  +            VdbeCoverage(v);
  1733   1736             }
  1734   1737           }
  1735   1738           sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
  1736   1739           sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0, 
  1737   1740                             pFK->zTo, P4_TRANSIENT);
  1738   1741           sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3);
  1739   1742           sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
  1740   1743           sqlite3VdbeResolveLabel(v, addrOk);
  1741   1744           sqlite3DbFree(db, aiCols);
  1742   1745         }
  1743         -      sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1);
         1746  +      sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
  1744   1747         sqlite3VdbeJumpHere(v, addrTop);
  1745   1748       }
  1746   1749     }
  1747   1750     break;
  1748   1751   #endif /* !defined(SQLITE_OMIT_TRIGGER) */
  1749   1752   #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
  1750   1753   
................................................................................
  1783   1786     case PragTyp_INTEGRITY_CHECK: {
  1784   1787       int i, j, addr, mxErr;
  1785   1788   
  1786   1789       /* Code that appears at the end of the integrity check.  If no error
  1787   1790       ** messages have been generated, output OK.  Otherwise output the
  1788   1791       ** error message
  1789   1792       */
         1793  +    static const int iLn = __LINE__+2;
  1790   1794       static const VdbeOpList endCode[] = {
  1791   1795         { OP_AddImm,      1, 0,        0},    /* 0 */
  1792   1796         { OP_IfNeg,       1, 0,        0},    /* 1 */
  1793   1797         { OP_String8,     0, 3,        0},    /* 2 */
  1794   1798         { OP_ResultRow,   3, 1,        0},
  1795   1799       };
  1796   1800   
................................................................................
  1831   1835         int cnt = 0;
  1832   1836   
  1833   1837         if( OMIT_TEMPDB && i==1 ) continue;
  1834   1838         if( iDb>=0 && i!=iDb ) continue;
  1835   1839   
  1836   1840         sqlite3CodeVerifySchema(pParse, i);
  1837   1841         addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */
         1842  +      VdbeCoverage(v);
  1838   1843         sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
  1839   1844         sqlite3VdbeJumpHere(v, addr);
  1840   1845   
  1841   1846         /* Do an integrity check of the B-Tree
  1842   1847         **
  1843   1848         ** Begin by filling registers 2, 3, ... with the root pages numbers
  1844   1849         ** for all tables and indices in the database.
................................................................................
  1862   1867   
  1863   1868         /* Make sure sufficient number of registers have been allocated */
  1864   1869         pParse->nMem = MAX( pParse->nMem, cnt+8 );
  1865   1870   
  1866   1871         /* Do the b-tree integrity checks */
  1867   1872         sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1);
  1868   1873         sqlite3VdbeChangeP5(v, (u8)i);
  1869         -      addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2);
         1874  +      addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
  1870   1875         sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
  1871   1876            sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
  1872   1877            P4_DYNAMIC);
  1873   1878         sqlite3VdbeAddOp2(v, OP_Move, 2, 4);
  1874   1879         sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
  1875   1880         sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1);
  1876   1881         sqlite3VdbeJumpHere(v, addr);
................................................................................
  1884   1889           int loopTop;
  1885   1890           int iDataCur, iIdxCur;
  1886   1891           int r1 = -1;
  1887   1892   
  1888   1893           if( pTab->pIndex==0 ) continue;
  1889   1894           pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
  1890   1895           addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1);  /* Stop if out of errors */
         1896  +        VdbeCoverage(v);
  1891   1897           sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
  1892   1898           sqlite3VdbeJumpHere(v, addr);
  1893   1899           sqlite3ExprCacheClear(pParse);
  1894   1900           sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
  1895   1901                                      1, 0, &iDataCur, &iIdxCur);
  1896   1902           sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
  1897   1903           for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
  1898   1904             sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
  1899   1905           }
  1900   1906           pParse->nMem = MAX(pParse->nMem, 8+j);
  1901         -        sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0);
         1907  +        sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
  1902   1908           loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
  1903   1909           for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
  1904   1910             int jmp2, jmp3, jmp4;
  1905   1911             if( pPk==pIdx ) continue;
  1906   1912             r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
  1907   1913                                          pPrior, r1);
  1908   1914             pPrior = pIdx;
  1909   1915             sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1);  /* increment entry count */
  1910   1916             jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, 0, r1,
  1911         -                                      pIdx->nColumn);
         1917  +                                      pIdx->nColumn); VdbeCoverage(v);
  1912   1918             sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
  1913   1919             sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC);
  1914   1920             sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
  1915   1921             sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, " missing from index ",
  1916   1922                               P4_STATIC);
  1917   1923             sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
  1918   1924             sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, pIdx->zName, P4_TRANSIENT);
  1919   1925             sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
  1920   1926             sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
  1921         -          jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1);
         1927  +          jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
  1922   1928             sqlite3VdbeAddOp0(v, OP_Halt);
  1923   1929             sqlite3VdbeJumpHere(v, jmp4);
  1924   1930             sqlite3VdbeJumpHere(v, jmp2);
  1925   1931             sqlite3VdbeResolveLabel(v, jmp3);
  1926   1932           }
  1927         -        sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop);
         1933  +        sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
  1928   1934           sqlite3VdbeJumpHere(v, loopTop-1);
  1929   1935   #ifndef SQLITE_OMIT_BTREECOUNT
  1930   1936           sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, 
  1931   1937                        "wrong # of entries in index ", P4_STATIC);
  1932   1938           for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
  1933   1939             if( pPk==pIdx ) continue;
  1934   1940             addr = sqlite3VdbeCurrentAddr(v);
  1935         -          sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2);
         1941  +          sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v);
  1936   1942             sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
  1937   1943             sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
  1938         -          sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3);
         1944  +          sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v);
  1939   1945             sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
  1940   1946             sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT);
  1941   1947             sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
  1942   1948             sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
  1943   1949           }
  1944   1950   #endif /* SQLITE_OMIT_BTREECOUNT */
  1945   1951         } 
  1946   1952       }
  1947         -    addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
         1953  +    addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
  1948   1954       sqlite3VdbeChangeP2(v, addr, -mxErr);
  1949   1955       sqlite3VdbeJumpHere(v, addr+1);
  1950   1956       sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
  1951   1957     }
  1952   1958     break;
  1953   1959   #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
  1954   1960   
................................................................................
  2078   2084       if( zRight && iCookie!=BTREE_FREE_PAGE_COUNT ){
  2079   2085         /* Write the specified cookie value */
  2080   2086         static const VdbeOpList setCookie[] = {
  2081   2087           { OP_Transaction,    0,  1,  0},    /* 0 */
  2082   2088           { OP_Integer,        0,  1,  0},    /* 1 */
  2083   2089           { OP_SetCookie,      0,  0,  1},    /* 2 */
  2084   2090         };
  2085         -      int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie);
         2091  +      int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0);
  2086   2092         sqlite3VdbeChangeP1(v, addr, iDb);
  2087   2093         sqlite3VdbeChangeP1(v, addr+1, sqlite3Atoi(zRight));
  2088   2094         sqlite3VdbeChangeP1(v, addr+2, iDb);
  2089   2095         sqlite3VdbeChangeP2(v, addr+2, iCookie);
  2090   2096       }else{
  2091   2097         /* Read the specified cookie value */
  2092   2098         static const VdbeOpList readCookie[] = {
  2093   2099           { OP_Transaction,     0,  0,  0},    /* 0 */
  2094   2100           { OP_ReadCookie,      0,  1,  0},    /* 1 */
  2095   2101           { OP_ResultRow,       1,  1,  0}
  2096   2102         };
  2097         -      int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
         2103  +      int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie, 0);
  2098   2104         sqlite3VdbeChangeP1(v, addr, iDb);
  2099   2105         sqlite3VdbeChangeP1(v, addr+1, iDb);
  2100   2106         sqlite3VdbeChangeP3(v, addr+1, iCookie);
  2101   2107         sqlite3VdbeSetNumCols(v, 1);
  2102   2108         sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
  2103   2109       }
  2104   2110     }

Changes to src/select.c.

   451    451       int addr1, addr2;
   452    452       int iLimit;
   453    453       if( pSelect->iOffset ){
   454    454         iLimit = pSelect->iOffset+1;
   455    455       }else{
   456    456         iLimit = pSelect->iLimit;
   457    457       }
   458         -    addr1 = sqlite3VdbeAddOp1(v, OP_IfZero, iLimit);
          458  +    addr1 = sqlite3VdbeAddOp1(v, OP_IfZero, iLimit); VdbeCoverage(v);
   459    459       sqlite3VdbeAddOp2(v, OP_AddImm, iLimit, -1);
   460    460       addr2 = sqlite3VdbeAddOp0(v, OP_Goto);
   461    461       sqlite3VdbeJumpHere(v, addr1);
   462    462       sqlite3VdbeAddOp1(v, OP_Last, pOrderBy->iECursor);
   463    463       sqlite3VdbeAddOp1(v, OP_Delete, pOrderBy->iECursor);
   464    464       sqlite3VdbeJumpHere(v, addr2);
   465    465     }
................................................................................
   472    472     Vdbe *v,          /* Generate code into this VM */
   473    473     int iOffset,      /* Register holding the offset counter */
   474    474     int iContinue     /* Jump here to skip the current record */
   475    475   ){
   476    476     if( iOffset>0 && iContinue!=0 ){
   477    477       int addr;
   478    478       sqlite3VdbeAddOp2(v, OP_AddImm, iOffset, -1);
   479         -    addr = sqlite3VdbeAddOp1(v, OP_IfNeg, iOffset);
          479  +    addr = sqlite3VdbeAddOp1(v, OP_IfNeg, iOffset); VdbeCoverage(v);
   480    480       sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
   481    481       VdbeComment((v, "skip OFFSET records"));
   482    482       sqlite3VdbeJumpHere(v, addr);
   483    483     }
   484    484   }
   485    485   
   486    486   /*
................................................................................
   500    500     int iMem           /* First element */
   501    501   ){
   502    502     Vdbe *v;
   503    503     int r1;
   504    504   
   505    505     v = pParse->pVdbe;
   506    506     r1 = sqlite3GetTempReg(pParse);
   507         -  sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N);
          507  +  sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v);
   508    508     sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
   509    509     sqlite3VdbeAddOp2(v, OP_IdxInsert, iTab, r1);
   510    510     sqlite3ReleaseTempReg(pParse, r1);
   511    511   }
   512    512   
   513    513   #ifndef SQLITE_OMIT_SUBQUERY
   514    514   /*
................................................................................
   640    640           pOp->p2 = regPrev;
   641    641   
   642    642           iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
   643    643           for(i=0; i<nResultCol; i++){
   644    644             CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
   645    645             if( i<nResultCol-1 ){
   646    646               sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
          647  +            VdbeCoverage(v);
   647    648             }else{
   648    649               sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
   649         -          }
          650  +            VdbeCoverage(v);
          651  +           }
   650    652             sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
   651    653             sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
   652    654           }
   653    655           assert( sqlite3VdbeCurrentAddr(v)==iJump );
   654    656           sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nResultCol-1);
   655    657           break;
   656    658         }
................................................................................
   708    710         if( eDest==SRT_DistTable ){
   709    711           /* If the destination is DistTable, then cursor (iParm+1) is open
   710    712           ** on an ephemeral index. If the current row is already present
   711    713           ** in the index, do not write it to the output. If not, add the
   712    714           ** current row to the index and proceed with writing it to the
   713    715           ** output table as well.  */
   714    716           int addr = sqlite3VdbeCurrentAddr(v) + 4;
   715         -        sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0);
          717  +        sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0); VdbeCoverage(v);
   716    718           sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r1);
   717    719           assert( pOrderBy==0 );
   718    720         }
   719    721   #endif
   720    722         if( pOrderBy ){
   721    723           pushOntoSorter(pParse, pOrderBy, p, r1);
   722    724         }else{
................................................................................
   819    821         sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3);
   820    822         if( eDest==SRT_DistQueue ){
   821    823           /* If the destination is DistQueue, then cursor (iParm+1) is open
   822    824           ** on a second ephemeral index that holds all values every previously
   823    825           ** added to the queue.  Only add this new value if it has never before
   824    826           ** been added */
   825    827           addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0, r3, 0);
          828  +        VdbeCoverage(v);
   826    829           sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r3);
   827    830           sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
   828    831         }
   829    832         for(i=0; i<nKey; i++){
   830    833           sqlite3VdbeAddOp2(v, OP_SCopy,
   831    834                             regResult + pSO->a[i].u.x.iOrderByCol - 1,
   832    835                             r2+i);
................................................................................
   857    860     }
   858    861   
   859    862     /* Jump to the end of the loop if the LIMIT is reached.  Except, if
   860    863     ** there is a sorter, in which case the sorter has already limited
   861    864     ** the output for us.
   862    865     */
   863    866     if( pOrderBy==0 && p->iLimit ){
   864         -    sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
          867  +    sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v);
   865    868     }
   866    869   }
   867    870   
   868    871   /*
   869    872   ** Allocate a KeyInfo object sufficient for an index of N key columns and
   870    873   ** X extra columns.
   871    874   */
................................................................................
  1076   1079       regRowid = sqlite3GetTempReg(pParse);
  1077   1080     }
  1078   1081     if( p->selFlags & SF_UseSorter ){
  1079   1082       int regSortOut = ++pParse->nMem;
  1080   1083       int ptab2 = pParse->nTab++;
  1081   1084       sqlite3VdbeAddOp3(v, OP_OpenPseudo, ptab2, regSortOut, pOrderBy->nExpr+2);
  1082   1085       addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
         1086  +    VdbeCoverage(v);
  1083   1087       codeOffset(v, p->iOffset, addrContinue);
  1084   1088       sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut);
  1085   1089       sqlite3VdbeAddOp3(v, OP_Column, ptab2, pOrderBy->nExpr+1, regRow);
  1086   1090       sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
  1087   1091     }else{
  1088         -    addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak);
         1092  +    addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
  1089   1093       codeOffset(v, p->iOffset, addrContinue);
  1090   1094       sqlite3VdbeAddOp3(v, OP_Column, iTab, pOrderBy->nExpr+1, regRow);
  1091   1095     }
  1092   1096     switch( eDest ){
  1093   1097       case SRT_Table:
  1094   1098       case SRT_EphemTab: {
  1095   1099         testcase( eDest==SRT_Table );
................................................................................
  1139   1143     sqlite3ReleaseTempReg(pParse, regRow);
  1140   1144     sqlite3ReleaseTempReg(pParse, regRowid);
  1141   1145   
  1142   1146     /* The bottom of the loop
  1143   1147     */
  1144   1148     sqlite3VdbeResolveLabel(v, addrContinue);
  1145   1149     if( p->selFlags & SF_UseSorter ){
  1146         -    sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr);
         1150  +    sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr); VdbeCoverage(v);
  1147   1151     }else{
  1148         -    sqlite3VdbeAddOp2(v, OP_Next, iTab, addr);
         1152  +    sqlite3VdbeAddOp2(v, OP_Next, iTab, addr); VdbeCoverage(v);
  1149   1153     }
  1150   1154     sqlite3VdbeResolveLabel(v, addrBreak);
  1151   1155     if( eDest==SRT_Output || eDest==SRT_Coroutine ){
  1152   1156       sqlite3VdbeAddOp2(v, OP_Close, pseudoTab, 0);
  1153   1157     }
  1154   1158   }
  1155   1159   
................................................................................
  1689   1693         if( n==0 ){
  1690   1694           sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
  1691   1695         }else if( n>=0 && p->nSelectRow>(u64)n ){
  1692   1696           p->nSelectRow = n;
  1693   1697         }
  1694   1698       }else{
  1695   1699         sqlite3ExprCode(pParse, p->pLimit, iLimit);
  1696         -      sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit);
         1700  +      sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
  1697   1701         VdbeComment((v, "LIMIT counter"));
  1698         -      sqlite3VdbeAddOp2(v, OP_IfZero, iLimit, iBreak);
         1702  +      sqlite3VdbeAddOp2(v, OP_IfZero, iLimit, iBreak); VdbeCoverage(v);
  1699   1703       }
  1700   1704       if( p->pOffset ){
  1701   1705         p->iOffset = iOffset = ++pParse->nMem;
  1702   1706         pParse->nMem++;   /* Allocate an extra register for limit+offset */
  1703   1707         sqlite3ExprCode(pParse, p->pOffset, iOffset);
  1704         -      sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset);
         1708  +      sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v);
  1705   1709         VdbeComment((v, "OFFSET counter"));
  1706         -      addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iOffset);
         1710  +      addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iOffset); VdbeCoverage(v);
  1707   1711         sqlite3VdbeAddOp2(v, OP_Integer, 0, iOffset);
  1708   1712         sqlite3VdbeJumpHere(v, addr1);
  1709   1713         sqlite3VdbeAddOp3(v, OP_Add, iLimit, iOffset, iOffset+1);
  1710   1714         VdbeComment((v, "LIMIT+OFFSET"));
  1711         -      addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iLimit);
         1715  +      addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iLimit); VdbeCoverage(v);
  1712   1716         sqlite3VdbeAddOp2(v, OP_Integer, -1, iOffset+1);
  1713   1717         sqlite3VdbeJumpHere(v, addr1);
  1714   1718       }
  1715   1719     }
  1716   1720   }
  1717   1721   
  1718   1722   #ifndef SQLITE_OMIT_COMPOUND_SELECT
................................................................................
  1893   1897     /* Store the results of the setup-query in Queue. */
  1894   1898     pSetup->pNext = 0;
  1895   1899     rc = sqlite3Select(pParse, pSetup, &destQueue);
  1896   1900     pSetup->pNext = p;
  1897   1901     if( rc ) goto end_of_recursive_query;
  1898   1902   
  1899   1903     /* Find the next row in the Queue and output that row */
  1900         -  addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iQueue, addrBreak);
         1904  +  addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iQueue, addrBreak); VdbeCoverage(v);
  1901   1905   
  1902   1906     /* Transfer the next row in Queue over to Current */
  1903   1907     sqlite3VdbeAddOp1(v, OP_NullRow, iCurrent); /* To reset column cache */
  1904   1908     if( pOrderBy ){
  1905   1909       sqlite3VdbeAddOp3(v, OP_Column, iQueue, pOrderBy->nExpr+1, regCurrent);
  1906   1910     }else{
  1907   1911       sqlite3VdbeAddOp2(v, OP_RowData, iQueue, regCurrent);
................................................................................
  1909   1913     sqlite3VdbeAddOp1(v, OP_Delete, iQueue);
  1910   1914   
  1911   1915     /* Output the single row in Current */
  1912   1916     addrCont = sqlite3VdbeMakeLabel(v);
  1913   1917     codeOffset(v, regOffset, addrCont);
  1914   1918     selectInnerLoop(pParse, p, p->pEList, iCurrent,
  1915   1919         0, 0, pDest, addrCont, addrBreak);
  1916         -  if( regLimit ) sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1);
         1920  +  if( regLimit ){
         1921  +    sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1);
         1922  +    VdbeCoverage(v);
         1923  +  }
  1917   1924     sqlite3VdbeResolveLabel(v, addrCont);
  1918   1925   
  1919   1926     /* Execute the recursive SELECT taking the single row in Current as
  1920   1927     ** the value for the recursive-table. Store the results in the Queue.
  1921   1928     */
  1922   1929     p->pPrior = 0;
  1923   1930     sqlite3Select(pParse, p, &destQueue);
................................................................................
  2069   2076         if( rc ){
  2070   2077           goto multi_select_end;
  2071   2078         }
  2072   2079         p->pPrior = 0;
  2073   2080         p->iLimit = pPrior->iLimit;
  2074   2081         p->iOffset = pPrior->iOffset;
  2075   2082         if( p->iLimit ){
  2076         -        addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit);
         2083  +        addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit); VdbeCoverage(v);
  2077   2084           VdbeComment((v, "Jump ahead if LIMIT reached"));
  2078   2085         }
  2079   2086         explainSetInteger(iSub2, pParse->iNextSelectId);
  2080   2087         rc = sqlite3Select(pParse, p, &dest);
  2081   2088         testcase( rc!=SQLITE_OK );
  2082   2089         pDelete = p->pPrior;
  2083   2090         p->pPrior = pPrior;
................................................................................
  2176   2183             Select *pFirst = p;
  2177   2184             while( pFirst->pPrior ) pFirst = pFirst->pPrior;
  2178   2185             generateColumnNames(pParse, 0, pFirst->pEList);
  2179   2186           }
  2180   2187           iBreak = sqlite3VdbeMakeLabel(v);
  2181   2188           iCont = sqlite3VdbeMakeLabel(v);
  2182   2189           computeLimitRegisters(pParse, p, iBreak);
  2183         -        sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak);
         2190  +        sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
  2184   2191           iStart = sqlite3VdbeCurrentAddr(v);
  2185   2192           selectInnerLoop(pParse, p, p->pEList, unionTab,
  2186   2193                           0, 0, &dest, iCont, iBreak);
  2187   2194           sqlite3VdbeResolveLabel(v, iCont);
  2188         -        sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart);
         2195  +        sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); VdbeCoverage(v);
  2189   2196           sqlite3VdbeResolveLabel(v, iBreak);
  2190   2197           sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
  2191   2198         }
  2192   2199         break;
  2193   2200       }
  2194   2201       default: assert( p->op==TK_INTERSECT ); {
  2195   2202         int tab1, tab2;
................................................................................
  2251   2258           Select *pFirst = p;
  2252   2259           while( pFirst->pPrior ) pFirst = pFirst->pPrior;
  2253   2260           generateColumnNames(pParse, 0, pFirst->pEList);
  2254   2261         }
  2255   2262         iBreak = sqlite3VdbeMakeLabel(v);
  2256   2263         iCont = sqlite3VdbeMakeLabel(v);
  2257   2264         computeLimitRegisters(pParse, p, iBreak);
  2258         -      sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak);
         2265  +      sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
  2259   2266         r1 = sqlite3GetTempReg(pParse);
  2260   2267         iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1);
  2261         -      sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
         2268  +      sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); VdbeCoverage(v);
  2262   2269         sqlite3ReleaseTempReg(pParse, r1);
  2263   2270         selectInnerLoop(pParse, p, p->pEList, tab1,
  2264   2271                         0, 0, &dest, iCont, iBreak);
  2265   2272         sqlite3VdbeResolveLabel(v, iCont);
  2266         -      sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart);
         2273  +      sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); VdbeCoverage(v);
  2267   2274         sqlite3VdbeResolveLabel(v, iBreak);
  2268   2275         sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
  2269   2276         sqlite3VdbeAddOp2(v, OP_Close, tab1, 0);
  2270   2277         break;
  2271   2278       }
  2272   2279     }
  2273   2280   
................................................................................
  2366   2373     addr = sqlite3VdbeCurrentAddr(v);
  2367   2374     iContinue = sqlite3VdbeMakeLabel(v);
  2368   2375   
  2369   2376     /* Suppress duplicates for UNION, EXCEPT, and INTERSECT 
  2370   2377     */
  2371   2378     if( regPrev ){
  2372   2379       int j1, j2;
  2373         -    j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev);
         2380  +    j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev); VdbeCoverage(v);
  2374   2381       j2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
  2375   2382                                 (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
  2376         -    sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2);
         2383  +    sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2); VdbeCoverage(v);
  2377   2384       sqlite3VdbeJumpHere(v, j1);
  2378   2385       sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regPrev+1, pIn->nSdst-1);
  2379   2386       sqlite3VdbeAddOp2(v, OP_Integer, 1, regPrev);
  2380   2387     }
  2381   2388     if( pParse->db->mallocFailed ) return 0;
  2382   2389   
  2383   2390     /* Suppress the first OFFSET entries if there is an OFFSET clause
................................................................................
  2470   2477         break;
  2471   2478       }
  2472   2479     }
  2473   2480   
  2474   2481     /* Jump to the end of the loop if the LIMIT is reached.
  2475   2482     */
  2476   2483     if( p->iLimit ){
  2477         -    sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
         2484  +    sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v);
  2478   2485     }
  2479   2486   
  2480   2487     /* Generate the subroutine return
  2481   2488     */
  2482   2489     sqlite3VdbeResolveLabel(v, iContinue);
  2483   2490     sqlite3VdbeAddOp1(v, OP_Return, regReturn);
  2484   2491   
................................................................................
  2786   2793     */
  2787   2794     if( op==TK_EXCEPT || op==TK_INTERSECT ){
  2788   2795       addrEofA_noB = addrEofA = labelEnd;
  2789   2796     }else{  
  2790   2797       VdbeNoopComment((v, "eof-A subroutine"));
  2791   2798       addrEofA = sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
  2792   2799       addrEofA_noB = sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, labelEnd);
         2800  +                                     VdbeCoverage(v);
  2793   2801       sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofA);
  2794   2802       p->nSelectRow += pPrior->nSelectRow;
  2795   2803     }
  2796   2804   
  2797   2805     /* Generate a subroutine to run when the results from select B
  2798   2806     ** are exhausted and only data in select A remains.
  2799   2807     */
  2800   2808     if( op==TK_INTERSECT ){
  2801   2809       addrEofB = addrEofA;
  2802   2810       if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
  2803   2811     }else{  
  2804   2812       VdbeNoopComment((v, "eof-B subroutine"));
  2805   2813       addrEofB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
  2806         -    sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd);
         2814  +    sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd); VdbeCoverage(v);
  2807   2815       sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofB);
  2808   2816     }
  2809   2817   
  2810   2818     /* Generate code to handle the case of A<B
  2811   2819     */
  2812   2820     VdbeNoopComment((v, "A-lt-B subroutine"));
  2813   2821     addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
  2814         -  sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA);
         2822  +  sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
  2815   2823     sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
  2816   2824   
  2817   2825     /* Generate code to handle the case of A==B
  2818   2826     */
  2819   2827     if( op==TK_ALL ){
  2820   2828       addrAeqB = addrAltB;
  2821   2829     }else if( op==TK_INTERSECT ){
  2822   2830       addrAeqB = addrAltB;
  2823   2831       addrAltB++;
  2824   2832     }else{
  2825   2833       VdbeNoopComment((v, "A-eq-B subroutine"));
  2826   2834       addrAeqB =
  2827         -    sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA);
         2835  +    sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
  2828   2836       sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
  2829   2837     }
  2830   2838   
  2831   2839     /* Generate code to handle the case of A>B
  2832   2840     */
  2833   2841     VdbeNoopComment((v, "A-gt-B subroutine"));
  2834   2842     addrAgtB = sqlite3VdbeCurrentAddr(v);
  2835   2843     if( op==TK_ALL || op==TK_UNION ){
  2836   2844       sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
  2837   2845     }
  2838         -  sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB);
         2846  +  sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
  2839   2847     sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
  2840   2848   
  2841   2849     /* This code runs once to initialize everything.
  2842   2850     */
  2843   2851     sqlite3VdbeJumpHere(v, j1);
  2844         -  sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB);
  2845         -  sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB);
         2852  +  sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB); VdbeCoverage(v);
         2853  +  sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
  2846   2854   
  2847   2855     /* Implement the main merge loop
  2848   2856     */
  2849   2857     sqlite3VdbeResolveLabel(v, labelCmpr);
  2850   2858     sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
  2851   2859     sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy,
  2852   2860                            (char*)pKeyMerge, P4_KEYINFO);
  2853   2861     sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE);
  2854         -  sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB);
         2862  +  sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); VdbeCoverage(v);
  2855   2863   
  2856   2864     /* Jump to the this point in order to terminate the query.
  2857   2865     */
  2858   2866     sqlite3VdbeResolveLabel(v, labelEnd);
  2859   2867   
  2860   2868     /* Set the number of output columns
  2861   2869     */
................................................................................
  4387   4395     ** may have been used, invalidating the underlying buffer holding the
  4388   4396     ** text or blob value. See ticket [883034dcb5].
  4389   4397     **
  4390   4398     ** Another solution would be to change the OP_SCopy used to copy cached
  4391   4399     ** values to an OP_Copy.
  4392   4400     */
  4393   4401     if( regHit ){
  4394         -    addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit);
         4402  +    addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit); VdbeCoverage(v);
  4395   4403     }
  4396   4404     sqlite3ExprCacheClear(pParse);
  4397   4405     for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
  4398   4406       sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
  4399   4407     }
  4400   4408     pAggInfo->directMode = 0;
  4401   4409     sqlite3ExprCacheClear(pParse);
................................................................................
  4921   4929           sqlite3ReleaseTempReg(pParse, regRecord);
  4922   4930           sqlite3ReleaseTempRange(pParse, regBase, nCol);
  4923   4931           sqlite3WhereEnd(pWInfo);
  4924   4932           sAggInfo.sortingIdxPTab = sortPTab = pParse->nTab++;
  4925   4933           sortOut = sqlite3GetTempReg(pParse);
  4926   4934           sqlite3VdbeAddOp3(v, OP_OpenPseudo, sortPTab, sortOut, nCol);
  4927   4935           sqlite3VdbeAddOp2(v, OP_SorterSort, sAggInfo.sortingIdx, addrEnd);
  4928         -        VdbeComment((v, "GROUP BY sort"));
         4936  +        VdbeComment((v, "GROUP BY sort")); VdbeCoverage(v);
  4929   4937           sAggInfo.useSortingIdx = 1;
  4930   4938           sqlite3ExprCacheClear(pParse);
  4931   4939         }
  4932   4940   
  4933   4941         /* Evaluate the current GROUP BY terms and store in b0, b1, b2...
  4934   4942         ** (b0 is memory location iBMem+0, b1 is iBMem+1, and so forth)
  4935   4943         ** Then compare the current GROUP BY terms against the GROUP BY terms
................................................................................
  4948   4956             sAggInfo.directMode = 1;
  4949   4957             sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
  4950   4958           }
  4951   4959         }
  4952   4960         sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
  4953   4961                             (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
  4954   4962         j1 = sqlite3VdbeCurrentAddr(v);
  4955         -      sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1);
         4963  +      sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1); VdbeCoverage(v);
  4956   4964   
  4957   4965         /* Generate code that runs whenever the GROUP BY changes.
  4958   4966         ** Changes in the GROUP BY are detected by the previous code
  4959   4967         ** block.  If there were no changes, this block is skipped.
  4960   4968         **
  4961   4969         ** This code copies current group by terms in b0,b1,b2,...
  4962   4970         ** over to a0,a1,a2.  It then calls the output subroutine
  4963   4971         ** and resets the aggregate accumulator registers in preparation
  4964   4972         ** for the next GROUP BY batch.
  4965   4973         */
  4966   4974         sqlite3ExprCodeMove(pParse, iBMem, iAMem, pGroupBy->nExpr);
  4967   4975         sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
  4968   4976         VdbeComment((v, "output one row"));
  4969         -      sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd);
         4977  +      sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd); VdbeCoverage(v);
  4970   4978         VdbeComment((v, "check abort flag"));
  4971   4979         sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
  4972   4980         VdbeComment((v, "reset accumulator"));
  4973   4981   
  4974   4982         /* Update the aggregate accumulators based on the content of
  4975   4983         ** the current row
  4976   4984         */
................................................................................
  4979   4987         sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag);
  4980   4988         VdbeComment((v, "indicate data in accumulator"));
  4981   4989   
  4982   4990         /* End of the loop
  4983   4991         */
  4984   4992         if( groupBySort ){
  4985   4993           sqlite3VdbeAddOp2(v, OP_SorterNext, sAggInfo.sortingIdx, addrTopOfLoop);
         4994  +        VdbeCoverage(v);
  4986   4995         }else{
  4987   4996           sqlite3WhereEnd(pWInfo);
  4988   4997           sqlite3VdbeChangeToNoop(v, addrSortingIdx);
  4989   4998         }
  4990   4999   
  4991   5000         /* Output the final row of result
  4992   5001         */
................................................................................
  5006   5015         */
  5007   5016         addrSetAbort = sqlite3VdbeCurrentAddr(v);
  5008   5017         sqlite3VdbeAddOp2(v, OP_Integer, 1, iAbortFlag);
  5009   5018         VdbeComment((v, "set abort flag"));
  5010   5019         sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
  5011   5020         sqlite3VdbeResolveLabel(v, addrOutputRow);
  5012   5021         addrOutputRow = sqlite3VdbeCurrentAddr(v);
  5013         -      sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
         5022  +      sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2); VdbeCoverage(v);
  5014   5023         VdbeComment((v, "Groupby result generator entry point"));
  5015   5024         sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
  5016   5025         finalizeAggFunctions(pParse, &sAggInfo);
  5017   5026         sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
  5018   5027         selectInnerLoop(pParse, p, p->pEList, -1, pOrderBy,
  5019   5028                         &sDistinct, pDest,
  5020   5029                         addrOutputRow+1, addrSetAbort);

Changes to src/sqlite.h.in.

  6113   6113   #define SQLITE_TESTCTRL_RESERVE                 14
  6114   6114   #define SQLITE_TESTCTRL_OPTIMIZATIONS           15
  6115   6115   #define SQLITE_TESTCTRL_ISKEYWORD               16
  6116   6116   #define SQLITE_TESTCTRL_SCRATCHMALLOC           17
  6117   6117   #define SQLITE_TESTCTRL_LOCALTIME_FAULT         18
  6118   6118   #define SQLITE_TESTCTRL_EXPLAIN_STMT            19
  6119   6119   #define SQLITE_TESTCTRL_NEVER_CORRUPT           20
  6120         -#define SQLITE_TESTCTRL_LAST                    20
         6120  +#define SQLITE_TESTCTRL_VDBE_COVERAGE           21
         6121  +#define SQLITE_TESTCTRL_LAST                    21
  6121   6122   
  6122   6123   /*
  6123   6124   ** CAPI3REF: SQLite Runtime Status
  6124   6125   **
  6125   6126   ** ^This interface is used to retrieve runtime status information
  6126   6127   ** about the performance of SQLite, and optionally to reset various
  6127   6128   ** highwater marks.  ^The first argument is an integer code for

Changes to src/sqliteInt.h.

  2653   2653     void (*xLog)(void*,int,const char*); /* Function for logging */
  2654   2654     void *pLogArg;                       /* First argument to xLog() */
  2655   2655     int bLocaltimeFault;              /* True to fail localtime() calls */
  2656   2656   #ifdef SQLITE_ENABLE_SQLLOG
  2657   2657     void(*xSqllog)(void*,sqlite3*,const char*, int);
  2658   2658     void *pSqllogArg;
  2659   2659   #endif
         2660  +#ifdef SQLITE_VDBE_COVERAGE
         2661  +  /* The following callback (if not NULL) is invoked on every VDBE branch
         2662  +  ** operation.  Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
         2663  +  */
         2664  +  void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx);  /* Callback */
         2665  +  void *pVdbeBranchArg;                                     /* 1st argument */
         2666  +#endif
  2660   2667   };
  2661   2668   
  2662   2669   /*
  2663   2670   ** This macro is used inside of assert() statements to indicate that
  2664   2671   ** the assert is only valid on a well-formed database.  Instead of:
  2665   2672   **
  2666   2673   **     assert( X );

Changes to src/trigger.c.

   562    562   #endif
   563    563   
   564    564     /* Generate code to destroy the database record of the trigger.
   565    565     */
   566    566     assert( pTable!=0 );
   567    567     if( (v = sqlite3GetVdbe(pParse))!=0 ){
   568    568       int base;
          569  +    static const int iLn = __LINE__+2;
   569    570       static const VdbeOpList dropTrigger[] = {
   570    571         { OP_Rewind,     0, ADDR(9),  0},
   571    572         { OP_String8,    0, 1,        0}, /* 1 */
   572    573         { OP_Column,     0, 1,        2},
   573    574         { OP_Ne,         2, ADDR(8),  1},
   574    575         { OP_String8,    0, 1,        0}, /* 4: "trigger" */
   575    576         { OP_Column,     0, 0,        2},
................................................................................
   576    577         { OP_Ne,         2, ADDR(8),  1},
   577    578         { OP_Delete,     0, 0,        0},
   578    579         { OP_Next,       0, ADDR(1),  0}, /* 8 */
   579    580       };
   580    581   
   581    582       sqlite3BeginWriteOperation(pParse, 0, iDb);
   582    583       sqlite3OpenMasterTable(pParse, iDb);
   583         -    base = sqlite3VdbeAddOpList(v,  ArraySize(dropTrigger), dropTrigger);
          584  +    base = sqlite3VdbeAddOpList(v,  ArraySize(dropTrigger), dropTrigger, iLn);
   584    585       sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, P4_TRANSIENT);
   585    586       sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC);
   586    587       sqlite3ChangeCookie(pParse, iDb);
   587    588       sqlite3VdbeAddOp2(v, OP_Close, 0, 0);
   588    589       sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
   589    590       if( pParse->nMem<3 ){
   590    591         pParse->nMem = 3;

Changes to src/update.c.

   430    430     }
   431    431   
   432    432     /* Top of the update loop */
   433    433     if( okOnePass ){
   434    434       if( aToOpen[iDataCur-iBaseCur] ){
   435    435         assert( pPk!=0 );
   436    436         sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey);
          437  +      VdbeCoverage(v);
   437    438       }
   438    439       labelContinue = labelBreak;
   439    440       sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
          441  +    VdbeCoverage(v);
   440    442     }else if( pPk ){
   441    443       labelContinue = sqlite3VdbeMakeLabel(v);
   442         -    sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak);
          444  +    sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v);
   443    445       addrTop = sqlite3VdbeAddOp2(v, OP_RowKey, iEph, regKey);
   444    446       sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0);
          447  +    VdbeCoverage(v);
   445    448     }else{
   446    449       labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, labelBreak,
   447    450                                regOldRowid);
          451  +    VdbeCoverage(v);
   448    452       sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
          453  +    VdbeCoverage(v);
   449    454     }
   450    455   
   451    456     /* If the record number will change, set register regNewRowid to
   452    457     ** contain the new value. If the record number is not being modified,
   453    458     ** then regNewRowid is the same register as regOldRowid, which is
   454    459     ** already populated.  */
   455    460     assert( chngKey || pTrigger || hasFK || regOldRowid==regNewRowid );
   456    461     if( chngRowid ){
   457    462       sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);
   458         -    sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid);
          463  +    sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid); VdbeCoverage(v);
   459    464     }
   460    465   
   461    466     /* Compute the old pre-UPDATE content of the row being changed, if that
   462    467     ** information is needed */
   463    468     if( chngPk || hasFK || pTrigger ){
   464    469       u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0);
   465    470       oldmask |= sqlite3TriggerColmask(pParse, 
................................................................................
   532    537       ** case, jump to the next row. No updates or AFTER triggers are 
   533    538       ** required. This behavior - what happens when the row being updated
   534    539       ** is deleted or renamed by a BEFORE trigger - is left undefined in the
   535    540       ** documentation.
   536    541       */
   537    542       if( pPk ){
   538    543         sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue,regKey,nKey);
          544  +      VdbeCoverage(v);
   539    545       }else{
   540    546         sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
          547  +      VdbeCoverage(v);
   541    548       }
   542    549   
   543    550       /* If it did not delete it, the row-trigger may still have modified 
   544    551       ** some of the columns of the row being updated. Load the values for 
   545    552       ** all columns not modified by the update statement into their 
   546    553       ** registers in case this has happened.
   547    554       */
................................................................................
   566    573         sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngKey);
   567    574       }
   568    575   
   569    576       /* Delete the index entries associated with the current record.  */
   570    577       if( bReplace || chngKey ){
   571    578         if( pPk ){
   572    579           j1 = sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, 0, regKey, nKey);
          580  +        VdbeCoverage(v);
   573    581         }else{
   574    582           j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid);
          583  +        VdbeCoverage(v);
   575    584         }
   576    585       }
   577    586       sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx);
   578    587     
   579    588       /* If changing the record number, delete the old record.  */
   580    589       if( hasFK || chngKey || pPk!=0 ){
   581    590         sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
................................................................................
   612    621     /* Repeat the above with the next record to be updated, until
   613    622     ** all record selected by the WHERE clause have been updated.
   614    623     */
   615    624     if( okOnePass ){
   616    625       /* Nothing to do at end-of-loop for a single-pass */
   617    626     }else if( pPk ){
   618    627       sqlite3VdbeResolveLabel(v, labelContinue);
   619         -    sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop);
          628  +    sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
   620    629     }else{
   621    630       sqlite3VdbeAddOp2(v, OP_Goto, 0, labelContinue);
   622    631     }
   623    632     sqlite3VdbeResolveLabel(v, labelBreak);
   624    633   
   625    634     /* Close all tables */
   626    635     for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
................................................................................
   741    750     */
   742    751     sqlite3SelectDestInit(&dest, SRT_Table, ephemTab);
   743    752     sqlite3Select(pParse, pSelect, &dest);
   744    753   
   745    754     /* Generate code to scan the ephemeral table and call VUpdate. */
   746    755     iReg = ++pParse->nMem;
   747    756     pParse->nMem += pTab->nCol+1;
   748         -  addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0);
          757  +  addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0); VdbeCoverage(v);
   749    758     sqlite3VdbeAddOp3(v, OP_Column,  ephemTab, 0, iReg);
   750    759     sqlite3VdbeAddOp3(v, OP_Column, ephemTab, (pRowid?1:0), iReg+1);
   751    760     for(i=0; i<pTab->nCol; i++){
   752    761       sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i);
   753    762     }
   754    763     sqlite3VtabMakeWritable(pParse, pTab);
   755    764     sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB);
   756    765     sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
   757    766     sqlite3MayAbort(pParse);
   758         -  sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1);
          767  +  sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1); VdbeCoverage(v);
   759    768     sqlite3VdbeJumpHere(v, addr);
   760    769     sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);
   761    770   
   762    771     /* Cleanup */
   763    772     sqlite3SelectDelete(db, pSelect);  
   764    773   }
   765    774   #endif /* SQLITE_OMIT_VIRTUALTABLE */

Changes to src/vdbe.c.

   103    103   */
   104    104   #if defined(SQLITE_TEST) && !defined(SQLITE_OMIT_BUILTIN_TEST)
   105    105   # define UPDATE_MAX_BLOBSIZE(P)  updateMaxBlobsize(P)
   106    106   #else
   107    107   # define UPDATE_MAX_BLOBSIZE(P)
   108    108   #endif
   109    109   
          110  +/*
          111  +** Invoke the VDBE coverage callback, if defined
          112  +*/
          113  +#if !defined(SQLITE_VDBE_COVERAGE)
          114  +# define VdbeBranchTaken(I,M)
          115  +#else
          116  +# define VdbeBranchTaken(I,M) \
          117  +    if( sqlite3GlobalConfig.xVdbeBranch!=0 ){ \
          118  +      sqlite3GlobalConfig.xVdbeBranch(sqlite3GlobalConfig.pVdbeBranchArg, \
          119  +                                      pOp->iSrcLine,(I),(M)); }
          120  +#endif
          121  +
   110    122   /*
   111    123   ** Convert the given register into a string if it isn't one
   112    124   ** already. Return non-zero if a malloc() fails.
   113    125   */
   114    126   #define Stringify(P, enc) \
   115    127      if(((P)->flags&(MEM_Str|MEM_Blob))==0 && sqlite3VdbeMemStringify(P,enc)) \
   116    128        { goto no_mem; }
................................................................................
  1634   1646   ** without data loss, then jump immediately to P2, or if P2==0
  1635   1647   ** raise an SQLITE_MISMATCH exception.
  1636   1648   */
  1637   1649   case OP_MustBeInt: {            /* jump, in1 */
  1638   1650     pIn1 = &aMem[pOp->p1];
  1639   1651     if( (pIn1->flags & MEM_Int)==0 ){
  1640   1652       applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
         1653  +    VdbeBranchTaken((pIn1->flags&MEM_Int)==0, 2);
  1641   1654       if( (pIn1->flags & MEM_Int)==0 ){
  1642   1655         if( pOp->p2==0 ){
  1643   1656           rc = SQLITE_MISMATCH;
  1644   1657           goto abort_due_to_error;
  1645   1658         }else{
  1646   1659           pc = pOp->p2 - 1;
  1647   1660           break;
................................................................................
  1887   1900           res = 1;  /* Results are not equal */
  1888   1901         }
  1889   1902       }else{
  1890   1903         /* SQLITE_NULLEQ is clear and at least one operand is NULL,
  1891   1904         ** then the result is always NULL.
  1892   1905         ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
  1893   1906         */
  1894         -      if( pOp->p5 & SQLITE_JUMPIFNULL ){
  1895         -        pc = pOp->p2-1;
  1896         -      }else if( pOp->p5 & SQLITE_STOREP2 ){
         1907  +      if( pOp->p5 & SQLITE_STOREP2 ){
  1897   1908           pOut = &aMem[pOp->p2];
  1898   1909           MemSetTypeFlag(pOut, MEM_Null);
  1899   1910           REGISTER_TRACE(pOp->p2, pOut);
         1911  +      }else{
         1912  +        VdbeBranchTaken((pOp->p5 & SQLITE_JUMPIFNULL)?2:3,4);
         1913  +        if( pOp->p5 & SQLITE_JUMPIFNULL ){
         1914  +          pc = pOp->p2-1;
         1915  +        }
  1900   1916         }
  1901   1917         break;
  1902   1918       }
  1903   1919     }else{
  1904   1920       /* Neither operand is NULL.  Do a comparison. */
  1905   1921       affinity = pOp->p5 & SQLITE_AFF_MASK;
  1906   1922       if( affinity ){
................................................................................
  1925   1941   
  1926   1942     if( pOp->p5 & SQLITE_STOREP2 ){
  1927   1943       pOut = &aMem[pOp->p2];
  1928   1944       memAboutToChange(p, pOut);
  1929   1945       MemSetTypeFlag(pOut, MEM_Int);
  1930   1946       pOut->u.i = res;
  1931   1947       REGISTER_TRACE(pOp->p2, pOut);
  1932         -  }else if( res ){
  1933         -    pc = pOp->p2-1;
         1948  +  }else{
         1949  +    VdbeBranchTaken(res!=0, 4);
         1950  +    if( res ){
         1951  +      pc = pOp->p2-1;
         1952  +    }
  1934   1953     }
  1935         -
  1936   1954     /* Undo any changes made by applyAffinity() to the input registers. */
  1937   1955     pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask);
  1938   1956     pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask);
  1939   1957     break;
  1940   1958   }
  1941   1959   
  1942   1960   /* Opcode: Permutation * * * P4 *
................................................................................
  2025   2043   **
  2026   2044   ** Jump to the instruction at address P1, P2, or P3 depending on whether
  2027   2045   ** in the most recent OP_Compare instruction the P1 vector was less than
  2028   2046   ** equal to, or greater than the P2 vector, respectively.
  2029   2047   */
  2030   2048   case OP_Jump: {             /* jump */
  2031   2049     if( iCompare<0 ){
  2032         -    pc = pOp->p1 - 1;
         2050  +    pc = pOp->p1 - 1;  VdbeBranchTaken(0,3);
  2033   2051     }else if( iCompare==0 ){
  2034         -    pc = pOp->p2 - 1;
         2052  +    pc = pOp->p2 - 1;  VdbeBranchTaken(1,3);
  2035   2053     }else{
  2036         -    pc = pOp->p3 - 1;
         2054  +    pc = pOp->p3 - 1;  VdbeBranchTaken(2,3);
  2037   2055     }
  2038   2056     break;
  2039   2057   }
  2040   2058   
  2041   2059   /* Opcode: And P1 P2 P3 * *
  2042   2060   ** Synopsis: r[P3]=(r[P1] && r[P2])
  2043   2061   **
................................................................................
  2133   2151   ** Check if OP_Once flag P1 is set. If so, jump to instruction P2. Otherwise,
  2134   2152   ** set the flag and fall through to the next instruction.  In other words,
  2135   2153   ** this opcode causes all following up codes up through P2 (but not including
  2136   2154   ** P2) to run just once and skipped on subsequent times through the loop.
  2137   2155   */
  2138   2156   case OP_Once: {             /* jump */
  2139   2157     assert( pOp->p1<p->nOnceFlag );
         2158  +  VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
  2140   2159     if( p->aOnceFlag[pOp->p1] ){
  2141   2160       pc = pOp->p2-1;
  2142   2161     }else{
  2143   2162       p->aOnceFlag[pOp->p1] = 1;
  2144   2163     }
  2145   2164     break;
  2146   2165   }
................................................................................
  2167   2186   #ifdef SQLITE_OMIT_FLOATING_POINT
  2168   2187       c = sqlite3VdbeIntValue(pIn1)!=0;
  2169   2188   #else
  2170   2189       c = sqlite3VdbeRealValue(pIn1)!=0.0;
  2171   2190   #endif
  2172   2191       if( pOp->opcode==OP_IfNot ) c = !c;
  2173   2192     }
         2193  +  VdbeBranchTaken(c!=0, 2);
  2174   2194     if( c ){
  2175   2195       pc = pOp->p2-1;
  2176   2196     }
  2177   2197     break;
  2178   2198   }
  2179   2199   
  2180   2200   /* Opcode: IsNull P1 P2 * * *
  2181   2201   ** Synopsis:  if r[P1]==NULL goto P2
  2182   2202   **
  2183   2203   ** Jump to P2 if the value in register P1 is NULL.
  2184   2204   */
  2185   2205   case OP_IsNull: {            /* same as TK_ISNULL, jump, in1 */
  2186   2206     pIn1 = &aMem[pOp->p1];
         2207  +  VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
  2187   2208     if( (pIn1->flags & MEM_Null)!=0 ){
  2188   2209       pc = pOp->p2 - 1;
  2189   2210     }
  2190   2211     break;
  2191   2212   }
  2192   2213   
  2193   2214   /* Opcode: NotNull P1 P2 * * *
  2194   2215   ** Synopsis: if r[P1]!=NULL goto P2
  2195   2216   **
  2196   2217   ** Jump to P2 if the value in register P1 is not NULL.  
  2197   2218   */
  2198   2219   case OP_NotNull: {            /* same as TK_NOTNULL, jump, in1 */
  2199   2220     pIn1 = &aMem[pOp->p1];
         2221  +  VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
  2200   2222     if( (pIn1->flags & MEM_Null)==0 ){
  2201   2223       pc = pOp->p2 - 1;
  2202   2224     }
  2203   2225     break;
  2204   2226   }
  2205   2227   
  2206   2228   /* Opcode: Column P1 P2 P3 P4 P5
................................................................................
  3470   3492   
  3471   3493       /* If the P3 value could not be converted into an integer without
  3472   3494       ** loss of information, then special processing is required... */
  3473   3495       if( (pIn3->flags & MEM_Int)==0 ){
  3474   3496         if( (pIn3->flags & MEM_Real)==0 ){
  3475   3497           /* If the P3 value cannot be converted into any kind of a number,
  3476   3498           ** then the seek is not possible, so jump to P2 */
  3477         -        pc = pOp->p2 - 1;
         3499  +        pc = pOp->p2 - 1;  VdbeBranchTaken(1,2);
  3478   3500           break;
  3479   3501         }
  3480   3502   
  3481   3503         /* If the approximation iKey is larger than the actual real search
  3482   3504         ** term, substitute >= for > and < for <=. e.g. if the search term
  3483   3505         ** is 4.9 and the integer approximation 5:
  3484   3506         **
................................................................................
  3565   3587         /* res might be negative because the table is empty.  Check to
  3566   3588         ** see if this is the case.
  3567   3589         */
  3568   3590         res = sqlite3BtreeEof(pC->pCursor);
  3569   3591       }
  3570   3592     }
  3571   3593     assert( pOp->p2>0 );
         3594  +  VdbeBranchTaken(res!=0,2);
  3572   3595     if( res ){
  3573   3596       pc = pOp->p2 - 1;
  3574   3597     }
  3575   3598     break;
  3576   3599   }
  3577   3600   
  3578   3601   /* Opcode: Seek P1 P2 * * *
................................................................................
  3698   3721     }
  3699   3722     if( pOp->opcode==OP_NoConflict ){
  3700   3723       /* For the OP_NoConflict opcode, take the jump if any of the
  3701   3724       ** input fields are NULL, since any key with a NULL will not
  3702   3725       ** conflict */
  3703   3726       for(ii=0; ii<r.nField; ii++){
  3704   3727         if( r.aMem[ii].flags & MEM_Null ){
  3705         -        pc = pOp->p2 - 1;
         3728  +        pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
  3706   3729           break;
  3707   3730         }
  3708   3731       }
  3709   3732     }
  3710   3733     rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
  3711   3734     if( pOp->p4.i==0 ){
  3712   3735       sqlite3DbFree(db, pFree);
................................................................................
  3716   3739     }
  3717   3740     pC->seekResult = res;
  3718   3741     alreadyExists = (res==0);
  3719   3742     pC->nullRow = 1-alreadyExists;
  3720   3743     pC->deferredMoveto = 0;
  3721   3744     pC->cacheStatus = CACHE_STALE;
  3722   3745     if( pOp->opcode==OP_Found ){
         3746  +    VdbeBranchTaken(alreadyExists!=0,2);
  3723   3747       if( alreadyExists ) pc = pOp->p2 - 1;
  3724   3748     }else{
         3749  +    VdbeBranchTaken(alreadyExists==0,2);
  3725   3750       if( !alreadyExists ) pc = pOp->p2 - 1;
  3726   3751     }
  3727   3752     break;
  3728   3753   }
  3729   3754   
  3730   3755   /* Opcode: NotExists P1 P2 P3 * *
  3731   3756   ** Synopsis: intkey=r[P3]
................................................................................
  3760   3785     iKey = pIn3->u.i;
  3761   3786     rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
  3762   3787     pC->lastRowid = pIn3->u.i;
  3763   3788     pC->rowidIsValid = res==0 ?1:0;
  3764   3789     pC->nullRow = 0;
  3765   3790     pC->cacheStatus = CACHE_STALE;
  3766   3791     pC->deferredMoveto = 0;
         3792  +  VdbeBranchTaken(res!=0,2);
  3767   3793     if( res!=0 ){
  3768   3794       pc = pOp->p2 - 1;
  3769   3795       assert( pC->rowidIsValid==0 );
  3770   3796     }
  3771   3797     pC->seekResult = res;
  3772   3798     break;
  3773   3799   }
................................................................................
  4134   4160   
  4135   4161     pC = p->apCsr[pOp->p1];
  4136   4162     assert( isSorter(pC) );
  4137   4163     assert( pOp->p4type==P4_INT32 );
  4138   4164     pIn3 = &aMem[pOp->p3];
  4139   4165     nIgnore = pOp->p4.i;
  4140   4166     rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res);
         4167  +  VdbeBranchTaken(res!=0,2);
  4141   4168     if( res ){
  4142   4169       pc = pOp->p2-1;
  4143   4170     }
  4144   4171     break;
  4145   4172   };
  4146   4173   
  4147   4174   /* Opcode: SorterData P1 P2 * * *
................................................................................
  4333   4360     res = 0;
  4334   4361     assert( pCrsr!=0 );
  4335   4362     rc = sqlite3BtreeLast(pCrsr, &res);
  4336   4363     pC->nullRow = (u8)res;
  4337   4364     pC->deferredMoveto = 0;
  4338   4365     pC->rowidIsValid = 0;
  4339   4366     pC->cacheStatus = CACHE_STALE;
  4340         -  if( pOp->p2>0 && res ){
  4341         -    pc = pOp->p2 - 1;
         4367  +  if( pOp->p2>0 ){
         4368  +    VdbeBranchTaken(res!=0,2);
         4369  +    if( res ) pc = pOp->p2 - 1;
  4342   4370     }
  4343   4371     break;
  4344   4372   }
  4345   4373   
  4346   4374   
  4347   4375   /* Opcode: Sort P1 P2 * * *
  4348   4376   **
................................................................................
  4391   4419       rc = sqlite3BtreeFirst(pCrsr, &res);
  4392   4420       pC->deferredMoveto = 0;
  4393   4421       pC->cacheStatus = CACHE_STALE;
  4394   4422       pC->rowidIsValid = 0;
  4395   4423     }
  4396   4424     pC->nullRow = (u8)res;
  4397   4425     assert( pOp->p2>0 && pOp->p2<p->nOp );
         4426  +  VdbeBranchTaken(res!=0,2);
  4398   4427     if( res ){
  4399   4428       pc = pOp->p2 - 1;
  4400   4429     }
  4401   4430     break;
  4402   4431   }
  4403   4432   
  4404   4433   /* Opcode: Next P1 P2 P3 P4 P5
................................................................................
  4481   4510     assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
  4482   4511     assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
  4483   4512     assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
  4484   4513     assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
  4485   4514     rc = pOp->p4.xAdvance(pC->pCursor, &res);
  4486   4515   next_tail:
  4487   4516     pC->cacheStatus = CACHE_STALE;
         4517  +  VdbeBranchTaken(res==0,2);
  4488   4518     if( res==0 ){
  4489   4519       pC->nullRow = 0;
  4490   4520       pc = pOp->p2 - 1;
  4491   4521       p->aCounter[pOp->p5]++;
  4492   4522   #ifdef SQLITE_TEST
  4493   4523       sqlite3_search_count++;
  4494   4524   #endif
................................................................................
  4706   4736     if( (pOp->opcode&1)==(OP_IdxLT&1) ){
  4707   4737       assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxLT );
  4708   4738       res = -res;
  4709   4739     }else{
  4710   4740       assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT );
  4711   4741       res++;
  4712   4742     }
         4743  +  VdbeBranchTaken(res>0,2);
  4713   4744     if( res>0 ){
  4714   4745       pc = pOp->p2 - 1 ;
  4715   4746     }
  4716   4747     break;
  4717   4748   }
  4718   4749   
  4719   4750   /* Opcode: Destroy P1 P2 P3 * *
................................................................................
  5067   5098     pIn1 = &aMem[pOp->p1];
  5068   5099     if( (pIn1->flags & MEM_RowSet)==0 
  5069   5100      || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
  5070   5101     ){
  5071   5102       /* The boolean index is empty */
  5072   5103       sqlite3VdbeMemSetNull(pIn1);
  5073   5104       pc = pOp->p2 - 1;
         5105  +    VdbeBranchTaken(1,2);
  5074   5106     }else{
  5075   5107       /* A value was pulled from the index */
  5076   5108       sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
         5109  +    VdbeBranchTaken(0,2);
  5077   5110     }
  5078   5111     goto check_for_interrupt;
  5079   5112   }
  5080   5113   
  5081   5114   /* Opcode: RowSetTest P1 P2 P3 P4
  5082   5115   ** Synopsis: if r[P3] in rowset(P1) goto P2
  5083   5116   **
................................................................................
  5121   5154   
  5122   5155     assert( pOp->p4type==P4_INT32 );
  5123   5156     assert( iSet==-1 || iSet>=0 );
  5124   5157     if( iSet ){
  5125   5158       exists = sqlite3RowSetTest(pIn1->u.pRowSet, 
  5126   5159                                  (u8)(iSet>=0 ? iSet & 0xf : 0xff),
  5127   5160                                  pIn3->u.i);
         5161  +    VdbeBranchTaken(exists!=0,2);
  5128   5162       if( exists ){
  5129   5163         pc = pOp->p2 - 1;
  5130   5164         break;
  5131   5165       }
  5132   5166     }
  5133   5167     if( iSet>=0 ){
  5134   5168       sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
................................................................................
  5313   5347   ** If P1 is non-zero, then the jump is taken if the database constraint-counter
  5314   5348   ** is zero (the one that counts deferred constraint violations). If P1 is
  5315   5349   ** zero, the jump is taken if the statement constraint-counter is zero
  5316   5350   ** (immediate foreign key constraint violations).
  5317   5351   */
  5318   5352   case OP_FkIfZero: {         /* jump */
  5319   5353     if( pOp->p1 ){
         5354  +    VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
  5320   5355       if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
  5321   5356     }else{
         5357  +    VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
  5322   5358       if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
  5323   5359     }
  5324   5360     break;
  5325   5361   }
  5326   5362   #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
  5327   5363   
  5328   5364   #ifndef SQLITE_OMIT_AUTOINCREMENT
................................................................................
  5363   5399   **
  5364   5400   ** It is illegal to use this instruction on a register that does
  5365   5401   ** not contain an integer.  An assertion fault will result if you try.
  5366   5402   */
  5367   5403   case OP_IfPos: {        /* jump, in1 */
  5368   5404     pIn1 = &aMem[pOp->p1];
  5369   5405     assert( pIn1->flags&MEM_Int );
         5406  +  VdbeBranchTaken( pIn1->u.i>0, 2);
  5370   5407     if( pIn1->u.i>0 ){
  5371   5408        pc = pOp->p2 - 1;
  5372   5409     }
  5373   5410     break;
  5374   5411   }
  5375   5412   
  5376   5413   /* Opcode: IfNeg P1 P2 * * *
................................................................................
  5380   5417   **
  5381   5418   ** It is illegal to use this instruction on a register that does
  5382   5419   ** not contain an integer.  An assertion fault will result if you try.
  5383   5420   */
  5384   5421   case OP_IfNeg: {        /* jump, in1 */
  5385   5422     pIn1 = &aMem[pOp->p1];
  5386   5423     assert( pIn1->flags&MEM_Int );
         5424  +  VdbeBranchTaken(pIn1->u.i<0, 2);
  5387   5425     if( pIn1->u.i<0 ){
  5388   5426        pc = pOp->p2 - 1;
  5389   5427     }
  5390   5428     break;
  5391   5429   }
  5392   5430   
  5393   5431   /* Opcode: IfZero P1 P2 P3 * *
................................................................................
  5399   5437   ** It is illegal to use this instruction on a register that does
  5400   5438   ** not contain an integer.  An assertion fault will result if you try.
  5401   5439   */
  5402   5440   case OP_IfZero: {        /* jump, in1 */
  5403   5441     pIn1 = &aMem[pOp->p1];
  5404   5442     assert( pIn1->flags&MEM_Int );
  5405   5443     pIn1->u.i += pOp->p3;
         5444  +  VdbeBranchTaken(pIn1->u.i==0, 2);
  5406   5445     if( pIn1->u.i==0 ){
  5407   5446        pc = pOp->p2 - 1;
  5408   5447     }
  5409   5448     break;
  5410   5449   }
  5411   5450   
  5412   5451   /* Opcode: AggStep * P2 P3 P4 P5
................................................................................
  5670   5709     Btree *pBt;
  5671   5710   
  5672   5711     assert( pOp->p1>=0 && pOp->p1<db->nDb );
  5673   5712     assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
  5674   5713     assert( p->readOnly==0 );
  5675   5714     pBt = db->aDb[pOp->p1].pBt;
  5676   5715     rc = sqlite3BtreeIncrVacuum(pBt);
         5716  +  VdbeBranchTaken(rc==SQLITE_DONE,2);
  5677   5717     if( rc==SQLITE_DONE ){
  5678   5718       pc = pOp->p2 - 1;
  5679   5719       rc = SQLITE_OK;
  5680   5720     }
  5681   5721     break;
  5682   5722   }
  5683   5723   #endif
................................................................................
  5876   5916       p->inVtabMethod = 1;
  5877   5917       rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
  5878   5918       p->inVtabMethod = 0;
  5879   5919       sqlite3VtabImportErrmsg(p, pVtab);
  5880   5920       if( rc==SQLITE_OK ){
  5881   5921         res = pModule->xEof(pVtabCursor);
  5882   5922       }
  5883         -
         5923  +    VdbeBranchTaken(res!=0,2);
  5884   5924       if( res ){
  5885   5925         pc = pOp->p2 - 1;
  5886   5926       }
  5887   5927     }
  5888   5928     pCur->nullRow = 0;
  5889   5929   
  5890   5930     break;
................................................................................
  5981   6021     p->inVtabMethod = 1;
  5982   6022     rc = pModule->xNext(pCur->pVtabCursor);
  5983   6023     p->inVtabMethod = 0;
  5984   6024     sqlite3VtabImportErrmsg(p, pVtab);
  5985   6025     if( rc==SQLITE_OK ){
  5986   6026       res = pModule->xEof(pCur->pVtabCursor);
  5987   6027     }
  5988         -
         6028  +  VdbeBranchTaken(!res,2);
  5989   6029     if( !res ){
  5990   6030       /* If there is data, jump to P2 */
  5991   6031       pc = pOp->p2 - 1;
  5992   6032     }
  5993   6033     goto check_for_interrupt;
  5994   6034   }
  5995   6035   #endif /* SQLITE_OMIT_VIRTUALTABLE */

Changes to src/vdbe.h.

    64     64   #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
    65     65     char *zComment;          /* Comment to improve readability */
    66     66   #endif
    67     67   #ifdef VDBE_PROFILE
    68     68     int cnt;                 /* Number of times this instruction was executed */
    69     69     u64 cycles;              /* Total time spent executing this instruction */
    70     70   #endif
           71  +#ifdef SQLITE_VDBE_COVERAGE
           72  +  int iSrcLine;            /* Source-code line that generated this opcode */
           73  +#endif
    71     74   };
    72     75   typedef struct VdbeOp VdbeOp;
    73     76   
    74     77   
    75     78   /*
    76     79   ** A sub-routine used to implement a trigger program.
    77     80   */
................................................................................
   163    166   Vdbe *sqlite3VdbeCreate(Parse*);
   164    167   int sqlite3VdbeAddOp0(Vdbe*,int);
   165    168   int sqlite3VdbeAddOp1(Vdbe*,int,int);
   166    169   int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
   167    170   int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
   168    171   int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
   169    172   int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
   170         -int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
          173  +int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
   171    174   void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
   172    175   void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
   173    176   void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
   174    177   void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
   175    178   void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
   176    179   void sqlite3VdbeJumpHere(Vdbe*, int addr);
   177    180   void sqlite3VdbeChangeToNoop(Vdbe*, int addr);
................................................................................
   233    236   #   define VdbeModuleComment(X)
   234    237   # endif
   235    238   #else
   236    239   # define VdbeComment(X)
   237    240   # define VdbeNoopComment(X)
   238    241   # define VdbeModuleComment(X)
   239    242   #endif
          243  +
          244  +/* Set the Opcode.iSrcline field of the previous opcode */
          245  +#ifdef SQLITE_VDBE_COVERAGE
          246  +  void sqlite3VdbeSetLineNumber(Vdbe*,int);
          247  +# define VdbeCoverage(v) sqlite3VdbeSetLineNumber(v,__LINE__)
          248  +# define VdbeCoverageIf(v,x) if(x)sqlite3VdbeSetLineNumber(v,__LINE__)
          249  +#else
          250  +# define VdbeCoverage(v)
          251  +# define VdbeCoverageIf(v,x)
          252  +#endif
   240    253   
   241    254   #endif

Changes to src/vdbeaux.c.

   170    170       test_addop_breakpoint();
   171    171     }
   172    172   #endif
   173    173   #ifdef VDBE_PROFILE
   174    174     pOp->cycles = 0;
   175    175     pOp->cnt = 0;
   176    176   #endif
          177  +#ifdef SQLITE_VDBE_COVERAGE
          178  +  pOp->iSrcLine = 0;
          179  +#endif
   177    180     return i;
   178    181   }
   179    182   int sqlite3VdbeAddOp0(Vdbe *p, int op){
   180    183     return sqlite3VdbeAddOp3(p, op, 0, 0, 0);
   181    184   }
   182    185   int sqlite3VdbeAddOp1(Vdbe *p, int op, int p1){
   183    186     return sqlite3VdbeAddOp3(p, op, p1, 0, 0);
................................................................................
   531    534     return aOp;
   532    535   }
   533    536   
   534    537   /*
   535    538   ** Add a whole list of operations to the operation stack.  Return the
   536    539   ** address of the first operation added.
   537    540   */
   538         -int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
          541  +int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp, int iLineno){
   539    542     int addr;
   540    543     assert( p->magic==VDBE_MAGIC_INIT );
   541    544     if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){
   542    545       return 0;
   543    546     }
   544    547     addr = p->nOp;
   545    548     if( ALWAYS(nOp>0) ){
................................................................................
   558    561         }
   559    562         pOut->p3 = pIn->p3;
   560    563         pOut->p4type = P4_NOTUSED;
   561    564         pOut->p4.p = 0;
   562    565         pOut->p5 = 0;
   563    566   #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
   564    567         pOut->zComment = 0;
          568  +#endif
          569  +#ifdef SQLITE_VDBE_COVERAGE
          570  +      pOut->iSrcLine = iLineno+i;
          571  +#else
          572  +      (void)iLineno;
   565    573   #endif
   566    574   #ifdef SQLITE_DEBUG
   567    575         if( p->db->flags & SQLITE_VdbeAddopTrace ){
   568    576           sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
   569    577         }
   570    578   #endif
   571    579       }
................................................................................
   847    855       va_start(ap, zFormat);
   848    856       vdbeVComment(p, zFormat, ap);
   849    857       va_end(ap);
   850    858     }
   851    859   }
   852    860   #endif  /* NDEBUG */
   853    861   
          862  +#ifdef SQLITE_VDBE_COVERAGE
          863  +/*
          864  +** Set the value if the iSrcLine field for the previously coded instruction.
          865  +*/
          866  +void sqlite3VdbeSetLineNumber(Vdbe *v, int iLine){
          867  +  sqlite3VdbeGetOp(v,-1)->iSrcLine = iLine;
          868  +}
          869  +#endif /* SQLITE_VDBE_COVERAGE */
          870  +
   854    871   /*
   855    872   ** Return the opcode for a given address.  If the address is -1, then
   856    873   ** return the most recently inserted opcode.
   857    874   **
   858    875   ** If a memory allocation error has occurred prior to the calling of this
   859    876   ** routine, then a pointer to a dummy VdbeOp will be returned.  That opcode
   860    877   ** is readable but not writable, though it is cast to a writable value.

Changes to src/vdbeblob.c.

   129    129     ** uses it to implement the blob_read(), blob_write() and 
   130    130     ** blob_bytes() functions.
   131    131     **
   132    132     ** The sqlite3_blob_close() function finalizes the vdbe program,
   133    133     ** which closes the b-tree cursor and (possibly) commits the 
   134    134     ** transaction.
   135    135     */
          136  +  static const int iLn = __LINE__+4;
   136    137     static const VdbeOpList openBlob[] = {
   137    138       /* {OP_Transaction, 0, 0, 0},  // 0: Inserted separately */
   138    139       {OP_TableLock, 0, 0, 0},       /* 1: Acquire a read or write lock */
   139         -
   140    140       /* One of the following two instructions is replaced by an OP_Noop. */
   141    141       {OP_OpenRead, 0, 0, 0},        /* 2: Open cursor 0 for reading */
   142    142       {OP_OpenWrite, 0, 0, 0},       /* 3: Open cursor 0 for read/write */
   143         -
   144    143       {OP_Variable, 1, 1, 1},        /* 4: Push the rowid to the stack */
   145    144       {OP_NotExists, 0, 10, 1},      /* 5: Seek the cursor */
   146    145       {OP_Column, 0, 0, 1},          /* 6  */
   147    146       {OP_ResultRow, 1, 0, 0},       /* 7  */
   148    147       {OP_Goto, 0, 4, 0},            /* 8  */
   149    148       {OP_Close, 0, 0, 0},           /* 9  */
   150    149       {OP_Halt, 0, 0, 0},            /* 10 */
................................................................................
   261    260         int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
   262    261   
   263    262   
   264    263         sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, flags, 
   265    264                              pTab->pSchema->schema_cookie,
   266    265                              pTab->pSchema->iGeneration);
   267    266         sqlite3VdbeChangeP5(v, 1);     
   268         -      sqlite3VdbeAddOpList(v, sizeof(openBlob)/sizeof(VdbeOpList), openBlob);
          267  +      sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn);
   269    268   
   270    269         /* Make sure a mutex is held on the table to be accessed */
   271    270         sqlite3VdbeUsesBtree(v, iDb); 
   272    271   
   273    272         /* Configure the OP_TableLock instruction */
   274    273   #ifdef SQLITE_OMIT_SHARED_CACHE
   275    274         sqlite3VdbeChangeToNoop(v, 1);

Changes to src/where.c.

  1704   1704     assert( pLevel->iIdxCur>=0 );
  1705   1705     pLevel->iIdxCur = pParse->nTab++;
  1706   1706     sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
  1707   1707     sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
  1708   1708     VdbeComment((v, "for %s", pTable->zName));
  1709   1709   
  1710   1710     /* Fill the automatic index with content */
  1711         -  addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur);
         1711  +  addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
  1712   1712     regRecord = sqlite3GetTempReg(pParse);
  1713   1713     sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
  1714   1714     sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
  1715   1715     sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
  1716         -  sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1);
         1716  +  sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
  1717   1717     sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
  1718   1718     sqlite3VdbeJumpHere(v, addrTop);
  1719   1719     sqlite3ReleaseTempReg(pParse, regRecord);
  1720   1720     
  1721   1721     /* Jump here when skipping the initialization */
  1722   1722     sqlite3VdbeJumpHere(v, addrInit);
  1723   1723   }
................................................................................
  2384   2384       iReg = iTarget;
  2385   2385       eType = sqlite3FindInIndex(pParse, pX, 0);
  2386   2386       if( eType==IN_INDEX_INDEX_DESC ){
  2387   2387         testcase( bRev );
  2388   2388         bRev = !bRev;
  2389   2389       }
  2390   2390       iTab = pX->iTable;
  2391         -    sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
         2391  +    sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0); VdbeCoverage(v);
  2392   2392       assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
  2393   2393       pLoop->wsFlags |= WHERE_IN_ABLE;
  2394   2394       if( pLevel->u.in.nIn==0 ){
  2395   2395         pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
  2396   2396       }
  2397   2397       pLevel->u.in.nIn++;
  2398   2398       pLevel->u.in.aInLoop =
................................................................................
  2404   2404         pIn->iCur = iTab;
  2405   2405         if( eType==IN_INDEX_ROWID ){
  2406   2406           pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
  2407   2407         }else{
  2408   2408           pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
  2409   2409         }
  2410   2410         pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen;
  2411         -      sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
         2411  +      sqlite3VdbeAddOp1(v, OP_IsNull, iReg); VdbeCoverage(v);
  2412   2412       }else{
  2413   2413         pLevel->u.in.nIn = 0;
  2414   2414       }
  2415   2415   #endif
  2416   2416     }
  2417   2417     disableTerm(pLevel, pTerm);
  2418   2418     return iReg;
................................................................................
  2498   2498     zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
  2499   2499     if( !zAff ){
  2500   2500       pParse->db->mallocFailed = 1;
  2501   2501     }
  2502   2502   
  2503   2503     if( nSkip ){
  2504   2504       int iIdxCur = pLevel->iIdxCur;
  2505         -    sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
         2505  +    sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur); VdbeCoverage(v);
  2506   2506       VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
  2507   2507       j = sqlite3VdbeAddOp0(v, OP_Goto);
  2508   2508       pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLT:OP_SeekGT),
  2509         -                            iIdxCur, 0, regBase, nSkip);
         2509  +                            iIdxCur, 0, regBase, nSkip); VdbeCoverage(v);
  2510   2510       sqlite3VdbeJumpHere(v, j);
  2511   2511       for(j=0; j<nSkip; j++){
  2512   2512         sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j);
  2513   2513         assert( pIdx->aiColumn[j]>=0 );
  2514   2514         VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName));
  2515   2515       }
  2516   2516     }    
................................................................................
  2783   2783     }
  2784   2784   
  2785   2785     /* Special case of a FROM clause subquery implemented as a co-routine */
  2786   2786     if( pTabItem->viaCoroutine ){
  2787   2787       int regYield = pTabItem->regReturn;
  2788   2788       sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
  2789   2789       pLevel->p2 =  sqlite3VdbeAddOp2(v, OP_Yield, regYield, addrBrk);
         2790  +    VdbeCoverage(v);
  2790   2791       VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
  2791   2792       pLevel->op = OP_Goto;
  2792   2793     }else
  2793   2794   
  2794   2795   #ifndef SQLITE_OMIT_VIRTUALTABLE
  2795   2796     if(  (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
  2796   2797       /* Case 1:  The table is a virtual-table.  Use the VFilter and VNext
................................................................................
  2815   2816         }
  2816   2817       }
  2817   2818       sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
  2818   2819       sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
  2819   2820       sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
  2820   2821                         pLoop->u.vtab.idxStr,
  2821   2822                         pLoop->u.vtab.needFree ? P4_MPRINTF : P4_STATIC);
         2823  +    VdbeCoverage(v);
  2822   2824       pLoop->u.vtab.needFree = 0;
  2823   2825       for(j=0; j<nConstraint && j<16; j++){
  2824   2826         if( (pLoop->u.vtab.omitMask>>j)&1 ){
  2825   2827           disableTerm(pLevel, pLoop->aLTerm[j]);
  2826   2828         }
  2827   2829       }
  2828   2830       pLevel->op = OP_VNext;
................................................................................
  2846   2848       pTerm = pLoop->aLTerm[0];
  2847   2849       assert( pTerm!=0 );
  2848   2850       assert( pTerm->pExpr!=0 );
  2849   2851       assert( omitTable==0 );
  2850   2852       testcase( pTerm->wtFlags & TERM_VIRTUAL );
  2851   2853       iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
  2852   2854       addrNxt = pLevel->addrNxt;
  2853         -    sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt);
         2855  +    sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt); VdbeCoverage(v);
  2854   2856       sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg);
         2857  +    VdbeCoverage(v);
  2855   2858       sqlite3ExprCacheAffinityChange(pParse, iRowidReg, 1);
  2856   2859       sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
  2857   2860       VdbeComment((v, "pk"));
  2858   2861       pLevel->op = OP_Noop;
  2859   2862     }else if( (pLoop->wsFlags & WHERE_IPK)!=0
  2860   2863            && (pLoop->wsFlags & WHERE_COLUMN_RANGE)!=0
  2861   2864     ){
................................................................................
  2897   2900         assert( (pStart->wtFlags & TERM_VNULL)==0 );
  2898   2901         testcase( pStart->wtFlags & TERM_VIRTUAL );
  2899   2902         pX = pStart->pExpr;
  2900   2903         assert( pX!=0 );
  2901   2904         testcase( pStart->leftCursor!=iCur ); /* transitive constraints */
  2902   2905         r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
  2903   2906         sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
  2904         -      VdbeComment((v, "pk"));
         2907  +      VdbeComment((v, "pk")); VdbeCoverage(v);
  2905   2908         sqlite3ExprCacheAffinityChange(pParse, r1, 1);
  2906   2909         sqlite3ReleaseTempReg(pParse, rTemp);
  2907   2910         disableTerm(pLevel, pStart);
  2908   2911       }else{
  2909   2912         sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk);
         2913  +      VdbeCoverage(v);
  2910   2914       }
  2911   2915       if( pEnd ){
  2912   2916         Expr *pX;
  2913   2917         pX = pEnd->pExpr;
  2914   2918         assert( pX!=0 );
  2915   2919         assert( (pEnd->wtFlags & TERM_VNULL)==0 );
  2916   2920         testcase( pEnd->leftCursor!=iCur ); /* Transitive constraints */
................................................................................
  2930   2934       pLevel->p2 = start;
  2931   2935       assert( pLevel->p5==0 );
  2932   2936       if( testOp!=OP_Noop ){
  2933   2937         iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
  2934   2938         sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
  2935   2939         sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
  2936   2940         sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
         2941  +      VdbeCoverage(v);
  2937   2942         sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
  2938   2943       }
  2939   2944     }else if( pLoop->wsFlags & WHERE_INDEXED ){
  2940   2945       /* Case 4: A scan using an index.
  2941   2946       **
  2942   2947       **         The WHERE clause may contain zero or more equality 
  2943   2948       **         terms ("==" or "IN" operators) that refer to the N
................................................................................
  3103   3108       testcase( op==OP_Rewind );
  3104   3109       testcase( op==OP_Last );
  3105   3110       testcase( op==OP_SeekGT );
  3106   3111       testcase( op==OP_SeekGE );
  3107   3112       testcase( op==OP_SeekLE );
  3108   3113       testcase( op==OP_SeekLT );
  3109   3114       sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
         3115  +    VdbeCoverage(v);
         3116  +    VdbeCoverageIf(v, op==OP_Rewind);
         3117  +    VdbeCoverageIf(v, op==OP_Last);
         3118  +    VdbeCoverageIf(v, op==OP_SeekGT);
         3119  +    VdbeCoverageIf(v, op==OP_SeekGE);
         3120  +    VdbeCoverageIf(v, op==OP_SeekLE);
         3121  +    VdbeCoverageIf(v, op==OP_SeekLT);
  3110   3122   
  3111   3123       /* Load the value for the inequality constraint at the end of the
  3112   3124       ** range (if any).
  3113   3125       */
  3114   3126       nConstraint = nEq;
  3115   3127       if( pRangeEnd ){
  3116   3128         Expr *pRight = pRangeEnd->pExpr->pRight;
................................................................................
  3140   3152       if( nConstraint ){
  3141   3153         op = aEndOp[bRev*2 + endEq];
  3142   3154         testcase( op==OP_IdxGT );
  3143   3155         testcase( op==OP_IdxGE );
  3144   3156         testcase( op==OP_IdxLT );
  3145   3157         testcase( op==OP_IdxLE );
  3146   3158         sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
         3159  +      VdbeCoverage(v);
  3147   3160       }
  3148   3161   
  3149   3162       /* Seek the table cursor, if required */
  3150   3163       disableTerm(pLevel, pRangeStart);
  3151   3164       disableTerm(pLevel, pRangeEnd);
  3152   3165       if( omitTable ){
  3153   3166         /* pIdx is a covering index.  No need to access the main table. */
................................................................................
  3160   3173         Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
  3161   3174         iRowidReg = sqlite3GetTempRange(pParse, pPk->nKeyCol);
  3162   3175         for(j=0; j<pPk->nKeyCol; j++){
  3163   3176           k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
  3164   3177           sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
  3165   3178         }
  3166   3179         sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
  3167         -                           iRowidReg, pPk->nKeyCol);
         3180  +                           iRowidReg, pPk->nKeyCol); VdbeCoverage(v);
  3168   3181       }
  3169   3182   
  3170   3183       /* Record the instruction used to terminate the loop. Disable 
  3171   3184       ** WHERE clause terms made redundant by the index range scan.
  3172   3185       */
  3173   3186       if( pLoop->wsFlags & WHERE_ONEROW ){
  3174   3187         pLevel->op = OP_Noop;
................................................................................
  3344   3357             if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
  3345   3358               int iSet = ((ii==pOrWc->nTerm-1)?-1:ii);
  3346   3359               int r;
  3347   3360               r = sqlite3ExprCodeGetColumn(pParse, pTabItem->pTab, -1, iCur, 
  3348   3361                                            regRowid, 0);
  3349   3362               sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset,
  3350   3363                                    sqlite3VdbeCurrentAddr(v)+2, r, iSet);
         3364  +            VdbeCoverage(v);
  3351   3365             }
  3352   3366             sqlite3VdbeAddOp2(v, OP_Gosub, regReturn, iLoopBody);
  3353   3367   
  3354   3368             /* The pSubWInfo->untestedTerms flag means that this OR term
  3355   3369             ** contained one or more AND term from a notReady table.  The
  3356   3370             ** terms from the notReady table could not be tested and will
  3357   3371             ** need to be tested later.
................................................................................
  3412   3426         /* Tables marked isRecursive have only a single row that is stored in
  3413   3427         ** a pseudo-cursor.  No need to Rewind or Next such cursors. */
  3414   3428         pLevel->op = OP_Noop;
  3415   3429       }else{
  3416   3430         pLevel->op = aStep[bRev];
  3417   3431         pLevel->p1 = iCur;
  3418   3432         pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
         3433  +      VdbeCoverageIf(v, bRev);
         3434  +      VdbeCoverageIf(v, !bRev);
  3419   3435         pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
  3420   3436       }
  3421   3437     }
  3422   3438   
  3423   3439     /* Insert code to test every subexpression that can be completely
  3424   3440     ** computed using the current set of tables.
  3425   3441     */
................................................................................
  5781   5797       int addr;
  5782   5798       pLevel = &pWInfo->a[i];
  5783   5799       pLoop = pLevel->pWLoop;
  5784   5800       sqlite3VdbeResolveLabel(v, pLevel->addrCont);
  5785   5801       if( pLevel->op!=OP_Noop ){
  5786   5802         sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
  5787   5803         sqlite3VdbeChangeP5(v, pLevel->p5);
         5804  +      VdbeCoverage(v);
  5788   5805       }
  5789   5806       if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
  5790   5807         struct InLoop *pIn;
  5791   5808         int j;
  5792   5809         sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
  5793   5810         for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
  5794   5811           sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
  5795   5812           sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
         5813  +        VdbeCoverage(v);
  5796   5814           sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
  5797   5815         }
  5798   5816         sqlite3DbFree(db, pLevel->u.in.aInLoop);
  5799   5817       }
  5800   5818       sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
  5801   5819       if( pLevel->addrSkip ){
  5802   5820         sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
  5803   5821         VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
  5804   5822         sqlite3VdbeJumpHere(v, pLevel->addrSkip);
  5805   5823         sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
  5806   5824       }
  5807   5825       if( pLevel->iLeftJoin ){
  5808         -      addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin);
         5826  +      addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
  5809   5827         assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
  5810   5828              || (pLoop->wsFlags & WHERE_INDEXED)!=0 );
  5811   5829         if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){
  5812   5830           sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
  5813   5831         }
  5814   5832         if( pLoop->wsFlags & WHERE_INDEXED ){
  5815   5833           sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);