/ Check-in [4a0929ac]
Login

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

Overview
Comment:A new implementation of sqlite3VdbeMakeLabel() is faster and makes fewer memory allocations by deferring memory allocation until sqlite3VdbeResolveLabel() is called, at which point the code generator has a better idea of how big the relocation table needs to be. The sqlite3VdbeMakeLabel() routine now takes a Parse* parameter instead of Vdbe*.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4a0929ac76d8aa5dd65eac3b83d6bbf41e505e01d175ca0fb2b19ba02d439415
User & Date: drh 2018-12-29 02:26:59
Context
2018-12-29
14:23
Additional small performance increase and size reduction to the sqlite3VdbeMakeLabel() mechanism. check-in: 1bdee199 user: drh tags: trunk
02:26
A new implementation of sqlite3VdbeMakeLabel() is faster and makes fewer memory allocations by deferring memory allocation until sqlite3VdbeResolveLabel() is called, at which point the code generator has a better idea of how big the relocation table needs to be. The sqlite3VdbeMakeLabel() routine now takes a Parse* parameter instead of Vdbe*. check-in: 4a0929ac user: drh tags: trunk
2018-12-28
20:48
Faster allocation of new sqlite3_stmt objects. check-in: 891f1f72 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/analyze.c.

  1152   1152       */
  1153   1153       addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
  1154   1154       VdbeCoverage(v);
  1155   1155       sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
  1156   1156       addrNextRow = sqlite3VdbeCurrentAddr(v);
  1157   1157   
  1158   1158       if( nColTest>0 ){
  1159         -      int endDistinctTest = sqlite3VdbeMakeLabel(v);
         1159  +      int endDistinctTest = sqlite3VdbeMakeLabel(pParse);
  1160   1160         int *aGotoChng;               /* Array of jump instruction addresses */
  1161   1161         aGotoChng = sqlite3DbMallocRawNN(db, sizeof(int)*nColTest);
  1162   1162         if( aGotoChng==0 ) continue;
  1163   1163   
  1164   1164         /*
  1165   1165         **  next_row:
  1166   1166         **   regChng = 0

Changes to src/delete.c.

   513    513           sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
   514    514         }
   515    515       }
   516    516     
   517    517       /* If this DELETE cannot use the ONEPASS strategy, this is the 
   518    518       ** end of the WHERE loop */
   519    519       if( eOnePass!=ONEPASS_OFF ){
   520         -      addrBypass = sqlite3VdbeMakeLabel(v);
          520  +      addrBypass = sqlite3VdbeMakeLabel(pParse);
   521    521       }else{
   522    522         sqlite3WhereEnd(pWInfo);
   523    523       }
   524    524     
   525    525       /* Unless this is a view, open cursors for the table we are 
   526    526       ** deleting from and all its indices. If this is a view, then the
   527    527       ** only effect this statement has is to fire the INSTEAD OF 
................................................................................
   702    702     assert( v );
   703    703     VdbeModuleComment((v, "BEGIN: GenRowDel(%d,%d,%d,%d)",
   704    704                            iDataCur, iIdxCur, iPk, (int)nPk));
   705    705   
   706    706     /* Seek cursor iCur to the row to delete. If this row no longer exists 
   707    707     ** (this can happen if a trigger program has already deleted it), do
   708    708     ** not attempt to delete it or fire any DELETE triggers.  */
   709         -  iLabel = sqlite3VdbeMakeLabel(v);
          709  +  iLabel = sqlite3VdbeMakeLabel(pParse);
   710    710     opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
   711    711     if( eMode==ONEPASS_OFF ){
   712    712       sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
   713    713       VdbeCoverageIf(v, opSeek==OP_NotExists);
   714    714       VdbeCoverageIf(v, opSeek==OP_NotFound);
   715    715     }
   716    716    
................................................................................
   908    908     Vdbe *v = pParse->pVdbe;
   909    909     int j;
   910    910     int regBase;
   911    911     int nCol;
   912    912   
   913    913     if( piPartIdxLabel ){
   914    914       if( pIdx->pPartIdxWhere ){
   915         -      *piPartIdxLabel = sqlite3VdbeMakeLabel(v);
          915  +      *piPartIdxLabel = sqlite3VdbeMakeLabel(pParse);
   916    916         pParse->iSelfTab = iDataCur + 1;
   917    917         sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel, 
   918    918                               SQLITE_JUMPIFNULL);
   919    919         pParse->iSelfTab = 0;
   920    920       }else{
   921    921         *piPartIdxLabel = 0;
   922    922       }

Changes to src/expr.c.

   549    549     Expr *pLeft = pExpr->pLeft;
   550    550     Expr *pRight = pExpr->pRight;
   551    551     int nLeft = sqlite3ExprVectorSize(pLeft);
   552    552     int i;
   553    553     int regLeft = 0;
   554    554     int regRight = 0;
   555    555     u8 opx = op;
   556         -  int addrDone = sqlite3VdbeMakeLabel(v);
          556  +  int addrDone = sqlite3VdbeMakeLabel(pParse);
   557    557   
   558    558     if( nLeft!=sqlite3ExprVectorSize(pRight) ){
   559    559       sqlite3ErrorMsg(pParse, "row value misused");
   560    560       return;
   561    561     }
   562    562     assert( pExpr->op==TK_EQ || pExpr->op==TK_NE 
   563    563          || pExpr->op==TK_IS || pExpr->op==TK_ISNOT 
................................................................................
  3029   3029     ** sequence of comparisons.
  3030   3030     **
  3031   3031     ** This is step (1) in the in-operator.md optimized algorithm.
  3032   3032     */
  3033   3033     if( eType==IN_INDEX_NOOP ){
  3034   3034       ExprList *pList = pExpr->x.pList;
  3035   3035       CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
  3036         -    int labelOk = sqlite3VdbeMakeLabel(v);
         3036  +    int labelOk = sqlite3VdbeMakeLabel(pParse);
  3037   3037       int r2, regToFree;
  3038   3038       int regCkNull = 0;
  3039   3039       int ii;
  3040   3040       assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
  3041   3041       if( destIfNull!=destIfFalse ){
  3042   3042         regCkNull = sqlite3GetTempReg(pParse);
  3043   3043         sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull);
................................................................................
  3073   3073     /* Step 2: Check to see if the LHS contains any NULL columns.  If the
  3074   3074     ** LHS does contain NULLs then the result must be either FALSE or NULL.
  3075   3075     ** We will then skip the binary search of the RHS.
  3076   3076     */
  3077   3077     if( destIfNull==destIfFalse ){
  3078   3078       destStep2 = destIfFalse;
  3079   3079     }else{
  3080         -    destStep2 = destStep6 = sqlite3VdbeMakeLabel(v);
         3080  +    destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
  3081   3081     }
  3082   3082     for(i=0; i<nVector; i++){
  3083   3083       Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
  3084   3084       if( sqlite3ExprCanBeNull(p) ){
  3085   3085         sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
  3086   3086         VdbeCoverage(v);
  3087   3087       }
................................................................................
  3131   3131     ** For a scalar LHS, it is sufficient to check just the first row
  3132   3132     ** of the RHS.
  3133   3133     */
  3134   3134     if( destStep6 ) sqlite3VdbeResolveLabel(v, destStep6);
  3135   3135     addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse);
  3136   3136     VdbeCoverage(v);
  3137   3137     if( nVector>1 ){
  3138         -    destNotNull = sqlite3VdbeMakeLabel(v);
         3138  +    destNotNull = sqlite3VdbeMakeLabel(pParse);
  3139   3139     }else{
  3140   3140       /* For nVector==1, combine steps 6 and 7 by immediately returning
  3141   3141       ** FALSE if the first comparison is not NULL */
  3142   3142       destNotNull = destIfFalse;
  3143   3143     }
  3144   3144     for(i=0; i<nVector; i++){
  3145   3145       Expr *p;
................................................................................
  3696   3696         }
  3697   3697   
  3698   3698         /* Attempt a direct implementation of the built-in COALESCE() and
  3699   3699         ** IFNULL() functions.  This avoids unnecessary evaluation of
  3700   3700         ** arguments past the first non-NULL argument.
  3701   3701         */
  3702   3702         if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
  3703         -        int endCoalesce = sqlite3VdbeMakeLabel(v);
         3703  +        int endCoalesce = sqlite3VdbeMakeLabel(pParse);
  3704   3704           assert( nFarg>=2 );
  3705   3705           sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
  3706   3706           for(i=1; i<nFarg; i++){
  3707   3707             sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
  3708   3708             VdbeCoverage(v);
  3709   3709             sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
  3710   3710           }
................................................................................
  3844   3844         ){
  3845   3845           sqlite3ErrorMsg(pParse, "%d columns assigned %d values",
  3846   3846                                   pExpr->iTable, n);
  3847   3847         }
  3848   3848         return pExpr->pLeft->iTable + pExpr->iColumn;
  3849   3849       }
  3850   3850       case TK_IN: {
  3851         -      int destIfFalse = sqlite3VdbeMakeLabel(v);
  3852         -      int destIfNull = sqlite3VdbeMakeLabel(v);
         3851  +      int destIfFalse = sqlite3VdbeMakeLabel(pParse);
         3852  +      int destIfNull = sqlite3VdbeMakeLabel(pParse);
  3853   3853         sqlite3VdbeAddOp2(v, OP_Null, 0, target);
  3854   3854         sqlite3ExprCodeIN(pParse, pExpr, destIfFalse, destIfNull);
  3855   3855         sqlite3VdbeAddOp2(v, OP_Integer, 1, target);
  3856   3856         sqlite3VdbeResolveLabel(v, destIfFalse);
  3857   3857         sqlite3VdbeAddOp2(v, OP_AddImm, target, 0);
  3858   3858         sqlite3VdbeResolveLabel(v, destIfNull);
  3859   3859         return target;
................................................................................
  3985   3985         Expr *pTest = 0;                  /* X==Ei (form A) or just Ei (form B) */
  3986   3986   
  3987   3987         assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
  3988   3988         assert(pExpr->x.pList->nExpr > 0);
  3989   3989         pEList = pExpr->x.pList;
  3990   3990         aListelem = pEList->a;
  3991   3991         nExpr = pEList->nExpr;
  3992         -      endLabel = sqlite3VdbeMakeLabel(v);
         3992  +      endLabel = sqlite3VdbeMakeLabel(pParse);
  3993   3993         if( (pX = pExpr->pLeft)!=0 ){
  3994   3994           tempX = *pX;
  3995   3995           testcase( pX->op==TK_COLUMN );
  3996   3996           exprToRegister(&tempX, exprCodeVector(pParse, &tempX, &regFree1));
  3997   3997           testcase( regFree1==0 );
  3998   3998           memset(&opCompare, 0, sizeof(opCompare));
  3999   3999           opCompare.op = TK_EQ;
................................................................................
  4008   4008         for(i=0; i<nExpr-1; i=i+2){
  4009   4009           if( pX ){
  4010   4010             assert( pTest!=0 );
  4011   4011             opCompare.pRight = aListelem[i].pExpr;
  4012   4012           }else{
  4013   4013             pTest = aListelem[i].pExpr;
  4014   4014           }
  4015         -        nextCase = sqlite3VdbeMakeLabel(v);
         4015  +        nextCase = sqlite3VdbeMakeLabel(pParse);
  4016   4016           testcase( pTest->op==TK_COLUMN );
  4017   4017           sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
  4018   4018           testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
  4019   4019           sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
  4020   4020           sqlite3VdbeGoto(v, endLabel);
  4021   4021           sqlite3VdbeResolveLabel(v, nextCase);
  4022   4022         }
................................................................................
  4377   4377   
  4378   4378     assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
  4379   4379     if( NEVER(v==0) )     return;  /* Existence of VDBE checked by caller */
  4380   4380     if( NEVER(pExpr==0) ) return;  /* No way this can happen */
  4381   4381     op = pExpr->op;
  4382   4382     switch( op ){
  4383   4383       case TK_AND: {
  4384         -      int d2 = sqlite3VdbeMakeLabel(v);
         4384  +      int d2 = sqlite3VdbeMakeLabel(pParse);
  4385   4385         testcase( jumpIfNull==0 );
  4386   4386         sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL);
  4387   4387         sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
  4388   4388         sqlite3VdbeResolveLabel(v, d2);
  4389   4389         break;
  4390   4390       }
  4391   4391       case TK_OR: {
................................................................................
  4463   4463       case TK_BETWEEN: {
  4464   4464         testcase( jumpIfNull==0 );
  4465   4465         exprCodeBetween(pParse, pExpr, dest, sqlite3ExprIfTrue, jumpIfNull);
  4466   4466         break;
  4467   4467       }
  4468   4468   #ifndef SQLITE_OMIT_SUBQUERY
  4469   4469       case TK_IN: {
  4470         -      int destIfFalse = sqlite3VdbeMakeLabel(v);
         4470  +      int destIfFalse = sqlite3VdbeMakeLabel(pParse);
  4471   4471         int destIfNull = jumpIfNull ? dest : destIfFalse;
  4472   4472         sqlite3ExprCodeIN(pParse, pExpr, destIfFalse, destIfNull);
  4473   4473         sqlite3VdbeGoto(v, dest);
  4474   4474         sqlite3VdbeResolveLabel(v, destIfFalse);
  4475   4475         break;
  4476   4476       }
  4477   4477   #endif
................................................................................
  4550   4550       case TK_AND: {
  4551   4551         testcase( jumpIfNull==0 );
  4552   4552         sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
  4553   4553         sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
  4554   4554         break;
  4555   4555       }
  4556   4556       case TK_OR: {
  4557         -      int d2 = sqlite3VdbeMakeLabel(v);
         4557  +      int d2 = sqlite3VdbeMakeLabel(pParse);
  4558   4558         testcase( jumpIfNull==0 );
  4559   4559         sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL);
  4560   4560         sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
  4561   4561         sqlite3VdbeResolveLabel(v, d2);
  4562   4562         break;
  4563   4563       }
  4564   4564       case TK_NOT: {
................................................................................
  4634   4634         break;
  4635   4635       }
  4636   4636   #ifndef SQLITE_OMIT_SUBQUERY
  4637   4637       case TK_IN: {
  4638   4638         if( jumpIfNull ){
  4639   4639           sqlite3ExprCodeIN(pParse, pExpr, dest, dest);
  4640   4640         }else{
  4641         -        int destIfNull = sqlite3VdbeMakeLabel(v);
         4641  +        int destIfNull = sqlite3VdbeMakeLabel(pParse);
  4642   4642           sqlite3ExprCodeIN(pParse, pExpr, dest, destIfNull);
  4643   4643           sqlite3VdbeResolveLabel(v, destIfNull);
  4644   4644         }
  4645   4645         break;
  4646   4646       }
  4647   4647   #endif
  4648   4648       default: {

Changes to src/fkey.c.

   325    325     int regData,          /* Address of array containing child table row */
   326    326     int nIncr,            /* Increment constraint counter by this */
   327    327     int isIgnore          /* If true, pretend pTab contains all NULL values */
   328    328   ){
   329    329     int i;                                    /* Iterator variable */
   330    330     Vdbe *v = sqlite3GetVdbe(pParse);         /* Vdbe to add code to */
   331    331     int iCur = pParse->nTab - 1;              /* Cursor number to use */
   332         -  int iOk = sqlite3VdbeMakeLabel(v);        /* jump here if parent key found */
          332  +  int iOk = sqlite3VdbeMakeLabel(pParse);   /* jump here if parent key found */
   333    333   
   334    334     sqlite3VdbeVerifyAbortable(v,
   335    335       (!pFKey->isDeferred
   336    336         && !(pParse->db->flags & SQLITE_DeferFKs)
   337    337         && !pParse->pToplevel 
   338    338         && !pParse->isMultiWrite) ? OE_Abort : OE_Ignore);
   339    339   
................................................................................
   725    725         ** the entire DELETE if there are no outstanding deferred constraints
   726    726         ** when this statement is run.  */
   727    727         FKey *p;
   728    728         for(p=pTab->pFKey; p; p=p->pNextFrom){
   729    729           if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
   730    730         }
   731    731         if( !p ) return;
   732         -      iSkip = sqlite3VdbeMakeLabel(v);
          732  +      iSkip = sqlite3VdbeMakeLabel(pParse);
   733    733         sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
   734    734       }
   735    735   
   736    736       pParse->disableTriggers = 1;
   737    737       sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0);
   738    738       pParse->disableTriggers = 0;
   739    739   

Changes to src/insert.c.

   862    862       */
   863    863       addrInsTop = addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
   864    864       VdbeCoverage(v);
   865    865     }
   866    866   
   867    867     /* Run the BEFORE and INSTEAD OF triggers, if there are any
   868    868     */
   869         -  endOfLoop = sqlite3VdbeMakeLabel(v);
          869  +  endOfLoop = sqlite3VdbeMakeLabel(pParse);
   870    870     if( tmask & TRIGGER_BEFORE ){
   871    871       int regCols = sqlite3GetTempRange(pParse, pTab->nCol+1);
   872    872   
   873    873       /* build the NEW.* reference row.  Note that if there is an INTEGER
   874    874       ** PRIMARY KEY into which a NULL is being inserted, that NULL will be
   875    875       ** translated into a unique ID for the row.  But on a BEFORE trigger,
   876    876       ** we do not know what the unique ID will be (because the insert has
................................................................................
  1352   1352       }
  1353   1353       assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail
  1354   1354           || onError==OE_Ignore || onError==OE_Replace );
  1355   1355       addr1 = 0;
  1356   1356       switch( onError ){
  1357   1357         case OE_Replace: {
  1358   1358           assert( onError==OE_Replace );
  1359         -        addr1 = sqlite3VdbeMakeLabel(v);
         1359  +        addr1 = sqlite3VdbeMakeLabel(pParse);
  1360   1360           sqlite3VdbeAddOp2(v, OP_NotNull, regNewData+1+i, addr1);
  1361   1361             VdbeCoverage(v);
  1362   1362           sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
  1363   1363           sqlite3VdbeAddOp2(v, OP_NotNull, regNewData+1+i, addr1);
  1364   1364             VdbeCoverage(v);
  1365   1365           onError = OE_Abort;
  1366   1366           /* Fall through into the OE_Abort case to generate code that runs
................................................................................
  1403   1403         if( aiChng
  1404   1404          && !sqlite3ExprReferencesUpdatedColumn(pExpr, aiChng, pkChng)
  1405   1405         ){
  1406   1406           /* The check constraints do not reference any of the columns being
  1407   1407           ** updated so there is no point it verifying the check constraint */
  1408   1408           continue;
  1409   1409         }
  1410         -      allOk = sqlite3VdbeMakeLabel(v);
         1410  +      allOk = sqlite3VdbeMakeLabel(pParse);
  1411   1411         sqlite3VdbeVerifyAbortable(v, onError);
  1412   1412         sqlite3ExprIfTrue(pParse, pExpr, allOk, SQLITE_JUMPIFNULL);
  1413   1413         if( onError==OE_Ignore ){
  1414   1414           sqlite3VdbeGoto(v, ignoreDest);
  1415   1415         }else{
  1416   1416           char *zName = pCheck->a[i].zName;
  1417   1417           if( zName==0 ) zName = pTab->zName;
................................................................................
  1470   1470       }
  1471   1471     }
  1472   1472   
  1473   1473     /* If rowid is changing, make sure the new rowid does not previously
  1474   1474     ** exist in the table.
  1475   1475     */
  1476   1476     if( pkChng && pPk==0 ){
  1477         -    int addrRowidOk = sqlite3VdbeMakeLabel(v);
         1477  +    int addrRowidOk = sqlite3VdbeMakeLabel(pParse);
  1478   1478   
  1479   1479       /* Figure out what action to take in case of a rowid collision */
  1480   1480       onError = pTab->keyConf;
  1481   1481       if( overrideError!=OE_Default ){
  1482   1482         onError = overrideError;
  1483   1483       }else if( onError==OE_Default ){
  1484   1484         onError = OE_Abort;
................................................................................
  1620   1620       if( aRegIdx[ix]==0 ) continue;  /* Skip indices that do not change */
  1621   1621       if( pUpIdx==pIdx ){
  1622   1622         addrUniqueOk = upsertJump+1;
  1623   1623         upsertBypass = sqlite3VdbeGoto(v, 0);
  1624   1624         VdbeComment((v, "Skip upsert subroutine"));
  1625   1625         sqlite3VdbeJumpHere(v, upsertJump);
  1626   1626       }else{
  1627         -      addrUniqueOk = sqlite3VdbeMakeLabel(v);
         1627  +      addrUniqueOk = sqlite3VdbeMakeLabel(pParse);
  1628   1628       }
  1629   1629       if( bAffinityDone==0 && (pUpIdx==0 || pUpIdx==pIdx) ){
  1630   1630         sqlite3TableAffinity(v, pTab, regNewData+1);
  1631   1631         bAffinityDone = 1;
  1632   1632       }
  1633   1633       VdbeNoopComment((v, "uniqueness check for %s", pIdx->zName));
  1634   1634       iThisCur = iIdxCur+ix;

Changes to src/pragma.c.

  1372   1372           pParent = sqlite3FindTable(db, pFK->zTo, zDb);
  1373   1373           pIdx = 0;
  1374   1374           aiCols = 0;
  1375   1375           if( pParent ){
  1376   1376             x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
  1377   1377             assert( x==0 );
  1378   1378           }
  1379         -        addrOk = sqlite3VdbeMakeLabel(v);
         1379  +        addrOk = sqlite3VdbeMakeLabel(pParse);
  1380   1380   
  1381   1381           /* Generate code to read the child key values into registers
  1382   1382           ** regRow..regRow+n. If any of the child key values are NULL, this 
  1383   1383           ** row cannot cause an FK violation. Jump directly to addrOk in 
  1384   1384           ** this case. */
  1385   1385           for(j=0; j<pFK->nCol; j++){
  1386   1386             int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom;
................................................................................
  1592   1592             integrityCheckResultRow(v);
  1593   1593             sqlite3VdbeJumpHere(v, jmp2);
  1594   1594           }
  1595   1595           /* Verify CHECK constraints */
  1596   1596           if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
  1597   1597             ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
  1598   1598             if( db->mallocFailed==0 ){
  1599         -            int addrCkFault = sqlite3VdbeMakeLabel(v);
  1600         -            int addrCkOk = sqlite3VdbeMakeLabel(v);
         1599  +            int addrCkFault = sqlite3VdbeMakeLabel(pParse);
         1600  +            int addrCkOk = sqlite3VdbeMakeLabel(pParse);
  1601   1601               char *zErr;
  1602   1602               int k;
  1603   1603               pParse->iSelfTab = iDataCur + 1;
  1604   1604               for(k=pCheck->nExpr-1; k>0; k--){
  1605   1605                 sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
  1606   1606               }
  1607   1607               sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk, 
................................................................................
  1616   1616             }
  1617   1617             sqlite3ExprListDelete(db, pCheck);
  1618   1618           }
  1619   1619           if( !isQuick ){ /* Omit the remaining tests for quick_check */
  1620   1620             /* Validate index entries for the current row */
  1621   1621             for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
  1622   1622               int jmp2, jmp3, jmp4, jmp5;
  1623         -            int ckUniq = sqlite3VdbeMakeLabel(v);
         1623  +            int ckUniq = sqlite3VdbeMakeLabel(pParse);
  1624   1624               if( pPk==pIdx ) continue;
  1625   1625               r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
  1626   1626                                            pPrior, r1);
  1627   1627               pPrior = pIdx;
  1628   1628               sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1);/* increment entry count */
  1629   1629               /* Verify that an index entry exists for the current table row */
  1630   1630               jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
