/ Check-in [bbc1b016]
Login

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

Overview
Comment:Improved extended comments of comparison operators when the SQLITE_STOREP2 flags is set on P5. No changes to non-debug code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | rowvalue
Files: files | file ages | folders
SHA1: bbc1b016164ed0793e07302614384d52119463e0
User & Date: drh 2016-08-24 21:24:04
Context
2016-08-24
21:54
Simplified VDBE code for the vector NOT IN null-scanning loop. check-in: 7ae504e6 user: drh tags: rowvalue
21:24
Improved extended comments of comparison operators when the SQLITE_STOREP2 flags is set on P5. No changes to non-debug code. check-in: bbc1b016 user: drh tags: rowvalue
18:51
In sqlite3FindInIndex(), improve internal comments and avoid an unreachable branch. check-in: 55945fc1 user: drh tags: rowvalue
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

   901    901     pIn1->u.i = (int)(pOp - aOp);
   902    902     REGISTER_TRACE(pOp->p1, pIn1);
   903    903     pOp = &aOp[pcDest];
   904    904     break;
   905    905   }
   906    906   
   907    907   /* Opcode:  HaltIfNull  P1 P2 P3 P4 P5
   908         -** Synopsis:  if r[P3]=null halt
          908  +** Synopsis: if r[P3]=null halt
   909    909   **
   910    910   ** Check the value in register P3.  If it is NULL then Halt using
   911    911   ** parameter P1, P2, and P4 as if this were a Halt instruction.  If the
   912    912   ** value in register P3 is not NULL, then this routine is a no-op.
   913    913   ** The P5 parameter should be 1.
   914    914   */
   915    915   case OP_HaltIfNull: {      /* in3 */
................................................................................
  1114   1114       if( pIn3->u.i==pOp->p5 ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term;
  1115   1115     }
  1116   1116   #endif
  1117   1117     break;
  1118   1118   }
  1119   1119   
  1120   1120   /* Opcode: Null P1 P2 P3 * *
  1121         -** Synopsis:  r[P2..P3]=NULL
         1121  +** Synopsis: r[P2..P3]=NULL
  1122   1122   **
  1123   1123   ** Write a NULL into registers P2.  If P3 greater than P2, then also write
  1124   1124   ** NULL into register P3 and every register in between P2 and P3.  If P3
  1125   1125   ** is less than P2 (typically P3 is zero) then only register P2 is
  1126   1126   ** set to NULL.
  1127   1127   **
  1128   1128   ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
................................................................................
  1143   1143       pOut->flags = nullFlag;
  1144   1144       cnt--;
  1145   1145     }
  1146   1146     break;
  1147   1147   }
  1148   1148   
  1149   1149   /* Opcode: SoftNull P1 * * * *
  1150         -** Synopsis:  r[P1]=NULL
         1150  +** Synopsis: r[P1]=NULL
  1151   1151   **
  1152   1152   ** Set register P1 to have the value NULL as seen by the OP_MakeRecord
  1153   1153   ** instruction, but do not free any string or blob memory associated with
  1154   1154   ** the register, so that if the value was a string or blob that was
  1155   1155   ** previously copied using OP_SCopy, the copies will continue to be valid.
  1156   1156   */
  1157   1157   case OP_SoftNull: {
................................................................................
  1196   1196     pOut = out2Prerelease(p, pOp);
  1197   1197     sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
  1198   1198     UPDATE_MAX_BLOBSIZE(pOut);
  1199   1199     break;
  1200   1200   }
  1201   1201   
  1202   1202   /* Opcode: Move P1 P2 P3 * *
  1203         -** Synopsis:  r[P2@P3]=r[P1@P3]
         1203  +** Synopsis: r[P2@P3]=r[P1@P3]
  1204   1204   **
  1205   1205   ** Move the P3 values in register P1..P1+P3-1 over into
  1206   1206   ** registers P2..P2+P3-1.  Registers P1..P1+P3-1 are
  1207   1207   ** left holding a NULL.  It is an error for register ranges
  1208   1208   ** P1..P1+P3-1 and P2..P2+P3-1 to overlap.  It is an error
  1209   1209   ** for P3 to be less than 1.
  1210   1210   */
