/ Check-in [9fb646f2]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Merge enhancements and bug fixes from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | reuse-subqueries
Files: files | file ages | folders
SHA3-256: 9fb646f29c05bca5f677a2c7c4f45c36bfe0a0c6a88cb7968b4a0459bdd63bb2
User & Date: drh 2018-12-31 18:30:41
Context
2018-12-31
20:13
Remove an optimization that can no longer occur, being superceded by the subquery-reuse optimization. Put an assert in place of the optimization to detect if the need for this optimization ever returns. Closed-Leaf check-in: 4fcdc7a2 user: drh tags: reuse-subqueries
18:30
Merge enhancements and bug fixes from trunk. check-in: 9fb646f2 user: drh tags: reuse-subqueries
17:58
Small changes to the OP_OpenEphemeral opcode to improve testability. check-in: f856676c user: drh tags: trunk
2018-12-28
21:32
Merge performance enhancements from trunk. check-in: 0f1b9ff9 user: drh tags: reuse-subqueries
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 
................................................................................
  3089   3089     ** sequence of comparisons.
  3090   3090     **
  3091   3091     ** This is step (1) in the in-operator.md optimized algorithm.
  3092   3092     */
  3093   3093     if( eType==IN_INDEX_NOOP ){
  3094   3094       ExprList *pList = pExpr->x.pList;
  3095   3095       CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
  3096         -    int labelOk = sqlite3VdbeMakeLabel(v);
         3096  +    int labelOk = sqlite3VdbeMakeLabel(pParse);
  3097   3097       int r2, regToFree;
  3098   3098       int regCkNull = 0;
  3099   3099       int ii;
  3100   3100       assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
  3101   3101       if( destIfNull!=destIfFalse ){
  3102   3102         regCkNull = sqlite3GetTempReg(pParse);
  3103   3103         sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull);
................................................................................
  3133   3133     /* Step 2: Check to see if the LHS contains any NULL columns.  If the
  3134   3134     ** LHS does contain NULLs then the result must be either FALSE or NULL.
  3135   3135     ** We will then skip the binary search of the RHS.
  3136   3136     */
  3137   3137     if( destIfNull==destIfFalse ){
  3138   3138       destStep2 = destIfFalse;
  3139   3139     }else{
  3140         -    destStep2 = destStep6 = sqlite3VdbeMakeLabel(v);
         3140  +    destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
  3141   3141     }
  3142   3142     for(i=0; i<nVector; i++){
  3143   3143       Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
  3144   3144       if( sqlite3ExprCanBeNull(p) ){
  3145   3145         sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
  3146   3146         VdbeCoverage(v);
  3147   3147       }
................................................................................
  3191   3191     ** For a scalar LHS, it is sufficient to check just the first row
  3192   3192     ** of the RHS.
  3193   3193     */
  3194   3194     if( destStep6 ) sqlite3VdbeResolveLabel(v, destStep6);
  3195   3195     addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, destIfFalse);
  3196   3196     VdbeCoverage(v);
  3197   3197     if( nVector>1 ){
  3198         -    destNotNull = sqlite3VdbeMakeLabel(v);
         3198  +    destNotNull = sqlite3VdbeMakeLabel(pParse);
  3199   3199     }else{
  3200   3200       /* For nVector==1, combine steps 6 and 7 by immediately returning
  3201   3201       ** FALSE if the first comparison is not NULL */
  3202   3202       destNotNull = destIfFalse;
  3203   3203     }
  3204   3204     for(i=0; i<nVector; i++){
  3205   3205       Expr *p;
................................................................................
  3756   3756         }
  3757   3757   
  3758   3758         /* Attempt a direct implementation of the built-in COALESCE() and
  3759   3759         ** IFNULL() functions.  This avoids unnecessary evaluation of
  3760   3760         ** arguments past the first non-NULL argument.
  3761   3761         */
  3762   3762         if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
  3763         -        int endCoalesce = sqlite3VdbeMakeLabel(v);
         3763  +        int endCoalesce = sqlite3VdbeMakeLabel(pParse);
  3764   3764           assert( nFarg>=2 );
  3765   3765           sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
  3766   3766           for(i=1; i<nFarg; i++){
  3767   3767             sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
  3768   3768             VdbeCoverage(v);
  3769   3769             sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
  3770   3770           }
................................................................................
  3904   3904         ){
  3905   3905           sqlite3ErrorMsg(pParse, "%d columns assigned %d values",
  3906   3906                                   pExpr->iTable, n);
  3907   3907         }
  3908   3908         return pExpr->pLeft->iTable + pExpr->iColumn;
  3909   3909       }
  3910   3910       case TK_IN: {
  3911         -      int destIfFalse = sqlite3VdbeMakeLabel(v);
  3912         -      int destIfNull = sqlite3VdbeMakeLabel(v);
         3911  +      int destIfFalse = sqlite3VdbeMakeLabel(pParse);
         3912  +      int destIfNull = sqlite3VdbeMakeLabel(pParse);
  3913   3913         sqlite3VdbeAddOp2(v, OP_Null, 0, target);
  3914   3914         sqlite3ExprCodeIN(pParse, pExpr, destIfFalse, destIfNull);
  3915   3915         sqlite3VdbeAddOp2(v, OP_Integer, 1, target);
  3916   3916         sqlite3VdbeResolveLabel(v, destIfFalse);
  3917   3917         sqlite3VdbeAddOp2(v, OP_AddImm, target, 0);
  3918   3918         sqlite3VdbeResolveLabel(v, destIfNull);
  3919   3919         return target;
................................................................................
  4045   4045         Expr *pTest = 0;                  /* X==Ei (form A) or just Ei (form B) */
  4046   4046   
  4047   4047         assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
  4048   4048         assert(pExpr->x.pList->nExpr > 0);
  4049   4049         pEList = pExpr->x.pList;
  4050   4050         aListelem = pEList->a;
  4051   4051         nExpr = pEList->nExpr;
  4052         -      endLabel = sqlite3VdbeMakeLabel(v);
         4052  +      endLabel = sqlite3VdbeMakeLabel(pParse);
  4053   4053         if( (pX = pExpr->pLeft)!=0 ){
  4054   4054           tempX = *pX;
  4055   4055           testcase( pX->op==TK_COLUMN );
  4056   4056           exprToRegister(&tempX, exprCodeVector(pParse, &tempX, &regFree1));
  4057   4057           testcase( regFree1==0 );
  4058   4058           memset(&opCompare, 0, sizeof(opCompare));
  4059   4059           opCompare.op = TK_EQ;
................................................................................
  4068   4068         for(i=0; i<nExpr-1; i=i+2){
  4069   4069           if( pX ){
  4070   4070             assert( pTest!=0 );
  4071   4071             opCompare.pRight = aListelem[i].pExpr;
  4072   4072           }else{
  4073   4073             pTest = aListelem[i].pExpr;
  4074   4074           }
  4075         -        nextCase = sqlite3VdbeMakeLabel(v);
         4075  +        nextCase = sqlite3VdbeMakeLabel(pParse);
  4076   4076           testcase( pTest->op==TK_COLUMN );
  4077   4077           sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
  4078   4078           testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
  4079   4079           sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
  4080   4080           sqlite3VdbeGoto(v, endLabel);
  4081   4081           sqlite3VdbeResolveLabel(v, nextCase);
  4082   4082         }
................................................................................
  4437   4437   
  4438   4438     assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
  4439   4439     if( NEVER(v==0) )     return;  /* Existence of VDBE checked by caller */
  4440   4440     if( NEVER(pExpr==0) ) return;  /* No way this can happen */
  4441   4441     op = pExpr->op;
  4442   4442     switch( op ){
  4443   4443       case TK_AND: {
  4444         -      int d2 = sqlite3VdbeMakeLabel(v);
         4444  +      int d2 = sqlite3VdbeMakeLabel(pParse);
  4445   4445         testcase( jumpIfNull==0 );
  4446   4446         sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL);
  4447   4447         sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
  4448   4448         sqlite3VdbeResolveLabel(v, d2);
  4449   4449         break;
  4450   4450       }
  4451   4451       case TK_OR: {
................................................................................
  4523   4523       case TK_BETWEEN: {
  4524   4524         testcase( jumpIfNull==0 );
  4525   4525         exprCodeBetween(pParse, pExpr, dest, sqlite3ExprIfTrue, jumpIfNull);
  4526   4526         break;
  4527   4527       }
  4528   4528   #ifndef SQLITE_OMIT_SUBQUERY
  4529   4529       case TK_IN: {
  4530         -      int destIfFalse = sqlite3VdbeMakeLabel(v);
         4530  +      int destIfFalse = sqlite3VdbeMakeLabel(pParse);
  4531   4531         int destIfNull = jumpIfNull ? dest : destIfFalse;
  4532   4532         sqlite3ExprCodeIN(pParse, pExpr, destIfFalse, destIfNull);
  4533   4533         sqlite3VdbeGoto(v, dest);
  4534   4534         sqlite3VdbeResolveLabel(v, destIfFalse);
  4535   4535         break;
  4536   4536       }
  4537   4537   #endif
................................................................................
  4610   4610       case TK_AND: {
  4611   4611         testcase( jumpIfNull==0 );
  4612   4612         sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
  4613   4613         sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
  4614   4614         break;
  4615   4615       }
  4616   4616       case TK_OR: {
  4617         -      int d2 = sqlite3VdbeMakeLabel(v);
         4617  +      int d2 = sqlite3VdbeMakeLabel(pParse);
  4618   4618         testcase( jumpIfNull==0 );
  4619   4619         sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL);
  4620   4620         sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
  4621   4621         sqlite3VdbeResolveLabel(v, d2);
  4622   4622         break;
  4623   4623       }
  4624   4624       case TK_NOT: {
................................................................................
  4694   4694         break;
  4695   4695       }
  4696   4696   #ifndef SQLITE_OMIT_SUBQUERY
  4697   4697       case TK_IN: {
  4698   4698         if( jumpIfNull ){
  4699   4699           sqlite3ExprCodeIN(pParse, pExpr, dest, dest);
  4700   4700         }else{
  4701         -        int destIfNull = sqlite3VdbeMakeLabel(v);
         4701  +        int destIfNull = sqlite3VdbeMakeLabel(pParse);
  4702   4702           sqlite3ExprCodeIN(pParse, pExpr, dest, destIfNull);
  4703   4703           sqlite3VdbeResolveLabel(v, destIfNull);
  4704   4704         }
  4705   4705         break;
  4706   4706       }
  4707   4707   #endif
  4708   4708       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.

  3069   3069     int iRangeReg;       /* First register in temporary register block */
  3070   3070     int nErr;            /* Number of errors seen */
  3071   3071     int nTab;            /* Number of previously allocated VDBE cursors */
  3072   3072     int nMem;            /* Number of memory cells used so far */
  3073   3073     int szOpAlloc;       /* Bytes of memory space allocated for Vdbe.aOp[] */
  3074   3074     int iSelfTab;        /* Table associated with an index on expr, or negative
  3075   3075                          ** of the base register during check-constraint eval */
  3076         -  int nLabel;          /* Number of labels used */
         3076  +  int nLabel;          /* The *negative* of the number of labels used */
         3077  +  int nLabelAlloc;     /* Number of slots in aLabel */
  3077   3078     int *aLabel;         /* Space to hold the labels */
  3078   3079     ExprList *pConstExpr;/* Constant expressions */
  3079   3080     Token constraintName;/* Name of the constraint currently being parsed */
  3080   3081     yDbMask writeMask;   /* Start a write transaction on these databases */
  3081   3082     yDbMask cookieMask;  /* Bitmask of schema verified databases */
  3082   3083     int regRowid;        /* Register holding rowid of CREATE TABLE entry */
  3083   3084     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.c.

  3624   3624   /* Opcode: OpenEphemeral P1 P2 * P4 P5
  3625   3625   ** Synopsis: nColumn=P2
  3626   3626   **
  3627   3627   ** Open a new cursor P1 to a transient table.
  3628   3628   ** The cursor is always opened read/write even if 
  3629   3629   ** the main database is read-only.  The ephemeral
  3630   3630   ** table is deleted automatically when the cursor is closed.
         3631  +**
         3632  +** If the cursor P1 is already opened on an ephermal table, the table
         3633  +** is cleared (all content is erased).
  3631   3634   **
  3632   3635   ** P2 is the number of columns in the ephemeral table.
  3633   3636   ** The cursor points to a BTree table if P4==0 and to a BTree index
  3634   3637   ** if P4 is not 0.  If P4 is not NULL, it points to a KeyInfo structure
  3635   3638   ** that defines the format of keys in the index.
  3636   3639   **
  3637   3640   ** The P5 parameter can be a mask of the BTREE_* flags defined
................................................................................
  3656   3659         SQLITE_OPEN_READWRITE |
  3657   3660         SQLITE_OPEN_CREATE |
  3658   3661         SQLITE_OPEN_EXCLUSIVE |
  3659   3662         SQLITE_OPEN_DELETEONCLOSE |
  3660   3663         SQLITE_OPEN_TRANSIENT_DB;
  3661   3664     assert( pOp->p1>=0 );
  3662   3665     assert( pOp->p2>=0 );
  3663         -  pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
  3664         -  if( pCx==0 ) goto no_mem;
  3665         -  pCx->nullRow = 1;
  3666         -  pCx->isEphemeral = 1;
  3667         -  rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx, 
  3668         -                        BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
  3669         -  if( rc==SQLITE_OK ){
  3670         -    rc = sqlite3BtreeBeginTrans(pCx->pBtx, 1, 0);
  3671         -  }
  3672         -  if( rc==SQLITE_OK ){
  3673         -    /* If a transient index is required, create it by calling
  3674         -    ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
  3675         -    ** opening it. If a transient table is required, just use the
  3676         -    ** automatically created table with root-page 1 (an BLOB_INTKEY table).
  3677         -    */
  3678         -    if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
  3679         -      int pgno;
  3680         -      assert( pOp->p4type==P4_KEYINFO );
  3681         -      rc = sqlite3BtreeCreateTable(pCx->pBtx, &pgno, BTREE_BLOBKEY | pOp->p5); 
  3682         -      if( rc==SQLITE_OK ){
  3683         -        assert( pgno==MASTER_ROOT+1 );
  3684         -        assert( pKeyInfo->db==db );
  3685         -        assert( pKeyInfo->enc==ENC(db) );
  3686         -        pCx->pgnoRoot = pgno;
  3687         -        rc = sqlite3BtreeCursor(pCx->pBtx, pgno, BTREE_WRCSR,
  3688         -                                pKeyInfo, pCx->uc.pCursor);
  3689         -      }
  3690         -      pCx->isTable = 0;
  3691         -    }else{
  3692         -      rc = sqlite3BtreeCursor(pCx->pBtx, MASTER_ROOT, BTREE_WRCSR,
  3693         -                              0, pCx->uc.pCursor);
  3694         -      pCx->isTable = 1;
  3695         -      pCx->pgnoRoot = MASTER_ROOT;
  3696         -    }
  3697         -  }
  3698         -  if( rc ) goto abort_due_to_error;
  3699         -  pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
         3666  +  pCx = p->apCsr[pOp->p1];
         3667  +  if( pCx ){
         3668  +    /* If the ephermeral table is already open, erase all existing content
         3669  +    ** so that the table is empty again, rather than creating a new table. */
         3670  +    rc = sqlite3BtreeClearTable(pCx->pBtx, pCx->pgnoRoot, 0);
         3671  +  }else{
         3672  +    pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
         3673  +    if( pCx==0 ) goto no_mem;
         3674  +    pCx->nullRow = 1;
         3675  +    pCx->isEphemeral = 1;
         3676  +    rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx, 
         3677  +                          BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5,
         3678  +                          vfsFlags);
         3679  +    if( rc==SQLITE_OK ){
         3680  +      rc = sqlite3BtreeBeginTrans(pCx->pBtx, 1, 0);
         3681  +    }
         3682  +    if( rc==SQLITE_OK ){
         3683  +      /* If a transient index is required, create it by calling
         3684  +      ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
         3685  +      ** opening it. If a transient table is required, just use the
         3686  +      ** automatically created table with root-page 1 (an BLOB_INTKEY table).
         3687  +      */
         3688  +      if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
         3689  +        assert( pOp->p4type==P4_KEYINFO );
         3690  +        rc = sqlite3BtreeCreateTable(pCx->pBtx, (int*)&pCx->pgnoRoot,
         3691  +                                     BTREE_BLOBKEY | pOp->p5); 
         3692  +        if( rc==SQLITE_OK ){
         3693  +          assert( pCx->pgnoRoot==MASTER_ROOT+1 );
         3694  +          assert( pKeyInfo->db==db );
         3695  +          assert( pKeyInfo->enc==ENC(db) );
         3696  +          rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
         3697  +                                  pKeyInfo, pCx->uc.pCursor);
         3698  +        }
         3699  +        pCx->isTable = 0;
         3700  +      }else{
         3701  +        pCx->pgnoRoot = MASTER_ROOT;
         3702  +        rc = sqlite3BtreeCursor(pCx->pBtx, MASTER_ROOT, BTREE_WRCSR,
         3703  +                                0, pCx->uc.pCursor);
         3704  +        pCx->isTable = 1;
         3705  +      }
         3706  +    }
         3707  +    pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
         3708  +  }
         3709  +  if( rc ) goto abort_due_to_error;
  3700   3710     break;
  3701   3711   }
  3702   3712   
  3703   3713   /* Opcode: SorterOpen P1 P2 P3 P4 *
  3704   3714   **
  3705   3715   ** This opcode works like OP_OpenEphemeral except that it opens
  3706   3716   ** a transient index that is specifically designed to sort large

Changes to src/vdbe.h.

   152    152   #   define COLNAME_N      1      /* Store only the name */
   153    153   # else
   154    154   #   define COLNAME_N      2      /* Store the name and decltype */
   155    155   # endif
   156    156   #endif
   157    157   
   158    158   /*
   159         -** The following macro converts a relative address in the p2 field
   160         -** of a VdbeOp structure into a negative number so that 
   161         -** sqlite3VdbeAddOpList() knows that the address is relative.  Calling
   162         -** the macro again restores the address.
          159  +** The following macro converts a label returned by sqlite3VdbeMakeLabel()
          160  +** into an index into the Parse.aLabel[] array that contains the resolved
          161  +** address of that label.
   163    162   */
   164         -#define ADDR(X)  (-1-(X))
          163  +#define ADDR(X)  (~(X))
   165    164   
   166    165   /*
   167    166   ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
   168    167   ** header file that defines a number for each opcode used by the VDBE.
   169    168   */
   170    169   #include "opcodes.h"
   171    170   