................................................................................
  1637   1637               sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
  1638   1638               jmp4 = integrityCheckResultRow(v);
  1639   1639               sqlite3VdbeJumpHere(v, jmp2);
  1640   1640               /* For UNIQUE indexes, verify that only one entry exists with the
  1641   1641               ** current key.  The entry is unique if (1) any column is NULL
  1642   1642               ** or (2) the next entry has a different key */
  1643   1643               if( IsUniqueIndex(pIdx) ){
  1644         -              int uniqOk = sqlite3VdbeMakeLabel(v);
         1644  +              int uniqOk = sqlite3VdbeMakeLabel(pParse);
  1645   1645                 int jmp6;
  1646   1646                 int kk;
  1647   1647                 for(kk=0; kk<pIdx->nKeyCol; kk++){
  1648   1648                   int iCol = pIdx->aiColumn[kk];
  1649   1649                   assert( iCol!=XN_ROWID && iCol<pTab->nCol );
  1650   1650                   if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
  1651   1651                   sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);

Changes to src/select.c.

   627    627       regBase = regData - nPrefixReg;
   628    628     }else{
   629    629       regBase = pParse->nMem + 1;
   630    630       pParse->nMem += nBase;
   631    631     }
   632    632     assert( pSelect->iOffset==0 || pSelect->iLimit!=0 );
   633    633     iLimit = pSelect->iOffset ? pSelect->iOffset+1 : pSelect->iLimit;
   634         -  pSort->labelDone = sqlite3VdbeMakeLabel(v);
          634  +  pSort->labelDone = sqlite3VdbeMakeLabel(pParse);
   635    635     sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, regOrigData,
   636    636                             SQLITE_ECEL_DUP | (regOrigData? SQLITE_ECEL_REF : 0));
   637    637     if( bSeq ){
   638    638       sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
   639    639     }
   640    640     if( nPrefixReg==0 && nData>0 ){
   641    641       sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
................................................................................
   666    666       memset(pKI->aSortOrder, 0, pKI->nKeyField); /* Makes OP_Jump testable */
   667    667       sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
   668    668       testcase( pKI->nAllField > pKI->nKeyField+2 );
   669    669       pOp->p4.pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pSort->pOrderBy,nOBSat,
   670    670                                              pKI->nAllField-pKI->nKeyField-1);
   671    671       addrJmp = sqlite3VdbeCurrentAddr(v);
   672    672       sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
   673         -    pSort->labelBkOut = sqlite3VdbeMakeLabel(v);
          673  +    pSort->labelBkOut = sqlite3VdbeMakeLabel(pParse);
   674    674       pSort->regReturn = ++pParse->nMem;
   675    675       sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
   676    676       sqlite3VdbeAddOp1(v, OP_ResetSorter, pSort->iECursor);
   677    677       if( iLimit ){
   678    678         sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, pSort->labelDone);
   679    679         VdbeCoverage(v);
   680    680       }