................................................................................
  1306   1306     assert( (pIn1->flags & MEM_Int)!=0 );
  1307   1307     pOut = &aMem[pOp->p2];
  1308   1308     sqlite3VdbeMemSetInt64(pOut, pIn1->u.i);
  1309   1309     break;
  1310   1310   }
  1311   1311   
  1312   1312   /* Opcode: ResultRow P1 P2 * * *
  1313         -** Synopsis:  output=r[P1@P2]
         1313  +** Synopsis: output=r[P1@P2]
  1314   1314   **
  1315   1315   ** The registers P1 through P1+P2-1 contain a single row of
  1316   1316   ** results. This opcode causes the sqlite3_step() call to terminate
  1317   1317   ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
  1318   1318   ** structure to provide access to the r(P1)..r(P1+P2-1) values as
  1319   1319   ** the result row.
  1320   1320   */
................................................................................
  1439   1439     pOut->n = (int)nByte;
  1440   1440     pOut->enc = encoding;
  1441   1441     UPDATE_MAX_BLOBSIZE(pOut);
  1442   1442     break;
  1443   1443   }
  1444   1444   
  1445   1445   /* Opcode: Add P1 P2 P3 * *
  1446         -** Synopsis:  r[P3]=r[P1]+r[P2]
         1446  +** Synopsis: r[P3]=r[P1]+r[P2]
  1447   1447   **
  1448   1448   ** Add the value in register P1 to the value in register P2
  1449   1449   ** and store the result in register P3.
  1450   1450   ** If either input is NULL, the result is NULL.
  1451   1451   */
  1452   1452   /* Opcode: Multiply P1 P2 P3 * *
  1453         -** Synopsis:  r[P3]=r[P1]*r[P2]
         1453  +** Synopsis: r[P3]=r[P1]*r[P2]
  1454   1454   **
  1455   1455   **
  1456   1456   ** Multiply the value in register P1 by the value in register P2
  1457   1457   ** and store the result in register P3.
  1458   1458   ** If either input is NULL, the result is NULL.
  1459   1459   */
  1460   1460   /* Opcode: Subtract P1 P2 P3 * *
  1461         -** Synopsis:  r[P3]=r[P2]-r[P1]
         1461  +** Synopsis: r[P3]=r[P2]-r[P1]
  1462   1462   **
  1463   1463   ** Subtract the value in register P1 from the value in register P2
  1464   1464   ** and store the result in register P3.
  1465   1465   ** If either input is NULL, the result is NULL.
  1466   1466   */
  1467   1467   /* Opcode: Divide P1 P2 P3 * *
  1468         -** Synopsis:  r[P3]=r[P2]/r[P1]
         1468  +** Synopsis: r[P3]=r[P2]/r[P1]
  1469   1469   **
  1470   1470   ** Divide the value in register P1 by the value in register P2
  1471   1471   ** and store the result in register P3 (P3=P2/P1). If the value in 
  1472   1472   ** register P1 is zero, then the result is NULL. If either input is 
  1473   1473   ** NULL, the result is NULL.
  1474   1474   */
  1475   1475   /* Opcode: Remainder P1 P2 P3 * *
  1476         -** Synopsis:  r[P3]=r[P2]%r[P1]
         1476  +** Synopsis: r[P3]=r[P2]%r[P1]
  1477   1477   **
  1478   1478   ** Compute the remainder after integer register P2 is divided by 
  1479   1479   ** register P1 and store the result in register P3. 
  1480   1480   ** If the value in register P1 is zero the result is NULL.
  1481   1481   ** If either operand is NULL, the result is NULL.
  1482   1482   */
  1483   1483   case OP_Add:                   /* same as TK_PLUS, in1, in2, out3 */
