/ Check-in [b92d31a9]
Login

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

Overview
Comment:Add VdbeCoverage() and VdbeCoverageIf() macros for improved VDBE coverage testing.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b92d31a97d5fe4606d9ae1393c7f3e052f46bf5a
User & Date: drh 2014-02-18 03:07:12
Context
2014-02-18
11:31
Fix VDBE branch accounting on comparison operators. check-in: b287520c user: drh tags: trunk
05:18
Enhance the Win32 VFS I/O retry logic. check-in: adba783c user: mistachkin tags: winIoRetry
03:07
Add VdbeCoverage() and VdbeCoverageIf() macros for improved VDBE coverage testing. check-in: b92d31a9 user: drh tags: trunk
01:07
Improvements to "NOT IN (SELECT ...)" processing. Only test for NULL values on the RHS on the first iteration, then remember the result. There has been logic to do this for year, but it didn't work right and ended up repeating the NULL test on every iteration. This inefficiency was found using the VDBE coverage testing tools. check-in: 915f6f1c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

  1365   1365       case TK_BLOB:
  1366   1366         return 0;
  1367   1367       default:
  1368   1368         return 1;
  1369   1369     }
  1370   1370   }
  1371   1371   
  1372         -/*
  1373         -** Generate an OP_IsNull instruction that tests register iReg and jumps
  1374         -** to location iDest if the value in iReg is NULL.  The value in iReg 
  1375         -** was computed by pExpr.  If we can look at pExpr at compile-time and
  1376         -** determine that it can never generate a NULL, then the OP_IsNull operation
  1377         -** can be omitted.
  1378         -*/
  1379         -void sqlite3ExprCodeIsNullJump(
  1380         -  Vdbe *v,            /* The VDBE under construction */
  1381         -  const Expr *pExpr,  /* Only generate OP_IsNull if this expr can be NULL */
  1382         -  int iReg,           /* Test the value in this register for NULL */
  1383         -  int iDest           /* Jump here if the value is null */
  1384         -){
  1385         -  if( sqlite3ExprCanBeNull(pExpr) ){
  1386         -    sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iDest); VdbeCoverage(v);
  1387         -  }
  1388         -}
  1389         -
  1390   1372   /*
  1391   1373   ** Return TRUE if the given expression is a constant which would be
  1392   1374   ** unchanged by OP_Affinity with the affinity given in the second
  1393   1375   ** argument.
  1394   1376   **
  1395   1377   ** This routine is used to determine if the OP_Affinity operation
  1396   1378   ** can be omitted.  When in doubt return FALSE.  A false negative
................................................................................
  1482   1464   
  1483   1465   /*
  1484   1466   ** Code an OP_Once instruction and allocate space for its flag. Return the 
  1485   1467   ** address of the new instruction.
  1486   1468   */
  1487   1469   int sqlite3CodeOnce(Parse *pParse){
  1488   1470     Vdbe *v = sqlite3GetVdbe(pParse);      /* Virtual machine being coded */
  1489         -  int addr = sqlite3VdbeAddOp1(v, OP_Once, pParse->nOnce++);
  1490         -  VdbeCoverage(v);
  1491         -  return addr;
         1471  +  return sqlite3VdbeAddOp1(v, OP_Once, pParse->nOnce++);
  1492   1472   }
  1493   1473   
  1494   1474   /*
  1495   1475   ** This function is used by the implementation of the IN (...) operator.
  1496   1476   ** The pX parameter is the expression on the RHS of the IN operator, which
  1497   1477   ** might be either a list of expressions or a subquery.
  1498   1478   **
................................................................................
  1592   1572   
  1593   1573       /* This function is only called from two places. In both cases the vdbe
  1594   1574       ** has already been allocated. So assume sqlite3GetVdbe() is always
  1595   1575       ** successful here.
  1596   1576       */
  1597   1577       assert(v);
  1598   1578       if( iCol<0 ){
  1599         -      int iAddr;
  1600         -
  1601         -      iAddr = sqlite3CodeOnce(pParse);
         1579  +      int iAddr = sqlite3CodeOnce(pParse);
         1580  +      VdbeCoverage(v);
  1602   1581   
  1603   1582         sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
  1604   1583         eType = IN_INDEX_ROWID;
  1605   1584   
  1606   1585         sqlite3VdbeJumpHere(v, iAddr);
  1607   1586       }else{
  1608   1587         Index *pIdx;                         /* Iterator variable */
................................................................................
  1619   1598         int affinity_ok = sqlite3IndexAffinityOk(pX, pTab->aCol[iCol].affinity);
  1620   1599   
  1621   1600         for(pIdx=pTab->pIndex; pIdx && eType==0 && affinity_ok; pIdx=pIdx->pNext){
  1622   1601           if( (pIdx->aiColumn[0]==iCol)
  1623   1602            && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
  1624   1603            && (!mustBeUnique || (pIdx->nKeyCol==1 && pIdx->onError!=OE_None))
  1625   1604           ){
  1626         -          int iAddr = sqlite3CodeOnce(pParse);
         1605  +          int iAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
  1627   1606             sqlite3VdbeAddOp3(v, OP_OpenRead, iTab, pIdx->tnum, iDb);
  1628   1607             sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
  1629   1608             VdbeComment((v, "%s", pIdx->zName));
  1630   1609             assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
  1631   1610             eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
  1632   1611   
  1633   1612             if( prNotFound && !pTab->aCol[iCol].notNull ){
................................................................................
  1719   1698     **    *  The right-hand side is an expression list containing variables
  1720   1699     **    *  We are inside a trigger
  1721   1700     **
  1722   1701     ** If all of the above are false, then we can run this code just once
  1723   1702     ** save the results, and reuse the same result on subsequent invocations.
  1724   1703     */
  1725   1704     if( !ExprHasProperty(pExpr, EP_VarSelect) ){
  1726         -    testAddr = sqlite3CodeOnce(pParse);
         1705  +    testAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
  1727   1706     }
  1728   1707   
  1729   1708   #ifndef SQLITE_OMIT_EXPLAIN
  1730   1709     if( pParse->explain==2 ){
  1731   1710       char *zMsg = sqlite3MPrintf(
  1732   1711           pParse->db, "EXECUTE %s%s SUBQUERY %d", testAddr>=0?"":"CORRELATED ",
  1733   1712           pExpr->op==TK_IN?"LIST":"SCALAR", pParse->iNextSelectId
................................................................................
  2544   2523   #endif /* SQLITE_OMIT_CAST */
  2545   2524       case TK_LT:
  2546   2525       case TK_LE:
  2547   2526       case TK_GT:
  2548   2527       case TK_GE:
  2549   2528       case TK_NE:
  2550   2529       case TK_EQ: {
  2551         -      assert( TK_LT==OP_Lt );
  2552         -      assert( TK_LE==OP_Le );
  2553         -      assert( TK_GT==OP_Gt );
  2554         -      assert( TK_GE==OP_Ge );
  2555         -      assert( TK_EQ==OP_Eq );
  2556         -      assert( TK_NE==OP_Ne );
  2557         -      testcase( op==TK_LT );
  2558         -      testcase( op==TK_LE );
  2559         -      testcase( op==TK_GT );
  2560         -      testcase( op==TK_GE );
  2561         -      testcase( op==TK_EQ );
  2562         -      testcase( op==TK_NE );
  2563   2530         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  2564   2531         r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  2565   2532         codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  2566         -                  r1, r2, inReg, SQLITE_STOREP2); VdbeCoverage(v);
         2533  +                  r1, r2, inReg, SQLITE_STOREP2);
         2534  +      assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
         2535  +      assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
         2536  +      assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
         2537  +      assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
         2538  +      assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
         2539  +      assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
  2567   2540         testcase( regFree1==0 );
  2568   2541         testcase( regFree2==0 );
  2569   2542         break;
  2570   2543       }
  2571   2544       case TK_IS:
  2572   2545       case TK_ISNOT: {
  2573   2546         testcase( op==TK_IS );
  2574   2547         testcase( op==TK_ISNOT );
  2575   2548         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  2576   2549         r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  2577   2550         op = (op==TK_IS) ? TK_EQ : TK_NE;
  2578   2551         codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  2579   2552                     r1, r2, inReg, SQLITE_STOREP2 | SQLITE_NULLEQ);
  2580         -      VdbeCoverage(v);
         2553  +      VdbeCoverageIf(v, op==TK_EQ);
         2554  +      VdbeCoverageIf(v, op==TK_NE);
  2581   2555         testcase( regFree1==0 );
  2582   2556         testcase( regFree2==0 );
  2583   2557         break;
  2584   2558       }
  2585   2559       case TK_AND:
  2586   2560       case TK_OR:
  2587   2561       case TK_PLUS:
................................................................................
  2590   2564       case TK_REM:
  2591   2565       case TK_BITAND:
  2592   2566       case TK_BITOR:
  2593   2567       case TK_SLASH:
  2594   2568       case TK_LSHIFT:
  2595   2569       case TK_RSHIFT: 
  2596   2570       case TK_CONCAT: {
  2597         -      assert( TK_AND==OP_And );
  2598         -      assert( TK_OR==OP_Or );
  2599         -      assert( TK_PLUS==OP_Add );
  2600         -      assert( TK_MINUS==OP_Subtract );
  2601         -      assert( TK_REM==OP_Remainder );
  2602         -      assert( TK_BITAND==OP_BitAnd );
  2603         -      assert( TK_BITOR==OP_BitOr );
  2604         -      assert( TK_SLASH==OP_Divide );
  2605         -      assert( TK_LSHIFT==OP_ShiftLeft );
  2606         -      assert( TK_RSHIFT==OP_ShiftRight );
  2607         -      assert( TK_CONCAT==OP_Concat );
  2608         -      testcase( op==TK_AND );
  2609         -      testcase( op==TK_OR );
  2610         -      testcase( op==TK_PLUS );
  2611         -      testcase( op==TK_MINUS );
  2612         -      testcase( op==TK_REM );
  2613         -      testcase( op==TK_BITAND );
  2614         -      testcase( op==TK_BITOR );
  2615         -      testcase( op==TK_SLASH );
  2616         -      testcase( op==TK_LSHIFT );
  2617         -      testcase( op==TK_RSHIFT );
  2618         -      testcase( op==TK_CONCAT );
         2571  +      assert( TK_AND==OP_And );            testcase( op==TK_AND );
         2572  +      assert( TK_OR==OP_Or );              testcase( op==TK_OR );
         2573  +      assert( TK_PLUS==OP_Add );           testcase( op==TK_PLUS );
         2574  +      assert( TK_MINUS==OP_Subtract );     testcase( op==TK_MINUS );
         2575  +      assert( TK_REM==OP_Remainder );      testcase( op==TK_REM );
         2576  +      assert( TK_BITAND==OP_BitAnd );      testcase( op==TK_BITAND );
         2577  +      assert( TK_BITOR==OP_BitOr );        testcase( op==TK_BITOR );
         2578  +      assert( TK_SLASH==OP_Divide );       testcase( op==TK_SLASH );
         2579  +      assert( TK_LSHIFT==OP_ShiftLeft );   testcase( op==TK_LSHIFT );
         2580  +      assert( TK_RSHIFT==OP_ShiftRight );  testcase( op==TK_RSHIFT );
         2581  +      assert( TK_CONCAT==OP_Concat );      testcase( op==TK_CONCAT );
  2619   2582         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  2620   2583         r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  2621   2584         sqlite3VdbeAddOp3(v, op, r2, r1, target);
  2622   2585         testcase( regFree1==0 );
  2623   2586         testcase( regFree2==0 );
  2624   2587         break;
  2625   2588       }
................................................................................
  2643   2606           testcase( regFree2==0 );
  2644   2607         }
  2645   2608         inReg = target;
  2646   2609         break;
  2647   2610       }
  2648   2611       case TK_BITNOT:
  2649   2612       case TK_NOT: {
  2650         -      assert( TK_BITNOT==OP_BitNot );
  2651         -      assert( TK_NOT==OP_Not );
  2652         -      testcase( op==TK_BITNOT );
  2653         -      testcase( op==TK_NOT );
         2613  +      assert( TK_BITNOT==OP_BitNot );   testcase( op==TK_BITNOT );
         2614  +      assert( TK_NOT==OP_Not );         testcase( op==TK_NOT );
  2654   2615         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  2655   2616         testcase( regFree1==0 );
  2656   2617         inReg = target;
  2657   2618         sqlite3VdbeAddOp2(v, op, r1, inReg);
  2658   2619         break;
  2659   2620       }
  2660   2621       case TK_ISNULL:
  2661   2622       case TK_NOTNULL: {
  2662   2623         int addr;
  2663         -      assert( TK_ISNULL==OP_IsNull );
  2664         -      assert( TK_NOTNULL==OP_NotNull );
  2665         -      testcase( op==TK_ISNULL );
  2666         -      testcase( op==TK_NOTNULL );
         2624  +      assert( TK_ISNULL==OP_IsNull );   testcase( op==TK_ISNULL );
         2625  +      assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
  2667   2626         sqlite3VdbeAddOp2(v, OP_Integer, 1, target);
  2668   2627         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  2669   2628         testcase( regFree1==0 );
  2670         -      addr = sqlite3VdbeAddOp1(v, op, r1); VdbeCoverage(v);
         2629  +      addr = sqlite3VdbeAddOp1(v, op, r1);
         2630  +      VdbeCoverageIf(v, op==TK_ISNULL);
         2631  +      VdbeCoverageIf(v, op==TK_NOTNULL);
  2671   2632         sqlite3VdbeAddOp2(v, OP_AddImm, target, -1);
  2672   2633         sqlite3VdbeJumpHere(v, addr);
  2673   2634         break;
  2674   2635       }
  2675   2636       case TK_AGG_FUNCTION: {
  2676   2637         AggInfo *pInfo = pExpr->pAggInfo;
  2677   2638         if( pInfo==0 ){
................................................................................
  2853   2814         r1 = sqlite3ExprCodeTemp(pParse, pLeft, &regFree1);
  2854   2815         r2 = sqlite3ExprCodeTemp(pParse, pRight, &regFree2);
  2855   2816         testcase( regFree1==0 );
  2856   2817         testcase( regFree2==0 );
  2857   2818         r3 = sqlite3GetTempReg(pParse);
  2858   2819         r4 = sqlite3GetTempReg(pParse);
  2859   2820         codeCompare(pParse, pLeft, pRight, OP_Ge,
  2860         -                  r1, r2, r3, SQLITE_STOREP2);
  2861         -      VdbeCoverage(v);
         2821  +                  r1, r2, r3, SQLITE_STOREP2);  VdbeCoverage(v);
  2862   2822         pLItem++;
  2863   2823         pRight = pLItem->pExpr;
  2864   2824         sqlite3ReleaseTempReg(pParse, regFree2);
  2865   2825         r2 = sqlite3ExprCodeTemp(pParse, pRight, &regFree2);
  2866   2826         testcase( regFree2==0 );
  2867   2827         codeCompare(pParse, pLeft, pRight, OP_Le, r1, r2, r4, SQLITE_STOREP2);
  2868   2828         VdbeCoverage(v);
................................................................................
  3601   3561       }
  3602   3562       case TK_LT:
  3603   3563       case TK_LE:
  3604   3564       case TK_GT:
  3605   3565       case TK_GE:
  3606   3566       case TK_NE:
  3607   3567       case TK_EQ: {
  3608         -      assert( TK_LT==OP_Lt );
  3609         -      assert( TK_LE==OP_Le );
  3610         -      assert( TK_GT==OP_Gt );
  3611         -      assert( TK_GE==OP_Ge );
  3612         -      assert( TK_EQ==OP_Eq );
  3613         -      assert( TK_NE==OP_Ne );
  3614         -      testcase( op==TK_LT );
  3615         -      testcase( op==TK_LE );
  3616         -      testcase( op==TK_GT );
  3617         -      testcase( op==TK_GE );
  3618         -      testcase( op==TK_EQ );
  3619         -      testcase( op==TK_NE );
  3620   3568         testcase( jumpIfNull==0 );
  3621   3569         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  3622   3570         r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  3623   3571         codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  3624         -                  r1, r2, dest, jumpIfNull);  VdbeCoverage(v);
         3572  +                  r1, r2, dest, jumpIfNull);
         3573  +      assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
         3574  +      assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
         3575  +      assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
         3576  +      assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
         3577  +      assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
         3578  +      assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
  3625   3579         testcase( regFree1==0 );
  3626   3580         testcase( regFree2==0 );
  3627   3581         break;
  3628   3582       }
  3629   3583       case TK_IS:
  3630   3584       case TK_ISNOT: {
  3631   3585         testcase( op==TK_IS );
  3632   3586         testcase( op==TK_ISNOT );
  3633   3587         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  3634   3588         r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  3635   3589         op = (op==TK_IS) ? TK_EQ : TK_NE;
  3636   3590         codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  3637         -                  r1, r2, dest, SQLITE_NULLEQ);  VdbeCoverage(v);
         3591  +                  r1, r2, dest, SQLITE_NULLEQ);
         3592  +      VdbeCoverageIf(v, op==TK_EQ);
         3593  +      VdbeCoverageIf(v, op==TK_NE);
  3638   3594         testcase( regFree1==0 );
  3639   3595         testcase( regFree2==0 );
  3640   3596         break;
  3641   3597       }
  3642   3598       case TK_ISNULL:
  3643   3599       case TK_NOTNULL: {
  3644         -      assert( TK_ISNULL==OP_IsNull );
  3645         -      assert( TK_NOTNULL==OP_NotNull );
  3646         -      testcase( op==TK_ISNULL );
  3647         -      testcase( op==TK_NOTNULL );
         3600  +      assert( TK_ISNULL==OP_IsNull );   testcase( op==TK_ISNULL );
         3601  +      assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
  3648   3602         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  3649         -      sqlite3VdbeAddOp2(v, op, r1, dest); VdbeCoverage(v);
         3603  +      sqlite3VdbeAddOp2(v, op, r1, dest);
         3604  +      VdbeCoverageIf(v, op==TK_ISNULL);
         3605  +      VdbeCoverageIf(v, op==TK_NOTNULL);
  3650   3606         testcase( regFree1==0 );
  3651   3607         break;
  3652   3608       }
  3653   3609       case TK_BETWEEN: {
  3654   3610         testcase( jumpIfNull==0 );
  3655   3611         exprCodeBetween(pParse, pExpr, dest, 1, jumpIfNull);
  3656   3612         break;
................................................................................
  3761   3717       }
  3762   3718       case TK_LT:
  3763   3719       case TK_LE:
  3764   3720       case TK_GT:
  3765   3721       case TK_GE:
  3766   3722       case TK_NE:
  3767   3723       case TK_EQ: {
  3768         -      testcase( op==TK_LT );
  3769         -      testcase( op==TK_LE );
  3770         -      testcase( op==TK_GT );
  3771         -      testcase( op==TK_GE );
  3772         -      testcase( op==TK_EQ );
  3773         -      testcase( op==TK_NE );
  3774   3724         testcase( jumpIfNull==0 );
  3775   3725         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  3776   3726         r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  3777   3727         codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  3778         -                  r1, r2, dest, jumpIfNull);  VdbeCoverage(v);
         3728  +                  r1, r2, dest, jumpIfNull);
         3729  +      assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
         3730  +      assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
         3731  +      assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
         3732  +      assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
         3733  +      assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
         3734  +      assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
  3779   3735         testcase( regFree1==0 );
  3780   3736         testcase( regFree2==0 );
  3781   3737         break;
  3782   3738       }
  3783   3739       case TK_IS:
  3784   3740       case TK_ISNOT: {
  3785   3741         testcase( pExpr->op==TK_IS );
  3786   3742         testcase( pExpr->op==TK_ISNOT );
  3787   3743         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  3788   3744         r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
  3789   3745         op = (pExpr->op==TK_IS) ? TK_NE : TK_EQ;
  3790   3746         codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
  3791         -                  r1, r2, dest, SQLITE_NULLEQ);  VdbeCoverage(v);
         3747  +                  r1, r2, dest, SQLITE_NULLEQ);
         3748  +      VdbeCoverageIf(v, op==TK_EQ);
         3749  +      VdbeCoverageIf(v, op==TK_NE);
  3792   3750         testcase( regFree1==0 );
  3793   3751         testcase( regFree2==0 );
  3794   3752         break;
  3795   3753       }
  3796   3754       case TK_ISNULL:
  3797   3755       case TK_NOTNULL: {
  3798         -      testcase( op==TK_ISNULL );
  3799         -      testcase( op==TK_NOTNULL );
  3800   3756         r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
  3801         -      sqlite3VdbeAddOp2(v, op, r1, dest); VdbeCoverage(v);
         3757  +      sqlite3VdbeAddOp2(v, op, r1, dest);
         3758  +      testcase( op==TK_ISNULL );   VdbeCoverageIf(v, op==TK_ISNULL);
         3759  +      testcase( op==TK_NOTNULL );  VdbeCoverageIf(v, op==TK_NOTNULL);
  3802   3760         testcase( regFree1==0 );
  3803   3761         break;
  3804   3762       }
  3805   3763       case TK_BETWEEN: {
  3806   3764         testcase( jumpIfNull==0 );
  3807   3765         exprCodeBetween(pParse, pExpr, dest, 0, jumpIfNull);
  3808   3766         break;

Changes to src/select.c.

  4591   4591         pItem->regReturn = ++pParse->nMem;
  4592   4592         topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
  4593   4593         pItem->addrFillSub = topAddr+1;
  4594   4594         if( pItem->isCorrelated==0 ){
  4595   4595           /* If the subquery is not correlated and if we are not inside of
  4596   4596           ** a trigger, then we only need to compute the value of the subquery
  4597   4597           ** once. */
  4598         -        onceAddr = sqlite3CodeOnce(pParse);
         4598  +        onceAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
  4599   4599           VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
  4600   4600         }else{
  4601   4601           VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
  4602   4602         }
  4603   4603         sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
  4604   4604         explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
  4605   4605         sqlite3Select(pParse, pSub, &dest);

Changes to src/sqliteInt.h.

  3083   3083   void sqlite3CloseSavepoints(sqlite3 *);
  3084   3084   void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
  3085   3085   int sqlite3ExprIsConstant(Expr*);
  3086   3086   int sqlite3ExprIsConstantNotJoin(Expr*);
  3087   3087   int sqlite3ExprIsConstantOrFunction(Expr*);
  3088   3088   int sqlite3ExprIsInteger(Expr*, int*);
  3089   3089   int sqlite3ExprCanBeNull(const Expr*);
  3090         -void sqlite3ExprCodeIsNullJump(Vdbe*, const Expr*, int, int);
  3091   3090   int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
  3092   3091   int sqlite3IsRowid(const char*);
  3093   3092   void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
  3094   3093   void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
  3095   3094   int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int);
  3096   3095   void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
  3097   3096                                        u8,u8,int,int*);