................................................................................
  1413   1413     Select *p,        /* The SELECT statement */
  1414   1414     SortCtx *pSort,   /* Information on the ORDER BY clause */
  1415   1415     int nColumn,      /* Number of columns of data */
  1416   1416     SelectDest *pDest /* Write the sorted results here */
  1417   1417   ){
  1418   1418     Vdbe *v = pParse->pVdbe;                     /* The prepared statement */
  1419   1419     int addrBreak = pSort->labelDone;            /* Jump here to exit loop */
  1420         -  int addrContinue = sqlite3VdbeMakeLabel(v);  /* Jump here for next cycle */
         1420  +  int addrContinue = sqlite3VdbeMakeLabel(pParse);/* Jump here for next cycle */
  1421   1421     int addr;                       /* Top of output loop. Jump for Next. */
  1422   1422     int addrOnce = 0;
  1423   1423     int iTab;
  1424   1424     ExprList *pOrderBy = pSort->pOrderBy;
  1425   1425     int eDest = pDest->eDest;
  1426   1426     int iParm = pDest->iSDParm;
  1427   1427     int regRow;
................................................................................
  2325   2325     }
  2326   2326   #endif
  2327   2327   
  2328   2328     /* Obtain authorization to do a recursive query */
  2329   2329     if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return;
  2330   2330   
  2331   2331     /* Process the LIMIT and OFFSET clauses, if they exist */
  2332         -  addrBreak = sqlite3VdbeMakeLabel(v);
         2332  +  addrBreak = sqlite3VdbeMakeLabel(pParse);
  2333   2333     p->nSelectRow = 320;  /* 4 billion rows */
  2334   2334     computeLimitRegisters(pParse, p, addrBreak);
  2335   2335     pLimit = p->pLimit;
  2336   2336     regLimit = p->iLimit;
  2337   2337     regOffset = p->iOffset;
  2338   2338     p->pLimit = 0;
  2339   2339     p->iLimit = p->iOffset = 0;