................................................................................
  1702   1702   
  1703   1703     REGISTER_TRACE(pOp->p3, pCtx->pOut);
  1704   1704     UPDATE_MAX_BLOBSIZE(pCtx->pOut);
  1705   1705     break;
  1706   1706   }
  1707   1707   
  1708   1708   /* Opcode: BitAnd P1 P2 P3 * *
  1709         -** Synopsis:  r[P3]=r[P1]&r[P2]
         1709  +** Synopsis: r[P3]=r[P1]&r[P2]
  1710   1710   **
  1711   1711   ** Take the bit-wise AND of the values in register P1 and P2 and
  1712   1712   ** store the result in register P3.
  1713   1713   ** If either input is NULL, the result is NULL.
  1714   1714   */
  1715   1715   /* Opcode: BitOr P1 P2 P3 * *
  1716         -** Synopsis:  r[P3]=r[P1]|r[P2]
         1716  +** Synopsis: r[P3]=r[P1]|r[P2]
  1717   1717   **
  1718   1718   ** Take the bit-wise OR of the values in register P1 and P2 and
  1719   1719   ** store the result in register P3.
  1720   1720   ** If either input is NULL, the result is NULL.
  1721   1721   */
  1722   1722   /* Opcode: ShiftLeft P1 P2 P3 * *
  1723         -** Synopsis:  r[P3]=r[P2]<<r[P1]
         1723  +** Synopsis: r[P3]=r[P2]<<r[P1]
  1724   1724   **
  1725   1725   ** Shift the integer value in register P2 to the left by the
  1726   1726   ** number of bits specified by the integer in register P1.
  1727   1727   ** Store the result in register P3.
  1728   1728   ** If either input is NULL, the result is NULL.
  1729   1729   */
  1730   1730   /* Opcode: ShiftRight P1 P2 P3 * *
  1731         -** Synopsis:  r[P3]=r[P2]>>r[P1]
         1731  +** Synopsis: r[P3]=r[P2]>>r[P1]
  1732   1732   **
  1733   1733   ** Shift the integer value in register P2 to the right by the
  1734   1734   ** number of bits specified by the integer in register P1.
  1735   1735   ** Store the result in register P3.
  1736   1736   ** If either input is NULL, the result is NULL.
  1737   1737   */
  1738   1738   case OP_BitAnd:                 /* same as TK_BITAND, in1, in2, out3 */