Changes to src/where.c.

  1597   1597     Bitmask extraCols;          /* Bitmap of additional columns */
  1598   1598     u8 sentWarning = 0;         /* True if a warnning has been issued */
  1599   1599   
  1600   1600     /* Generate code to skip over the creation and initialization of the
  1601   1601     ** transient index on 2nd and subsequent iterations of the loop. */
  1602   1602     v = pParse->pVdbe;
  1603   1603     assert( v!=0 );
  1604         -  addrInit = sqlite3CodeOnce(pParse);
         1604  +  addrInit = sqlite3CodeOnce(pParse); VdbeCoverage(v);
  1605   1605   
  1606   1606     /* Count the number of columns that will be added to the index
  1607   1607     ** and used to match WHERE clause constraints */
  1608   1608     nKeyCol = 0;
  1609   1609     pTable = pSrc->pTab;
  1610   1610     pWCEnd = &pWC->a[pWC->nTerm];
  1611   1611     pLoop = pLevel->pWLoop;
................................................................................
  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); VdbeCoverage(v);
         2391  +    sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
         2392  +    VdbeCoverageIf(v, bRev);
         2393  +    VdbeCoverageIf(v, !bRev);
  2392   2394       assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
  2393   2395       pLoop->wsFlags |= WHERE_IN_ABLE;
  2394   2396       if( pLevel->u.in.nIn==0 ){
  2395   2397         pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
  2396   2398       }
  2397   2399       pLevel->u.in.nIn++;
  2398   2400       pLevel->u.in.aInLoop =
