/ Check-in [acc40ff6]
Login

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

Overview
Comment:Convert several ALWAYS() macros in vdbe.c into assert() statements.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: acc40ff6b47595432ebc1b3ec71ac50384bec323
User & Date: drh 2013-11-11 03:24:11
Context
2013-11-11
03:37
Fix issue with several memory allocation tests due to KeyInfo allocations now being shared. check-in: 569fedd6 user: mistachkin tags: trunk
03:24
Convert several ALWAYS() macros in vdbe.c into assert() statements. check-in: acc40ff6 user: drh tags: trunk
02:46
Fix several harmless compiler warnings. check-in: e6ff492f user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

  2305   2305         assert( (payloadSize64 & SQLITE_MAX_U32)==(u64)payloadSize64 );
  2306   2306         payloadSize = (u32)payloadSize64;
  2307   2307       }else{
  2308   2308         assert( sqlite3BtreeCursorIsValid(pCrsr) );
  2309   2309         VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &payloadSize);
  2310   2310         assert( rc==SQLITE_OK );   /* DataSize() cannot fail */
  2311   2311       }
  2312         -  }else if( ALWAYS(pC->pseudoTableReg>0) ){
         2312  +  }else{
         2313  +    assert( pC->pseudoTableReg>0 );
  2313   2314       pReg = &aMem[pC->pseudoTableReg];
  2314   2315       if( pC->multiPseudo ){
  2315   2316         sqlite3VdbeMemShallowCopy(pDest, pReg+p2, MEM_Ephem);
  2316   2317         Deephemeralize(pDest);
  2317   2318         goto op_column_out;
  2318   2319       }
  2319   2320       assert( pReg->flags & MEM_Blob );
  2320   2321       assert( memIsValid(pReg) );
  2321   2322       payloadSize = pReg->n;
  2322   2323       zRec = pReg->z;
  2323   2324       pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr;
  2324   2325       assert( payloadSize==0 || zRec!=0 );
  2325         -  }else{
  2326         -    /* Consider the row to be NULL */
  2327         -    payloadSize = 0;
  2328   2326     }
  2329   2327   
  2330   2328     /* If payloadSize is 0, then just store a NULL.  This can happen because of
  2331   2329     ** nullRow or because of a corrupt database. */
  2332   2330     if( payloadSize==0 ){
  2333   2331       MemSetTypeFlag(pDest, MEM_Null);
  2334   2332       goto op_column_out;
................................................................................
  2712   2710   */
  2713   2711   #ifndef SQLITE_OMIT_BTREECOUNT
  2714   2712   case OP_Count: {         /* out2-prerelease */
  2715   2713     i64 nEntry;
  2716   2714     BtCursor *pCrsr;
  2717   2715   
  2718   2716     pCrsr = p->apCsr[pOp->p1]->pCursor;
  2719         -  if( ALWAYS(pCrsr) ){
  2720         -    rc = sqlite3BtreeCount(pCrsr, &nEntry);
  2721         -  }else{
  2722         -    nEntry = 0;
  2723         -  }
         2717  +  assert( pCrsr );
         2718  +  rc = sqlite3BtreeCount(pCrsr, &nEntry);
  2724   2719     pOut->u.i = nEntry;
  2725   2720     break;
  2726   2721   }
  2727   2722   #endif
  2728   2723   
  2729   2724   /* Opcode: Savepoint P1 * * P4 *
  2730   2725   **
................................................................................
  3527   3522     pC = p->apCsr[pOp->p1];
  3528   3523     assert( pC!=0 );
  3529   3524     assert( pC->pseudoTableReg==0 );
  3530   3525     assert( OP_SeekLe == OP_SeekLt+1 );
  3531   3526     assert( OP_SeekGe == OP_SeekLt+2 );
  3532   3527     assert( OP_SeekGt == OP_SeekLt+3 );
  3533   3528     assert( pC->isOrdered );
  3534         -  if( ALWAYS(pC->pCursor!=0) ){
  3535         -    oc = pOp->opcode;
  3536         -    pC->nullRow = 0;
  3537         -    if( pC->isTable ){
  3538         -      /* The input value in P3 might be of any type: integer, real, string,
  3539         -      ** blob, or NULL.  But it needs to be an integer before we can do
  3540         -      ** the seek, so covert it. */
  3541         -      pIn3 = &aMem[pOp->p3];
  3542         -      applyNumericAffinity(pIn3);
  3543         -      iKey = sqlite3VdbeIntValue(pIn3);
  3544         -      pC->rowidIsValid = 0;
  3545         -
  3546         -      /* If the P3 value could not be converted into an integer without
  3547         -      ** loss of information, then special processing is required... */
  3548         -      if( (pIn3->flags & MEM_Int)==0 ){
  3549         -        if( (pIn3->flags & MEM_Real)==0 ){
  3550         -          /* If the P3 value cannot be converted into any kind of a number,
  3551         -          ** then the seek is not possible, so jump to P2 */
  3552         -          pc = pOp->p2 - 1;
  3553         -          break;
  3554         -        }
  3555         -        /* If we reach this point, then the P3 value must be a floating
  3556         -        ** point number. */
  3557         -        assert( (pIn3->flags & MEM_Real)!=0 );
  3558         -
  3559         -        if( iKey==SMALLEST_INT64 && (pIn3->r<(double)iKey || pIn3->r>0) ){
  3560         -          /* The P3 value is too large in magnitude to be expressed as an
  3561         -          ** integer. */
  3562         -          res = 1;
  3563         -          if( pIn3->r<0 ){
  3564         -            if( oc>=OP_SeekGe ){  assert( oc==OP_SeekGe || oc==OP_SeekGt );
  3565         -              rc = sqlite3BtreeFirst(pC->pCursor, &res);
  3566         -              if( rc!=SQLITE_OK ) goto abort_due_to_error;
  3567         -            }
  3568         -          }else{
  3569         -            if( oc<=OP_SeekLe ){  assert( oc==OP_SeekLt || oc==OP_SeekLe );
  3570         -              rc = sqlite3BtreeLast(pC->pCursor, &res);
  3571         -              if( rc!=SQLITE_OK ) goto abort_due_to_error;
  3572         -            }
         3529  +  assert( pC->pCursor!=0 );
         3530  +  oc = pOp->opcode;
         3531  +  pC->nullRow = 0;
         3532  +  if( pC->isTable ){
         3533  +    /* The input value in P3 might be of any type: integer, real, string,
         3534  +    ** blob, or NULL.  But it needs to be an integer before we can do
         3535  +    ** the seek, so covert it. */
         3536  +    pIn3 = &aMem[pOp->p3];
         3537  +    applyNumericAffinity(pIn3);
         3538  +    iKey = sqlite3VdbeIntValue(pIn3);
         3539  +    pC->rowidIsValid = 0;
         3540  +
         3541  +    /* If the P3 value could not be converted into an integer without
         3542  +    ** loss of information, then special processing is required... */
         3543  +    if( (pIn3->flags & MEM_Int)==0 ){
         3544  +      if( (pIn3->flags & MEM_Real)==0 ){
         3545  +        /* If the P3 value cannot be converted into any kind of a number,
         3546  +        ** then the seek is not possible, so jump to P2 */
         3547  +        pc = pOp->p2 - 1;
         3548  +        break;
         3549  +      }
         3550  +      /* If we reach this point, then the P3 value must be a floating
         3551  +      ** point number. */
         3552  +      assert( (pIn3->flags & MEM_Real)!=0 );
         3553  +
         3554  +      if( iKey==SMALLEST_INT64 && (pIn3->r<(double)iKey || pIn3->r>0) ){
         3555  +        /* The P3 value is too large in magnitude to be expressed as an
         3556  +        ** integer. */
         3557  +        res = 1;
         3558  +        if( pIn3->r<0 ){
         3559  +          if( oc>=OP_SeekGe ){  assert( oc==OP_SeekGe || oc==OP_SeekGt );
         3560  +            rc = sqlite3BtreeFirst(pC->pCursor, &res);
         3561  +            if( rc!=SQLITE_OK ) goto abort_due_to_error;
         3562  +          }
         3563  +        }else{
         3564  +          if( oc<=OP_SeekLe ){  assert( oc==OP_SeekLt || oc==OP_SeekLe );
         3565  +            rc = sqlite3BtreeLast(pC->pCursor, &res);
         3566  +            if( rc!=SQLITE_OK ) goto abort_due_to_error;
  3573   3567             }
  3574         -          if( res ){
  3575         -            pc = pOp->p2 - 1;
  3576         -          }
  3577         -          break;
  3578         -        }else if( oc==OP_SeekLt || oc==OP_SeekGe ){
  3579         -          /* Use the ceiling() function to convert real->int */
  3580         -          if( pIn3->r > (double)iKey ) iKey++;
  3581         -        }else{
  3582         -          /* Use the floor() function to convert real->int */
  3583         -          assert( oc==OP_SeekLe || oc==OP_SeekGt );
  3584         -          if( pIn3->r < (double)iKey ) iKey--;
         3568  +        }
         3569  +        if( res ){
         3570  +          pc = pOp->p2 - 1;
  3585   3571           }
  3586         -      } 
  3587         -      rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
  3588         -      if( rc!=SQLITE_OK ){
  3589         -        goto abort_due_to_error;
         3572  +        break;
         3573  +      }else if( oc==OP_SeekLt || oc==OP_SeekGe ){
         3574  +        /* Use the ceiling() function to convert real->int */
         3575  +        if( pIn3->r > (double)iKey ) iKey++;
         3576  +      }else{
         3577  +        /* Use the floor() function to convert real->int */
         3578  +        assert( oc==OP_SeekLe || oc==OP_SeekGt );
         3579  +        if( pIn3->r < (double)iKey ) iKey--;
  3590   3580         }
  3591         -      if( res==0 ){
  3592         -        pC->rowidIsValid = 1;
  3593         -        pC->lastRowid = iKey;
  3594         -      }
  3595         -    }else{
  3596         -      nField = pOp->p4.i;
  3597         -      assert( pOp->p4type==P4_INT32 );
  3598         -      assert( nField>0 );
  3599         -      r.pKeyInfo = pC->pKeyInfo;
  3600         -      r.nField = (u16)nField;
  3601         -
  3602         -      /* The next line of code computes as follows, only faster:
  3603         -      **   if( oc==OP_SeekGt || oc==OP_SeekLe ){
  3604         -      **     r.flags = UNPACKED_INCRKEY;
  3605         -      **   }else{
  3606         -      **     r.flags = 0;
  3607         -      **   }
  3608         -      */
  3609         -      r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLt)));
  3610         -      assert( oc!=OP_SeekGt || r.flags==UNPACKED_INCRKEY );
  3611         -      assert( oc!=OP_SeekLe || r.flags==UNPACKED_INCRKEY );
  3612         -      assert( oc!=OP_SeekGe || r.flags==0 );
  3613         -      assert( oc!=OP_SeekLt || r.flags==0 );
  3614         -
  3615         -      r.aMem = &aMem[pOp->p3];
         3581  +    } 
         3582  +    rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
         3583  +    if( rc!=SQLITE_OK ){
         3584  +      goto abort_due_to_error;
         3585  +    }
         3586  +    if( res==0 ){
         3587  +      pC->rowidIsValid = 1;
         3588  +      pC->lastRowid = iKey;
         3589  +    }
         3590  +  }else{
         3591  +    nField = pOp->p4.i;
         3592  +    assert( pOp->p4type==P4_INT32 );
         3593  +    assert( nField>0 );
         3594  +    r.pKeyInfo = pC->pKeyInfo;
         3595  +    r.nField = (u16)nField;
         3596  +
         3597  +    /* The next line of code computes as follows, only faster:
         3598  +    **   if( oc==OP_SeekGt || oc==OP_SeekLe ){
         3599  +    **     r.flags = UNPACKED_INCRKEY;
         3600  +    **   }else{
         3601  +    **     r.flags = 0;
         3602  +    **   }
         3603  +    */
         3604  +    r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLt)));
         3605  +    assert( oc!=OP_SeekGt || r.flags==UNPACKED_INCRKEY );
         3606  +    assert( oc!=OP_SeekLe || r.flags==UNPACKED_INCRKEY );
         3607  +    assert( oc!=OP_SeekGe || r.flags==0 );
         3608  +    assert( oc!=OP_SeekLt || r.flags==0 );
         3609  +
         3610  +    r.aMem = &aMem[pOp->p3];
  3616   3611   #ifdef SQLITE_DEBUG
  3617         -      { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
         3612  +    { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
  3618   3613   #endif
  3619         -      ExpandBlob(r.aMem);
  3620         -      rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res);
  3621         -      if( rc!=SQLITE_OK ){
  3622         -        goto abort_due_to_error;
  3623         -      }
  3624         -      pC->rowidIsValid = 0;
         3614  +    ExpandBlob(r.aMem);
         3615  +    rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res);
         3616  +    if( rc!=SQLITE_OK ){
         3617  +      goto abort_due_to_error;
  3625   3618       }
  3626         -    pC->deferredMoveto = 0;
  3627         -    pC->cacheStatus = CACHE_STALE;
         3619  +    pC->rowidIsValid = 0;
         3620  +  }
         3621  +  pC->deferredMoveto = 0;
         3622  +  pC->cacheStatus = CACHE_STALE;
  3628   3623   #ifdef SQLITE_TEST
  3629         -    sqlite3_search_count++;
         3624  +  sqlite3_search_count++;
  3630   3625   #endif
  3631         -    if( oc>=OP_SeekGe ){  assert( oc==OP_SeekGe || oc==OP_SeekGt );
  3632         -      if( res<0 || (res==0 && oc==OP_SeekGt) ){
  3633         -        rc = sqlite3BtreeNext(pC->pCursor, &res);
  3634         -        if( rc!=SQLITE_OK ) goto abort_due_to_error;
  3635         -        pC->rowidIsValid = 0;
  3636         -      }else{
  3637         -        res = 0;
  3638         -      }
         3626  +  if( oc>=OP_SeekGe ){  assert( oc==OP_SeekGe || oc==OP_SeekGt );
         3627  +    if( res<0 || (res==0 && oc==OP_SeekGt) ){
         3628  +      rc = sqlite3BtreeNext(pC->pCursor, &res);
         3629  +      if( rc!=SQLITE_OK ) goto abort_due_to_error;
         3630  +      pC->rowidIsValid = 0;
         3631  +    }else{
         3632  +      res = 0;
         3633  +    }
         3634  +  }else{
         3635  +    assert( oc==OP_SeekLt || oc==OP_SeekLe );
         3636  +    if( res>0 || (res==0 && oc==OP_SeekLt) ){
         3637  +      rc = sqlite3BtreePrevious(pC->pCursor, &res);
         3638  +      if( rc!=SQLITE_OK ) goto abort_due_to_error;
         3639  +      pC->rowidIsValid = 0;
  3639   3640       }else{
  3640         -      assert( oc==OP_SeekLt || oc==OP_SeekLe );
  3641         -      if( res>0 || (res==0 && oc==OP_SeekLt) ){
  3642         -        rc = sqlite3BtreePrevious(pC->pCursor, &res);
  3643         -        if( rc!=SQLITE_OK ) goto abort_due_to_error;
  3644         -        pC->rowidIsValid = 0;
  3645         -      }else{
  3646         -        /* res might be negative because the table is empty.  Check to
  3647         -        ** see if this is the case.
  3648         -        */
  3649         -        res = sqlite3BtreeEof(pC->pCursor);
  3650         -      }
         3641  +      /* res might be negative because the table is empty.  Check to
         3642  +      ** see if this is the case.
         3643  +      */
         3644  +      res = sqlite3BtreeEof(pC->pCursor);
  3651   3645       }
  3652         -    assert( pOp->p2>0 );
  3653         -    if( res ){
  3654         -      pc = pOp->p2 - 1;
  3655         -    }
  3656         -  }else{
  3657         -    /* This happens when attempting to open the sqlite3_master table
  3658         -    ** for read access returns SQLITE_EMPTY. In this case always
  3659         -    ** take the jump (since there are no records in the table).
  3660         -    */
         3646  +  }
         3647  +  assert( pOp->p2>0 );
         3648  +  if( res ){
  3661   3649       pc = pOp->p2 - 1;
  3662   3650     }
  3663   3651     break;
  3664   3652   }
  3665   3653   
  3666   3654   /* Opcode: Seek P1 P2 * * *
  3667   3655   ** Synopsis:  intkey=r[P2]
................................................................................
  3675   3663   */
  3676   3664   case OP_Seek: {    /* in2 */
  3677   3665     VdbeCursor *pC;
  3678   3666   
  3679   3667     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  3680   3668     pC = p->apCsr[pOp->p1];
  3681   3669     assert( pC!=0 );
  3682         -  if( ALWAYS(pC->pCursor!=0) ){
  3683         -    assert( pC->isTable );
  3684         -    pC->nullRow = 0;
  3685         -    pIn2 = &aMem[pOp->p2];
  3686         -    pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
  3687         -    pC->rowidIsValid = 0;
  3688         -    pC->deferredMoveto = 1;
  3689         -  }
         3670  +  assert( pC->pCursor!=0 );
         3671  +  assert( pC->isTable );
         3672  +  pC->nullRow = 0;
         3673  +  pIn2 = &aMem[pOp->p2];
         3674  +  pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
         3675  +  pC->rowidIsValid = 0;
         3676  +  pC->deferredMoveto = 1;
  3690   3677     break;
  3691   3678   }
  3692   3679     
  3693   3680   
  3694   3681   /* Opcode: Found P1 P2 P3 P4 *
  3695   3682   ** Synopsis: key=r[P3@P4]
  3696   3683   **
................................................................................
  3756   3743   
  3757   3744     alreadyExists = 0;
  3758   3745     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  3759   3746     assert( pOp->p4type==P4_INT32 );
  3760   3747     pC = p->apCsr[pOp->p1];
  3761   3748     assert( pC!=0 );
  3762   3749     pIn3 = &aMem[pOp->p3];
  3763         -  if( ALWAYS(pC->pCursor!=0) ){
  3764         -
  3765         -    assert( pC->isTable==0 );
  3766         -    if( pOp->p4.i>0 ){
  3767         -      r.pKeyInfo = pC->pKeyInfo;
  3768         -      r.nField = (u16)pOp->p4.i;
  3769         -      r.aMem = pIn3;
         3750  +  assert( pC->pCursor!=0 );
         3751  +  assert( pC->isTable==0 );
         3752  +  if( pOp->p4.i>0 ){
         3753  +    r.pKeyInfo = pC->pKeyInfo;
         3754  +    r.nField = (u16)pOp->p4.i;
         3755  +    r.aMem = pIn3;
  3770   3756   #ifdef SQLITE_DEBUG
  3771         -      {
  3772         -        int i;
  3773         -        for(i=0; i<r.nField; i++){
  3774         -          assert( memIsValid(&r.aMem[i]) );
  3775         -          if( i ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]);
  3776         -        }
         3757  +    {
         3758  +      int i;
         3759  +      for(i=0; i<r.nField; i++){
         3760  +        assert( memIsValid(&r.aMem[i]) );
         3761  +        if( i ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]);
  3777   3762         }
  3778         -#endif
  3779         -      r.flags = UNPACKED_PREFIX_MATCH;
  3780         -      pIdxKey = &r;
  3781         -    }else{
  3782         -      pIdxKey = sqlite3VdbeAllocUnpackedRecord(
  3783         -          pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
  3784         -      ); 
  3785         -      if( pIdxKey==0 ) goto no_mem;
  3786         -      assert( pIn3->flags & MEM_Blob );
  3787         -      assert( (pIn3->flags & MEM_Zero)==0 );  /* zeroblobs already expanded */
  3788         -      sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
  3789         -      pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
  3790         -    }
  3791         -    if( pOp->opcode==OP_NoConflict ){
  3792         -      /* For the OP_NoConflict opcode, take the jump if any of the
  3793         -      ** input fields are NULL, since any key with a NULL will not
  3794         -      ** conflict */
  3795         -      for(ii=0; ii<r.nField; ii++){
  3796         -        if( r.aMem[ii].flags & MEM_Null ){
  3797         -          pc = pOp->p2 - 1;
  3798         -          break;
  3799         -        }
         3763  +    }
         3764  +#endif
         3765  +    r.flags = UNPACKED_PREFIX_MATCH;
         3766  +    pIdxKey = &r;
         3767  +  }else{
         3768  +    pIdxKey = sqlite3VdbeAllocUnpackedRecord(
         3769  +        pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
         3770  +    ); 
         3771  +    if( pIdxKey==0 ) goto no_mem;
         3772  +    assert( pIn3->flags & MEM_Blob );
         3773  +    assert( (pIn3->flags & MEM_Zero)==0 );  /* zeroblobs already expanded */
         3774  +    sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
         3775  +    pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
         3776  +  }
         3777  +  if( pOp->opcode==OP_NoConflict ){
         3778  +    /* For the OP_NoConflict opcode, take the jump if any of the
         3779  +    ** input fields are NULL, since any key with a NULL will not
         3780  +    ** conflict */
         3781  +    for(ii=0; ii<r.nField; ii++){
         3782  +      if( r.aMem[ii].flags & MEM_Null ){
         3783  +        pc = pOp->p2 - 1;
         3784  +        break;
  3800   3785         }
  3801   3786       }
  3802         -    rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
  3803         -    if( pOp->p4.i==0 ){
  3804         -      sqlite3DbFree(db, pFree);
  3805         -    }
  3806         -    if( rc!=SQLITE_OK ){
  3807         -      break;
  3808         -    }
  3809         -    pC->seekResult = res;
  3810         -    alreadyExists = (res==0);
  3811         -    pC->nullRow = 1-alreadyExists;
  3812         -    pC->deferredMoveto = 0;
  3813         -    pC->cacheStatus = CACHE_STALE;
  3814   3787     }
         3788  +  rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
         3789  +  if( pOp->p4.i==0 ){
         3790  +    sqlite3DbFree(db, pFree);
         3791  +  }
         3792  +  if( rc!=SQLITE_OK ){
         3793  +    break;
         3794  +  }
         3795  +  pC->seekResult = res;
         3796  +  alreadyExists = (res==0);
         3797  +  pC->nullRow = 1-alreadyExists;
         3798  +  pC->deferredMoveto = 0;
         3799  +  pC->cacheStatus = CACHE_STALE;
  3815   3800     if( pOp->opcode==OP_Found ){
  3816   3801       if( alreadyExists ) pc = pOp->p2 - 1;
  3817   3802     }else{
  3818   3803       if( !alreadyExists ) pc = pOp->p2 - 1;
  3819   3804     }
  3820   3805     break;
  3821   3806   }