................................................................................
  1784   1784     }
  1785   1785     pOut->u.i = iA;
  1786   1786     MemSetTypeFlag(pOut, MEM_Int);
  1787   1787     break;
  1788   1788   }
  1789   1789   
  1790   1790   /* Opcode: AddImm  P1 P2 * * *
  1791         -** Synopsis:  r[P1]=r[P1]+P2
         1791  +** Synopsis: r[P1]=r[P1]+P2
  1792   1792   ** 
  1793   1793   ** Add the constant P2 to the value in register P1.
  1794   1794   ** The result is always an integer.
  1795   1795   **
  1796   1796   ** To force any register to be an integer, just add 0.
  1797   1797   */
  1798   1798   case OP_AddImm: {            /* in1 */
................................................................................
  1877   1877     UPDATE_MAX_BLOBSIZE(pIn1);
  1878   1878     if( rc ) goto abort_due_to_error;
  1879   1879     break;
  1880   1880   }
  1881   1881   #endif /* SQLITE_OMIT_CAST */
  1882   1882   
  1883   1883   /* Opcode: Eq P1 P2 P3 P4 P5
  1884         -** Synopsis: if r[P1]==r[P3] goto P2
         1884  +** Synopsis: IF r[P1]==r[P3]
  1885   1885   **
  1886   1886   ** Compare the values in register P1 and P3.  If reg(P3)==reg(P1) then
  1887   1887   ** jump to address P2.  Or if the SQLITE_STOREP2 flag is set in P5, then
  1888   1888   ** store the result of comparison in register P2.
  1889   1889   **
  1890   1890   ** The SQLITE_AFF_MASK portion of P5 must be an affinity character -
  1891   1891   ** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made 
................................................................................
  1911   1911   ** If neither operand is NULL the result is the same as it would be if
  1912   1912   ** the SQLITE_NULLEQ flag were omitted from P5.
  1913   1913   **
  1914   1914   ** If both SQLITE_STOREP2 and SQLITE_KEEPNULL flags are set then the
  1915   1915   ** content of r[P2] is only set to 1 (true) if it was not previously NULL.
  1916   1916   */
  1917   1917   /* Opcode: Ne P1 P2 P3 P4 P5
  1918         -** Synopsis: if r[P1]!=r[P3] goto P2
         1918  +** Synopsis: IF r[P1]!=r[P3]
  1919   1919   **
  1920   1920   ** This works just like the Eq opcode except that the jump is taken if
  1921   1921   ** the operands in registers P1 and P3 are not equal.  See the Eq opcode for
  1922   1922   ** additional information.
  1923   1923   **
  1924   1924   ** If both SQLITE_STOREP2 and SQLITE_KEEPNULL flags are set then the
  1925   1925   ** content of r[P2] is only set to 0 (false) if it was not previously NULL.
  1926   1926   */
  1927   1927   /* Opcode: Lt P1 P2 P3 P4 P5
  1928         -** Synopsis: if r[P1]<r[P3] goto P2
         1928  +** Synopsis: IF r[P1]<r[P3]
  1929   1929   **
  1930   1930   ** Compare the values in register P1 and P3.  If reg(P3)<reg(P1) then
  1931   1931   ** jump to address P2.  Or if the SQLITE_STOREP2 flag is set in P5 store
  1932   1932   ** the result of comparison (0 or 1 or NULL) into register P2.
  1933   1933   **
  1934   1934   ** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
  1935   1935   ** reg(P3) is NULL then the take the jump.  If the SQLITE_JUMPIFNULL 
................................................................................
  1950   1950   ** P4 is  used to do the comparison.  If P4 is not specified then
  1951   1951   ** memcmp() is used to compare text string.  If both values are
  1952   1952   ** numeric, then a numeric comparison is used. If the two values
  1953   1953   ** are of different types, then numbers are considered less than
  1954   1954   ** strings and strings are considered less than blobs.
  1955   1955   */
  1956   1956   /* Opcode: Le P1 P2 P3 P4 P5
  1957         -** Synopsis: if r[P1]<=r[P3] goto P2
         1957  +** Synopsis: IF r[P1]<=r[P3]
  1958   1958   **
  1959   1959   ** This works just like the Lt opcode except that the jump is taken if
  1960   1960   ** the content of register P3 is less than or equal to the content of
  1961   1961   ** register P1.  See the Lt opcode for additional information.
  1962   1962   */
  1963   1963   /* Opcode: Gt P1 P2 P3 P4 P5
  1964         -** Synopsis: if r[P1]>r[P3] goto P2
         1964  +** Synopsis: IF r[P1]>r[P3]
  1965   1965   **
  1966   1966   ** This works just like the Lt opcode except that the jump is taken if
  1967   1967   ** the content of register P3 is greater than the content of
  1968   1968   ** register P1.  See the Lt opcode for additional information.
  1969   1969   */
  1970   1970   /* Opcode: Ge P1 P2 P3 P4 P5
  1971         -** Synopsis: if r[P1]>=r[P3] goto P2
         1971  +** Synopsis: IF r[P1]>=r[P3]
  1972   1972   **
  1973   1973   ** This works just like the Lt opcode except that the jump is taken if
  1974   1974   ** the content of register P3 is greater than or equal to the content of
  1975   1975   ** register P1.  See the Lt opcode for additional information.
  1976   1976   */
  1977   1977   case OP_Eq:               /* same as TK_EQ, jump, in1, in3 */
  1978   1978   case OP_Ne:               /* same as TK_NE, jump, in1, in3 */