................................................................................
  2498   2500     zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
  2499   2501     if( !zAff ){
  2500   2502       pParse->db->mallocFailed = 1;
  2501   2503     }
  2502   2504   
  2503   2505     if( nSkip ){
  2504   2506       int iIdxCur = pLevel->iIdxCur;
  2505         -    sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur); VdbeCoverage(v);
         2507  +    sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
         2508  +    VdbeCoverageIf(v, bRev==0);
         2509  +    VdbeCoverageIf(v, bRev!=0);
  2506   2510       VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
  2507   2511       j = sqlite3VdbeAddOp0(v, OP_Goto);
  2508   2512       pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLT:OP_SeekGT),
  2509         -                            iIdxCur, 0, regBase, nSkip); VdbeCoverage(v);
         2513  +                            iIdxCur, 0, regBase, nSkip);
         2514  +    VdbeCoverageIf(v, bRev==0);
         2515  +    VdbeCoverageIf(v, bRev!=0);
  2510   2516       sqlite3VdbeJumpHere(v, j);
  2511   2517       for(j=0; j<nSkip; j++){
  2512   2518         sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j);
  2513   2519         assert( pIdx->aiColumn[j]>=0 );
  2514   2520         VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName));
  2515   2521       }
  2516   2522     }    
................................................................................
  2535   2541           sqlite3VdbeAddOp2(v, OP_SCopy, r1, regBase+j);
  2536   2542         }
  2537   2543       }
  2538   2544       testcase( pTerm->eOperator & WO_ISNULL );
  2539   2545       testcase( pTerm->eOperator & WO_IN );
  2540   2546       if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){
  2541   2547         Expr *pRight = pTerm->pExpr->pRight;
  2542         -      sqlite3ExprCodeIsNullJump(v, pRight, regBase+j, pLevel->addrBrk);
         2548  +      if( sqlite3ExprCanBeNull(pRight) ){
         2549  +        sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
         2550  +        VdbeCoverage(v);
         2551  +      }
  2543   2552         if( zAff ){
  2544   2553           if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_NONE ){
  2545   2554             zAff[j] = SQLITE_AFF_NONE;
  2546   2555           }
  2547   2556           if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
  2548   2557             zAff[j] = SQLITE_AFF_NONE;
  2549   2558           }