................................................................................
   233    232   int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
   234    233   int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
   235    234   void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
   236    235   void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
   237    236   void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
   238    237   void sqlite3VdbeUsesBtree(Vdbe*, int);
   239    238   VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
   240         -int sqlite3VdbeMakeLabel(Vdbe*);
          239  +int sqlite3VdbeMakeLabel(Parse*);
   241    240   void sqlite3VdbeRunOnlyOnce(Vdbe*);
   242    241   void sqlite3VdbeReusable(Vdbe*);
   243    242   void sqlite3VdbeDelete(Vdbe*);
   244    243   void sqlite3VdbeClearObject(sqlite3*,Vdbe*);
   245    244   void sqlite3VdbeMakeReady(Vdbe*,Parse*);
   246    245   int sqlite3VdbeFinalize(Vdbe*);
   247    246   void sqlite3VdbeResolveLabel(Vdbe*, int);

Changes to src/vdbeaux.c.

   456    456   ** the label is resolved to a specific address, the VDBE will scan
   457    457   ** through its operation list and change all values of P2 which match
   458    458   ** the label into the resolved address.
   459    459   **
   460    460   ** The VDBE knows that a P2 value is a label because labels are
   461    461   ** always negative and P2 values are suppose to be non-negative.
   462    462   ** Hence, a negative P2 value is a label that has yet to be resolved.
          463  +** (Later:) This is only true for opcodes that have the OPFLG_JUMP
          464  +** property.
   463    465   **
   464         -** Zero is returned if a malloc() fails.
          466  +** Variable usage notes:
          467  +**
          468  +**     Parse.aLabel[x]     Stores the address that the x-th label resolves
          469  +**                         into.  For testing (SQLITE_DEBUG), unresolved
          470  +**                         labels stores -1, but that is not required.
          471  +**     Parse.nLabelAlloc   Number of slots allocated to Parse.aLabel[]
          472  +**     Parse.nLabel        The *negative* of the number of labels that have
          473  +**                         been issued.  The negative is stored because
          474  +**                         that gives a performance improvement over storing
          475  +**                         the equivalent positive value.
   465    476   */
   466         -int sqlite3VdbeMakeLabel(Vdbe *v){
   467         -  Parse *p = v->pParse;
   468         -  int i = p->nLabel++;
   469         -  assert( v->magic==VDBE_MAGIC_INIT );
   470         -  if( (i & (i-1))==0 ){
   471         -    p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel, 
   472         -                                       (i*2+1)*sizeof(p->aLabel[0]));
   473         -  }
   474         -  if( p->aLabel ){
   475         -    p->aLabel[i] = -1;
   476         -  }
   477         -  return ADDR(i);
          477  +int sqlite3VdbeMakeLabel(Parse *pParse){
          478  +  return --pParse->nLabel;
   478    479   }
   479    480   
   480    481   /*
   481    482   ** Resolve label "x" to be the address of the next instruction to
   482    483   ** be inserted.  The parameter "x" must have been obtained from
   483    484   ** a prior call to sqlite3VdbeMakeLabel().
   484    485   */
          486  +static SQLITE_NOINLINE void resizeResolveLabel(Parse *p, Vdbe *v, int j){
          487  +  int nNewSize = 10 - p->nLabel;
          488  +  p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
          489  +                     nNewSize*sizeof(p->aLabel[0]));
          490  +  if( p->aLabel==0 ){
          491  +    p->nLabelAlloc = 0;
          492  +  }else{
          493  +#ifdef SQLITE_DEBUG
          494  +    int i;
          495  +    for(i=p->nLabelAlloc; i<nNewSize; i++) p->aLabel[i] = -1;
          496  +#endif
          497  +    p->nLabelAlloc = nNewSize;
          498  +    p->aLabel[j] = v->nOp;
          499  +  }
          500  +}
   485    501   void sqlite3VdbeResolveLabel(Vdbe *v, int x){
   486    502     Parse *p = v->pParse;
   487    503     int j = ADDR(x);
   488    504     assert( v->magic==VDBE_MAGIC_INIT );
   489         -  assert( j<p->nLabel );
          505  +  assert( j<-p->nLabel );
   490    506     assert( j>=0 );
   491         -  if( p->aLabel ){
   492    507   #ifdef SQLITE_DEBUG
   493         -    if( p->db->flags & SQLITE_VdbeAddopTrace ){
   494         -      printf("RESOLVE LABEL %d to %d\n", x, v->nOp);
   495         -    }
          508  +  if( p->db->flags & SQLITE_VdbeAddopTrace ){
          509  +    printf("RESOLVE LABEL %d to %d\n", x, v->nOp);
          510  +  }
   496    511   #endif
          512  +  if( p->nLabelAlloc + p->nLabel < 0 ){
          513  +    resizeResolveLabel(p,v,j);
          514  +  }else{
   497    515       assert( p->aLabel[j]==(-1) ); /* Labels may only be resolved once */
   498    516       p->aLabel[j] = v->nOp;
   499    517     }
   500    518   }
   501    519   
   502    520   /*
   503    521   ** Mark the VDBE as one that can only be run one time.
................................................................................
   765    783   #endif
   766    784           default: {
   767    785             if( pOp->p2<0 ){
   768    786               /* The mkopcodeh.tcl script has so arranged things that the only
   769    787               ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
   770    788               ** have non-negative values for P2. */
   771    789               assert( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 );
   772         -            assert( ADDR(pOp->p2)<pParse->nLabel );
          790  +            assert( ADDR(pOp->p2)<-pParse->nLabel );
   773    791               pOp->p2 = aLabel[ADDR(pOp->p2)];
   774    792             }
   775    793             break;
   776    794           }
   777    795         }
   778    796         /* The mkopcodeh.tcl script has so arranged things that the only
   779    797         ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to

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     );
................................................................................
  4640   4640     pWInfo->pParse = pParse;
  4641   4641     pWInfo->pTabList = pTabList;
  4642   4642     pWInfo->pOrderBy = pOrderBy;
  4643   4643     pWInfo->pWhere = pWhere;
  4644   4644     pWInfo->pResultSet = pResultSet;
  4645   4645     pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
  4646   4646     pWInfo->nLevel = nTabList;
  4647         -  pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
         4647  +  pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(pParse);
  4648   4648     pWInfo->wctrlFlags = wctrlFlags;
  4649   4649     pWInfo->iLimit = iAuxArg;
  4650   4650     pWInfo->savedNQueryLoop = pParse->nQueryLoop;
  4651   4651     memset(&pWInfo->nOBSat, 0, 
  4652   4652            offsetof(WhereInfo,sWC) - offsetof(WhereInfo,nOBSat));
  4653   4653     memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel));
  4654   4654     assert( pWInfo->eOnePass==ONEPASS_OFF );  /* ONEPASS defaults to OFF */