................................................................................
  2395   2395       sqlite3VdbeAddOp3(v, OP_Column, iQueue, pOrderBy->nExpr+1, regCurrent);
  2396   2396     }else{
  2397   2397       sqlite3VdbeAddOp2(v, OP_RowData, iQueue, regCurrent);
  2398   2398     }
  2399   2399     sqlite3VdbeAddOp1(v, OP_Delete, iQueue);
  2400   2400   
  2401   2401     /* Output the single row in Current */
  2402         -  addrCont = sqlite3VdbeMakeLabel(v);
         2402  +  addrCont = sqlite3VdbeMakeLabel(pParse);
  2403   2403     codeOffset(v, regOffset, addrCont);
  2404   2404     selectInnerLoop(pParse, p, iCurrent,
  2405   2405         0, 0, pDest, addrCont, addrBreak);
  2406   2406     if( regLimit ){
  2407   2407       sqlite3VdbeAddOp2(v, OP_DecrJumpZero, regLimit, addrBreak);
  2408   2408       VdbeCoverage(v);
  2409   2409     }
................................................................................
  2703   2703           /* Convert the data in the temporary table into whatever form
  2704   2704           ** it is that we currently need.
  2705   2705           */
  2706   2706           assert( unionTab==dest.iSDParm || dest.eDest!=priorOp );
  2707   2707           if( dest.eDest!=priorOp ){
  2708   2708             int iCont, iBreak, iStart;
  2709   2709             assert( p->pEList );
  2710         -          iBreak = sqlite3VdbeMakeLabel(v);
  2711         -          iCont = sqlite3VdbeMakeLabel(v);
         2710  +          iBreak = sqlite3VdbeMakeLabel(pParse);
         2711  +          iCont = sqlite3VdbeMakeLabel(pParse);
  2712   2712             computeLimitRegisters(pParse, p, iBreak);
  2713   2713             sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
  2714   2714             iStart = sqlite3VdbeCurrentAddr(v);
  2715   2715             selectInnerLoop(pParse, p, unionTab,
  2716   2716                             0, 0, &dest, iCont, iBreak);
  2717   2717             sqlite3VdbeResolveLabel(v, iCont);
  2718   2718             sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); VdbeCoverage(v);