................................................................................
  2900   2909         assert( (pStart->wtFlags & TERM_VNULL)==0 );
  2901   2910         testcase( pStart->wtFlags & TERM_VIRTUAL );
  2902   2911         pX = pStart->pExpr;
  2903   2912         assert( pX!=0 );
  2904   2913         testcase( pStart->leftCursor!=iCur ); /* transitive constraints */
  2905   2914         r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
  2906   2915         sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
  2907         -      VdbeComment((v, "pk")); VdbeCoverage(v);
         2916  +      VdbeComment((v, "pk"));
         2917  +      VdbeCoverageIf(v, pX->op==TK_GT);
         2918  +      VdbeCoverageIf(v, pX->op==TK_LE);
         2919  +      VdbeCoverageIf(v, pX->op==TK_LT);
         2920  +      VdbeCoverageIf(v, pX->op==TK_GE);
  2908   2921         sqlite3ExprCacheAffinityChange(pParse, r1, 1);
  2909   2922         sqlite3ReleaseTempReg(pParse, rTemp);
  2910   2923         disableTerm(pLevel, pStart);
  2911   2924       }else{
  2912   2925         sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk);
  2913         -      VdbeCoverage(v);
         2926  +      VdbeCoverageIf(v, bRev==0);
         2927  +      VdbeCoverageIf(v, bRev!=0);
  2914   2928       }
  2915   2929       if( pEnd ){
  2916   2930         Expr *pX;
  2917   2931         pX = pEnd->pExpr;
  2918   2932         assert( pX!=0 );
  2919   2933         assert( (pEnd->wtFlags & TERM_VNULL)==0 );
  2920   2934         testcase( pEnd->leftCursor!=iCur ); /* Transitive constraints */
................................................................................
  2934   2948       pLevel->p2 = start;
  2935   2949       assert( pLevel->p5==0 );
  2936   2950       if( testOp!=OP_Noop ){
  2937   2951         iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
  2938   2952         sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
  2939   2953         sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
  2940   2954         sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
  2941         -      VdbeCoverage(v);
         2955  +      VdbeCoverageIf(v, testOp==OP_Le);
         2956  +      VdbeCoverageIf(v, testOp==OP_Lt);
         2957  +      VdbeCoverageIf(v, testOp==OP_Ge);
         2958  +      VdbeCoverageIf(v, testOp==OP_Gt);
  2942   2959         sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
  2943   2960       }
  2944   2961     }else if( pLoop->wsFlags & WHERE_INDEXED ){
  2945   2962       /* Case 4: A scan using an index.
  2946   2963       **
  2947   2964       **         The WHERE clause may contain zero or more equality 
  2948   2965       **         terms ("==" or "IN" operators) that refer to the N
................................................................................
  3076   3093       start_constraints = pRangeStart || nEq>0;
  3077   3094   
  3078   3095       /* Seek the index cursor to the start of the range. */
  3079   3096       nConstraint = nEq;
  3080   3097       if( pRangeStart ){
  3081   3098         Expr *pRight = pRangeStart->pExpr->pRight;
  3082   3099         sqlite3ExprCode(pParse, pRight, regBase+nEq);
  3083         -      if( (pRangeStart->wtFlags & TERM_VNULL)==0 ){
  3084         -        sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
         3100  +      if( (pRangeStart->wtFlags & TERM_VNULL)==0
         3101  +       && sqlite3ExprCanBeNull(pRight)
         3102  +      ){
         3103  +        sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
         3104  +        VdbeCoverage(v);
  3085   3105         }
  3086   3106         if( zStartAff ){
  3087   3107           if( sqlite3CompareAffinity(pRight, zStartAff[nEq])==SQLITE_AFF_NONE){
  3088   3108             /* Since the comparison is to be performed with no conversions
  3089   3109             ** applied to the operands, set the affinity to apply to pRight to 
  3090   3110             ** SQLITE_AFF_NONE.  */
  3091   3111             zStartAff[nEq] = SQLITE_AFF_NONE;
................................................................................
  3101   3121         nConstraint++;
  3102   3122         startEq = 0;
  3103   3123         start_constraints = 1;
  3104   3124       }
  3105   3125       codeApplyAffinity(pParse, regBase, nConstraint - bSeekPastNull, zStartAff);
  3106   3126       op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
  3107   3127       assert( op!=0 );
  3108         -    testcase( op==OP_Rewind );
  3109         -    testcase( op==OP_Last );
  3110         -    testcase( op==OP_SeekGT );
  3111         -    testcase( op==OP_SeekGE );
  3112         -    testcase( op==OP_SeekLE );
  3113         -    testcase( op==OP_SeekLT );
  3114   3128       sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
  3115   3129       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);
         3130  +    VdbeCoverageIf(v, op==OP_Rewind);  testcase( op==OP_Rewind );
         3131  +    VdbeCoverageIf(v, op==OP_Last);    testcase( op==OP_Last );
         3132  +    VdbeCoverageIf(v, op==OP_SeekGT);  testcase( op==OP_SeekGT );
         3133  +    VdbeCoverageIf(v, op==OP_SeekGE);  testcase( op==OP_SeekGE );
         3134  +    VdbeCoverageIf(v, op==OP_SeekLE);  testcase( op==OP_SeekLE );
         3135  +    VdbeCoverageIf(v, op==OP_SeekLT);  testcase( op==OP_SeekLT );
  3122   3136   
  3123   3137       /* Load the value for the inequality constraint at the end of the
  3124   3138       ** range (if any).
  3125   3139       */
  3126   3140       nConstraint = nEq;
  3127   3141       if( pRangeEnd ){
  3128   3142         Expr *pRight = pRangeEnd->pExpr->pRight;
  3129   3143         sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
  3130   3144         sqlite3ExprCode(pParse, pRight, regBase+nEq);
  3131         -      if( (pRangeEnd->wtFlags & TERM_VNULL)==0 ){
  3132         -        sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
         3145  +      if( (pRangeEnd->wtFlags & TERM_VNULL)==0
         3146  +       && sqlite3ExprCanBeNull(pRight)
         3147  +      ){
         3148  +        sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
         3149  +        VdbeCoverage(v);
  3133   3150         }
  3134   3151         if( sqlite3CompareAffinity(pRight, cEndAff)!=SQLITE_AFF_NONE
  3135   3152          && !sqlite3ExprNeedsNoAffinityChange(pRight, cEndAff)
  3136   3153         ){
  3137   3154           codeApplyAffinity(pParse, regBase+nEq, 1, &cEndAff);
  3138   3155         }
  3139   3156         nConstraint++;
................................................................................
  3147   3164   
  3148   3165       /* Top of the loop body */
  3149   3166       pLevel->p2 = sqlite3VdbeCurrentAddr(v);
  3150   3167   
  3151   3168       /* Check if the index cursor is past the end of the range. */
  3152   3169       if( nConstraint ){
  3153   3170         op = aEndOp[bRev*2 + endEq];
  3154         -      testcase( op==OP_IdxGT );
  3155         -      testcase( op==OP_IdxGE );
  3156         -      testcase( op==OP_IdxLT );
  3157         -      testcase( op==OP_IdxLE );
  3158   3171         sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
  3159         -      VdbeCoverage(v);
         3172  +      testcase( op==OP_IdxGT );  VdbeCoverageIf(v, op==OP_IdxGT );
         3173  +      testcase( op==OP_IdxGE );  VdbeCoverageIf(v, op==OP_IdxGE );
         3174  +      testcase( op==OP_IdxLT );  VdbeCoverageIf(v, op==OP_IdxLT );
         3175  +      testcase( op==OP_IdxLE );  VdbeCoverageIf(v, op==OP_IdxLE );
  3160   3176       }
  3161   3177   
  3162   3178       /* Seek the table cursor, if required */
  3163   3179       disableTerm(pLevel, pRangeStart);
  3164   3180       disableTerm(pLevel, pRangeEnd);
  3165   3181       if( omitTable ){
  3166   3182         /* pIdx is a covering index.  No need to access the main table. */
................................................................................
  3426   3442         /* Tables marked isRecursive have only a single row that is stored in
  3427   3443         ** a pseudo-cursor.  No need to Rewind or Next such cursors. */
  3428   3444         pLevel->op = OP_Noop;
  3429   3445       }else{
  3430   3446         pLevel->op = aStep[bRev];
  3431   3447         pLevel->p1 = iCur;
  3432   3448         pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
  3433         -      VdbeCoverageIf(v, bRev);
  3434         -      VdbeCoverageIf(v, !bRev);
         3449  +      VdbeCoverageIf(v, bRev==0);
         3450  +      VdbeCoverageIf(v, bRev!=0);
  3435   3451         pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
  3436   3452       }
  3437   3453     }
  3438   3454   
  3439   3455     /* Insert code to test every subexpression that can be completely
  3440   3456     ** computed using the current set of tables.
  3441   3457     */
................................................................................
  5798   5814       pLevel = &pWInfo->a[i];
  5799   5815       pLoop = pLevel->pWLoop;
  5800   5816       sqlite3VdbeResolveLabel(v, pLevel->addrCont);
  5801   5817       if( pLevel->op!=OP_Noop ){
  5802   5818         sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
  5803   5819         sqlite3VdbeChangeP5(v, pLevel->p5);
  5804   5820         VdbeCoverage(v);
         5821  +      VdbeCoverageIf(v, pLevel->op==OP_Next);
         5822  +      VdbeCoverageIf(v, pLevel->op==OP_Prev);
         5823  +      VdbeCoverageIf(v, pLevel->op==OP_VNext);
  5805   5824       }
  5806   5825       if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
  5807   5826         struct InLoop *pIn;
  5808   5827         int j;
  5809   5828         sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
  5810   5829         for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
  5811   5830           sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
  5812   5831           sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
  5813   5832           VdbeCoverage(v);
         5833  +        VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
         5834  +        VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
  5814   5835           sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
  5815   5836         }
  5816   5837         sqlite3DbFree(db, pLevel->u.in.aInLoop);
  5817   5838       }
  5818   5839       sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
  5819   5840       if( pLevel->addrSkip ){
  5820   5841         sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);