Changes to src/wherecode.c.

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

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   

Changes to test/window1.test.

   616    616     SELECT y, y+1, y+2 FROM (
   617    617       SELECT c IN (
   618    618         SELECT (row_number() OVER()) FROM t1
   619    619       ) AS y FROM t2
   620    620     );
   621    621   } {1 2 3}
   622    622   
          623  +# 2018-12-31
          624  +# https://www.sqlite.org/src/info/d0866b26f83e9c55
          625  +# Window function in correlated subquery causes assertion fault 
          626  +#
          627  +do_catchsql_test 15.0 {
          628  +  WITH t(id, parent) AS (
          629  +  SELECT CAST(1 AS INT), CAST(NULL AS INT)
          630  +  UNION ALL
          631  +  SELECT 2, NULL
          632  +  UNION ALL
          633  +  SELECT 3, 1
          634  +  UNION ALL
          635  +  SELECT 4, 1
          636  +  UNION ALL
          637  +  SELECT 5, 2
          638  +  UNION ALL
          639  +  SELECT 6, 2
          640  +  ), q AS (
          641  +  SELECT t.*, ROW_NUMBER() OVER (ORDER BY t.id) AS rn
          642  +    FROM t
          643  +   WHERE parent IS NULL
          644  +   UNION ALL
          645  +  SELECT t.*, ROW_NUMBER() OVER (ORDER BY t.id) AS rn
          646  +    FROM q
          647  +    JOIN t
          648  +      ON t.parent = q.id
          649  +  )
          650  +  SELECT *
          651  +    FROM q;
          652  +} {1 {cannot use window functions in recursive queries}}
          653  +do_execsql_test 15.1 {
          654  +  DROP TABLE IF EXISTS t1;
          655  +  DROP TABLE IF EXISTS t2;
          656  +  CREATE TABLE t1(x);
          657  +  INSERT INTO t1 VALUES('a'), ('b'), ('c');
          658  +  CREATE TABLE t2(a, b);
          659  +  INSERT INTO t2 VALUES('X', 1), ('X', 2), ('Y', 2), ('Y', 3);
          660  +  SELECT x, (
          661  +    SELECT sum(b)
          662  +      OVER (PARTITION BY a ROWS BETWEEN UNBOUNDED PRECEDING
          663  +                                    AND UNBOUNDED FOLLOWING)
          664  +    FROM t2 WHERE b<x
          665  +  ) FROM t1;
          666  +} {a 3 b 3 c 3}
          667  +
   623    668   finish_test