................................................................................
  2772   2772           sqlite3ExprDelete(db, p->pLimit);
  2773   2773           p->pLimit = pLimit;
  2774   2774     
  2775   2775           /* Generate code to take the intersection of the two temporary
  2776   2776           ** tables.
  2777   2777           */
  2778   2778           assert( p->pEList );
  2779         -        iBreak = sqlite3VdbeMakeLabel(v);
  2780         -        iCont = sqlite3VdbeMakeLabel(v);
         2779  +        iBreak = sqlite3VdbeMakeLabel(pParse);
         2780  +        iCont = sqlite3VdbeMakeLabel(pParse);
  2781   2781           computeLimitRegisters(pParse, p, iBreak);
  2782   2782           sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
  2783   2783           r1 = sqlite3GetTempReg(pParse);
  2784   2784           iStart = sqlite3VdbeAddOp2(v, OP_RowData, tab1, r1);
  2785   2785           sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
  2786   2786           VdbeCoverage(v);
  2787   2787           sqlite3ReleaseTempReg(pParse, r1);
................................................................................
  2903   2903     int iBreak              /* Jump here if we hit the LIMIT */
  2904   2904   ){
  2905   2905     Vdbe *v = pParse->pVdbe;
  2906   2906     int iContinue;
  2907   2907     int addr;
  2908   2908   
  2909   2909     addr = sqlite3VdbeCurrentAddr(v);
  2910         -  iContinue = sqlite3VdbeMakeLabel(v);
         2910  +  iContinue = sqlite3VdbeMakeLabel(pParse);
  2911   2911   
  2912   2912     /* Suppress duplicates for UNION, EXCEPT, and INTERSECT 
  2913   2913     */
  2914   2914     if( regPrev ){
  2915   2915       int addr1, addr2;
  2916   2916       addr1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev); VdbeCoverage(v);
  2917   2917       addr2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
................................................................................
  3140   3140     int *aPermute;        /* Mapping from ORDER BY terms to result set columns */
  3141   3141   
  3142   3142     assert( p->pOrderBy!=0 );
  3143   3143     assert( pKeyDup==0 ); /* "Managed" code needs this.  Ticket #3382. */
  3144   3144     db = pParse->db;
  3145   3145     v = pParse->pVdbe;
  3146   3146     assert( v!=0 );       /* Already thrown the error if VDBE alloc failed */
  3147         -  labelEnd = sqlite3VdbeMakeLabel(v);
  3148         -  labelCmpr = sqlite3VdbeMakeLabel(v);
         3147  +  labelEnd = sqlite3VdbeMakeLabel(pParse);
         3148  +  labelCmpr = sqlite3VdbeMakeLabel(pParse);
  3149   3149   
  3150   3150   
  3151   3151     /* Patch up the ORDER BY clause
  3152   3152     */
  3153   3153     op = p->op;  
  3154   3154     pPrior = p->pPrior;
  3155   3155     assert( pPrior->pOrderBy==0 );
................................................................................
  5326   5326         regAgg = sqlite3GetTempRange(pParse, nArg);
  5327   5327         sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
  5328   5328       }else{
  5329   5329         nArg = 0;
  5330   5330         regAgg = 0;
  5331   5331       }
  5332   5332       if( pF->iDistinct>=0 ){
  5333         -      addrNext = sqlite3VdbeMakeLabel(v);
         5333  +      addrNext = sqlite3VdbeMakeLabel(pParse);
  5334   5334         testcase( nArg==0 );  /* Error condition */
  5335   5335         testcase( nArg>1 );   /* Also an error */
  5336   5336         codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
  5337   5337       }
  5338   5338       if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
  5339   5339         CollSeq *pColl = 0;
  5340   5340         struct ExprList_item *pItem;
................................................................................
  6034   6034     */
  6035   6035     if( pDest->eDest==SRT_EphemTab ){
  6036   6036       sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
  6037   6037     }
  6038   6038   
  6039   6039     /* Set the limiter.
  6040   6040     */
  6041         -  iEnd = sqlite3VdbeMakeLabel(v);
         6041  +  iEnd = sqlite3VdbeMakeLabel(pParse);
  6042   6042     if( (p->selFlags & SF_FixedLimit)==0 ){
  6043   6043       p->nSelectRow = 320;  /* 4 billion rows */
  6044   6044     }
  6045   6045     computeLimitRegisters(pParse, p, iEnd);
  6046   6046     if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
  6047   6047       sqlite3VdbeChangeOpcode(v, sSort.addrSortIndex, OP_SorterOpen);
  6048   6048       sSort.sortFlags |= SORTFLAG_UseSorter;
