/ Check-in [8a0b730d]
Login

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

Overview
Comment:Update and correct the documentation on the OP_OpenRead, OP_OpenWrite, and OP_ReopenIdx opcodes. No code changes other than the addition of an assert().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8a0b730d0ea640d5cf75febe39b2162411a12eb5275765a85882158b5a085681
User & Date: drh 2018-06-05 13:43:02
Context
2018-06-05
23:21
Avoid unnecessary loads of columns in an aggregate query that are not within an aggregate function and that are not part of the GROUP BY clause. check-in: e15e1006 user: drh tags: trunk
20:04
Calculate non-aggregate expressions in the SELECT list of an aggregate query that does not use min() or max() once per group, instead of once per row visited. Closed-Leaf check-in: dce2dfbe user: dan tags: exp-agg-opt
13:54
Merge trunk changes. check-in: 047295c5 user: drh tags: multikey-opt-idea
13:43
Update and correct the documentation on the OP_OpenRead, OP_OpenWrite, and OP_ReopenIdx opcodes. No code changes other than the addition of an assert(). check-in: 8a0b730d user: drh tags: trunk
2018-06-04
19:24
Version 3.24.0 check-in: c7ee0833 user: drh tags: trunk, release, version-3.24.0
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

  3366   3366   ** P2 in a database file.  The database file is determined by P3. 
  3367   3367   ** P3==0 means the main database, P3==1 means the database used for 
  3368   3368   ** temporary tables, and P3>1 means used the corresponding attached
  3369   3369   ** database.  Give the new cursor an identifier of P1.  The P1
  3370   3370   ** values need not be contiguous but all P1 values should be small integers.
  3371   3371   ** It is an error for P1 to be negative.
  3372   3372   **
  3373         -** If P5!=0 then use the content of register P2 as the root page, not
  3374         -** the value of P2 itself.
  3375         -**
  3376         -** There will be a read lock on the database whenever there is an
  3377         -** open cursor.  If the database was unlocked prior to this instruction
  3378         -** then a read lock is acquired as part of this instruction.  A read
  3379         -** lock allows other processes to read the database but prohibits
  3380         -** any other process from modifying the database.  The read lock is
  3381         -** released when all cursors are closed.  If this instruction attempts
  3382         -** to get a read lock but fails, the script terminates with an
  3383         -** SQLITE_BUSY error code.
         3373  +** Allowed P5 bits:
         3374  +** <ul>
         3375  +** <li>  <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
         3376  +**       equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT
         3377  +**       of OP_SeekLE/OP_IdxGT)
         3378  +** </ul>
  3384   3379   **
  3385   3380   ** The P4 value may be either an integer (P4_INT32) or a pointer to
  3386   3381   ** a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo 
  3387         -** structure, then said structure defines the content and collating 
  3388         -** sequence of the index being opened. Otherwise, if P4 is an integer 
  3389         -** value, it is set to the number of columns in the table.
         3382  +** object, then table being opened must be an [index b-tree] where the
         3383  +** KeyInfo object defines the content and collating 
         3384  +** sequence of that index b-tree. Otherwise, if P4 is an integer 
         3385  +** value, then the table being opened must be a [table b-tree] with a
         3386  +** number of columns no less than the value of P4.
  3390   3387   **
  3391   3388   ** See also: OpenWrite, ReopenIdx
  3392   3389   */
  3393   3390   /* Opcode: ReopenIdx P1 P2 P3 P4 P5
  3394   3391   ** Synopsis: root=P2 iDb=P3
  3395   3392   **
  3396         -** The ReopenIdx opcode works exactly like ReadOpen except that it first
  3397         -** checks to see if the cursor on P1 is already open with a root page
  3398         -** number of P2 and if it is this opcode becomes a no-op.  In other words,
         3393  +** The ReopenIdx opcode works like OP_OpenRead except that it first
         3394  +** checks to see if the cursor on P1 is already open on the same
         3395  +** b-tree and if it is this opcode becomes a no-op.  In other words,
  3399   3396   ** if the cursor is already open, do not reopen it.
  3400   3397   **
  3401         -** The ReopenIdx opcode may only be used with P5==0 and with P4 being
  3402         -** a P4_KEYINFO object.  Furthermore, the P3 value must be the same as
  3403         -** every other ReopenIdx or OpenRead for the same cursor number.
         3398  +** The ReopenIdx opcode may only be used with P5==0 or P5==OPFLAG_SEEKEQ
         3399  +** and with P4 being a P4_KEYINFO object.  Furthermore, the P3 value must
         3400  +** be the same as every other ReopenIdx or OpenRead for the same cursor
         3401  +** number.
  3404   3402   **
  3405         -** See the OpenRead opcode documentation for additional information.
         3403  +** Allowed P5 bits:
         3404  +** <ul>
         3405  +** <li>  <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
         3406  +**       equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT
         3407  +**       of OP_SeekLE/OP_IdxGT)
         3408  +** </ul>
         3409  +**
         3410  +** See also: OP_OpenRead, OP_OpenWrite
  3406   3411   */
  3407   3412   /* Opcode: OpenWrite P1 P2 P3 P4 P5
  3408   3413   ** Synopsis: root=P2 iDb=P3
  3409   3414   **
  3410   3415   ** Open a read/write cursor named P1 on the table or index whose root
  3411         -** page is P2.  Or if P5!=0 use the content of register P2 to find the
  3412         -** root page.
         3416  +** page is P2 (or whose root page is held in register P2 if the
         3417  +** OPFLAG_P2ISREG bit is set in P5 - see below).
  3413   3418   **
  3414   3419   ** The P4 value may be either an integer (P4_INT32) or a pointer to
  3415   3420   ** a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo 
  3416         -** structure, then said structure defines the content and collating 
  3417         -** sequence of the index being opened. Otherwise, if P4 is an integer 
  3418         -** value, it is set to the number of columns in the table, or to the
  3419         -** largest index of any column of the table that is actually used.
         3421  +** object, then table being opened must be an [index b-tree] where the
         3422  +** KeyInfo object defines the content and collating 
         3423  +** sequence of that index b-tree. Otherwise, if P4 is an integer 
         3424  +** value, then the table being opened must be a [table b-tree] with a
         3425  +** number of columns no less than the value of P4.
  3420   3426   **
  3421         -** This instruction works just like OpenRead except that it opens the cursor
  3422         -** in read/write mode.  For a given table, there can be one or more read-only
  3423         -** cursors or a single read/write cursor but not both.
         3427  +** Allowed P5 bits:
         3428  +** <ul>
         3429  +** <li>  <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
         3430  +**       equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT
         3431  +**       of OP_SeekLE/OP_IdxGT)
         3432  +** <li>  <b>0x08 OPFLAG_FORDELETE</b>: This cursor is used only to seek
         3433  +**       and subsequently delete entries in an index btree.  This is a
         3434  +**       hint to the storage engine that the storage engine is allowed to
         3435  +**       ignore.  The hint is not used by the official SQLite b*tree storage
         3436  +**       engine, but is used by COMDB2.
         3437  +** <li>  <b>0x10 OPFLAG_P2ISREG</b>: Use the content of register P2
         3438  +**       as the root page, not the value of P2 itself.
         3439  +** </ul>
  3424   3440   **
  3425         -** See also OpenRead.
         3441  +** This instruction works like OpenRead except that it opens the cursor
         3442  +** in read/write mode.
         3443  +**
         3444  +** See also: OP_OpenRead, OP_ReopenIdx
  3426   3445   */
  3427   3446   case OP_ReopenIdx: {
  3428   3447     int nField;
  3429   3448     KeyInfo *pKeyInfo;
  3430   3449     int p2;
  3431   3450     int iDb;
  3432   3451     int wrFlag;
................................................................................
  3474   3493       }
  3475   3494     }else{
  3476   3495       wrFlag = 0;
  3477   3496     }
  3478   3497     if( pOp->p5 & OPFLAG_P2ISREG ){
  3479   3498       assert( p2>0 );
  3480   3499       assert( p2<=(p->nMem+1 - p->nCursor) );
         3500  +    assert( pOp->opcode==OP_OpenWrite );
  3481   3501       pIn2 = &aMem[p2];
  3482   3502       assert( memIsValid(pIn2) );
  3483   3503       assert( (pIn2->flags & MEM_Int)!=0 );
  3484   3504       sqlite3VdbeMemIntegerify(pIn2);
  3485   3505       p2 = (int)pIn2->u.i;
  3486   3506       /* The p2 value always comes from a prior OP_CreateBtree opcode and
  3487   3507       ** that opcode will always set the p2 value to 2 or more or else fail.