................................................................................
  2366   2366     if( c ){
  2367   2367       goto jump_to_p2;
  2368   2368     }
  2369   2369     break;
  2370   2370   }
  2371   2371   
  2372   2372   /* Opcode: IsNull P1 P2 * * *
  2373         -** Synopsis:  if r[P1]==NULL goto P2
         2373  +** Synopsis: if r[P1]==NULL goto P2
  2374   2374   **
  2375   2375   ** Jump to P2 if the value in register P1 is NULL.
  2376   2376   */
  2377   2377   case OP_IsNull: {            /* same as TK_ISNULL, jump, in1 */
  2378   2378     pIn1 = &aMem[pOp->p1];
  2379   2379     VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
  2380   2380     if( (pIn1->flags & MEM_Null)!=0 ){
................................................................................
  2394   2394     if( (pIn1->flags & MEM_Null)==0 ){
  2395   2395       goto jump_to_p2;
  2396   2396     }
  2397   2397     break;
  2398   2398   }
  2399   2399   
  2400   2400   /* Opcode: Column P1 P2 P3 P4 P5
  2401         -** Synopsis:  r[P3]=PX
         2401  +** Synopsis: r[P3]=PX
  2402   2402   **
  2403   2403   ** Interpret the data that cursor P1 points to as a structure built using
  2404   2404   ** the MakeRecord instruction.  (See the MakeRecord opcode for additional
  2405   2405   ** information about the format of the data.)  Extract the P2-th column
  2406   2406   ** from this record.  If there are less that (P2+1) 
  2407   2407   ** values in the record, extract a NULL.
  2408   2408   **
................................................................................
  4336   4336   ** value of register P2 will then change.  Make sure this does not
  4337   4337   ** cause any problems.)
  4338   4338   **
  4339   4339   ** This instruction only works on tables.  The equivalent instruction
  4340   4340   ** for indices is OP_IdxInsert.
  4341   4341   */
  4342   4342   /* Opcode: InsertInt P1 P2 P3 P4 P5
  4343         -** Synopsis:  intkey=P3 data=r[P2]
         4343  +** Synopsis: intkey=P3 data=r[P2]
  4344   4344   **
  4345   4345   ** This works exactly like OP_Insert except that the key is the
  4346   4346   ** integer value P3, not the value of the integer stored in register P3.
  4347   4347   */
  4348   4348   case OP_Insert: 
  4349   4349   case OP_InsertInt: {
  4350   4350     Mem *pData;       /* MEM cell holding data for the record to be inserted */
................................................................................
  4567   4567   case OP_ResetCount: {
  4568   4568     sqlite3VdbeSetChanges(db, p->nChange);
  4569   4569     p->nChange = 0;
  4570   4570     break;
  4571   4571   }
  4572   4572   
  4573   4573   /* Opcode: SorterCompare P1 P2 P3 P4
  4574         -** Synopsis:  if key(P1)!=trim(r[P3],P4) goto P2
         4574  +** Synopsis: if key(P1)!=trim(r[P3],P4) goto P2
  4575   4575   **
  4576   4576   ** P1 is a sorter cursor. This instruction compares a prefix of the
  4577   4577   ** record blob in register P3 against a prefix of the entry that 
  4578   4578   ** the sorter cursor currently points to.  Only the first P4 fields
  4579   4579   ** of r[P3] and the sorter record are compared.
  4580   4580   **
  4581   4581   ** If either P3 or the sorter contains a NULL in one of their significant
................................................................................
  5094   5094     }
  5095   5095     assert( pC->deferredMoveto==0 );
  5096   5096     pC->cacheStatus = CACHE_STALE;
  5097   5097     break;
  5098   5098   }
  5099   5099   
  5100   5100   /* Opcode: Seek P1 * P3 P4 *
  5101         -** Synopsis:  Move P3 to P1.rowid
         5101  +** Synopsis: Move P3 to P1.rowid
  5102   5102   **
  5103   5103   ** P1 is an open index cursor and P3 is a cursor on the corresponding
  5104   5104   ** table.  This opcode does a deferred seek of the P3 table cursor
  5105   5105   ** to the row that corresponds to the current row of P1.
  5106   5106   **
  5107   5107   ** This is a deferred seek.  Nothing actually happens until
  5108   5108   ** the cursor is used to read a record.  That way, if no reads
................................................................................
  5601   5601     UPDATE_MAX_BLOBSIZE(pIn1);
  5602   5602     sqlite3VdbeChangeEncoding(pIn1, encoding);
  5603   5603     break;
  5604   5604   }
  5605   5605   #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
  5606   5606   
  5607   5607   /* Opcode: RowSetAdd P1 P2 * * *
  5608         -** Synopsis:  rowset(P1)=r[P2]
         5608  +** Synopsis: rowset(P1)=r[P2]
  5609   5609   **
  5610   5610   ** Insert the integer value held by register P2 into a boolean index
  5611   5611   ** held in register P1.
  5612   5612   **
  5613   5613   ** An assertion fails if P2 is not an integer.
  5614   5614   */
  5615   5615   case OP_RowSetAdd: {       /* in1, in2 */
................................................................................
  5621   5621       if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem;
  5622   5622     }
  5623   5623     sqlite3RowSetInsert(pIn1->u.pRowSet, pIn2->u.i);
  5624   5624     break;
  5625   5625   }
  5626   5626   
  5627   5627   /* Opcode: RowSetRead P1 P2 P3 * *
  5628         -** Synopsis:  r[P3]=rowset(P1)
         5628  +** Synopsis: r[P3]=rowset(P1)
  5629   5629   **
  5630   5630   ** Extract the smallest value from boolean index P1 and put that value into
  5631   5631   ** register P3.  Or, if boolean index P1 is initially empty, leave P3
  5632   5632   ** unchanged and jump to instruction P2.
  5633   5633   */
  5634   5634   case OP_RowSetRead: {       /* jump, in1, out3 */
  5635   5635     i64 val;
................................................................................
  6800   6800     pOut->u.i = sqlite3BtreeMaxPageCount(pBt, newMax);
  6801   6801     break;
  6802   6802   }
  6803   6803   #endif
  6804   6804   
  6805   6805   
  6806   6806   /* Opcode: Init * P2 * P4 *
  6807         -** Synopsis:  Start at P2
         6807  +** Synopsis: Start at P2
  6808   6808   **
  6809   6809   ** Programs contain a single instance of this opcode as the very first
  6810   6810   ** opcode.
  6811   6811   **
  6812   6812   ** If tracing is enabled (by the sqlite3_trace()) interface, then
  6813   6813   ** the UTF-8 string contained in P4 is emitted on the trace callback.
  6814   6814   ** Or if P4 is blank, use the string returned by sqlite3_sql().

Changes to src/vdbeaux.c.

  1090   1090     char *zTemp,       /* Write result here */
  1091   1091     int nTemp          /* Space available in zTemp[] */
  1092   1092   ){
  1093   1093     const char *zOpName;
  1094   1094     const char *zSynopsis;
  1095   1095     int nOpName;
  1096   1096     int ii, jj;
         1097  +  char zAlt[50];
  1097   1098     zOpName = sqlite3OpcodeName(pOp->opcode);
  1098   1099     nOpName = sqlite3Strlen30(zOpName);
  1099   1100     if( zOpName[nOpName+1] ){
  1100   1101       int seenCom = 0;
  1101   1102       char c;
  1102   1103       zSynopsis = zOpName += nOpName + 1;
         1104  +    if( strncmp(zSynopsis,"IF ",3)==0 ){
         1105  +      if( pOp->p5 & SQLITE_STOREP2 ){
         1106  +        sqlite3_snprintf(sizeof(zAlt), zAlt, "r[P2] = (%s)", zSynopsis+3);
         1107  +      }else{
         1108  +        sqlite3_snprintf(sizeof(zAlt), zAlt, "if %s goto P2", zSynopsis+3);
         1109  +      }
         1110  +      zSynopsis = zAlt;
         1111  +    }
  1103   1112       for(ii=jj=0; jj<nTemp-1 && (c = zSynopsis[ii])!=0; ii++){
  1104   1113         if( c=='P' ){
  1105   1114           c = zSynopsis[++ii];
  1106   1115           if( c=='4' ){
  1107   1116             sqlite3_snprintf(nTemp-jj, zTemp+jj, "%s", zP4);
  1108   1117           }else if( c=='X' ){
  1109   1118             sqlite3_snprintf(nTemp-jj, zTemp+jj, "%s", pOp->zComment);