................................................................................
  6101   6101       if( sSort.addrSortIndex>=0 && sSort.pOrderBy==0 ){
  6102   6102         sqlite3VdbeChangeToNoop(v, sSort.addrSortIndex);
  6103   6103       }
  6104   6104   
  6105   6105       assert( p->pEList==pEList );
  6106   6106   #ifndef SQLITE_OMIT_WINDOWFUNC
  6107   6107       if( pWin ){
  6108         -      int addrGosub = sqlite3VdbeMakeLabel(v);
  6109         -      int iCont = sqlite3VdbeMakeLabel(v);
  6110         -      int iBreak = sqlite3VdbeMakeLabel(v);
         6108  +      int addrGosub = sqlite3VdbeMakeLabel(pParse);
         6109  +      int iCont = sqlite3VdbeMakeLabel(pParse);
         6110  +      int iBreak = sqlite3VdbeMakeLabel(pParse);
  6111   6111         int regGosub = ++pParse->nMem;
  6112   6112   
  6113   6113         sqlite3WindowCodeStep(pParse, p, pWInfo, regGosub, addrGosub);
  6114   6114   
  6115   6115         sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
  6116   6116         sqlite3VdbeResolveLabel(v, addrGosub);
  6117   6117         VdbeNoopComment((v, "inner-loop subroutine"));
................................................................................
  6178   6178       ** ORDER BY and GROUP BY clauses are the same by setting the orderByGrp
  6179   6179       ** variable.  */
  6180   6180       if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
  6181   6181         orderByGrp = 1;
  6182   6182       }
  6183   6183    
  6184   6184       /* Create a label to jump to when we want to abort the query */
  6185         -    addrEnd = sqlite3VdbeMakeLabel(v);
         6185  +    addrEnd = sqlite3VdbeMakeLabel(pParse);
  6186   6186   
  6187   6187       /* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in
  6188   6188       ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
  6189   6189       ** SELECT statement.
  6190   6190       */
  6191   6191       memset(&sNC, 0, sizeof(sNC));
  6192   6192       sNC.pParse = pParse;
................................................................................
  6267   6267             0, (char*)pKeyInfo, P4_KEYINFO);
  6268   6268   
  6269   6269         /* Initialize memory locations used by GROUP BY aggregate processing
  6270   6270         */
  6271   6271         iUseFlag = ++pParse->nMem;
  6272   6272         iAbortFlag = ++pParse->nMem;
  6273   6273         regOutputRow = ++pParse->nMem;
  6274         -      addrOutputRow = sqlite3VdbeMakeLabel(v);
         6274  +      addrOutputRow = sqlite3VdbeMakeLabel(pParse);
  6275   6275         regReset = ++pParse->nMem;
  6276         -      addrReset = sqlite3VdbeMakeLabel(v);
         6276  +      addrReset = sqlite3VdbeMakeLabel(pParse);
  6277   6277         iAMem = pParse->nMem + 1;
  6278   6278         pParse->nMem += pGroupBy->nExpr;
  6279   6279         iBMem = pParse->nMem + 1;
  6280   6280         pParse->nMem += pGroupBy->nExpr;
  6281   6281         sqlite3VdbeAddOp2(v, OP_Integer, 0, iAbortFlag);
  6282   6282         VdbeComment((v, "clear abort flag"));
  6283   6283         sqlite3VdbeAddOp3(v, OP_Null, 0, iAMem, iAMem+pGroupBy->nExpr-1);

Changes to src/sqliteInt.h.

  3065   3065     int nErr;            /* Number of errors seen */
  3066   3066     int nTab;            /* Number of previously allocated VDBE cursors */
  3067   3067     int nMem;            /* Number of memory cells used so far */
  3068   3068     int szOpAlloc;       /* Bytes of memory space allocated for Vdbe.aOp[] */
  3069   3069     int iSelfTab;        /* Table associated with an index on expr, or negative
  3070   3070                          ** of the base register during check-constraint eval */
  3071   3071     int nLabel;          /* Number of labels used */
         3072  +  int nLabelAlloc;     /* Number of slots in aLabel */
  3072   3073     int *aLabel;         /* Space to hold the labels */
  3073   3074     ExprList *pConstExpr;/* Constant expressions */
  3074   3075     Token constraintName;/* Name of the constraint currently being parsed */
  3075   3076     yDbMask writeMask;   /* Start a write transaction on these databases */
  3076   3077     yDbMask cookieMask;  /* Bitmask of schema verified databases */
  3077   3078     int regRowid;        /* Register holding rowid of CREATE TABLE entry */
  3078   3079     int regRoot;         /* Register holding root page number for new objects */

Changes to src/trigger.c.

   940    940       ** (or NULL) the sub-vdbe is immediately halted by jumping to the 
   941    941       ** OP_Halt inserted at the end of the program.  */
   942    942       if( pTrigger->pWhen ){
   943    943         pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
   944    944         if( SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen) 
   945    945          && db->mallocFailed==0 
   946    946         ){
   947         -        iEndTrigger = sqlite3VdbeMakeLabel(v);
          947  +        iEndTrigger = sqlite3VdbeMakeLabel(pSubParse);
   948    948           sqlite3ExprIfFalse(pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
   949    949         }
   950    950         sqlite3ExprDelete(db, pWhen);
   951    951       }
   952    952   
   953    953       /* Code the trigger program into the sub-vdbe. */
   954    954       codeTriggerProgram(pSubParse, pTrigger->step_list, orconf);

Changes to src/update.c.

   437    437       updateVirtualTable(pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef,
   438    438                          pWhere, onError);
   439    439       goto update_cleanup;
   440    440     }
   441    441   #endif
   442    442   
   443    443     /* Jump to labelBreak to abandon further processing of this UPDATE */
   444         -  labelContinue = labelBreak = sqlite3VdbeMakeLabel(v);
          444  +  labelContinue = labelBreak = sqlite3VdbeMakeLabel(pParse);
   445    445   
   446    446     /* Not an UPSERT.  Normal processing.  Begin by
   447    447     ** initialize the count of updated rows */
   448    448     if( (db->flags&SQLITE_CountRows)!=0
   449    449      && !pParse->pTriggerTab
   450    450      && !pParse->nested
   451    451      && pUpsert==0
................................................................................
   572    572       if( eOnePass!=ONEPASS_OFF ){
   573    573         if( !isView && aiCurOnePass[0]!=iDataCur && aiCurOnePass[1]!=iDataCur ){
   574    574           assert( pPk );
   575    575           sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey,nKey);
   576    576           VdbeCoverage(v);
   577    577         }
   578    578         if( eOnePass!=ONEPASS_SINGLE ){
   579         -        labelContinue = sqlite3VdbeMakeLabel(v);
          579  +        labelContinue = sqlite3VdbeMakeLabel(pParse);
   580    580         }
   581    581         sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
   582    582         VdbeCoverageIf(v, pPk==0);
   583    583         VdbeCoverageIf(v, pPk!=0);
   584    584       }else if( pPk ){
   585         -      labelContinue = sqlite3VdbeMakeLabel(v);
          585  +      labelContinue = sqlite3VdbeMakeLabel(pParse);
   586    586         sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v);
   587    587         addrTop = sqlite3VdbeAddOp2(v, OP_RowData, iEph, regKey);
   588    588         sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0);
   589    589         VdbeCoverage(v);
   590    590       }else{
   591    591         labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet,labelBreak,
   592    592                                  regOldRowid);