................................................................................
  3844   3829     assert( pIn3->flags & MEM_Int );
  3845   3830     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  3846   3831     pC = p->apCsr[pOp->p1];
  3847   3832     assert( pC!=0 );
  3848   3833     assert( pC->isTable );
  3849   3834     assert( pC->pseudoTableReg==0 );
  3850   3835     pCrsr = pC->pCursor;
  3851         -  if( ALWAYS(pCrsr!=0) ){
  3852         -    res = 0;
  3853         -    iKey = pIn3->u.i;
  3854         -    rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
  3855         -    pC->lastRowid = pIn3->u.i;
  3856         -    pC->rowidIsValid = res==0 ?1:0;
  3857         -    pC->nullRow = 0;
  3858         -    pC->cacheStatus = CACHE_STALE;
  3859         -    pC->deferredMoveto = 0;
  3860         -    if( res!=0 ){
  3861         -      pc = pOp->p2 - 1;
  3862         -      assert( pC->rowidIsValid==0 );
  3863         -    }
  3864         -    pC->seekResult = res;
  3865         -  }else{
  3866         -    /* This happens when an attempt to open a read cursor on the 
  3867         -    ** sqlite_master table returns SQLITE_EMPTY.
  3868         -    */
         3836  +  assert( pCrsr!=0 );
         3837  +  res = 0;
         3838  +  iKey = pIn3->u.i;
         3839  +  rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
         3840  +  pC->lastRowid = pIn3->u.i;
         3841  +  pC->rowidIsValid = res==0 ?1:0;
         3842  +  pC->nullRow = 0;
         3843  +  pC->cacheStatus = CACHE_STALE;
         3844  +  pC->deferredMoveto = 0;
         3845  +  if( res!=0 ){
  3869   3846       pc = pOp->p2 - 1;
  3870   3847       assert( pC->rowidIsValid==0 );
  3871         -    pC->seekResult = 0;
  3872   3848     }
         3849  +  pC->seekResult = res;
  3873   3850     break;
  3874   3851   }
  3875   3852   
  3876   3853   /* Opcode: Sequence P1 P2 * * *
  3877   3854   ** Synopsis: r[P2]=rowid
  3878   3855   **
  3879   3856   ** Find the next available sequence number for cursor P1.
................................................................................
  4445   4422     int res;
  4446   4423   
  4447   4424     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  4448   4425     pC = p->apCsr[pOp->p1];
  4449   4426     assert( pC!=0 );
  4450   4427     pCrsr = pC->pCursor;
  4451   4428     res = 0;
  4452         -  if( ALWAYS(pCrsr!=0) ){
  4453         -    rc = sqlite3BtreeLast(pCrsr, &res);
  4454         -  }
         4429  +  assert( pCrsr!=0 );
         4430  +  rc = sqlite3BtreeLast(pCrsr, &res);
  4455   4431     pC->nullRow = (u8)res;
  4456   4432     pC->deferredMoveto = 0;
  4457   4433     pC->rowidIsValid = 0;
  4458   4434     pC->cacheStatus = CACHE_STALE;
  4459   4435     if( pOp->p2>0 && res ){
  4460   4436       pc = pOp->p2 - 1;
  4461   4437     }
................................................................................
  4614   4590     pC = p->apCsr[pOp->p1];
  4615   4591     assert( pC!=0 );
  4616   4592     assert( pC->isSorter==(pOp->opcode==OP_SorterInsert) );
  4617   4593     pIn2 = &aMem[pOp->p2];
  4618   4594     assert( pIn2->flags & MEM_Blob );
  4619   4595     pCrsr = pC->pCursor;
  4620   4596     if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
  4621         -  if( ALWAYS(pCrsr!=0) ){
  4622         -    assert( pC->isTable==0 );
  4623         -    rc = ExpandBlob(pIn2);
  4624         -    if( rc==SQLITE_OK ){
  4625         -      if( isSorter(pC) ){
  4626         -        rc = sqlite3VdbeSorterWrite(db, pC, pIn2);
  4627         -      }else{
  4628         -        nKey = pIn2->n;
  4629         -        zKey = pIn2->z;
  4630         -        rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0, 0, pOp->p3, 
  4631         -            ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
  4632         -            );
  4633         -        assert( pC->deferredMoveto==0 );
  4634         -        pC->cacheStatus = CACHE_STALE;
  4635         -      }
         4597  +  assert( pCrsr!=0 );
         4598  +  assert( pC->isTable==0 );
         4599  +  rc = ExpandBlob(pIn2);
         4600  +  if( rc==SQLITE_OK ){
         4601  +    if( isSorter(pC) ){
         4602  +      rc = sqlite3VdbeSorterWrite(db, pC, pIn2);
         4603  +    }else{
         4604  +      nKey = pIn2->n;
         4605  +      zKey = pIn2->z;
         4606  +      rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0, 0, pOp->p3, 
         4607  +          ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
         4608  +          );
         4609  +      assert( pC->deferredMoveto==0 );
         4610  +      pC->cacheStatus = CACHE_STALE;
  4636   4611       }
  4637   4612     }
  4638   4613     break;
  4639   4614   }
  4640   4615   
  4641   4616   /* Opcode: IdxDelete P1 P2 P3 * P5
  4642   4617   ** Synopsis: key=r[P2@P3]
................................................................................
  4653   4628   
  4654   4629     assert( pOp->p3>0 );
  4655   4630     assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 );
  4656   4631     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  4657   4632     pC = p->apCsr[pOp->p1];
  4658   4633     assert( pC!=0 );
  4659   4634     pCrsr = pC->pCursor;
         4635  +  assert( pCrsr!=0 );
  4660   4636     if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
  4661         -  if( ALWAYS(pCrsr!=0) ){
  4662         -    r.pKeyInfo = pC->pKeyInfo;
  4663         -    r.nField = (u16)pOp->p3;
  4664         -    r.flags = UNPACKED_PREFIX_MATCH;
  4665         -    r.aMem = &aMem[pOp->p2];
         4637  +  r.pKeyInfo = pC->pKeyInfo;
         4638  +  r.nField = (u16)pOp->p3;
         4639  +  r.flags = UNPACKED_PREFIX_MATCH;
         4640  +  r.aMem = &aMem[pOp->p2];
  4666   4641   #ifdef SQLITE_DEBUG
  4667         -    { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
         4642  +  { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
  4668   4643   #endif
  4669         -    rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
  4670         -    if( rc==SQLITE_OK && res==0 ){
  4671         -      rc = sqlite3BtreeDelete(pCrsr);
  4672         -    }
  4673         -    assert( pC->deferredMoveto==0 );
  4674         -    pC->cacheStatus = CACHE_STALE;
         4644  +  rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
         4645  +  if( rc==SQLITE_OK && res==0 ){
         4646  +    rc = sqlite3BtreeDelete(pCrsr);
  4675   4647     }
         4648  +  assert( pC->deferredMoveto==0 );
         4649  +  pC->cacheStatus = CACHE_STALE;
  4676   4650     break;
  4677   4651   }
  4678   4652   
  4679   4653   /* Opcode: IdxRowid P1 P2 * * *
  4680   4654   ** Synopsis: r[P2]=rowid
  4681   4655   **
  4682   4656   ** Write into register P2 an integer which is the last entry in the record at
................................................................................
  4690   4664     VdbeCursor *pC;
  4691   4665     i64 rowid;
  4692   4666   
  4693   4667     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  4694   4668     pC = p->apCsr[pOp->p1];
  4695   4669     assert( pC!=0 );
  4696   4670     pCrsr = pC->pCursor;
         4671  +  assert( pCrsr!=0 );
  4697   4672     pOut->flags = MEM_Null;
  4698         -  if( ALWAYS(pCrsr!=0) ){
  4699         -    rc = sqlite3VdbeCursorMoveto(pC);
  4700         -    if( NEVER(rc) ) goto abort_due_to_error;
  4701         -    assert( pC->deferredMoveto==0 );
  4702         -    assert( pC->isTable==0 );
  4703         -    if( !pC->nullRow ){
  4704         -      rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
  4705         -      if( rc!=SQLITE_OK ){
  4706         -        goto abort_due_to_error;
  4707         -      }
  4708         -      pOut->u.i = rowid;
  4709         -      pOut->flags = MEM_Int;
         4673  +  rc = sqlite3VdbeCursorMoveto(pC);
         4674  +  if( NEVER(rc) ) goto abort_due_to_error;
         4675  +  assert( pC->deferredMoveto==0 );
         4676  +  assert( pC->isTable==0 );
         4677  +  if( !pC->nullRow ){
         4678  +    rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
         4679  +    if( rc!=SQLITE_OK ){
         4680  +      goto abort_due_to_error;
  4710   4681       }
         4682  +    pOut->u.i = rowid;
         4683  +    pOut->flags = MEM_Int;
  4711   4684     }
  4712   4685     break;
  4713   4686   }
  4714   4687   
  4715   4688   /* Opcode: IdxGE P1 P2 P3 P4 P5
  4716   4689   ** Synopsis: key=r[P3@P4]
  4717   4690   **
................................................................................
  4746   4719     int res;
  4747   4720     UnpackedRecord r;
  4748   4721   
  4749   4722     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  4750   4723     pC = p->apCsr[pOp->p1];
  4751   4724     assert( pC!=0 );
  4752   4725     assert( pC->isOrdered );
  4753         -  if( ALWAYS(pC->pCursor!=0) ){
  4754         -    assert( pC->deferredMoveto==0 );
  4755         -    assert( pOp->p5==0 || pOp->p5==1 );
  4756         -    assert( pOp->p4type==P4_INT32 );
  4757         -    r.pKeyInfo = pC->pKeyInfo;
  4758         -    r.nField = (u16)pOp->p4.i;
  4759         -    if( pOp->p5 ){
  4760         -      r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
  4761         -    }else{
  4762         -      r.flags = UNPACKED_PREFIX_MATCH;
  4763         -    }
  4764         -    r.aMem = &aMem[pOp->p3];
         4726  +  assert( pC->pCursor!=0);
         4727  +  assert( pC->deferredMoveto==0 );
         4728  +  assert( pOp->p5==0 || pOp->p5==1 );
         4729  +  assert( pOp->p4type==P4_INT32 );
         4730  +  r.pKeyInfo = pC->pKeyInfo;
         4731  +  r.nField = (u16)pOp->p4.i;
         4732  +  if( pOp->p5 ){
         4733  +    r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
         4734  +  }else{
         4735  +    r.flags = UNPACKED_PREFIX_MATCH;
         4736  +  }
         4737  +  r.aMem = &aMem[pOp->p3];
  4765   4738   #ifdef SQLITE_DEBUG
  4766         -    { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
         4739  +  { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
  4767   4740   #endif
  4768         -    rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
  4769         -    if( pOp->opcode==OP_IdxLT ){
  4770         -      res = -res;
  4771         -    }else{
  4772         -      assert( pOp->opcode==OP_IdxGE );
  4773         -      res++;
  4774         -    }
  4775         -    if( res>0 ){
  4776         -      pc = pOp->p2 - 1 ;
  4777         -    }
         4741  +  rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
         4742  +  if( pOp->opcode==OP_IdxLT ){
         4743  +    res = -res;
         4744  +  }else{
         4745  +    assert( pOp->opcode==OP_IdxGE );
         4746  +    res++;
         4747  +  }
         4748  +  if( res>0 ){
         4749  +    pc = pOp->p2 - 1 ;
  4778   4750     }
  4779   4751     break;
  4780   4752   }
  4781   4753   
  4782   4754   /* Opcode: Destroy P1 P2 P3 * *
  4783   4755   **
  4784   4756   ** Delete an entire database table or index whose root page in the database