/ Check-in [9744ffb3]
Login

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

Overview
Comment:Enhancements to the VDBE opcode loop to reduce the number of machine-code instructions evaluated by about 10%.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9744ffb3f5bc6d8fd59fbb6577a0d549411cd967
User & Date: drh 2009-11-17 23:59:58
Context
2009-11-18
01:25
Suppress more instances of unnecessary OP_IsNull and OP_Affinity opcodes. check-in: bf6c0bd1 user: drh tags: trunk
2009-11-17
23:59
Enhancements to the VDBE opcode loop to reduce the number of machine-code instructions evaluated by about 10%. check-in: 9744ffb3 user: drh tags: trunk
18:31
Code generator tries to avoid pointless OP_IsNull and OP_Affinity opcodes. check-in: ebb0c8a3 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

   539    539   ){
   540    540     int pc;                    /* The program counter */
   541    541     Op *aOp = p->aOp;          /* Copy of p->aOp */
   542    542     Op *pOp;                   /* Current operation */
   543    543     int rc = SQLITE_OK;        /* Value to return */
   544    544     sqlite3 *db = p->db;       /* The database */
   545    545     u8 encoding = ENC(db);     /* The database encoding */
   546         -  u8 opProperty;
   547    546   #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
   548    547     u8 checkProgress;          /* True if progress callbacks are enabled */
   549    548     int nProgressOps = 0;      /* Opcodes executed since progress callback. */
   550    549   #endif
   551    550     Mem *aMem = p->aMem;       /* Copy of p->aMem */
   552    551     Mem *pIn1 = 0;             /* 1st input operand */
   553    552     Mem *pIn2 = 0;             /* 2nd input operand */
................................................................................
   656    655           }
   657    656           nProgressOps = 0;
   658    657         }
   659    658         nProgressOps++;
   660    659       }
   661    660   #endif
   662    661   
   663         -    /* Do common setup processing for any opcode that is marked
   664         -    ** with the "out2-prerelease" tag.  Such opcodes have a single
   665         -    ** output which is specified by the P2 parameter.  The P2 register
   666         -    ** is initialized to a NULL.
          662  +    /* On any opcode with the "out2-prerelase" tag, free any
          663  +    ** external allocations out of mem[p2] and set mem[p2] to be
          664  +    ** an undefined integer.  Opcodes will either fill in the integer
          665  +    ** value or convert mem[p2] to a different type.
   667    666       */
   668    667       assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
   669         -    opProperty = pOp->opflags;
   670         -    if( opProperty & (OPFLG_OUT2_PRERELEASE | OPFLG_IN1 | OPFLG_IN2
   671         -                      | OPFLG_IN3 | OPFLG_OUT2 | OPFLG_OUT3)
   672         -    ){
   673         -      if( (opProperty & OPFLG_OUT2_PRERELEASE)!=0 ){
   674         -        assert( pOp->p2>0 );
   675         -        assert( pOp->p2<=p->nMem );
   676         -        pOut = &aMem[pOp->p2];
   677         -        sqlite3VdbeMemReleaseExternal(pOut);
   678         -        pOut->flags = MEM_Null;
   679         -        pOut->n = 0;
   680         -      }else{
   681         -        if( (opProperty & OPFLG_IN1)!=0 ){
   682         -          assert( pOp->p1>0 );
   683         -          assert( pOp->p1<=p->nMem );
   684         -          pIn1 = &aMem[pOp->p1];
   685         -          REGISTER_TRACE(pOp->p1, pIn1);
   686         -        }
   687         -        if( (opProperty & (OPFLG_IN2|OPFLG_OUT2))!=0 ){
   688         -          assert( pOp->p2>0 );
   689         -          assert( pOp->p2<=p->nMem );
   690         -          assert( (opProperty & OPFLG_OUT2)==0 || (opProperty & OPFLG_IN3)==0 );
   691         -          pIn2 = pOut = &aMem[pOp->p2];
   692         -        }
   693         -        if( (opProperty & (OPFLG_IN3|OPFLG_OUT3))!=0 ){
   694         -          assert( pOp->p3>0 );
   695         -          assert( pOp->p3<=p->nMem );
   696         -          pIn3 = pOut = &aMem[pOp->p3];
   697         -        }
          668  +    if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){
          669  +      assert( pOp->p2>0 );
          670  +      assert( pOp->p2<=p->nMem );
          671  +      pOut = &aMem[pOp->p2];
          672  +      sqlite3VdbeMemReleaseExternal(pOut);
          673  +      pOut->flags = MEM_Int;
          674  +    }
          675  +
          676  +    /* Sanity checking on other operands */
   698    677   #ifdef SQLITE_DEBUG
   699         -        if( opProperty & OPFLG_IN2 ){ REGISTER_TRACE(pOp->p2, pIn2); }
   700         -        if( opProperty & OPFLG_IN3 ){ REGISTER_TRACE(pOp->p3, pIn3); }
          678  +    if( (pOp->opflags & OPFLG_IN1)!=0 ){
          679  +      assert( pOp->p1>0 );
          680  +      assert( pOp->p1<=p->nMem );
          681  +      REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
          682  +    }
          683  +    if( (pOp->opflags & OPFLG_IN2)!=0 ){
          684  +      assert( pOp->p2>0 );
          685  +      assert( pOp->p2<=p->nMem );
          686  +      REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
          687  +    }
          688  +    if( (pOp->opflags & OPFLG_IN3)!=0 ){
          689  +      assert( pOp->p3>0 );
          690  +      assert( pOp->p3<=p->nMem );
          691  +      REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
          692  +    }
          693  +    if( (pOp->opflags & OPFLG_OUT2)!=0 ){
          694  +      assert( pOp->p2>0 );
          695  +      assert( pOp->p2<=p->nMem );
          696  +    }
          697  +    if( (pOp->opflags & OPFLG_OUT3)!=0 ){
          698  +      assert( pOp->p3>0 );
          699  +      assert( pOp->p3<=p->nMem );
          700  +    }
   701    701   #endif
   702         -      }
   703         -    }
   704    702     
   705    703       switch( pOp->opcode ){
   706    704   
   707    705   /*****************************************************************************
   708    706   ** What follows is a massive switch statement where each case implements a
   709    707   ** separate instruction in the virtual machine.  If we follow the usual
   710    708   ** indentation conventions, each case should be indented by 6 spaces.  But
................................................................................
   754    752   
   755    753   /* Opcode:  Gosub P1 P2 * * *
   756    754   **
   757    755   ** Write the current address onto register P1
   758    756   ** and then jump to address P2.
   759    757   */
   760    758   case OP_Gosub: {            /* jump, in1 */
          759  +  pIn1 = &aMem[pOp->p1];
   761    760     assert( (pIn1->flags & MEM_Dyn)==0 );
   762    761     pIn1->flags = MEM_Int;
   763    762     pIn1->u.i = pc;
   764    763     REGISTER_TRACE(pOp->p1, pIn1);
   765    764     pc = pOp->p2 - 1;
   766    765     break;
   767    766   }
   768    767   
   769    768   /* Opcode:  Return P1 * * * *
   770    769   **
   771    770   ** Jump to the next instruction after the address in register P1.
   772    771   */
   773    772   case OP_Return: {           /* in1 */
          773  +  pIn1 = &aMem[pOp->p1];
   774    774     assert( pIn1->flags & MEM_Int );
   775    775     pc = (int)pIn1->u.i;
   776    776     break;
   777    777   }
   778    778   
   779    779   /* Opcode:  Yield P1 * * * *
   780    780   **
   781    781   ** Swap the program counter with the value in register P1.
   782    782   */
   783    783   case OP_Yield: {            /* in1 */
   784    784     int pcDest;
          785  +  pIn1 = &aMem[pOp->p1];
   785    786     assert( (pIn1->flags & MEM_Dyn)==0 );
   786    787     pIn1->flags = MEM_Int;
   787    788     pcDest = (int)pIn1->u.i;
   788    789     pIn1->u.i = pc;
   789    790     REGISTER_TRACE(pOp->p1, pIn1);
   790    791     pc = pcDest;
   791    792     break;
................................................................................
   794    795   /* Opcode:  HaltIfNull  P1 P2 P3 P4 *
   795    796   **
   796    797   ** Check the value in register P3.  If is is NULL then Halt using
   797    798   ** parameter P1, P2, and P4 as if this were a Halt instruction.  If the
   798    799   ** value in register P3 is not NULL, then this routine is a no-op.
   799    800   */
   800    801   case OP_HaltIfNull: {      /* in3 */
          802  +  pIn3 = &aMem[pOp->p3];
   801    803     if( (pIn3->flags & MEM_Null)==0 ) break;
   802    804     /* Fall through into OP_Halt */
   803    805   }
   804    806   
   805    807   /* Opcode:  Halt P1 P2 * P4 *
   806    808   **
   807    809   ** Exit immediately.  All open cursors, etc are closed
................................................................................
   861    863   }
   862    864   
   863    865   /* Opcode: Integer P1 P2 * * *
   864    866   **
   865    867   ** The 32-bit integer value P1 is written into register P2.
   866    868   */
   867    869   case OP_Integer: {         /* out2-prerelease */
   868         -  pOut->flags = MEM_Int;
   869    870     pOut->u.i = pOp->p1;
   870    871     break;
   871    872   }
   872    873   
   873    874   /* Opcode: Int64 * P2 * P4 *
   874    875   **
   875    876   ** P4 is a pointer to a 64-bit integer value.
   876    877   ** Write that value into register P2.
   877    878   */
   878    879   case OP_Int64: {           /* out2-prerelease */
   879    880     assert( pOp->p4.pI64!=0 );
   880         -  pOut->flags = MEM_Int;
   881    881     pOut->u.i = *pOp->p4.pI64;
   882    882     break;
   883    883   }
   884    884   
   885    885   /* Opcode: Real * P2 * P4 *
   886    886   **
   887    887   ** P4 is a pointer to a 64-bit floating point value.
................................................................................
   943    943   }
   944    944   
   945    945   /* Opcode: Null * P2 * * *
   946    946   **
   947    947   ** Write a NULL into register P2.
   948    948   */
   949    949   case OP_Null: {           /* out2-prerelease */
          950  +  pOut->flags = MEM_Null;
   950    951     break;
   951    952   }
   952    953   
   953    954   
   954    955   /* Opcode: Blob P1 P2 * P4
   955    956   **
   956    957   ** P4 points to a blob of data P1 bytes long.  Store this
................................................................................
  1042   1043   **
  1043   1044   ** Make a copy of register P1 into register P2.
  1044   1045   **
  1045   1046   ** This instruction makes a deep copy of the value.  A duplicate
  1046   1047   ** is made of any string or blob constant.  See also OP_SCopy.
  1047   1048   */
  1048   1049   case OP_Copy: {             /* in1, out2 */
         1050  +  pIn1 = &aMem[pOp->p1];
         1051  +  pOut = &aMem[pOp->p2];
  1049   1052     assert( pOut!=pIn1 );
  1050   1053     sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
  1051   1054     Deephemeralize(pOut);
  1052   1055     REGISTER_TRACE(pOp->p2, pOut);
  1053   1056     break;
  1054   1057   }
  1055   1058   
................................................................................
  1062   1065   ** original and hence if the original changes so will the copy.
  1063   1066   ** Worse, if the original is deallocated, the copy becomes invalid.
  1064   1067   ** Thus the program must guarantee that the original will not change
  1065   1068   ** during the lifetime of the copy.  Use OP_Copy to make a complete
  1066   1069   ** copy.
  1067   1070   */
  1068   1071   case OP_SCopy: {            /* in1, out2 */
         1072  +  pIn1 = &aMem[pOp->p1];
         1073  +  pOut = &aMem[pOp->p2];
  1069   1074     assert( pOut!=pIn1 );
  1070   1075     sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
  1071   1076     REGISTER_TRACE(pOp->p2, pOut);
  1072   1077     break;
  1073   1078   }
  1074   1079   
  1075   1080   /* Opcode: ResultRow P1 P2 * * *
................................................................................
  1150   1155   ** It is illegal for P1 and P3 to be the same register. Sometimes,
  1151   1156   ** if P3 is the same register as P2, the implementation is able
  1152   1157   ** to avoid a memcpy().
  1153   1158   */
  1154   1159   case OP_Concat: {           /* same as TK_CONCAT, in1, in2, out3 */
  1155   1160     i64 nByte;
  1156   1161   
         1162  +  pIn1 = &aMem[pOp->p1];
         1163  +  pIn2 = &aMem[pOp->p2];
         1164  +  pOut = &aMem[pOp->p3];
  1157   1165     assert( pIn1!=pOut );
  1158   1166     if( (pIn1->flags | pIn2->flags) & MEM_Null ){
  1159   1167       sqlite3VdbeMemSetNull(pOut);
  1160   1168       break;
  1161   1169     }
  1162   1170     if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem;
  1163   1171     Stringify(pIn1, encoding);
................................................................................
  1223   1231   case OP_Remainder: {           /* same as TK_REM, in1, in2, out3 */
  1224   1232     int flags;      /* Combined MEM_* flags from both inputs */
  1225   1233     i64 iA;         /* Integer value of left operand */
  1226   1234     i64 iB;         /* Integer value of right operand */
  1227   1235     double rA;      /* Real value of left operand */
  1228   1236     double rB;      /* Real value of right operand */
  1229   1237   
         1238  +  pIn1 = &aMem[pOp->p1];
  1230   1239     applyNumericAffinity(pIn1);
         1240  +  pIn2 = &aMem[pOp->p2];
  1231   1241     applyNumericAffinity(pIn2);
         1242  +  pOut = &aMem[pOp->p3];
  1232   1243     flags = pIn1->flags | pIn2->flags;
  1233   1244     if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
  1234   1245     if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
  1235   1246       iA = pIn1->u.i;
  1236   1247       iB = pIn2->u.i;
  1237   1248       switch( pOp->opcode ){
  1238   1249         case OP_Add:         iB += iA;       break;
................................................................................
  1455   1466   case OP_BitAnd:                 /* same as TK_BITAND, in1, in2, out3 */
  1456   1467   case OP_BitOr:                  /* same as TK_BITOR, in1, in2, out3 */
  1457   1468   case OP_ShiftLeft:              /* same as TK_LSHIFT, in1, in2, out3 */
  1458   1469   case OP_ShiftRight: {           /* same as TK_RSHIFT, in1, in2, out3 */
  1459   1470     i64 a;
  1460   1471     i64 b;
  1461   1472   
         1473  +  pIn1 = &aMem[pOp->p1];
         1474  +  pIn2 = &aMem[pOp->p2];
         1475  +  pOut = &aMem[pOp->p3];
  1462   1476     if( (pIn1->flags | pIn2->flags) & MEM_Null ){
  1463   1477       sqlite3VdbeMemSetNull(pOut);
  1464   1478       break;
  1465   1479     }
  1466   1480     a = sqlite3VdbeIntValue(pIn2);
  1467   1481     b = sqlite3VdbeIntValue(pIn1);
  1468   1482     switch( pOp->opcode ){
................................................................................
  1481   1495   ** 
  1482   1496   ** Add the constant P2 to the value in register P1.
  1483   1497   ** The result is always an integer.
  1484   1498   **
  1485   1499   ** To force any register to be an integer, just add 0.
  1486   1500   */
  1487   1501   case OP_AddImm: {            /* in1 */
         1502  +  pIn1 = &aMem[pOp->p1];
  1488   1503     sqlite3VdbeMemIntegerify(pIn1);
  1489   1504     pIn1->u.i += pOp->p2;
  1490   1505     break;
  1491   1506   }
  1492   1507   
  1493   1508   /* Opcode: MustBeInt P1 P2 * * *
  1494   1509   ** 
  1495   1510   ** Force the value in register P1 to be an integer.  If the value
  1496   1511   ** in P1 is not an integer and cannot be converted into an integer
  1497   1512   ** without data loss, then jump immediately to P2, or if P2==0
  1498   1513   ** raise an SQLITE_MISMATCH exception.
  1499   1514   */
  1500   1515   case OP_MustBeInt: {            /* jump, in1 */
         1516  +  pIn1 = &aMem[pOp->p1];
  1501   1517     applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
  1502   1518     if( (pIn1->flags & MEM_Int)==0 ){
  1503   1519       if( pOp->p2==0 ){
  1504   1520         rc = SQLITE_MISMATCH;
  1505   1521         goto abort_due_to_error;
  1506   1522       }else{
  1507   1523         pc = pOp->p2 - 1;
................................................................................
  1518   1534   **
  1519   1535   ** This opcode is used when extracting information from a column that
  1520   1536   ** has REAL affinity.  Such column values may still be stored as
  1521   1537   ** integers, for space efficiency, but after extraction we want them
  1522   1538   ** to have only a real value.
  1523   1539   */
  1524   1540   case OP_RealAffinity: {                  /* in1 */
         1541  +  pIn1 = &aMem[pOp->p1];
  1525   1542     if( pIn1->flags & MEM_Int ){
  1526   1543       sqlite3VdbeMemRealify(pIn1);
  1527   1544     }
  1528   1545     break;
  1529   1546   }
  1530   1547   
  1531   1548   #ifndef SQLITE_OMIT_CAST
................................................................................
  1535   1552   ** If the value is numeric, convert it to a string using the
  1536   1553   ** equivalent of printf().  Blob values are unchanged and
  1537   1554   ** are afterwards simply interpreted as text.
  1538   1555   **
  1539   1556   ** A NULL value is not changed by this routine.  It remains NULL.
  1540   1557   */
  1541   1558   case OP_ToText: {                  /* same as TK_TO_TEXT, in1 */
         1559  +  pIn1 = &aMem[pOp->p1];
  1542   1560     if( pIn1->flags & MEM_Null ) break;
  1543   1561     assert( MEM_Str==(MEM_Blob>>3) );
  1544   1562     pIn1->flags |= (pIn1->flags&MEM_Blob)>>3;
  1545   1563     applyAffinity(pIn1, SQLITE_AFF_TEXT, encoding);
  1546   1564     rc = ExpandBlob(pIn1);
  1547   1565     assert( pIn1->flags & MEM_Str || db->mallocFailed );
  1548   1566     pIn1->flags &= ~(MEM_Int|MEM_Real|MEM_Blob|MEM_Zero);
................................................................................
  1556   1574   ** If the value is numeric, convert it to a string first.
  1557   1575   ** Strings are simply reinterpreted as blobs with no change
  1558   1576   ** to the underlying data.
  1559   1577   **
  1560   1578   ** A NULL value is not changed by this routine.  It remains NULL.
  1561   1579   */
  1562   1580   case OP_ToBlob: {                  /* same as TK_TO_BLOB, in1 */
         1581  +  pIn1 = &aMem[pOp->p1];
  1563   1582     if( pIn1->flags & MEM_Null ) break;
  1564   1583     if( (pIn1->flags & MEM_Blob)==0 ){
  1565   1584       applyAffinity(pIn1, SQLITE_AFF_TEXT, encoding);
  1566   1585       assert( pIn1->flags & MEM_Str || db->mallocFailed );
  1567   1586       MemSetTypeFlag(pIn1, MEM_Blob);
  1568   1587     }else{
  1569   1588       pIn1->flags &= ~(MEM_TypeMask&~MEM_Blob);
................................................................................
  1579   1598   ** If the value is text or blob, try to convert it to an using the
  1580   1599   ** equivalent of atoi() or atof() and store 0 if no such conversion 
  1581   1600   ** is possible.
  1582   1601   **
  1583   1602   ** A NULL value is not changed by this routine.  It remains NULL.
  1584   1603   */
  1585   1604   case OP_ToNumeric: {                  /* same as TK_TO_NUMERIC, in1 */
         1605  +  pIn1 = &aMem[pOp->p1];
  1586   1606     if( (pIn1->flags & (MEM_Null|MEM_Int|MEM_Real))==0 ){
  1587   1607       sqlite3VdbeMemNumerify(pIn1);
  1588   1608     }
  1589   1609     break;
  1590   1610   }
  1591   1611   #endif /* SQLITE_OMIT_CAST */
  1592   1612   
................................................................................
  1596   1616   ** The value is currently a real number, drop its fractional part.
  1597   1617   ** If the value is text or blob, try to convert it to an integer using the
  1598   1618   ** equivalent of atoi() and store 0 if no such conversion is possible.
  1599   1619   **
  1600   1620   ** A NULL value is not changed by this routine.  It remains NULL.
  1601   1621   */
  1602   1622   case OP_ToInt: {                  /* same as TK_TO_INT, in1 */
         1623  +  pIn1 = &aMem[pOp->p1];
  1603   1624     if( (pIn1->flags & MEM_Null)==0 ){
  1604   1625       sqlite3VdbeMemIntegerify(pIn1);
  1605   1626     }
  1606   1627     break;
  1607   1628   }
  1608   1629   
  1609   1630   #ifndef SQLITE_OMIT_CAST
................................................................................
  1613   1634   ** If The value is currently an integer, convert it.
  1614   1635   ** If the value is text or blob, try to convert it to an integer using the
  1615   1636   ** equivalent of atoi() and store 0.0 if no such conversion is possible.
  1616   1637   **
  1617   1638   ** A NULL value is not changed by this routine.  It remains NULL.
  1618   1639   */
  1619   1640   case OP_ToReal: {                  /* same as TK_TO_REAL, in1 */
         1641  +  pIn1 = &aMem[pOp->p1];
  1620   1642     if( (pIn1->flags & MEM_Null)==0 ){
  1621   1643       sqlite3VdbeMemRealify(pIn1);
  1622   1644     }
  1623   1645     break;
  1624   1646   }
  1625   1647   #endif /* SQLITE_OMIT_CAST */
  1626   1648   
................................................................................
  1701   1723   case OP_Lt:               /* same as TK_LT, jump, in1, in3 */
  1702   1724   case OP_Le:               /* same as TK_LE, jump, in1, in3 */
  1703   1725   case OP_Gt:               /* same as TK_GT, jump, in1, in3 */
  1704   1726   case OP_Ge: {             /* same as TK_GE, jump, in1, in3 */
  1705   1727     int res;            /* Result of the comparison of pIn1 against pIn3 */
  1706   1728     char affinity;      /* Affinity to use for comparison */
  1707   1729   
         1730  +  pIn1 = &aMem[pOp->p1];
         1731  +  pIn3 = &aMem[pOp->p3];
  1708   1732     if( (pIn1->flags | pIn3->flags)&MEM_Null ){
  1709   1733       /* One or both operands are NULL */
  1710   1734       if( pOp->p5 & SQLITE_NULLEQ ){
  1711   1735         /* If SQLITE_NULLEQ is set (which will only happen if the operator is
  1712   1736         ** OP_Eq or OP_Ne) then take the jump or not depending on whether
  1713   1737         ** or not both operands are null.
  1714   1738         */
................................................................................
  1872   1896   ** give a NULL output.
  1873   1897   */
  1874   1898   case OP_And:              /* same as TK_AND, in1, in2, out3 */
  1875   1899   case OP_Or: {             /* same as TK_OR, in1, in2, out3 */
  1876   1900     int v1;    /* Left operand:  0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
  1877   1901     int v2;    /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
  1878   1902   
         1903  +  pIn1 = &aMem[pOp->p1];
  1879   1904     if( pIn1->flags & MEM_Null ){
  1880   1905       v1 = 2;
  1881   1906     }else{
  1882   1907       v1 = sqlite3VdbeIntValue(pIn1)!=0;
  1883   1908     }
         1909  +  pIn2 = &aMem[pOp->p2];
  1884   1910     if( pIn2->flags & MEM_Null ){
  1885   1911       v2 = 2;
  1886   1912     }else{
  1887   1913       v2 = sqlite3VdbeIntValue(pIn2)!=0;
  1888   1914     }
  1889   1915     if( pOp->opcode==OP_And ){
  1890   1916       static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
  1891   1917       v1 = and_logic[v1*3+v2];
  1892   1918     }else{
  1893   1919       static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
  1894   1920       v1 = or_logic[v1*3+v2];
  1895   1921     }
         1922  +  pOut = &aMem[pOp->p3];
  1896   1923     if( v1==2 ){
  1897   1924       MemSetTypeFlag(pOut, MEM_Null);
  1898   1925     }else{
  1899   1926       pOut->u.i = v1;
  1900   1927       MemSetTypeFlag(pOut, MEM_Int);
  1901   1928     }
  1902   1929     break;
................................................................................
  1905   1932   /* Opcode: Not P1 P2 * * *
  1906   1933   **
  1907   1934   ** Interpret the value in register P1 as a boolean value.  Store the
  1908   1935   ** boolean complement in register P2.  If the value in register P1 is 
  1909   1936   ** NULL, then a NULL is stored in P2.
  1910   1937   */
  1911   1938   case OP_Not: {                /* same as TK_NOT, in1, out2 */
         1939  +  pIn1 = &aMem[pOp->p1];
         1940  +  pOut = &aMem[pOp->p2];
  1912   1941     if( pIn1->flags & MEM_Null ){
  1913   1942       sqlite3VdbeMemSetNull(pOut);
  1914   1943     }else{
  1915   1944       sqlite3VdbeMemSetInt64(pOut, !sqlite3VdbeIntValue(pIn1));
  1916   1945     }
  1917   1946     break;
  1918   1947   }
................................................................................
  1920   1949   /* Opcode: BitNot P1 P2 * * *
  1921   1950   **
  1922   1951   ** Interpret the content of register P1 as an integer.  Store the
  1923   1952   ** ones-complement of the P1 value into register P2.  If P1 holds
  1924   1953   ** a NULL then store a NULL in P2.
  1925   1954   */
  1926   1955   case OP_BitNot: {             /* same as TK_BITNOT, in1, out2 */
         1956  +  pIn1 = &aMem[pOp->p1];
         1957  +  pOut = &aMem[pOp->p2];
  1927   1958     if( pIn1->flags & MEM_Null ){
  1928   1959       sqlite3VdbeMemSetNull(pOut);
  1929   1960     }else{
  1930   1961       sqlite3VdbeMemSetInt64(pOut, ~sqlite3VdbeIntValue(pIn1));
  1931   1962     }
  1932   1963     break;
  1933   1964   }
................................................................................
  1943   1974   ** Jump to P2 if the value in register P1 is False.  The value is
  1944   1975   ** is considered true if it has a numeric value of zero.  If the value
  1945   1976   ** in P1 is NULL then take the jump if P3 is true.
  1946   1977   */
  1947   1978   case OP_If:                 /* jump, in1 */
  1948   1979   case OP_IfNot: {            /* jump, in1 */
  1949   1980     int c;
         1981  +  pIn1 = &aMem[pOp->p1];
  1950   1982     if( pIn1->flags & MEM_Null ){
  1951   1983       c = pOp->p3;
  1952   1984     }else{
  1953   1985   #ifdef SQLITE_OMIT_FLOATING_POINT
  1954   1986       c = sqlite3VdbeIntValue(pIn1)!=0;
  1955   1987   #else
  1956   1988       c = sqlite3VdbeRealValue(pIn1)!=0.0;
................................................................................
  1964   1996   }
  1965   1997   
  1966   1998   /* Opcode: IsNull P1 P2 * * *
  1967   1999   **
  1968   2000   ** Jump to P2 if the value in register P1 is NULL.
  1969   2001   */
  1970   2002   case OP_IsNull: {            /* same as TK_ISNULL, jump, in1 */
         2003  +  pIn1 = &aMem[pOp->p1];
  1971   2004     if( (pIn1->flags & MEM_Null)!=0 ){
  1972   2005       pc = pOp->p2 - 1;
  1973   2006     }
  1974   2007     break;
  1975   2008   }
  1976   2009   
  1977   2010   /* Opcode: NotNull P1 P2 * * *
  1978   2011   **
  1979   2012   ** Jump to P2 if the value in register P1 is not NULL.  
  1980   2013   */
  1981   2014   case OP_NotNull: {            /* same as TK_NOTNULL, jump, in1 */
         2015  +  pIn1 = &aMem[pOp->p1];
  1982   2016     if( (pIn1->flags & MEM_Null)==0 ){
  1983   2017       pc = pOp->p2 - 1;
  1984   2018     }
  1985   2019     break;
  1986   2020   }
  1987   2021   
  1988   2022   /* Opcode: Column P1 P2 P3 P4 P5
................................................................................
  2452   2486   
  2453   2487     pCrsr = p->apCsr[pOp->p1]->pCursor;
  2454   2488     if( pCrsr ){
  2455   2489       rc = sqlite3BtreeCount(pCrsr, &nEntry);
  2456   2490     }else{
  2457   2491       nEntry = 0;
  2458   2492     }
  2459         -  pOut->flags = MEM_Int;
  2460   2493     pOut->u.i = nEntry;
  2461   2494     break;
  2462   2495   }
  2463   2496   #endif
  2464   2497   
  2465   2498   /* Opcode: Savepoint P1 * * P4 *
  2466   2499   **
................................................................................
  2773   2806     assert( pOp->p3<SQLITE_N_BTREE_META );
  2774   2807     assert( iDb>=0 && iDb<db->nDb );
  2775   2808     assert( db->aDb[iDb].pBt!=0 );
  2776   2809     assert( (p->btreeMask & (1<<iDb))!=0 );
  2777   2810   
  2778   2811     sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
  2779   2812     pOut->u.i = iMeta;
  2780         -  MemSetTypeFlag(pOut, MEM_Int);
  2781   2813     break;
  2782   2814   }
  2783   2815   
  2784   2816   /* Opcode: SetCookie P1 P2 P3 * *
  2785   2817   **
  2786   2818   ** Write the content of register P3 (interpreted as an integer)
  2787   2819   ** into cookie number P2 of database P1.  P2==1 is the schema version.  
................................................................................
  2794   2826   case OP_SetCookie: {       /* in3 */
  2795   2827     Db *pDb;
  2796   2828     assert( pOp->p2<SQLITE_N_BTREE_META );
  2797   2829     assert( pOp->p1>=0 && pOp->p1<db->nDb );
  2798   2830     assert( (p->btreeMask & (1<<pOp->p1))!=0 );
  2799   2831     pDb = &db->aDb[pOp->p1];
  2800   2832     assert( pDb->pBt!=0 );
         2833  +  pIn3 = &aMem[pOp->p3];
  2801   2834     sqlite3VdbeMemIntegerify(pIn3);
  2802   2835     /* See note about index shifting on OP_ReadCookie */
  2803   2836     rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, (int)pIn3->u.i);
  2804   2837     if( pOp->p2==BTREE_SCHEMA_VERSION ){
  2805   2838       /* When the schema cookie changes, record the new cookie internally */
  2806   2839       pDb->pSchema->schema_cookie = (int)pIn3->u.i;
  2807   2840       db->flags |= SQLITE_InternChanges;
................................................................................
  3178   3211     if( pC->pCursor!=0 ){
  3179   3212       oc = pOp->opcode;
  3180   3213       pC->nullRow = 0;
  3181   3214       if( pC->isTable ){
  3182   3215         /* The input value in P3 might be of any type: integer, real, string,
  3183   3216         ** blob, or NULL.  But it needs to be an integer before we can do
  3184   3217         ** the seek, so covert it. */
         3218  +      pIn3 = &aMem[pOp->p3];
  3185   3219         applyNumericAffinity(pIn3);
  3186   3220         iKey = sqlite3VdbeIntValue(pIn3);
  3187   3221         pC->rowidIsValid = 0;
  3188   3222   
  3189   3223         /* If the P3 value could not be converted into an integer without
  3190   3224         ** loss of information, then special processing is required... */
  3191   3225         if( (pIn3->flags & MEM_Int)==0 ){
................................................................................
  3317   3351   
  3318   3352     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  3319   3353     pC = p->apCsr[pOp->p1];
  3320   3354     assert( pC!=0 );
  3321   3355     if( ALWAYS(pC->pCursor!=0) ){
  3322   3356       assert( pC->isTable );
  3323   3357       pC->nullRow = 0;
         3358  +    pIn2 = &aMem[pOp->p2];
  3324   3359       pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
  3325   3360       pC->rowidIsValid = 0;
  3326   3361       pC->deferredMoveto = 1;
  3327   3362     }
  3328   3363     break;
  3329   3364   }
  3330   3365     
................................................................................
  3367   3402   #endif
  3368   3403   
  3369   3404     alreadyExists = 0;
  3370   3405     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  3371   3406     assert( pOp->p4type==P4_INT32 );
  3372   3407     pC = p->apCsr[pOp->p1];
  3373   3408     assert( pC!=0 );
         3409  +  pIn3 = &aMem[pOp->p3];
  3374   3410     if( ALWAYS(pC->pCursor!=0) ){
  3375   3411   
  3376   3412       assert( pC->isTable==0 );
  3377   3413       if( pOp->p4.i>0 ){
  3378   3414         r.pKeyInfo = pC->pKeyInfo;
  3379   3415         r.nField = pOp->p4.i;
  3380   3416         r.aMem = pIn3;
................................................................................
  3440   3476     VdbeCursor *pCx;
  3441   3477     BtCursor *pCrsr;
  3442   3478     u16 nField;
  3443   3479     Mem *aMx;
  3444   3480     UnpackedRecord r;                  /* B-Tree index search key */
  3445   3481     i64 R;                             /* Rowid stored in register P3 */
  3446   3482   
         3483  +  pIn3 = &aMem[pOp->p3];
  3447   3484     aMx = &aMem[pOp->p4.i];
  3448   3485     /* Assert that the values of parameters P1 and P4 are in range. */
  3449   3486     assert( pOp->p4type==P4_INT32 );
  3450   3487     assert( pOp->p4.i>0 && pOp->p4.i<=p->nMem );
  3451   3488     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  3452   3489   
  3453   3490     /* Find the index cursor. */
................................................................................
  3508   3545   */
  3509   3546   case OP_NotExists: {        /* jump, in3 */
  3510   3547     VdbeCursor *pC;
  3511   3548     BtCursor *pCrsr;
  3512   3549     int res;
  3513   3550     u64 iKey;
  3514   3551   
         3552  +  pIn3 = &aMem[pOp->p3];
  3515   3553     assert( pIn3->flags & MEM_Int );
  3516   3554     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  3517   3555     pC = p->apCsr[pOp->p1];
  3518   3556     assert( pC!=0 );
  3519   3557     assert( pC->isTable );
  3520   3558     assert( pC->pseudoTableReg==0 );
  3521   3559     pCrsr = pC->pCursor;
................................................................................
  3551   3589   ** The sequence number on the cursor is incremented after this
  3552   3590   ** instruction.  
  3553   3591   */
  3554   3592   case OP_Sequence: {           /* out2-prerelease */
  3555   3593     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  3556   3594     assert( p->apCsr[pOp->p1]!=0 );
  3557   3595     pOut->u.i = p->apCsr[pOp->p1]->seqCount++;
  3558         -  MemSetTypeFlag(pOut, MEM_Int);
  3559   3596     break;
  3560   3597   }
  3561   3598   
  3562   3599   
  3563   3600   /* Opcode: NewRowid P1 P2 P3 * *
  3564   3601   **
  3565   3602   ** Get a new integer record number (a.k.a "rowid") used as the key to a table.
................................................................................
  3688   3725           goto abort_due_to_error;
  3689   3726         }
  3690   3727       }
  3691   3728       pC->rowidIsValid = 0;
  3692   3729       pC->deferredMoveto = 0;
  3693   3730       pC->cacheStatus = CACHE_STALE;
  3694   3731     }
  3695         -  MemSetTypeFlag(pOut, MEM_Int);
  3696   3732     pOut->u.i = v;
  3697   3733     break;
  3698   3734   }
  3699   3735   
  3700   3736   /* Opcode: Insert P1 P2 P3 P4 P5
  3701   3737   **
  3702   3738   ** Write an entry into the table of cursor P1.  A new entry is
................................................................................
  3980   4016     const sqlite3_module *pModule;
  3981   4017   
  3982   4018     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  3983   4019     pC = p->apCsr[pOp->p1];
  3984   4020     assert( pC!=0 );
  3985   4021     assert( pC->pseudoTableReg==0 );
  3986   4022     if( pC->nullRow ){
  3987         -    /* Do nothing so that reg[P2] remains NULL */
         4023  +    pOut->flags = MEM_Null;
  3988   4024       break;
  3989   4025     }else if( pC->deferredMoveto ){
  3990   4026       v = pC->movetoTarget;
  3991   4027   #ifndef SQLITE_OMIT_VIRTUALTABLE
  3992   4028     }else if( pC->pVtabCursor ){
  3993   4029       pVtab = pC->pVtabCursor->pVtab;
  3994   4030       pModule = pVtab->pModule;
................................................................................
  4008   4044         v = pC->lastRowid;
  4009   4045       }else{
  4010   4046         rc = sqlite3BtreeKeySize(pC->pCursor, &v);
  4011   4047         assert( rc==SQLITE_OK );  /* Always so because of CursorMoveto() above */
  4012   4048       }
  4013   4049     }
  4014   4050     pOut->u.i = v;
  4015         -  MemSetTypeFlag(pOut, MEM_Int);
  4016   4051     break;
  4017   4052   }
  4018   4053   
  4019   4054   /* Opcode: NullRow P1 * * * *
  4020   4055   **
  4021   4056   ** Move the cursor P1 to a null row.  Any OP_Column operations
  4022   4057   ** that occur while the cursor is on the null row will always
................................................................................
  4193   4228     BtCursor *pCrsr;
  4194   4229     int nKey;
  4195   4230     const char *zKey;
  4196   4231   
  4197   4232     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  4198   4233     pC = p->apCsr[pOp->p1];
  4199   4234     assert( pC!=0 );
         4235  +  pIn2 = &aMem[pOp->p2];
  4200   4236     assert( pIn2->flags & MEM_Blob );
  4201   4237     pCrsr = pC->pCursor;
  4202   4238     if( ALWAYS(pCrsr!=0) ){
  4203   4239       assert( pC->isTable==0 );
  4204   4240       rc = ExpandBlob(pIn2);
  4205   4241       if( rc==SQLITE_OK ){
  4206   4242         nKey = pIn2->n;
................................................................................
  4261   4297     VdbeCursor *pC;
  4262   4298     i64 rowid;
  4263   4299   
  4264   4300     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  4265   4301     pC = p->apCsr[pOp->p1];
  4266   4302     assert( pC!=0 );
  4267   4303     pCrsr = pC->pCursor;
         4304  +  pOut->flags = MEM_Null;
  4268   4305     if( ALWAYS(pCrsr!=0) ){
  4269   4306       rc = sqlite3VdbeCursorMoveto(pC);
  4270   4307       if( NEVER(rc) ) goto abort_due_to_error;
  4271   4308       assert( pC->deferredMoveto==0 );
  4272   4309       assert( pC->isTable==0 );
  4273   4310       if( !pC->nullRow ){
  4274   4311         rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
  4275   4312         if( rc!=SQLITE_OK ){
  4276   4313           goto abort_due_to_error;
  4277   4314         }
  4278         -      MemSetTypeFlag(pOut, MEM_Int);
  4279   4315         pOut->u.i = rowid;
         4316  +      pOut->flags = MEM_Int;
  4280   4317       }
  4281   4318     }
  4282   4319     break;
  4283   4320   }
  4284   4321   
  4285   4322   /* Opcode: IdxGE P1 P2 P3 P4 P5
  4286   4323   **
................................................................................
  4374   4411       if( pVdbe->magic==VDBE_MAGIC_RUN && pVdbe->inVtabMethod<2 && pVdbe->pc>=0 ){
  4375   4412         iCnt++;
  4376   4413       }
  4377   4414     }
  4378   4415   #else
  4379   4416     iCnt = db->activeVdbeCnt;
  4380   4417   #endif
         4418  +  pOut->flags = MEM_Null;
  4381   4419     if( iCnt>1 ){
  4382   4420       rc = SQLITE_LOCKED;
  4383   4421       p->errorAction = OE_Abort;
  4384   4422     }else{
  4385   4423       iDb = pOp->p3;
  4386   4424       assert( iCnt==1 );
  4387   4425       assert( (p->btreeMask & (1<<iDb))!=0 );
  4388   4426       rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
  4389         -    MemSetTypeFlag(pOut, MEM_Int);
         4427  +    pOut->flags = MEM_Int;
  4390   4428       pOut->u.i = iMoved;
  4391   4429   #ifndef SQLITE_OMIT_AUTOVACUUM
  4392   4430       if( rc==SQLITE_OK && iMoved!=0 ){
  4393   4431         sqlite3RootPageMoved(&db->aDb[iDb], iMoved, pOp->p1);
  4394   4432       }
  4395   4433   #endif
  4396   4434     }
................................................................................
  4469   4507       /* flags = BTREE_INTKEY; */
  4470   4508       flags = BTREE_LEAFDATA|BTREE_INTKEY;
  4471   4509     }else{
  4472   4510       flags = BTREE_ZERODATA;
  4473   4511     }
  4474   4512     rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags);
  4475   4513     pOut->u.i = pgno;
  4476         -  MemSetTypeFlag(pOut, MEM_Int);
  4477   4514     break;
  4478   4515   }
  4479   4516   
  4480   4517   /* Opcode: ParseSchema P1 P2 * P4 *
  4481   4518   **
  4482   4519   ** Read and parse all entries from the SQLITE_MASTER table of database P1
  4483   4520   ** that match the WHERE clause P4.  P2 is the "force" flag.   Always do
................................................................................
  4668   4705   **
  4669   4706   ** Insert the integer value held by register P2 into a boolean index
  4670   4707   ** held in register P1.
  4671   4708   **
  4672   4709   ** An assertion fails if P2 is not an integer.
  4673   4710   */
  4674   4711   case OP_RowSetAdd: {       /* in1, in2 */
         4712  +  pIn1 = &aMem[pOp->p1];
         4713  +  pIn2 = &aMem[pOp->p2];
  4675   4714     assert( (pIn2->flags & MEM_Int)!=0 );
  4676   4715     if( (pIn1->flags & MEM_RowSet)==0 ){
  4677   4716       sqlite3VdbeMemSetRowSet(pIn1);
  4678   4717       if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem;
  4679   4718     }
  4680   4719     sqlite3RowSetInsert(pIn1->u.pRowSet, pIn2->u.i);
  4681   4720     break;
................................................................................
  4686   4725   ** Extract the smallest value from boolean index P1 and put that value into
  4687   4726   ** register P3.  Or, if boolean index P1 is initially empty, leave P3
  4688   4727   ** unchanged and jump to instruction P2.
  4689   4728   */
  4690   4729   case OP_RowSetRead: {       /* jump, in1, out3 */
  4691   4730     i64 val;
  4692   4731     CHECK_FOR_INTERRUPT;
         4732  +  pIn1 = &aMem[pOp->p1];
  4693   4733     if( (pIn1->flags & MEM_RowSet)==0 
  4694   4734      || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
  4695   4735     ){
  4696   4736       /* The boolean index is empty */
  4697   4737       sqlite3VdbeMemSetNull(pIn1);
  4698   4738       pc = pOp->p2 - 1;
  4699   4739     }else{
  4700   4740       /* A value was pulled from the index */
  4701         -    sqlite3VdbeMemSetInt64(pOut, val);
         4741  +    sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
  4702   4742     }
  4703   4743     break;
  4704   4744   }
  4705   4745   
  4706   4746   /* Opcode: RowSetTest P1 P2 P3 P4
  4707   4747   **
  4708   4748   ** Register P3 is assumed to hold a 64-bit integer value. If register P1
................................................................................
  4726   4766   ** previously inserted as part of set X (only if it was previously
  4727   4767   ** inserted as part of some other set).
  4728   4768   */
  4729   4769   case OP_RowSetTest: {                     /* jump, in1, in3 */
  4730   4770     int iSet;
  4731   4771     int exists;
  4732   4772   
         4773  +  pIn1 = &aMem[pOp->p1];
         4774  +  pIn3 = &aMem[pOp->p3];
  4733   4775     iSet = pOp->p4.i;
  4734   4776     assert( pIn3->flags&MEM_Int );
  4735   4777   
  4736   4778     /* If there is anything other than a rowset object in memory cell P1,
  4737   4779     ** delete it now and initialize P1 with an empty rowset
  4738   4780     */
  4739   4781     if( (pIn1->flags & MEM_RowSet)==0 ){
................................................................................
  4952   4994     if( p->pFrame ){
  4953   4995       for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
  4954   4996       pIn1 = &pFrame->aMem[pOp->p1];
  4955   4997     }else{
  4956   4998       pIn1 = &aMem[pOp->p1];
  4957   4999     }
  4958   5000     sqlite3VdbeMemIntegerify(pIn1);
         5001  +  pIn2 = &aMem[pOp->p2];
  4959   5002     sqlite3VdbeMemIntegerify(pIn2);
  4960   5003     if( pIn1->u.i<pIn2->u.i){
  4961   5004       pIn1->u.i = pIn2->u.i;
  4962   5005     }
  4963   5006     break;
  4964   5007   }
  4965   5008   #endif /* SQLITE_OMIT_AUTOINCREMENT */
................................................................................
  4968   5011   **
  4969   5012   ** If the value of register P1 is 1 or greater, jump to P2.
  4970   5013   **
  4971   5014   ** It is illegal to use this instruction on a register that does
  4972   5015   ** not contain an integer.  An assertion fault will result if you try.
  4973   5016   */
  4974   5017   case OP_IfPos: {        /* jump, in1 */
         5018  +  pIn1 = &aMem[pOp->p1];
  4975   5019     assert( pIn1->flags&MEM_Int );
  4976   5020     if( pIn1->u.i>0 ){
  4977   5021        pc = pOp->p2 - 1;
  4978   5022     }
  4979   5023     break;
  4980   5024   }
  4981   5025   
................................................................................
  4983   5027   **
  4984   5028   ** If the value of register P1 is less than zero, jump to P2. 
  4985   5029   **
  4986   5030   ** It is illegal to use this instruction on a register that does
  4987   5031   ** not contain an integer.  An assertion fault will result if you try.
  4988   5032   */
  4989   5033   case OP_IfNeg: {        /* jump, in1 */
         5034  +  pIn1 = &aMem[pOp->p1];
  4990   5035     assert( pIn1->flags&MEM_Int );
  4991   5036     if( pIn1->u.i<0 ){
  4992   5037        pc = pOp->p2 - 1;
  4993   5038     }
  4994   5039     break;
  4995   5040   }
  4996   5041   
................................................................................
  4999   5044   ** The register P1 must contain an integer.  Add literal P3 to the
  5000   5045   ** value in register P1.  If the result is exactly 0, jump to P2. 
  5001   5046   **
  5002   5047   ** It is illegal to use this instruction on a register that does
  5003   5048   ** not contain an integer.  An assertion fault will result if you try.
  5004   5049   */
  5005   5050   case OP_IfZero: {        /* jump, in1 */
         5051  +  pIn1 = &aMem[pOp->p1];
  5006   5052     assert( pIn1->flags&MEM_Int );
  5007   5053     pIn1->u.i += pOp->p3;
  5008   5054     if( pIn1->u.i==0 ){
  5009   5055        pc = pOp->p2 - 1;
  5010   5056     }
  5011   5057     break;
  5012   5058   }
................................................................................
  5561   5607     p1 = pOp->p1; 
  5562   5608     pPager = sqlite3BtreePager(db->aDb[p1].pBt);
  5563   5609     rc = sqlite3PagerPagecount(pPager, &nPage);
  5564   5610     /* OP_Pagecount is always called from within a read transaction.  The
  5565   5611     ** page count has already been successfully read and cached.  So the
  5566   5612     ** sqlite3PagerPagecount() call above cannot fail. */
  5567   5613     if( ALWAYS(rc==SQLITE_OK) ){
  5568         -    pOut->flags = MEM_Int;
  5569   5614       pOut->u.i = nPage;
  5570   5615     }
  5571   5616     break;
  5572   5617   }
  5573   5618   #endif
  5574   5619   
  5575   5620   #ifndef SQLITE_OMIT_TRACE
................................................................................
  5639   5684       */
  5640   5685   #ifndef NDEBUG
  5641   5686       assert( pc>=-1 && pc<p->nOp );
  5642   5687   
  5643   5688   #ifdef SQLITE_DEBUG
  5644   5689       if( p->trace ){
  5645   5690         if( rc!=0 ) fprintf(p->trace,"rc=%d\n",rc);
  5646         -      if( opProperty & OPFLG_OUT2_PRERELEASE ){
  5647         -        registerTrace(p->trace, pOp->p2, pOut);
         5691  +      if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){
         5692  +        registerTrace(p->trace, pOp->p2, &aMem[pOp->p2]);
  5648   5693         }
  5649         -      if( opProperty & OPFLG_OUT3 ){
  5650         -        registerTrace(p->trace, pOp->p3, pOut);
         5694  +      if( pOp->opflags & OPFLG_OUT3 ){
         5695  +        registerTrace(p->trace, pOp->p3, &aMem[pOp->p3]);
  5651   5696         }
  5652   5697       }
  5653   5698   #endif  /* SQLITE_DEBUG */
  5654   5699   #endif  /* NDEBUG */
  5655   5700     }  /* The end of the for(;;) loop the loops through opcodes */
  5656   5701   
  5657   5702     /* If we reach this point, it means that execution is finished with