Changes to src/vdbe.h.

   226    226   int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
   227    227   int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
   228    228   void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
   229    229   void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
   230    230   void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
   231    231   void sqlite3VdbeUsesBtree(Vdbe*, int);
   232    232   VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
   233         -int sqlite3VdbeMakeLabel(Vdbe*);
          233  +int sqlite3VdbeMakeLabel(Parse*);
   234    234   void sqlite3VdbeRunOnlyOnce(Vdbe*);
   235    235   void sqlite3VdbeReusable(Vdbe*);
   236    236   void sqlite3VdbeDelete(Vdbe*);
   237    237   void sqlite3VdbeClearObject(sqlite3*,Vdbe*);
   238    238   void sqlite3VdbeMakeReady(Vdbe*,Parse*);
   239    239   int sqlite3VdbeFinalize(Vdbe*);
   240    240   void sqlite3VdbeResolveLabel(Vdbe*, int);

Changes to src/vdbeaux.c.

   444    444   **
   445    445   ** The VDBE knows that a P2 value is a label because labels are
   446    446   ** always negative and P2 values are suppose to be non-negative.
   447    447   ** Hence, a negative P2 value is a label that has yet to be resolved.
   448    448   **
   449    449   ** Zero is returned if a malloc() fails.
   450    450   */
   451         -int sqlite3VdbeMakeLabel(Vdbe *v){
   452         -  Parse *p = v->pParse;
   453         -  int i = p->nLabel++;
   454         -  assert( v->magic==VDBE_MAGIC_INIT );
   455         -  if( (i & (i-1))==0 ){
   456         -    p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel, 
   457         -                                       (i*2+1)*sizeof(p->aLabel[0]));
   458         -  }
   459         -  if( p->aLabel ){
   460         -    p->aLabel[i] = -1;
   461         -  }
   462         -  return ADDR(i);
          451  +int sqlite3VdbeMakeLabel(Parse *pParse){
          452  +  return ADDR(pParse->nLabel++);
   463    453   }
   464    454   
   465    455   /*
   466    456   ** Resolve label "x" to be the address of the next instruction to
   467    457   ** be inserted.  The parameter "x" must have been obtained from
   468    458   ** a prior call to sqlite3VdbeMakeLabel().
   469    459   */
          460  +static SQLITE_NOINLINE void resizeResolveLabel(Parse *p, Vdbe *v, int j){
          461  +  int nNewSize = p->nLabel+10;
          462  +  p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
          463  +                     nNewSize*sizeof(p->aLabel[0]));
          464  +  if( p->aLabel==0 ){
          465  +    p->nLabelAlloc = 0;
          466  +  }else{
          467  +#ifdef SQLITE_DEBUG
          468  +    int i;
          469  +    for(i=p->nLabelAlloc; i<nNewSize; i++) p->aLabel[i] = -1;
          470  +#endif
          471  +    p->nLabelAlloc = nNewSize;
          472  +    p->aLabel[j] = v->nOp;
          473  +  }
          474  +}
   470    475   void sqlite3VdbeResolveLabel(Vdbe *v, int x){
   471    476     Parse *p = v->pParse;
   472    477     int j = ADDR(x);
   473    478     assert( v->magic==VDBE_MAGIC_INIT );
   474    479     assert( j<p->nLabel );
   475    480     assert( j>=0 );
   476         -  if( p->aLabel ){
   477    481   #ifdef SQLITE_DEBUG
   478         -    if( p->db->flags & SQLITE_VdbeAddopTrace ){
   479         -      printf("RESOLVE LABEL %d to %d\n", x, v->nOp);
   480         -    }
          482  +  if( p->db->flags & SQLITE_VdbeAddopTrace ){
          483  +    printf("RESOLVE LABEL %d to %d\n", x, v->nOp);
          484  +  }
   481    485   #endif
          486  +  if( p->nLabelAlloc < p->nLabel ){
          487  +    resizeResolveLabel(p,v,j);
          488  +  }else{
   482    489       assert( p->aLabel[j]==(-1) ); /* Labels may only be resolved once */
   483    490       p->aLabel[j] = v->nOp;
   484    491     }
   485    492   }
   486    493   
   487    494   /*
   488    495   ** Mark the VDBE as one that can only be run one time.

Changes to src/where.c.

   833    833       addrTop =  sqlite3VdbeAddOp1(v, OP_Yield, regYield);
   834    834       VdbeCoverage(v);
   835    835       VdbeComment((v, "next row of %s", pTabItem->pTab->zName));
   836    836     }else{
   837    837       addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
   838    838     }
   839    839     if( pPartial ){
   840         -    iContinue = sqlite3VdbeMakeLabel(v);
          840  +    iContinue = sqlite3VdbeMakeLabel(pParse);
   841    841       sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL);
   842    842       pLoop->wsFlags |= WHERE_PARTIALIDX;
   843    843     }
   844    844     regRecord = sqlite3GetTempReg(pParse);
   845    845     regBase = sqlite3GenerateIndexKey(
   846    846         pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0
   847    847     );
................................................................................
  4639   4639     pWInfo->pParse = pParse;
  4640   4640     pWInfo->pTabList = pTabList;
  4641   4641     pWInfo->pOrderBy = pOrderBy;
  4642   4642     pWInfo->pWhere = pWhere;
  4643   4643     pWInfo->pResultSet = pResultSet;
  4644   4644     pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
  4645   4645     pWInfo->nLevel = nTabList;
  4646         -  pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
         4646  +  pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(pParse);
  4647   4647     pWInfo->wctrlFlags = wctrlFlags;
  4648   4648     pWInfo->iLimit = iAuxArg;
  4649   4649     pWInfo->savedNQueryLoop = pParse->nQueryLoop;
  4650   4650     memset(&pWInfo->nOBSat, 0, 
  4651   4651            offsetof(WhereInfo,sWC) - offsetof(WhereInfo,nOBSat));
  4652   4652     memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel));
  4653   4653     assert( pWInfo->eOnePass==ONEPASS_OFF );  /* ONEPASS defaults to OFF */

Changes to src/wherecode.c.

   561    561       sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
   562    562       VdbeCoverageIf(v, bRev);
   563    563       VdbeCoverageIf(v, !bRev);
   564    564       assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
   565    565   
   566    566       pLoop->wsFlags |= WHERE_IN_ABLE;
   567    567       if( pLevel->u.in.nIn==0 ){
   568         -      pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
          568  +      pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
   569    569       }
   570    570   
   571    571       i = pLevel->u.in.nIn;
   572    572       pLevel->u.in.nIn += nEq;
   573    573       pLevel->u.in.aInLoop =
   574    574          sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
   575    575                                 sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
................................................................................
  1209   1209     ** loop.
  1210   1210     **
  1211   1211     ** When there is an IN operator, we also have a "addrNxt" label that
  1212   1212     ** means to continue with the next IN value combination.  When
  1213   1213     ** there are no IN operators in the constraints, the "addrNxt" label
  1214   1214     ** is the same as "addrBrk".
  1215   1215     */
  1216         -  addrBrk = pLevel->addrBrk = pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
  1217         -  addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(v);
         1216  +  addrBrk = pLevel->addrBrk = pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
         1217  +  addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(pParse);
  1218   1218   
  1219   1219     /* If this is the right table of a LEFT OUTER JOIN, allocate and
  1220   1220     ** initialize a memory cell that records if this table matches any
  1221   1221     ** row of the left table of the join.
  1222   1222     */
  1223   1223     assert( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)
  1224   1224          || pLevel->iFrom>0 || (pTabItem[0].fg.jointype & JT_LEFT)==0
................................................................................
  1831   1831       SrcList *pOrTab;       /* Shortened table list or OR-clause generation */
  1832   1832       Index *pCov = 0;             /* Potential covering index (or NULL) */
  1833   1833       int iCovCur = pParse->nTab++;  /* Cursor used for index scans (if any) */
  1834   1834   
  1835   1835       int regReturn = ++pParse->nMem;           /* Register used with OP_Gosub */
  1836   1836       int regRowset = 0;                        /* Register for RowSet object */
  1837   1837       int regRowid = 0;                         /* Register holding rowid */
  1838         -    int iLoopBody = sqlite3VdbeMakeLabel(v);  /* Start of loop body */
         1838  +    int iLoopBody = sqlite3VdbeMakeLabel(pParse);/* Start of loop body */
  1839   1839       int iRetInit;                             /* Address of regReturn init */
  1840   1840       int untestedTerms = 0;             /* Some terms not completely tested */
  1841   1841       int ii;                            /* Loop counter */
  1842   1842       u16 wctrlFlags;                    /* Flags for sub-WHERE clause */
  1843   1843       Expr *pAndExpr = 0;                /* An ".. AND (...)" expression */
  1844   1844       Table *pTab = pTabItem->pTab;
  1845   1845   

Changes to src/window.c.

  1326   1326     Window *pWin;
  1327   1327     for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
  1328   1328       FuncDef *pFunc = pWin->pFunc;
  1329   1329       if( pFunc->zName==nth_valueName
  1330   1330        || pFunc->zName==first_valueName
  1331   1331       ){
  1332   1332         int csr = pWin->csrApp;
  1333         -      int lbl = sqlite3VdbeMakeLabel(v);
         1333  +      int lbl = sqlite3VdbeMakeLabel(pParse);
  1334   1334         int tmpReg = sqlite3GetTempReg(pParse);
  1335   1335         sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
  1336   1336   
  1337   1337         if( pFunc->zName==nth_valueName ){
  1338   1338           sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+1,tmpReg);
  1339   1339           windowCheckIntValue(pParse, tmpReg, 2);
  1340   1340         }else{
................................................................................
  1349   1349         sqlite3VdbeResolveLabel(v, lbl);
  1350   1350         sqlite3ReleaseTempReg(pParse, tmpReg);
  1351   1351       }
  1352   1352       else if( pFunc->zName==leadName || pFunc->zName==lagName ){
  1353   1353         int nArg = pWin->pOwner->x.pList->nExpr;
  1354   1354         int iEph = pMWin->iEphCsr;
  1355   1355         int csr = pWin->csrApp;
  1356         -      int lbl = sqlite3VdbeMakeLabel(v);
         1356  +      int lbl = sqlite3VdbeMakeLabel(pParse);
  1357   1357         int tmpReg = sqlite3GetTempReg(pParse);
  1358   1358   
  1359   1359         if( nArg<3 ){
  1360   1360           sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
  1361   1361         }else{
  1362   1362           sqlite3VdbeAddOp3(v, OP_Column, iEph, pWin->iArgCol+2, pWin->regResult);
  1363   1363         }
................................................................................
  1610   1610          || pMWin->eEnd==TK_CURRENT 
  1611   1611          || pMWin->eEnd==TK_UNBOUNDED 
  1612   1612          || pMWin->eEnd==TK_PRECEDING 
  1613   1613     );
  1614   1614   
  1615   1615     /* Allocate register and label for the "flush_partition" sub-routine. */
  1616   1616     regFlushPart = ++pParse->nMem;
  1617         -  lblFlushPart = sqlite3VdbeMakeLabel(v);
  1618         -  lblFlushDone = sqlite3VdbeMakeLabel(v);
         1617  +  lblFlushPart = sqlite3VdbeMakeLabel(pParse);
         1618  +  lblFlushDone = sqlite3VdbeMakeLabel(pParse);
  1619   1619   
  1620   1620     regStart = ++pParse->nMem;
  1621   1621     regEnd = ++pParse->nMem;
  1622   1622   
  1623   1623     windowPartitionCache(pParse, p, pWInfo, regFlushPart, lblFlushPart, &regSize);
  1624   1624   
  1625   1625     addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
................................................................................
  1721   1721       sqlite3VdbeJumpHere(v, addrIfPos2);
  1722   1722     }
  1723   1723   
  1724   1724     if( pMWin->eStart==TK_CURRENT 
  1725   1725      || pMWin->eStart==TK_PRECEDING 
  1726   1726      || pMWin->eStart==TK_FOLLOWING 
  1727   1727     ){
  1728         -    int lblSkipInverse = sqlite3VdbeMakeLabel(v);;
         1728  +    int lblSkipInverse = sqlite3VdbeMakeLabel(pParse);;
  1729   1729       if( pMWin->eStart==TK_PRECEDING ){
  1730   1730         sqlite3VdbeAddOp3(v, OP_IfPos, regStart, lblSkipInverse, 1);
  1731   1731         VdbeCoverage(v);
  1732   1732       }
  1733   1733       if( pMWin->eStart==TK_FOLLOWING ){
  1734   1734         sqlite3VdbeAddOp2(v, OP_Next, csrStart, sqlite3VdbeCurrentAddr(v)+2);
  1735   1735         VdbeCoverage(v);
................................................................................
  1886   1886   
  1887   1887     assert( (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_CURRENT) 
  1888   1888          || (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_UNBOUNDED) 
  1889   1889          || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_CURRENT) 
  1890   1890          || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_UNBOUNDED) 
  1891   1891     );
  1892   1892   
  1893         -  lblEmpty = sqlite3VdbeMakeLabel(v);
         1893  +  lblEmpty = sqlite3VdbeMakeLabel(pParse);
  1894   1894     regNewPeer = pParse->nMem+1;
  1895   1895     pParse->nMem += nPeer;
  1896   1896   
  1897   1897     /* Allocate register and label for the "flush_partition" sub-routine. */
  1898   1898     regFlushPart = ++pParse->nMem;
  1899         -  lblFlushPart = sqlite3VdbeMakeLabel(v);
         1899  +  lblFlushPart = sqlite3VdbeMakeLabel(pParse);
  1900   1900   
  1901   1901     csrLead = pParse->nTab++;
  1902   1902     regCtr = ++pParse->nMem;
  1903   1903   
  1904   1904     windowPartitionCache(pParse, p, pWInfo, regFlushPart, lblFlushPart, &regSize);
  1905   1905     addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
  1906   1906