/ Check-in [c8f009bd]
Login

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

Overview
Comment:More simplifications to vdbe.c. Remove a NEVER() from vdbe.c that is possible after all. (CVS 6796)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:c8f009bd24cb4e4b5ce9fbfd8ab09921f19d41af
User & Date: drh 2009-06-22 11:10:48
Context
2009-06-22
12:05
Make sure sqlite3BtreeCreateTable() returns an error code if the largest rootpage field is invalid in auto_vacuum mode. Update file-format comments to describe all of the "meta" values. (CVS 6797) check-in: bda38f5e user: drh tags: trunk
11:10
More simplifications to vdbe.c. Remove a NEVER() from vdbe.c that is possible after all. (CVS 6796) check-in: c8f009bd user: drh tags: trunk
05:43
If an OOM error occurs just after obtaining a shared lock on the database file, release the lock before returning. (CVS 6795) check-in: 971a9650 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.858 2009/06/22 00:55:31 drh Exp $
           46  +** $Id: vdbe.c,v 1.859 2009/06/22 11:10:48 drh Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include "vdbeInt.h"
    50     50   
    51     51   /*
    52     52   ** The following global variable is incremented every time a cursor
    53     53   ** moves, either by the OP_SeekXX, OP_Next, or OP_Prev opcodes.  The test
................................................................................
  2463   2463   ** will be allocated and initialized.
  2464   2464   **
  2465   2465   ** The statement is begun on the database file with index P1.  The main
  2466   2466   ** database file has an index of 0 and the file used for temporary tables
  2467   2467   ** has an index of 1.
  2468   2468   */
  2469   2469   case OP_Statement: {
  2470         -  int i;
  2471   2470     Btree *pBt;
  2472   2471     if( db->autoCommit==0 || db->activeVdbeCnt>1 ){
  2473         -    i = pOp->p1;
  2474         -    assert( i>=0 && i<db->nDb );
  2475         -    assert( db->aDb[i].pBt!=0 );
  2476         -    pBt = db->aDb[i].pBt;
         2472  +    assert( pOp->p1>=0 && pOp->p1<db->nDb );
         2473  +    assert( db->aDb[pOp->p1].pBt!=0 );
         2474  +    pBt = db->aDb[pOp->p1].pBt;
  2477   2475       assert( sqlite3BtreeIsInTrans(pBt) );
  2478         -    assert( (p->btreeMask & (1<<i))!=0 );
         2476  +    assert( (p->btreeMask & (1<<pOp->p1))!=0 );
  2479   2477       if( p->iStatement==0 ){
  2480   2478         assert( db->nStatement>=0 && db->nSavepoint>=0 );
  2481   2479         db->nStatement++; 
  2482   2480         p->iStatement = db->nSavepoint + db->nStatement;
  2483   2481       }
  2484   2482       rc = sqlite3BtreeBeginStmt(pBt, p->iStatement);
  2485   2483     }
................................................................................
  2713   2711   ** write transaction must be started before any changes can be made to the
  2714   2712   ** database.  If P2 is 2 or greater then an EXCLUSIVE lock is also obtained
  2715   2713   ** on the file.
  2716   2714   **
  2717   2715   ** If P2 is zero, then a read-lock is obtained on the database file.
  2718   2716   */
  2719   2717   case OP_Transaction: {
  2720         -  int i;
  2721   2718     Btree *pBt;
  2722   2719   
  2723         -  i = pOp->p1;
  2724         -  assert( i>=0 && i<db->nDb );
  2725         -  assert( (p->btreeMask & (1<<i))!=0 );
  2726         -  pBt = db->aDb[i].pBt;
         2720  +  assert( pOp->p1>=0 && pOp->p1<db->nDb );
         2721  +  assert( (p->btreeMask & (1<<pOp->p1))!=0 );
         2722  +  pBt = db->aDb[pOp->p1].pBt;
  2727   2723   
  2728   2724     if( pBt ){
  2729   2725       rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
  2730   2726       if( rc==SQLITE_BUSY ){
  2731   2727         p->pc = pc;
  2732   2728         p->rc = rc = SQLITE_BUSY;
  2733   2729         goto vdbe_return;
................................................................................
  2908   2904   **
  2909   2905   ** See also OpenRead.
  2910   2906   */
  2911   2907   case OP_OpenRead:
  2912   2908   case OP_OpenWrite: {
  2913   2909     int nField;
  2914   2910     KeyInfo *pKeyInfo;
  2915         -  int i;
  2916   2911     int p2;
  2917   2912     int iDb;
  2918   2913     int wrFlag;
  2919   2914     Btree *pX;
  2920   2915     VdbeCursor *pCur;
  2921   2916     Db *pDb;
  2922   2917     int flags;
  2923   2918   
  2924   2919     nField = 0;
  2925   2920     pKeyInfo = 0;
  2926         -  i = pOp->p1;
  2927   2921     p2 = pOp->p2;
  2928   2922     iDb = pOp->p3;
  2929   2923     assert( iDb>=0 && iDb<db->nDb );
  2930   2924     assert( (p->btreeMask & (1<<iDb))!=0 );
  2931   2925     pDb = &db->aDb[iDb];
  2932   2926     pX = pDb->pBt;
  2933   2927     assert( pX!=0 );
................................................................................
  2941   2935     }
  2942   2936     if( pOp->p5 ){
  2943   2937       assert( p2>0 );
  2944   2938       assert( p2<=p->nMem );
  2945   2939       pIn2 = &p->aMem[p2];
  2946   2940       sqlite3VdbeMemIntegerify(pIn2);
  2947   2941       p2 = (int)pIn2->u.i;
  2948         -    if( NEVER(p2<2) ) {
         2942  +    if( p2<2 ) {
  2949   2943         rc = SQLITE_CORRUPT_BKPT;
  2950   2944         goto abort_due_to_error;
  2951   2945       }
  2952   2946     }
  2953         -  assert( i>=0 );
  2954   2947     if( pOp->p4type==P4_KEYINFO ){
  2955   2948       pKeyInfo = pOp->p4.pKeyInfo;
  2956   2949       pKeyInfo->enc = ENC(p->db);
  2957   2950       nField = pKeyInfo->nField+1;
  2958   2951     }else if( pOp->p4type==P4_INT32 ){
  2959   2952       nField = pOp->p4.i;
  2960   2953     }
  2961         -  pCur = allocateCursor(p, i, nField, iDb, 1);
         2954  +  assert( pOp->p1>=0 );
         2955  +  pCur = allocateCursor(p, pOp->p1, nField, iDb, 1);
  2962   2956     if( pCur==0 ) goto no_mem;
  2963   2957     pCur->nullRow = 1;
  2964   2958     rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
  2965   2959     pCur->pKeyInfo = pKeyInfo;
  2966   2960   
  2967   2961     switch( rc ){
  2968   2962       case SQLITE_OK: {
................................................................................
  3021   3015   ** This opcode was once called OpenTemp.  But that created
  3022   3016   ** confusion because the term "temp table", might refer either
  3023   3017   ** to a TEMP table at the SQL level, or to a table opened by
  3024   3018   ** this opcode.  Then this opcode was call OpenVirtual.  But
  3025   3019   ** that created confusion with the whole virtual-table idea.
  3026   3020   */
  3027   3021   case OP_OpenEphemeral: {
  3028         -  int i;
  3029   3022     VdbeCursor *pCx;
  3030   3023     static const int openFlags = 
  3031   3024         SQLITE_OPEN_READWRITE |
  3032   3025         SQLITE_OPEN_CREATE |
  3033   3026         SQLITE_OPEN_EXCLUSIVE |
  3034   3027         SQLITE_OPEN_DELETEONCLOSE |
  3035   3028         SQLITE_OPEN_TRANSIENT_DB;
  3036   3029   
  3037         -  i = pOp->p1;
  3038         -  assert( i>=0 );
  3039         -  pCx = allocateCursor(p, i, pOp->p2, -1, 1);
         3030  +  assert( pOp->p1>=0 );
         3031  +  pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
  3040   3032     if( pCx==0 ) goto no_mem;
  3041   3033     pCx->nullRow = 1;
  3042   3034     rc = sqlite3BtreeFactory(db, 0, 1, SQLITE_DEFAULT_TEMP_CACHE_SIZE, openFlags,
  3043   3035                              &pCx->pBt);
  3044   3036     if( rc==SQLITE_OK ){
  3045   3037       rc = sqlite3BtreeBeginTrans(pCx->pBt, 1);
  3046   3038     }
................................................................................
  3091   3083   ** memory cell containing the row data is not overwritten until the
  3092   3084   ** pseudo table is closed (or a new row is inserted into it).
  3093   3085   **
  3094   3086   ** P3 is the number of fields in the records that will be stored by
  3095   3087   ** the pseudo-table.
  3096   3088   */
  3097   3089   case OP_OpenPseudo: {
  3098         -  int i;
  3099   3090     VdbeCursor *pCx;
  3100   3091   
  3101         -  i = pOp->p1;
  3102         -  assert( i>=0 );
  3103         -  pCx = allocateCursor(p, i, pOp->p3, -1, 0);
         3092  +  assert( pOp->p1>=0 );
         3093  +  pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
  3104   3094     if( pCx==0 ) goto no_mem;
  3105   3095     pCx->nullRow = 1;
  3106   3096     pCx->pseudoTable = 1;
  3107   3097     pCx->ephemPseudoTable = (u8)pOp->p2;
  3108   3098     pCx->isTable = 1;
  3109   3099     pCx->isIndex = 0;
  3110   3100     break;
................................................................................
  3112   3102   
  3113   3103   /* Opcode: Close P1 * * * *
  3114   3104   **
  3115   3105   ** Close a cursor previously opened as P1.  If P1 is not
  3116   3106   ** currently open, this instruction is a no-op.
  3117   3107   */
  3118   3108   case OP_Close: {
  3119         -  int i;
  3120         -  i = pOp->p1;
  3121         -  assert( i>=0 && i<p->nCursor );
  3122         -  sqlite3VdbeFreeCursor(p, p->apCsr[i]);
  3123         -  p->apCsr[i] = 0;
         3109  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
         3110  +  sqlite3VdbeFreeCursor(p, p->apCsr[pOp->p1]);
         3111  +  p->apCsr[pOp->p1] = 0;
  3124   3112     break;
  3125   3113   }
  3126   3114   
  3127   3115   /* Opcode: SeekGe P1 P2 P3 P4 *
  3128   3116   **
  3129   3117   ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys), 
  3130   3118   ** use the value in register P3 as the key.  If cursor P1 refers 
................................................................................
  3176   3164   **
  3177   3165   ** See also: Found, NotFound, Distinct, SeekGt, SeekGe, SeekLt
  3178   3166   */
  3179   3167   case OP_SeekLt:         /* jump, in3 */
  3180   3168   case OP_SeekLe:         /* jump, in3 */
  3181   3169   case OP_SeekGe:         /* jump, in3 */
  3182   3170   case OP_SeekGt: {       /* jump, in3 */
  3183         -  int i;
  3184   3171     int res;
  3185   3172     int oc;
  3186   3173     VdbeCursor *pC;
  3187   3174     UnpackedRecord r;
  3188   3175     int nField;
  3189   3176     i64 iKey;      /* The rowid we are to seek to */
  3190   3177   
  3191         -  i = pOp->p1;
  3192         -  assert( i>=0 && i<p->nCursor );
         3178  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  3193   3179     assert( pOp->p2!=0 );
  3194         -  pC = p->apCsr[i];
         3180  +  pC = p->apCsr[pOp->p1];
  3195   3181     assert( pC!=0 );
  3196   3182     if( pC->pCursor!=0 ){
  3197   3183       oc = pOp->opcode;
  3198   3184       pC->nullRow = 0;
  3199   3185       if( pC->isTable ){
  3200   3186         /* The input value in P3 might be of any type: integer, real, string,
  3201   3187         ** blob, or NULL.  But it needs to be an integer before we can do
................................................................................
  3318   3304   ** for P1 to move so that it points to the rowid given by P2.
  3319   3305   **
  3320   3306   ** This is actually a deferred seek.  Nothing actually happens until
  3321   3307   ** the cursor is used to read a record.  That way, if no reads
  3322   3308   ** occur, no unnecessary I/O happens.
  3323   3309   */
  3324   3310   case OP_Seek: {    /* in2 */
  3325         -  int i;
  3326   3311     VdbeCursor *pC;
  3327   3312   
  3328         -  i = pOp->p1;
  3329         -  assert( i>=0 && i<p->nCursor );
  3330         -  pC = p->apCsr[i];
         3313  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
         3314  +  pC = p->apCsr[pOp->p1];
  3331   3315     assert( pC!=0 );
  3332   3316     if( ALWAYS(pC->pCursor!=0) ){
  3333   3317       assert( pC->isTable );
  3334   3318       pC->nullRow = 0;
  3335   3319       pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
  3336   3320       pC->rowidIsValid = 0;
  3337   3321       pC->deferredMoveto = 1;
................................................................................
  3550   3534   **
  3551   3535   ** Find the next available sequence number for cursor P1.
  3552   3536   ** Write the sequence number into register P2.
  3553   3537   ** The sequence number on the cursor is incremented after this
  3554   3538   ** instruction.  
  3555   3539   */
  3556   3540   case OP_Sequence: {           /* out2-prerelease */
  3557         -  int i = pOp->p1;
  3558         -  assert( i>=0 && i<p->nCursor );
  3559         -  assert( p->apCsr[i]!=0 );
  3560         -  pOut->u.i = p->apCsr[i]->seqCount++;
         3541  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
         3542  +  assert( p->apCsr[pOp->p1]!=0 );
         3543  +  pOut->u.i = p->apCsr[pOp->p1]->seqCount++;
  3561   3544     MemSetTypeFlag(pOut, MEM_Int);
  3562   3545     break;
  3563   3546   }
  3564   3547   
  3565   3548   
  3566   3549   /* Opcode: NewRowid P1 P2 P3 * *
  3567   3550   **
................................................................................
  3713   3696   ** This instruction only works on tables.  The equivalent instruction
  3714   3697   ** for indices is OP_IdxInsert.
  3715   3698   */
  3716   3699   case OP_Insert: {
  3717   3700     Mem *pData;
  3718   3701     Mem *pKey;
  3719   3702     i64 iKey;   /* The integer ROWID or key for the record to be inserted */
  3720         -  int i;
  3721   3703     VdbeCursor *pC;
  3722   3704     int nZero;
  3723   3705     int seekResult;
  3724   3706     const char *zDb;
  3725   3707     const char *zTbl;
  3726   3708     int op;
  3727   3709   
  3728   3710     pData = &p->aMem[pOp->p2];
  3729   3711     pKey = &p->aMem[pOp->p3];
  3730         -  i = pOp->p1;
  3731         -  assert( i>=0 && i<p->nCursor );
  3732         -  pC = p->apCsr[i];
         3712  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
         3713  +  pC = p->apCsr[pOp->p1];
  3733   3714     assert( pC!=0 );
  3734   3715     assert( pC->pCursor!=0 || pC->pseudoTable );
  3735   3716     assert( pKey->flags & MEM_Int );
  3736   3717     assert( pC->isTable );
  3737   3718     REGISTER_TRACE(pOp->p2, pData);
  3738   3719     REGISTER_TRACE(pOp->p3, pKey);
  3739   3720   
................................................................................
  3814   3795   **
  3815   3796   ** If P4 is not NULL, then it is the name of the table that P1 is
  3816   3797   ** pointing to.  The update hook will be invoked, if it exists.
  3817   3798   ** If P4 is not NULL then the P1 cursor must have been positioned
  3818   3799   ** using OP_NotFound prior to invoking this opcode.
  3819   3800   */
  3820   3801   case OP_Delete: {
  3821         -  int i;
  3822   3802     i64 iKey;
  3823   3803     VdbeCursor *pC;
  3824   3804   
  3825         -  i = pOp->p1;
  3826   3805     iKey = 0;
  3827         -  assert( i>=0 && i<p->nCursor );
  3828         -  pC = p->apCsr[i];
         3806  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
         3807  +  pC = p->apCsr[pOp->p1];
  3829   3808     assert( pC!=0 );
  3830   3809     assert( pC->pCursor!=0 );  /* Only valid for real tables, no pseudotables */
  3831   3810   
  3832   3811     /* If the update-hook will be invoked, set iKey to the rowid of the
  3833   3812     ** row being deleted.
  3834   3813     */
  3835   3814     if( db->xUpdateCallback && pOp->p4.z ){
................................................................................
  3888   3867   ** it is found in the database file.
  3889   3868   **
  3890   3869   ** If the P1 cursor must be pointing to a valid row (not a NULL row)
  3891   3870   ** of a real table, not a pseudo-table.
  3892   3871   */
  3893   3872   case OP_RowKey:
  3894   3873   case OP_RowData: {
  3895         -  int i;
  3896   3874     VdbeCursor *pC;
  3897   3875     BtCursor *pCrsr;
  3898   3876     u32 n;
  3899   3877     i64 n64;
  3900   3878   
  3901         -  i = pOp->p1;
  3902   3879     pOut = &p->aMem[pOp->p2];
  3903   3880   
  3904   3881     /* Note that RowKey and RowData are really exactly the same instruction */
  3905         -  assert( i>=0 && i<p->nCursor );
  3906         -  pC = p->apCsr[i];
         3882  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
         3883  +  pC = p->apCsr[pOp->p1];
  3907   3884     assert( pC->isTable || pOp->opcode==OP_RowKey );
  3908   3885     assert( pC->isIndex || pOp->opcode==OP_RowData );
  3909   3886     assert( pC!=0 );
  3910   3887     assert( pC->nullRow==0 );
  3911   3888     assert( pC->pseudoTable==0 );
  3912   3889     assert( pC->pCursor!=0 );
  3913   3890     pCrsr = pC->pCursor;
................................................................................
  3947   3924   ** P1 is currently point to.
  3948   3925   **
  3949   3926   ** P1 can be either an ordinary table or a virtual table.  There used to
  3950   3927   ** be a separate OP_VRowid opcode for use with virtual tables, but this
  3951   3928   ** one opcode now works for both table types.
  3952   3929   */
  3953   3930   case OP_Rowid: {                 /* out2-prerelease */
  3954         -  int i;
  3955   3931     VdbeCursor *pC;
  3956   3932     i64 v;
  3957   3933     sqlite3_vtab *pVtab;
  3958   3934     const sqlite3_module *pModule;
  3959   3935   
  3960         -  i = pOp->p1;
  3961         -  assert( i>=0 && i<p->nCursor );
  3962         -  pC = p->apCsr[i];
         3936  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
         3937  +  pC = p->apCsr[pOp->p1];
  3963   3938     assert( pC!=0 );
  3964   3939     if( pC->nullRow ){
  3965   3940       /* Do nothing so that reg[P2] remains NULL */
  3966   3941       break;
  3967   3942     }else if( pC->deferredMoveto ){
  3968   3943       v = pC->movetoTarget;
  3969   3944     }else if( pC->pseudoTable ){
................................................................................
  3998   3973   /* Opcode: NullRow P1 * * * *
  3999   3974   **
  4000   3975   ** Move the cursor P1 to a null row.  Any OP_Column operations
  4001   3976   ** that occur while the cursor is on the null row will always
  4002   3977   ** write a NULL.
  4003   3978   */
  4004   3979   case OP_NullRow: {
  4005         -  int i;
  4006   3980     VdbeCursor *pC;
  4007   3981   
  4008         -  i = pOp->p1;
  4009         -  assert( i>=0 && i<p->nCursor );
  4010         -  pC = p->apCsr[i];
         3982  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
         3983  +  pC = p->apCsr[pOp->p1];
  4011   3984     assert( pC!=0 );
  4012   3985     pC->nullRow = 1;
  4013   3986     pC->rowidIsValid = 0;
  4014   3987     if( pC->pCursor ){
  4015   3988       sqlite3BtreeClearCursor(pC->pCursor);
  4016   3989     }
  4017   3990     break;
................................................................................
  4022   3995   ** The next use of the Rowid or Column or Next instruction for P1 
  4023   3996   ** will refer to the last entry in the database table or index.
  4024   3997   ** If the table or index is empty and P2>0, then jump immediately to P2.
  4025   3998   ** If P2 is 0 or if the table or index is not empty, fall through
  4026   3999   ** to the following instruction.
  4027   4000   */
  4028   4001   case OP_Last: {        /* jump */
  4029         -  int i;
  4030   4002     VdbeCursor *pC;
  4031   4003     BtCursor *pCrsr;
  4032   4004     int res;
  4033   4005   
  4034         -  i = pOp->p1;
  4035         -  assert( i>=0 && i<p->nCursor );
  4036         -  pC = p->apCsr[i];
         4006  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
         4007  +  pC = p->apCsr[pOp->p1];
  4037   4008     assert( pC!=0 );
  4038   4009     pCrsr = pC->pCursor;
  4039   4010     assert( pCrsr!=0 );
  4040   4011     rc = sqlite3BtreeLast(pCrsr, &res);
  4041   4012     pC->nullRow = (u8)res;
  4042   4013     pC->deferredMoveto = 0;
  4043   4014     pC->rowidIsValid = 0;
................................................................................
  4074   4045   ** The next use of the Rowid or Column or Next instruction for P1 
  4075   4046   ** will refer to the first entry in the database table or index.
  4076   4047   ** If the table or index is empty and P2>0, then jump immediately to P2.
  4077   4048   ** If P2 is 0 or if the table or index is not empty, fall through
  4078   4049   ** to the following instruction.
  4079   4050   */
  4080   4051   case OP_Rewind: {        /* jump */
  4081         -  int i;
  4082   4052     VdbeCursor *pC;
  4083   4053     BtCursor *pCrsr;
  4084   4054     int res;
  4085   4055   
  4086         -  i = pOp->p1;
  4087         -  assert( i>=0 && i<p->nCursor );
  4088         -  pC = p->apCsr[i];
         4056  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
         4057  +  pC = p->apCsr[pOp->p1];
  4089   4058     assert( pC!=0 );
  4090   4059     if( (pCrsr = pC->pCursor)!=0 ){
  4091   4060       rc = sqlite3BtreeFirst(pCrsr, &res);
  4092   4061       pC->atFirst = res==0 ?1:0;
  4093   4062       pC->deferredMoveto = 0;
  4094   4063       pC->cacheStatus = CACHE_STALE;
  4095   4064       pC->rowidIsValid = 0;
................................................................................
  4164   4133   ** P3 is a flag that provides a hint to the b-tree layer that this
  4165   4134   ** insert is likely to be an append.
  4166   4135   **
  4167   4136   ** This instruction only works for indices.  The equivalent instruction
  4168   4137   ** for tables is OP_Insert.
  4169   4138   */
  4170   4139   case OP_IdxInsert: {        /* in2 */
  4171         -  int i;
  4172   4140     VdbeCursor *pC;
  4173   4141     BtCursor *pCrsr;
  4174   4142     int nKey;
  4175   4143     const char *zKey;
  4176   4144   
  4177         -  i = pOp->p1;
  4178         -  assert( i>=0 && i<p->nCursor );
  4179         -  assert( p->apCsr[i]!=0 );
         4145  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
         4146  +  pC = p->apCsr[pOp->p1];
         4147  +  assert( pC!=0 );
  4180   4148     assert( pIn2->flags & MEM_Blob );
  4181         -  if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){
         4149  +  pCrsr = pC->pCursor;
         4150  +  if( pCrsr!=0 ){
  4182   4151       assert( pC->isTable==0 );
  4183   4152       rc = ExpandBlob(pIn2);
  4184   4153       if( rc==SQLITE_OK ){
  4185   4154         nKey = pIn2->n;
  4186   4155         zKey = pIn2->z;
  4187   4156         rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0, 0, pOp->p3, 
  4188   4157             ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
................................................................................
  4197   4166   /* Opcode: IdxDelete P1 P2 P3 * *
  4198   4167   **
  4199   4168   ** The content of P3 registers starting at register P2 form
  4200   4169   ** an unpacked index key. This opcode removes that entry from the 
  4201   4170   ** index opened by cursor P1.
  4202   4171   */
  4203   4172   case OP_IdxDelete: {
  4204         -  int i;
  4205   4173     VdbeCursor *pC;
  4206   4174     BtCursor *pCrsr;
  4207   4175   
  4208         -  i = pOp->p1;
  4209   4176     assert( pOp->p3>0 );
  4210   4177     assert( pOp->p2>0 && pOp->p2+pOp->p3<=p->nMem+1 );
  4211         -  assert( i>=0 && i<p->nCursor );
  4212         -  assert( p->apCsr[i]!=0 );
  4213         -  if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){
         4178  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
         4179  +  pC = p->apCsr[pOp->p1];
         4180  +  assert( pC!=0 );
         4181  +  pCrsr = pC->pCursor;
         4182  +  if( pCrsr!=0 ){
  4214   4183       int res;
  4215   4184       UnpackedRecord r;
  4216   4185       r.pKeyInfo = pC->pKeyInfo;
  4217   4186       r.nField = (u16)pOp->p3;
  4218   4187       r.flags = 0;
  4219   4188       r.aMem = &p->aMem[pOp->p2];
  4220   4189       rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
................................................................................
  4232   4201   ** Write into register P2 an integer which is the last entry in the record at
  4233   4202   ** the end of the index key pointed to by cursor P1.  This integer should be
  4234   4203   ** the rowid of the table entry to which this index entry points.
  4235   4204   **
  4236   4205   ** See also: Rowid, MakeRecord.
  4237   4206   */
  4238   4207   case OP_IdxRowid: {              /* out2-prerelease */
  4239         -  int i;
  4240   4208     BtCursor *pCrsr;
  4241   4209     VdbeCursor *pC;
  4242   4210     i64 rowid;
  4243   4211   
  4244         -  i = pOp->p1;
  4245         -  assert( i>=0 && i<p->nCursor );
  4246         -  assert( p->apCsr[i]!=0 );
  4247         -  if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){
         4212  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
         4213  +  pC = p->apCsr[pOp->p1];
         4214  +  assert( pC!=0 );
         4215  +  pCrsr = pC->pCursor;
         4216  +  if( pCrsr!=0 ){
  4248   4217       rc = sqlite3VdbeCursorMoveto(pC);
  4249   4218       if( rc ) goto abort_due_to_error;
  4250   4219       assert( pC->deferredMoveto==0 );
  4251   4220       assert( pC->isTable==0 );
  4252   4221       if( !pC->nullRow ){
  4253   4222         rc = sqlite3VdbeIdxRowid(pCrsr, &rowid);
  4254   4223         if( rc!=SQLITE_OK ){
................................................................................
  4285   4254   ** Otherwise fall through to the next instruction.
  4286   4255   **
  4287   4256   ** If P5 is non-zero then the key value is increased by an epsilon prior 
  4288   4257   ** to the comparison.  This makes the opcode work like IdxLE.
  4289   4258   */
  4290   4259   case OP_IdxLT:          /* jump, in3 */
  4291   4260   case OP_IdxGE: {        /* jump, in3 */
  4292         -  int i;
  4293   4261     VdbeCursor *pC;
  4294   4262     int res;
  4295   4263     UnpackedRecord r;
  4296   4264   
  4297         -  i = pOp->p1;
  4298         -  assert( i>=0 && i<p->nCursor );
  4299         -  assert( p->apCsr[i]!=0 );
  4300         -  if( (pC = p->apCsr[i])->pCursor!=0 ){
         4265  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
         4266  +  pC = p->apCsr[pOp->p1];
         4267  +  assert( pC!=0 );
         4268  +  if( pC->pCursor!=0 ){
  4301   4269       assert( pC->deferredMoveto==0 );
  4302   4270       assert( pOp->p5==0 || pOp->p5==1 );
  4303   4271       assert( pOp->p4type==P4_INT32 );
  4304   4272       r.pKeyInfo = pC->pKeyInfo;
  4305   4273       r.nField = (u16)pOp->p4.i;
  4306   4274       if( pOp->p5 ){
  4307   4275         r.flags = UNPACKED_INCRKEY | UNPACKED_IGNORE_ROWID;