/ Check-in [6a00a34e]
Login

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

Overview
Comment:Merge latest trunk changes into this branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | begin-concurrent
Files: files | file ages | folders
SHA3-256: 6a00a34e198408d69d638a25763f64b8a5beec61a60affb4d344426a2e232d72
User & Date: dan 2018-07-12 19:28:43
Wiki:begin-concurrent
Context
2018-09-28
20:58
Merge latest trunk into this branch. check-in: 86750c92 user: dan tags: begin-concurrent
2018-07-12
19:39
Merge latest begin-concurrent changes with this branch. check-in: d33527d2 user: dan tags: begin-concurrent-pnu
19:28
Merge latest trunk changes into this branch. check-in: 6a00a34e user: dan tags: begin-concurrent
19:14
Add a test-control to disable the skip-scan optimization. check-in: 650a3fe0 user: dan tags: trunk
2018-07-10
15:45
Merge latest trunk changes into this branch. check-in: e9a3e864 user: dan tags: begin-concurrent
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/analyze.c.

  1270   1270         callStatGet(v, regStat4, STAT_GET_ROWID, regSampleRowid);
  1271   1271         addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid);
  1272   1272         VdbeCoverage(v);
  1273   1273         callStatGet(v, regStat4, STAT_GET_NEQ, regEq);
  1274   1274         callStatGet(v, regStat4, STAT_GET_NLT, regLt);
  1275   1275         callStatGet(v, regStat4, STAT_GET_NDLT, regDLt);
  1276   1276         sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
  1277         -      /* We know that the regSampleRowid row exists because it was read by
  1278         -      ** the previous loop.  Thus the not-found jump of seekOp will never
  1279         -      ** be taken */
  1280         -      VdbeCoverageNeverTaken(v);
         1277  +      VdbeCoverage(v);
  1281   1278   #ifdef SQLITE_ENABLE_STAT3
  1282   1279         sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iTabCur, 0, regSample);
  1283   1280   #else
  1284   1281         for(i=0; i<nCol; i++){
  1285   1282           sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iTabCur, i, regCol+i);
  1286   1283         }
  1287   1284         sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol, regSample);

Changes to src/expr.c.

  1483   1483       pNew->addrOpenEphm[1] = -1;
  1484   1484       pNew->nSelectRow = p->nSelectRow;
  1485   1485       pNew->pWith = withDup(db, p->pWith);
  1486   1486   #ifndef SQLITE_OMIT_WINDOWFUNC
  1487   1487       pNew->pWin = 0;
  1488   1488       pNew->pWinDefn = sqlite3WindowListDup(db, p->pWinDefn);
  1489   1489   #endif
  1490         -    sqlite3SelectSetName(pNew, p->zSelName);
         1490  +    pNew->selId = p->selId;
  1491   1491       *pp = pNew;
  1492   1492       pp = &pNew->pPrior;
  1493   1493       pNext = pNew;
  1494   1494     }
  1495   1495   
  1496   1496     return pRet;
  1497   1497   }

Changes to src/insert.c.

  1628   1628     for(ix=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, ix++){
  1629   1629       int regIdx;          /* Range of registers hold conent for pIdx */
  1630   1630       int regR;            /* Range of registers holding conflicting PK */
  1631   1631       int iThisCur;        /* Cursor for this UNIQUE index */
  1632   1632       int addrUniqueOk;    /* Jump here if the UNIQUE constraint is satisfied */
  1633   1633   
  1634   1634       if( aRegIdx[ix]==0 ) continue;  /* Skip indices that do not change */
         1635  +    if( bAffinityDone==0 ){
         1636  +      sqlite3TableAffinity(v, pTab, regNewData+1);
         1637  +      bAffinityDone = 1;
         1638  +    }
  1635   1639       if( pUpIdx==pIdx ){
  1636   1640         addrUniqueOk = sAddr.upsertBtm;
  1637   1641         upsertBypass = sqlite3VdbeGoto(v, 0);
  1638   1642         VdbeComment((v, "Skip upsert subroutine"));
  1639   1643         sqlite3VdbeResolveLabel(v, sAddr.upsertTop2);
  1640   1644       }else{
  1641   1645         addrUniqueOk = sqlite3VdbeMakeLabel(v);
  1642   1646       }
  1643   1647       VdbeNoopComment((v, "uniqueness check for %s", pIdx->zName));
  1644         -    if( bAffinityDone==0 ){
  1645         -      sqlite3TableAffinity(v, pTab, regNewData+1);
  1646         -      bAffinityDone = 1;
  1647         -    }
  1648   1648       iThisCur = iIdxCur+ix;
  1649   1649   
  1650   1650   
  1651   1651       /* Skip partial indices for which the WHERE clause is not true */
  1652   1652       if( pIdx->pPartIdxWhere ){
  1653   1653         sqlite3VdbeAddOp2(v, OP_Null, 0, aRegIdx[ix]);
  1654   1654         pParse->iSelfTab = -(regNewData+1);

Changes to src/main.c.

  3970   3970       /*   sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, xCallback, ptr);
  3971   3971       **
  3972   3972       ** Set the VDBE coverage callback function to xCallback with context 
  3973   3973       ** pointer ptr.
  3974   3974       */
  3975   3975       case SQLITE_TESTCTRL_VDBE_COVERAGE: {
  3976   3976   #ifdef SQLITE_VDBE_COVERAGE
  3977         -      typedef void (*branch_callback)(void*,int,u8,u8);
         3977  +      typedef void (*branch_callback)(void*,unsigned int,
         3978  +                                      unsigned char,unsigned char);
  3978   3979         sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback);
  3979   3980         sqlite3GlobalConfig.pVdbeBranchArg = va_arg(ap,void*);
  3980   3981   #endif
  3981   3982         break;
  3982   3983       }
  3983   3984   
  3984   3985       /*   sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP, db, nMax); */

Changes to src/parse.y.

   542    542     A = pRhs;
   543    543   }
   544    544   %type multiselect_op {int}
   545    545   multiselect_op(A) ::= UNION(OP).             {A = @OP; /*A-overwrites-OP*/}
   546    546   multiselect_op(A) ::= UNION ALL.             {A = TK_ALL;}
   547    547   multiselect_op(A) ::= EXCEPT|INTERSECT(OP).  {A = @OP; /*A-overwrites-OP*/}
   548    548   %endif SQLITE_OMIT_COMPOUND_SELECT
   549         -oneselect(A) ::= SELECT(S) distinct(D) selcollist(W) from(X) where_opt(Y)
          549  +oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
   550    550                    groupby_opt(P) having_opt(Q) 
   551    551   %ifndef SQLITE_OMIT_WINDOWFUNC
   552    552                    windowdefn_opt(R)
   553    553   %endif
   554    554                    orderby_opt(Z) limit_opt(L). {
   555         -#if SELECTTRACE_ENABLED
   556         -  Token s = S; /*A-overwrites-S*/
   557         -#endif
   558    555     A = sqlite3SelectNew(pParse,W,X,Y,P,Q,Z,D,L);
   559    556   #ifndef SQLITE_OMIT_WINDOWFUNC
   560    557     if( A ){
   561    558       A->pWinDefn = R;
   562    559     }else{
   563    560       sqlite3WindowListDelete(pParse->db, R);
   564    561     }
   565    562   #endif /* SQLITE_OMIT_WINDOWFUNC */
   566         -#if SELECTTRACE_ENABLED
   567         -  /* Populate the Select.zSelName[] string that is used to help with
   568         -  ** query planner debugging, to differentiate between multiple Select
   569         -  ** objects in a complex query.
   570         -  **
   571         -  ** If the SELECT keyword is immediately followed by a C-style comment
   572         -  ** then extract the first few alphanumeric characters from within that
   573         -  ** comment to be the zSelName value.  Otherwise, the label is #N where
   574         -  ** is an integer that is incremented with each SELECT statement seen.
   575         -  */
   576         -  if( A!=0 ){
   577         -    const char *z = s.z+6;
   578         -    int i;
   579         -    sqlite3_snprintf(sizeof(A->zSelName), A->zSelName,"#%d",++pParse->nSelect);
   580         -    while( z[0]==' ' ) z++;
   581         -    if( z[0]=='/' && z[1]=='*' ){
   582         -      z += 2;
   583         -      while( z[0]==' ' ) z++;
   584         -      for(i=0; sqlite3Isalnum(z[i]); i++){}
   585         -      sqlite3_snprintf(sizeof(A->zSelName), A->zSelName, "%.*s", i, z);
   586         -    }
   587         -  }
   588         -#endif /* SELECTRACE_ENABLED */
   589    563   }
   590    564   oneselect(A) ::= values(A).
   591    565   
   592    566   %type values {Select*}
   593    567   %destructor values {sqlite3SelectDelete(pParse->db, $$);}
   594    568   values(A) ::= VALUES LP nexprlist(X) RP. {
   595    569     A = sqlite3SelectNew(pParse,X,0,0,0,0,0,SF_Values,0);

Changes to src/select.c.

    17     17   /*
    18     18   ** Trace output macros
    19     19   */
    20     20   #if SELECTTRACE_ENABLED
    21     21   /***/ int sqlite3SelectTrace = 0;
    22     22   # define SELECTTRACE(K,P,S,X)  \
    23     23     if(sqlite3SelectTrace&(K))   \
    24         -    sqlite3DebugPrintf("%s/%d/%p: ",(S)->zSelName,(P)->addrExplain,(S)),\
           24  +    sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\
    25     25       sqlite3DebugPrintf X
    26     26   #else
    27     27   # define SELECTTRACE(K,P,S,X)
    28     28   #endif
    29     29   
    30     30   
    31     31   /*
................................................................................
   147    147                                      sqlite3Expr(pParse->db,TK_ASTERISK,0));
   148    148     }
   149    149     pNew->pEList = pEList;
   150    150     pNew->op = TK_SELECT;
   151    151     pNew->selFlags = selFlags;
   152    152     pNew->iLimit = 0;
   153    153     pNew->iOffset = 0;
   154         -#if SELECTTRACE_ENABLED
   155         -  pNew->zSelName[0] = 0;
   156         -#endif
          154  +  pNew->selId = ++pParse->nSelect;
   157    155     pNew->addrOpenEphm[0] = -1;
   158    156     pNew->addrOpenEphm[1] = -1;
   159    157     pNew->nSelectRow = 0;
   160    158     if( pSrc==0 ) pSrc = sqlite3DbMallocZero(pParse->db, sizeof(*pSrc));
   161    159     pNew->pSrc = pSrc;
   162    160     pNew->pWhere = pWhere;
   163    161     pNew->pGroupBy = pGroupBy;
................................................................................
   177    175     }else{
   178    176       assert( pNew->pSrc!=0 || pParse->nErr>0 );
   179    177     }
   180    178     assert( pNew!=&standin );
   181    179     return pNew;
   182    180   }
   183    181   
   184         -#if SELECTTRACE_ENABLED
   185         -/*
   186         -** Set the name of a Select object
   187         -*/
   188         -void sqlite3SelectSetName(Select *p, const char *zName){
   189         -  if( p && zName ){
   190         -    sqlite3_snprintf(sizeof(p->zSelName), p->zSelName, "%s", zName);
   191         -  }
   192         -}
   193         -#endif
   194         -
   195    182   
   196    183   /*
   197    184   ** Delete the given Select structure and all of its substructures.
   198    185   */
   199    186   void sqlite3SelectDelete(sqlite3 *db, Select *p){
   200    187     if( OK_IF_ALWAYS_TRUE(p) ) clearSelect(db, p, 1);
   201    188   }
................................................................................
  3834   3821     ** subquery is for the subquery to be one term of a join.  But if the
  3835   3822     ** subquery is a join, then the flattening has already been stopped by
  3836   3823     ** restriction (17d3)
  3837   3824     */
  3838   3825     assert( (p->selFlags & SF_Recursive)==0 || pSub->pPrior==0 );
  3839   3826   
  3840   3827     /***** If we reach this point, flattening is permitted. *****/
  3841         -  SELECTTRACE(1,pParse,p,("flatten %s.%p from term %d\n",
  3842         -                   pSub->zSelName, pSub, iFrom));
         3828  +  SELECTTRACE(1,pParse,p,("flatten %u.%p from term %d\n",
         3829  +                   pSub->selId, pSub, iFrom));
  3843   3830   
  3844   3831     /* Authorize the subquery */
  3845   3832     pParse->zAuthContext = pSubitem->zName;
  3846   3833     TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0);
  3847   3834     testcase( i==SQLITE_DENY );
  3848   3835     pParse->zAuthContext = zSavedAuthContext;
  3849   3836   
................................................................................
  3886   3873       Expr *pLimit = p->pLimit;
  3887   3874       Select *pPrior = p->pPrior;
  3888   3875       p->pOrderBy = 0;
  3889   3876       p->pSrc = 0;
  3890   3877       p->pPrior = 0;
  3891   3878       p->pLimit = 0;
  3892   3879       pNew = sqlite3SelectDup(db, p, 0);
  3893         -    sqlite3SelectSetName(pNew, pSub->zSelName);
  3894   3880       p->pLimit = pLimit;
  3895   3881       p->pOrderBy = pOrderBy;
  3896   3882       p->pSrc = pSrc;
  3897   3883       p->op = TK_ALL;
  3898   3884       if( pNew==0 ){
  3899   3885         p->pPrior = pPrior;
  3900   3886       }else{
  3901   3887         pNew->pPrior = pPrior;
  3902   3888         if( pPrior ) pPrior->pNext = pNew;
  3903   3889         pNew->pNext = p;
  3904   3890         p->pPrior = pNew;
  3905   3891         SELECTTRACE(2,pParse,p,("compound-subquery flattener"
  3906         -                              " creates %s.%p as peer\n",pNew->zSelName, pNew));
         3892  +                              " creates %u as peer\n",pNew->selId));
  3907   3893       }
  3908   3894       if( db->mallocFailed ) return 1;
  3909   3895     }
  3910   3896   
  3911   3897     /* Begin flattening the iFrom-th entry of the FROM clause 
  3912   3898     ** in the outer query.
  3913   3899     */
................................................................................
  4619   4605     assert( pSel );
  4620   4606     pFrom->pTab = pTab = sqlite3DbMallocZero(pParse->db, sizeof(Table));
  4621   4607     if( pTab==0 ) return SQLITE_NOMEM;
  4622   4608     pTab->nTabRef = 1;
  4623   4609     if( pFrom->zAlias ){
  4624   4610       pTab->zName = sqlite3DbStrDup(pParse->db, pFrom->zAlias);
  4625   4611     }else{
  4626         -    pTab->zName = sqlite3MPrintf(pParse->db, "subquery_%p", (void*)pTab);
         4612  +    pTab->zName = sqlite3MPrintf(pParse->db, "subquery_%u", pSel->selId);
  4627   4613     }
  4628   4614     while( pSel->pPrior ){ pSel = pSel->pPrior; }
  4629   4615     sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
  4630   4616     pTab->iPKey = -1;
  4631   4617     pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
  4632   4618     pTab->tabFlags |= TF_Ephemeral;
  4633   4619   
................................................................................
  4725   4711         }
  4726   4712   #if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE)
  4727   4713         if( IsVirtual(pTab) || pTab->pSelect ){
  4728   4714           i16 nCol;
  4729   4715           if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
  4730   4716           assert( pFrom->pSelect==0 );
  4731   4717           pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
  4732         -        sqlite3SelectSetName(pFrom->pSelect, pTab->zName);
  4733   4718           nCol = pTab->nCol;
  4734   4719           pTab->nCol = -1;
  4735   4720           sqlite3WalkSelect(pWalker, pFrom->pSelect);
  4736   4721           pTab->nCol = nCol;
  4737   4722         }
  4738   4723   #endif
  4739   4724       }
................................................................................
  5717   5702         int addrTop = sqlite3VdbeCurrentAddr(v)+1;
  5718   5703        
  5719   5704         pItem->regReturn = ++pParse->nMem;
  5720   5705         sqlite3VdbeAddOp3(v, OP_InitCoroutine, pItem->regReturn, 0, addrTop);
  5721   5706         VdbeComment((v, "%s", pItem->pTab->zName));
  5722   5707         pItem->addrFillSub = addrTop;
  5723   5708         sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
  5724         -      ExplainQueryPlan((pParse, 1, "CO-ROUTINE 0x%p", pSub));
         5709  +      ExplainQueryPlan((pParse, 1, "CO-ROUTINE %u", pSub->selId));
  5725   5710         sqlite3Select(pParse, pSub, &dest);
  5726   5711         pItem->pTab->nRowLogEst = pSub->nSelectRow;
  5727   5712         pItem->fg.viaCoroutine = 1;
  5728   5713         pItem->regResult = dest.iSdst;
  5729   5714         sqlite3VdbeEndCoroutine(v, pItem->regReturn);
  5730   5715         sqlite3VdbeJumpHere(v, addrTop-1);
  5731   5716         sqlite3ClearTempRegCache(pParse);
................................................................................
  5756   5741         pPrior = isSelfJoinView(pTabList, pItem);
  5757   5742         if( pPrior ){
  5758   5743           sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pPrior->iCursor);
  5759   5744           assert( pPrior->pSelect!=0 );
  5760   5745           pSub->nSelectRow = pPrior->pSelect->nSelectRow;
  5761   5746         }else{
  5762   5747           sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
  5763         -        ExplainQueryPlan((pParse, 1, "MATERIALIZE 0x%p", pSub));
         5748  +        ExplainQueryPlan((pParse, 1, "MATERIALIZE %u", pSub->selId));
  5764   5749           sqlite3Select(pParse, pSub, &dest);
  5765   5750         }
  5766   5751         pItem->pTab->nRowLogEst = pSub->nSelectRow;
  5767   5752         if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
  5768   5753         retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
  5769   5754         VdbeComment((v, "end %s", pItem->pTab->zName));
  5770   5755         sqlite3VdbeChangeP1(v, topAddr, retAddr);
................................................................................
  5936   5921         int iBreak = sqlite3VdbeMakeLabel(v);
  5937   5922         int regGosub = ++pParse->nMem;
  5938   5923   
  5939   5924         sqlite3WindowCodeStep(pParse, p, pWInfo, regGosub, addrGosub);
  5940   5925   
  5941   5926         sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
  5942   5927         sqlite3VdbeResolveLabel(v, addrGosub);
  5943         -      VdbeNoopComment((v, "SELECT inner-loop subroutine"));
         5928  +      VdbeNoopComment((v, "inner-loop subroutine"));
  5944   5929         selectInnerLoop(pParse, p, -1, &sSort, &sDistinct, pDest, iCont, iBreak);
  5945   5930         sqlite3VdbeResolveLabel(v, iCont);
  5946   5931         sqlite3VdbeAddOp1(v, OP_Return, regGosub);
  5947   5932         VdbeComment((v, "end inner-loop subroutine"));
  5948   5933         sqlite3VdbeResolveLabel(v, iBreak);
  5949   5934       }else
  5950   5935   #endif /* SQLITE_OMIT_WINDOWFUNC */

Changes to src/sqliteInt.h.

  1580   1580   #define SQLITE_OmitNoopJoin   0x0100   /* Omit unused tables in joins */
  1581   1581   #define SQLITE_CountOfView    0x0200   /* The count-of-view optimization */
  1582   1582   #define SQLITE_CursorHints    0x0400   /* Add OP_CursorHint opcodes */
  1583   1583   #define SQLITE_Stat34         0x0800   /* Use STAT3 or STAT4 data */
  1584   1584      /* TH3 expects the Stat34  ^^^^^^ value to be 0x0800.  Don't change it */
  1585   1585   #define SQLITE_PushDown       0x1000   /* The push-down optimization */
  1586   1586   #define SQLITE_SimplifyJoin   0x2000   /* Convert LEFT JOIN to JOIN */
         1587  +#define SQLITE_SkipScan       0x4000   /* Skip-scans */
  1587   1588   #define SQLITE_AllOpts        0xffff   /* All optimizations */
  1588   1589   
  1589   1590   /*
  1590   1591   ** Macros for testing whether or not optimizations are enabled or disabled.
  1591   1592   */
  1592   1593   #define OptimizationDisabled(db, mask)  (((db)->dbOptFlags&(mask))!=0)
  1593   1594   #define OptimizationEnabled(db, mask)   (((db)->dbOptFlags&(mask))==0)
................................................................................
  2805   2806   */
  2806   2807   struct Select {
  2807   2808     ExprList *pEList;      /* The fields of the result */
  2808   2809     u8 op;                 /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
  2809   2810     LogEst nSelectRow;     /* Estimated number of result rows */
  2810   2811     u32 selFlags;          /* Various SF_* values */
  2811   2812     int iLimit, iOffset;   /* Memory registers holding LIMIT & OFFSET counters */
  2812         -#if SELECTTRACE_ENABLED
  2813         -  char zSelName[12];     /* Symbolic name of this SELECT use for debugging */
  2814         -#endif
         2813  +  u32 selId;             /* Unique identifier number for this SELECT */
  2815   2814     int addrOpenEphm[2];   /* OP_OpenEphem opcodes related to this select */
  2816   2815     SrcList *pSrc;         /* The FROM clause */
  2817   2816     Expr *pWhere;          /* The WHERE clause */
  2818   2817     ExprList *pGroupBy;    /* The GROUP BY clause */
  2819   2818     Expr *pHaving;         /* The HAVING clause */
  2820   2819     ExprList *pOrderBy;    /* The ORDER BY clause */
  2821   2820     Select *pPrior;        /* Prior select in a compound select statement */
................................................................................
  3068   3067     ExprList *pConstExpr;/* Constant expressions */
  3069   3068     Token constraintName;/* Name of the constraint currently being parsed */
  3070   3069     yDbMask writeMask;   /* Start a write transaction on these databases */
  3071   3070     yDbMask cookieMask;  /* Bitmask of schema verified databases */
  3072   3071     int regRowid;        /* Register holding rowid of CREATE TABLE entry */
  3073   3072     int regRoot;         /* Register holding root page number for new objects */
  3074   3073     int nMaxArg;         /* Max args passed to user function by sub-program */
  3075         -#if SELECTTRACE_ENABLED
  3076         -  int nSelect;         /* Number of SELECT statements seen */
  3077         -#endif
         3074  +  int nSelect;         /* Number of SELECT stmts. Counter for Select.selId */
  3078   3075   #ifndef SQLITE_OMIT_SHARED_CACHE
  3079   3076     int nTableLock;        /* Number of locks in aTableLock */
  3080   3077     TableLock *aTableLock; /* Required table locks for shared-cache mode */
  3081   3078   #endif
  3082   3079     AutoincInfo *pAinc;  /* Information about AUTOINCREMENT counters */
  3083   3080     Parse *pToplevel;    /* Parse structure for main program (or NULL) */
  3084   3081     Table *pTriggerTab;  /* Table triggers are being coded for */
................................................................................
  3384   3381     void(*xSqllog)(void*,sqlite3*,const char*, int);
  3385   3382     void *pSqllogArg;
  3386   3383   #endif
  3387   3384   #ifdef SQLITE_VDBE_COVERAGE
  3388   3385     /* The following callback (if not NULL) is invoked on every VDBE branch
  3389   3386     ** operation.  Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
  3390   3387     */
  3391         -  void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx);  /* Callback */
         3388  +  void (*xVdbeBranch)(void*,unsigned iSrcLine,u8 eThis,u8 eMx);  /* Callback */
  3392   3389     void *pVdbeBranchArg;                                     /* 1st argument */
  3393   3390   #endif
  3394   3391   #ifndef SQLITE_UNTESTABLE
  3395   3392     int (*xTestCallback)(int);        /* Invoked by sqlite3FaultSim() */
  3396   3393   #endif
  3397   3394     int bLocaltimeFault;              /* True to fail localtime() calls */
  3398   3395     int iOnceResetThreshold;          /* When to reset OP_Once counters */
................................................................................
  3516   3513     u8 eStart;              /* UNBOUNDED, CURRENT, PRECEDING or FOLLOWING */
  3517   3514     u8 eEnd;                /* UNBOUNDED, CURRENT, PRECEDING or FOLLOWING */
  3518   3515     Expr *pStart;           /* Expression for "<expr> PRECEDING" */
  3519   3516     Expr *pEnd;             /* Expression for "<expr> FOLLOWING" */
  3520   3517     Window *pNextWin;       /* Next window function belonging to this SELECT */
  3521   3518     Expr *pFilter;          /* The FILTER expression */
  3522   3519     FuncDef *pFunc;         /* The function */
  3523         -  int iEphCsr;            /* Temp table used by this window */
         3520  +  int iEphCsr;            /* Partition buffer or Peer buffer */
  3524   3521     int regAccum;
  3525   3522     int regResult;
  3526   3523     int csrApp;             /* Function cursor (used by min/max) */
  3527   3524     int regApp;             /* Function register (also used by min/max) */
  3528   3525     int regPart;            /* First in a set of registers holding PARTITION BY
  3529   3526                             ** and ORDER BY values for the window */
  3530   3527     Expr *pOwner;           /* Expression object this window is attached to */
................................................................................
  4021   4018   void sqlite3UniqueConstraint(Parse*, int, Index*);
  4022   4019   void sqlite3RowidConstraint(Parse*, int, Table*);
  4023   4020   Expr *sqlite3ExprDup(sqlite3*,Expr*,int);
  4024   4021   ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int);
  4025   4022   SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int);
  4026   4023   IdList *sqlite3IdListDup(sqlite3*,IdList*);
  4027   4024   Select *sqlite3SelectDup(sqlite3*,Select*,int);
  4028         -#if SELECTTRACE_ENABLED
  4029         -void sqlite3SelectSetName(Select*,const char*);
  4030         -#else
  4031         -# define sqlite3SelectSetName(A,B)
  4032         -#endif
  4033   4025   void sqlite3InsertBuiltinFuncs(FuncDef*,int);
  4034   4026   FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,u8,u8);
  4035   4027   void sqlite3RegisterBuiltinFunctions(void);
  4036   4028   void sqlite3RegisterDateTimeFunctions(void);
  4037   4029   void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3*);
  4038   4030   int sqlite3SafetyCheckOk(sqlite3*);
  4039   4031   int sqlite3SafetyCheckSickOrOk(sqlite3*);

Changes to src/test1.c.

  6950   6950       { "distinct-opt",        SQLITE_DistinctOpt    },
  6951   6951       { "cover-idx-scan",      SQLITE_CoverIdxScan   },
  6952   6952       { "order-by-idx-join",   SQLITE_OrderByIdxJoin },
  6953   6953       { "transitive",          SQLITE_Transitive     },
  6954   6954       { "omit-noop-join",      SQLITE_OmitNoopJoin   },
  6955   6955       { "stat3",               SQLITE_Stat34         },
  6956   6956       { "stat4",               SQLITE_Stat34         },
         6957  +    { "skip-scan",           SQLITE_SkipScan       },
  6957   6958     };
  6958   6959   
  6959   6960     if( objc!=4 ){
  6960   6961       Tcl_WrongNumArgs(interp, 1, objv, "DB OPT BOOLEAN");
  6961   6962       return TCL_ERROR;
  6962   6963     }
  6963   6964     if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;

Changes to src/treeview.c.

   135    135     pView = sqlite3TreeViewPush(pView, moreToFollow);
   136    136     if( p->pWith ){
   137    137       sqlite3TreeViewWith(pView, p->pWith, 1);
   138    138       cnt = 1;
   139    139       sqlite3TreeViewPush(pView, 1);
   140    140     }
   141    141     do{
   142         -#if SELECTTRACE_ENABLED
   143    142       sqlite3TreeViewLine(pView,
   144         -      "SELECT%s%s (%s/%p) selFlags=0x%x nSelectRow=%d",
          143  +      "SELECT%s%s (%u/%p) selFlags=0x%x nSelectRow=%d",
   145    144         ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
   146    145         ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""),
   147         -      p->zSelName, p, p->selFlags,
          146  +      p->selId, p, p->selFlags,
   148    147         (int)p->nSelectRow
   149    148       );
   150         -#else
   151         -    sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x nSelectRow=%d",
   152         -      ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
   153         -      ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags,
   154         -      (int)p->nSelectRow
   155         -    );
   156         -#endif
   157    149       if( cnt++ ) sqlite3TreeViewPop(pView);
   158    150       if( p->pPrior ){
   159    151         n = 1000;
   160    152       }else{
   161    153         n = 0;
   162    154         if( p->pSrc && p->pSrc->nSrc ) n++;
   163    155         if( p->pWhere ) n++;

Changes to src/update.c.

   519    519       }
   520    520     
   521    521       /* Top of the update loop */
   522    522       if( eOnePass!=ONEPASS_OFF ){
   523    523         if( !isView && aiCurOnePass[0]!=iDataCur && aiCurOnePass[1]!=iDataCur ){
   524    524           assert( pPk );
   525    525           sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey,nKey);
   526         -        VdbeCoverageNeverTaken(v);
          526  +        VdbeCoverage(v);
   527    527         }
   528    528         if( eOnePass!=ONEPASS_SINGLE ){
   529    529           labelContinue = sqlite3VdbeMakeLabel(v);
   530    530         }
   531    531         sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
   532    532         VdbeCoverageIf(v, pPk==0);
   533    533         VdbeCoverageIf(v, pPk!=0);

Changes to src/vdbe.c.

   130    130   #endif
   131    131   
   132    132   /*
   133    133   ** Invoke the VDBE coverage callback, if that callback is defined.  This
   134    134   ** feature is used for test suite validation only and does not appear an
   135    135   ** production builds.
   136    136   **
   137         -** M is an integer, 2 or 3, that indices how many different ways the
   138         -** branch can go.  It is usually 2.  "I" is the direction the branch
   139         -** goes.  0 means falls through.  1 means branch is taken.  2 means the
   140         -** second alternative branch is taken.
          137  +** M is an integer between 2 and 4.  2 indicates a ordinary two-way
          138  +** branch (I=0 means fall through and I=1 means taken).  3 indicates
          139  +** a 3-way branch where the third way is when one of the operands is
          140  +** NULL.  4 indicates the OP_Jump instruction which has three destinations
          141  +** depending on whether the first operand is less than, equal to, or greater
          142  +** than the second. 
   141    143   **
   142    144   ** iSrcLine is the source code line (from the __LINE__ macro) that
   143         -** generated the VDBE instruction.  This instrumentation assumes that all
   144         -** source code is in a single file (the amalgamation).  Special values 1
   145         -** and 2 for the iSrcLine parameter mean that this particular branch is
   146         -** always taken or never taken, respectively.
          145  +** generated the VDBE instruction combined with flag bits.  The source
          146  +** code line number is in the lower 24 bits of iSrcLine and the upper
          147  +** 8 bytes are flags.  The lower three bits of the flags indicate
          148  +** values for I that should never occur.  For example, if the branch is
          149  +** always taken, the flags should be 0x05 since the fall-through and
          150  +** alternate branch are never taken.  If a branch is never taken then
          151  +** flags should be 0x06 since only the fall-through approach is allowed.
          152  +**
          153  +** Bit 0x04 of the flags indicates an OP_Jump opcode that is only
          154  +** interested in equal or not-equal.  In other words, I==0 and I==2
          155  +** should be treated the same.
          156  +**
          157  +** Since only a line number is retained, not the filename, this macro
          158  +** only works for amalgamation builds.  But that is ok, since these macros
          159  +** should be no-ops except for special builds used to measure test coverage.
   147    160   */
   148    161   #if !defined(SQLITE_VDBE_COVERAGE)
   149    162   # define VdbeBranchTaken(I,M)
   150    163   #else
   151    164   # define VdbeBranchTaken(I,M) vdbeTakeBranch(pOp->iSrcLine,I,M)
   152         -  static void vdbeTakeBranch(int iSrcLine, u8 I, u8 M){
   153         -    if( iSrcLine<=2 && ALWAYS(iSrcLine>0) ){
   154         -      M = iSrcLine;
   155         -      /* Assert the truth of VdbeCoverageAlwaysTaken() and 
   156         -      ** VdbeCoverageNeverTaken() */
   157         -      assert( (M & I)==I );
   158         -    }else{
   159         -      if( sqlite3GlobalConfig.xVdbeBranch==0 ) return;  /*NO_TEST*/
   160         -      sqlite3GlobalConfig.xVdbeBranch(sqlite3GlobalConfig.pVdbeBranchArg,
   161         -                                      iSrcLine,I,M);
          165  +  static void vdbeTakeBranch(u32 iSrcLine, u8 I, u8 M){
          166  +    u8 mNever;
          167  +    assert( I<=2 );  /* 0: fall through,  1: taken,  2: alternate taken */
          168  +    assert( M<=4 );  /* 2: two-way branch, 3: three-way branch, 4: OP_Jump */
          169  +    assert( I<M );   /* I can only be 2 if M is 3 or 4 */
          170  +    /* Transform I from a integer [0,1,2] into a bitmask of [1,2,4] */
          171  +    I = 1<<I;
          172  +    /* The upper 8 bits of iSrcLine are flags.  The lower three bits of
          173  +    ** the flags indicate directions that the branch can never go.  If
          174  +    ** a branch really does go in one of those directions, assert right
          175  +    ** away. */
          176  +    mNever = iSrcLine >> 24;
          177  +    assert( (I & mNever)==0 );
          178  +    if( sqlite3GlobalConfig.xVdbeBranch==0 ) return;  /*NO_TEST*/
          179  +    I |= mNever;
          180  +    if( M==2 ) I |= 0x04;
          181  +    if( M==4 ){
          182  +      I |= 0x08;
          183  +      if( (mNever&0x08)!=0 && (I&0x05)!=0) I |= 0x05; /*NO_TEST*/
   162    184       }
          185  +    sqlite3GlobalConfig.xVdbeBranch(sqlite3GlobalConfig.pVdbeBranchArg,
          186  +                                    iSrcLine&0xffffff, I, M);
   163    187     }
   164    188   #endif
   165    189   
   166    190   /*
   167    191   ** Convert the given register into a string if it isn't one
   168    192   ** already. Return non-zero if a malloc() fails.
   169    193   */
................................................................................
  2158   2182   **
  2159   2183   ** Jump to the instruction at address P1, P2, or P3 depending on whether
  2160   2184   ** in the most recent OP_Compare instruction the P1 vector was less than
  2161   2185   ** equal to, or greater than the P2 vector, respectively.
  2162   2186   */
  2163   2187   case OP_Jump: {             /* jump */
  2164   2188     if( iCompare<0 ){
  2165         -    VdbeBranchTaken(0,3); pOp = &aOp[pOp->p1 - 1];
         2189  +    VdbeBranchTaken(0,4); pOp = &aOp[pOp->p1 - 1];
  2166   2190     }else if( iCompare==0 ){
  2167         -    VdbeBranchTaken(1,3); pOp = &aOp[pOp->p2 - 1];
         2191  +    VdbeBranchTaken(1,4); pOp = &aOp[pOp->p2 - 1];
  2168   2192     }else{
  2169         -    VdbeBranchTaken(2,3); pOp = &aOp[pOp->p3 - 1];
         2193  +    VdbeBranchTaken(2,4); pOp = &aOp[pOp->p3 - 1];
  2170   2194     }
  2171   2195     break;
  2172   2196   }
  2173   2197   
  2174   2198   /* Opcode: And P1 P2 P3 * *
  2175   2199   ** Synopsis: r[P3]=(r[P1] && r[P2])
  2176   2200   **

Changes to src/vdbe.h.

    69     69     char *zComment;          /* Comment to improve readability */
    70     70   #endif
    71     71   #ifdef VDBE_PROFILE
    72     72     u32 cnt;                 /* Number of times this instruction was executed */
    73     73     u64 cycles;              /* Total time spent executing this instruction */
    74     74   #endif
    75     75   #ifdef SQLITE_VDBE_COVERAGE
    76         -  int iSrcLine;            /* Source-code line that generated this opcode */
           76  +  u32 iSrcLine;            /* Source-code line that generated this opcode
           77  +                           ** with flags in the upper 8 bits */
    77     78   #endif
    78     79   };
    79     80   typedef struct VdbeOp VdbeOp;
    80     81   
    81     82   
    82     83   /*
    83     84   ** A sub-routine used to implement a trigger program.
................................................................................
   313    314   **
   314    315   **    VdbeCoverageIf(v, conditional)   // Mark previous if conditional true
   315    316   **
   316    317   **    VdbeCoverageAlwaysTaken(v)       // Previous branch is always taken
   317    318   **
   318    319   **    VdbeCoverageNeverTaken(v)        // Previous branch is never taken
   319    320   **
          321  +**    VdbeCoverageNeverNull(v)         // Previous three-way branch is only
          322  +**                                     // taken on the first two ways.  The
          323  +**                                     // NULL option is not possible
          324  +**
          325  +**    VdbeCoverageEqNe(v)              // Previous OP_Jump is only interested
          326  +**                                     // in distingishing equal and not-equal.
          327  +**
   320    328   ** Every VDBE branch operation must be tagged with one of the macros above.
   321    329   ** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and
   322    330   ** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
   323    331   ** routine in vdbe.c, alerting the developer to the missed tag.
          332  +**
          333  +** During testing, the test application will invoke
          334  +** sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE,...) to set a callback
          335  +** routine that is invoked as each bytecode branch is taken.  The callback
          336  +** contains the sqlite3.c source line number ov the VdbeCoverage macro and
          337  +** flags to indicate whether or not the branch was taken.  The test application
          338  +** is responsible for keeping track of this and reporting byte-code branches
          339  +** that are never taken.
          340  +**
          341  +** See the VdbeBranchTaken() macro and vdbeTakeBranch() function in the
          342  +** vdbe.c source file for additional information.
   324    343   */
   325    344   #ifdef SQLITE_VDBE_COVERAGE
   326    345     void sqlite3VdbeSetLineNumber(Vdbe*,int);
   327    346   # define VdbeCoverage(v) sqlite3VdbeSetLineNumber(v,__LINE__)
   328    347   # define VdbeCoverageIf(v,x) if(x)sqlite3VdbeSetLineNumber(v,__LINE__)
   329         -# define VdbeCoverageAlwaysTaken(v) sqlite3VdbeSetLineNumber(v,2);
   330         -# define VdbeCoverageNeverTaken(v) sqlite3VdbeSetLineNumber(v,1);
          348  +# define VdbeCoverageAlwaysTaken(v) \
          349  +         sqlite3VdbeSetLineNumber(v,__LINE__|0x5000000);
          350  +# define VdbeCoverageNeverTaken(v) \
          351  +         sqlite3VdbeSetLineNumber(v,__LINE__|0x6000000);
          352  +# define VdbeCoverageNeverNull(v) \
          353  +         sqlite3VdbeSetLineNumber(v,__LINE__|0x4000000);
          354  +# define VdbeCoverageNeverNullIf(v,x) \
          355  +         if(x)sqlite3VdbeSetLineNumber(v,__LINE__|0x4000000);
          356  +# define VdbeCoverageEqNe(v) \
          357  +         sqlite3VdbeSetLineNumber(v,__LINE__|0x8000000);
   331    358   # define VDBE_OFFSET_LINENO(x) (__LINE__+x)
   332    359   #else
   333    360   # define VdbeCoverage(v)
   334    361   # define VdbeCoverageIf(v,x)
   335    362   # define VdbeCoverageAlwaysTaken(v)
   336    363   # define VdbeCoverageNeverTaken(v)
          364  +# define VdbeCoverageNeverNull(v)
          365  +# define VdbeCoverageNeverNullIf(v,x)
          366  +# define VdbeCoverageEqNe(v)
   337    367   # define VDBE_OFFSET_LINENO(x) 0
   338    368   #endif
   339    369   
   340    370   #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
   341    371   void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*);
   342    372   #else
   343    373   # define sqlite3VdbeScanStatus(a,b,c,d,e)

Changes to src/where.c.

   806    806     pTabItem = &pWC->pWInfo->pTabList->a[pLevel->iFrom];
   807    807     if( pTabItem->fg.viaCoroutine ){
   808    808       int regYield = pTabItem->regReturn;
   809    809       addrCounter = sqlite3VdbeAddOp2(v, OP_Integer, 0, 0);
   810    810       sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
   811    811       addrTop =  sqlite3VdbeAddOp1(v, OP_Yield, regYield);
   812    812       VdbeCoverage(v);
   813         -    VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
          813  +    VdbeComment((v, "next row of %s", pTabItem->pTab->zName));
   814    814     }else{
   815    815       addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
   816    816     }
   817    817     if( pPartial ){
   818    818       iContinue = sqlite3VdbeMakeLabel(v);
   819    819       sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL);
   820    820       pLoop->wsFlags |= WHERE_PARTIALIDX;
................................................................................
  2668   2668     ** the code). And, even if it is not, it should not be too much slower. 
  2669   2669     ** On the other hand, the extra seeks could end up being significantly
  2670   2670     ** more expensive.  */
  2671   2671     assert( 42==sqlite3LogEst(18) );
  2672   2672     if( saved_nEq==saved_nSkip
  2673   2673      && saved_nEq+1<pProbe->nKeyCol
  2674   2674      && pProbe->noSkipScan==0
         2675  +   && OptimizationEnabled(db, SQLITE_SkipScan)
  2675   2676      && pProbe->aiRowLogEst[saved_nEq+1]>=42  /* TUNING: Minimum for skip-scan */
  2676   2677      && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
  2677   2678     ){
  2678   2679       LogEst nIter;
  2679   2680       pNew->u.btree.nEq++;
  2680   2681       pNew->nSkip++;
  2681   2682       pNew->aLTerm[pNew->nLTerm++] = 0;

Changes to src/wherecode.c.

   146    146       isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
   147    147               || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
   148    148               || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
   149    149   
   150    150       sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
   151    151       sqlite3_str_appendall(&str, isSearch ? "SEARCH" : "SCAN");
   152    152       if( pItem->pSelect ){
   153         -      sqlite3_str_appendf(&str, " SUBQUERY 0x%p", pItem->pSelect);
          153  +      sqlite3_str_appendf(&str, " SUBQUERY %u", pItem->pSelect->selId);
   154    154       }else{
   155    155         sqlite3_str_appendf(&str, " TABLE %s", pItem->zName);
   156    156       }
   157    157   
   158    158       if( pItem->zAlias ){
   159    159         sqlite3_str_appendf(&str, " AS %s", pItem->zAlias);
   160    160       }
................................................................................
  1238   1238   
  1239   1239     /* Special case of a FROM clause subquery implemented as a co-routine */
  1240   1240     if( pTabItem->fg.viaCoroutine ){
  1241   1241       int regYield = pTabItem->regReturn;
  1242   1242       sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
  1243   1243       pLevel->p2 =  sqlite3VdbeAddOp2(v, OP_Yield, regYield, addrBrk);
  1244   1244       VdbeCoverage(v);
  1245         -    VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
         1245  +    VdbeComment((v, "next row of %s", pTabItem->pTab->zName));
  1246   1246       pLevel->op = OP_Goto;
  1247   1247     }else
  1248   1248   
  1249   1249   #ifndef SQLITE_OMIT_VIRTUALTABLE
  1250   1250     if(  (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
  1251   1251       /* Case 1:  The table is a virtual-table.  Use the VFilter and VNext
  1252   1252       **          to access the data.

Changes to src/window.c.

   585    585   /*
   586    586   ** Context object passed through sqlite3WalkExprList() to
   587    587   ** selectWindowRewriteExprCb() by selectWindowRewriteEList().
   588    588   */
   589    589   typedef struct WindowRewrite WindowRewrite;
   590    590   struct WindowRewrite {
   591    591     Window *pWin;
          592  +  SrcList *pSrc;
   592    593     ExprList *pSub;
          594  +  Select *pSubSelect;             /* Current sub-select, if any */
   593    595   };
   594    596   
   595    597   /*
   596    598   ** Callback function used by selectWindowRewriteEList(). If necessary,
   597    599   ** this function appends to the output expression-list and updates 
   598    600   ** expression (*ppExpr) in place.
   599    601   */
   600    602   static int selectWindowRewriteExprCb(Walker *pWalker, Expr *pExpr){
   601    603     struct WindowRewrite *p = pWalker->u.pRewrite;
   602    604     Parse *pParse = pWalker->pParse;
          605  +
          606  +  /* If this function is being called from within a scalar sub-select
          607  +  ** that used by the SELECT statement being processed, only process
          608  +  ** TK_COLUMN expressions that refer to it (the outer SELECT). Do
          609  +  ** not process aggregates or window functions at all, as they belong
          610  +  ** to the scalar sub-select.  */
          611  +  if( p->pSubSelect ){
          612  +    if( pExpr->op!=TK_COLUMN ){
          613  +      return WRC_Continue;
          614  +    }else{
          615  +      int nSrc = p->pSrc->nSrc;
          616  +      int i;
          617  +      for(i=0; i<nSrc; i++){
          618  +        if( pExpr->iTable==p->pSrc->a[i].iCursor ) break;
          619  +      }
          620  +      if( i==nSrc ) return WRC_Continue;
          621  +    }
          622  +  }
   603    623   
   604    624     switch( pExpr->op ){
   605    625   
   606    626       case TK_FUNCTION:
   607    627         if( pExpr->pWin==0 ){
   608    628           break;
   609    629         }else{
................................................................................
   639    659       default: /* no-op */
   640    660         break;
   641    661     }
   642    662   
   643    663     return WRC_Continue;
   644    664   }
   645    665   static int selectWindowRewriteSelectCb(Walker *pWalker, Select *pSelect){
   646         -  UNUSED_PARAMETER(pWalker);
   647         -  UNUSED_PARAMETER(pSelect);
          666  +  struct WindowRewrite *p = pWalker->u.pRewrite;
          667  +  Select *pSave = p->pSubSelect;
          668  +  if( pSave==pSelect ){
          669  +    return WRC_Continue;
          670  +  }else{
          671  +    p->pSubSelect = pSelect;
          672  +    sqlite3WalkSelect(pWalker, pSelect);
          673  +    p->pSubSelect = pSave;
          674  +  }
   648    675     return WRC_Prune;
   649    676   }
   650    677   
   651    678   
   652    679   /*
   653    680   ** Iterate through each expression in expression-list pEList. For each:
   654    681   **
   655    682   **   * TK_COLUMN,
   656    683   **   * aggregate function, or
   657    684   **   * window function with a Window object that is not a member of the 
   658         -**     linked list passed as the second argument (pWin)
          685  +**     Window list passed as the second argument (pWin).
   659    686   **
   660    687   ** Append the node to output expression-list (*ppSub). And replace it
   661    688   ** with a TK_COLUMN that reads the (N-1)th element of table 
   662    689   ** pWin->iEphCsr, where N is the number of elements in (*ppSub) after
   663    690   ** appending the new one.
   664    691   */
   665    692   static void selectWindowRewriteEList(
   666    693     Parse *pParse, 
   667    694     Window *pWin,
          695  +  SrcList *pSrc,
   668    696     ExprList *pEList,               /* Rewrite expressions in this list */
   669    697     ExprList **ppSub                /* IN/OUT: Sub-select expression-list */
   670    698   ){
   671    699     Walker sWalker;
   672    700     WindowRewrite sRewrite;
   673    701   
   674    702     memset(&sWalker, 0, sizeof(Walker));
   675    703     memset(&sRewrite, 0, sizeof(WindowRewrite));
   676    704   
   677    705     sRewrite.pSub = *ppSub;
   678    706     sRewrite.pWin = pWin;
          707  +  sRewrite.pSrc = pSrc;
   679    708   
   680    709     sWalker.pParse = pParse;
   681    710     sWalker.xExprCallback = selectWindowRewriteExprCb;
   682    711     sWalker.xSelectCallback = selectWindowRewriteSelectCb;
   683    712     sWalker.u.pRewrite = &sRewrite;
   684    713   
   685    714     (void)sqlite3WalkExprList(&sWalker, pEList);
................................................................................
   749    778       }
   750    779   
   751    780       /* Assign a cursor number for the ephemeral table used to buffer rows.
   752    781       ** The OpenEphemeral instruction is coded later, after it is known how
   753    782       ** many columns the table will have.  */
   754    783       pMWin->iEphCsr = pParse->nTab++;
   755    784   
   756         -    selectWindowRewriteEList(pParse, pMWin, p->pEList, &pSublist);
   757         -    selectWindowRewriteEList(pParse, pMWin, p->pOrderBy, &pSublist);
          785  +    selectWindowRewriteEList(pParse, pMWin, pSrc, p->pEList, &pSublist);
          786  +    selectWindowRewriteEList(pParse, pMWin, pSrc, p->pOrderBy, &pSublist);
   758    787       pMWin->nBufferCol = (pSublist ? pSublist->nExpr : 0);
   759    788   
   760    789       /* Append the PARTITION BY and ORDER BY expressions to the to the 
   761    790       ** sub-select expression list. They are required to figure out where 
   762    791       ** boundaries for partitions and sets of peer rows lie.  */
   763    792       pSublist = exprListAppendList(pParse, pSublist, pMWin->pPartition);
   764    793       pSublist = exprListAppendList(pParse, pSublist, pMWin->pOrderBy);
................................................................................
  1034   1063     assert( eCond==0 || eCond==1 || eCond==2 );
  1035   1064     sqlite3VdbeAddOp2(v, OP_Integer, 0, regZero);
  1036   1065     sqlite3VdbeAddOp2(v, OP_MustBeInt, reg, sqlite3VdbeCurrentAddr(v)+2);
  1037   1066     VdbeCoverageIf(v, eCond==0);
  1038   1067     VdbeCoverageIf(v, eCond==1);
  1039   1068     VdbeCoverageIf(v, eCond==2);
  1040   1069     sqlite3VdbeAddOp3(v, aOp[eCond], regZero, sqlite3VdbeCurrentAddr(v)+2, reg);
  1041         -  VdbeCoverageIf(v, eCond==0);
  1042         -  VdbeCoverageIf(v, eCond==1);
  1043         -  VdbeCoverageIf(v, eCond==2);
         1070  +  VdbeCoverageNeverNullIf(v, eCond==0);
         1071  +  VdbeCoverageNeverNullIf(v, eCond==1);
         1072  +  VdbeCoverageNeverNullIf(v, eCond==2);
  1044   1073     sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_ERROR, OE_Abort);
  1045   1074     sqlite3VdbeAppendP4(v, (void*)azErr[eCond], P4_STATIC);
  1046   1075     sqlite3ReleaseTempReg(pParse, regZero);
  1047   1076   }
  1048   1077   
  1049   1078   /*
  1050   1079   ** Return the number of arguments passed to the window-function associated
................................................................................
  1116   1145         if( bInverse==0 ){
  1117   1146           sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1, 1);
  1118   1147           sqlite3VdbeAddOp2(v, OP_SCopy, regArg, pWin->regApp);
  1119   1148           sqlite3VdbeAddOp3(v, OP_MakeRecord, pWin->regApp, 2, pWin->regApp+2);
  1120   1149           sqlite3VdbeAddOp2(v, OP_IdxInsert, pWin->csrApp, pWin->regApp+2);
  1121   1150         }else{
  1122   1151           sqlite3VdbeAddOp4Int(v, OP_SeekGE, pWin->csrApp, 0, regArg, 1);
  1123         -        VdbeCoverage(v);
         1152  +        VdbeCoverageNeverTaken(v);
  1124   1153           sqlite3VdbeAddOp1(v, OP_Delete, pWin->csrApp);
  1125   1154           sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
  1126   1155         }
  1127   1156         sqlite3VdbeJumpHere(v, addrIsNull);
  1128   1157       }else if( pWin->regApp ){
  1129   1158         assert( pWin->pFunc->zName==nth_valueName
  1130   1159              || pWin->pFunc->zName==first_valueName
................................................................................
  1228   1257     int reg = pParse->nMem+1;
  1229   1258     int regRecord = reg+nSub;
  1230   1259     int regRowid = regRecord+1;
  1231   1260   
  1232   1261     *pRegSize = regRowid;
  1233   1262     pParse->nMem += nSub + 2;
  1234   1263   
  1235         -  /* Martial the row returned by the sub-select into an array of 
  1236         -  ** registers. */
         1264  +  /* Load the column values for the row returned by the sub-select
         1265  +  ** into an array of registers starting at reg. */
  1237   1266     for(k=0; k<nSub; k++){
  1238   1267       sqlite3VdbeAddOp3(v, OP_Column, iSubCsr, k, reg+k);
  1239   1268     }
  1240   1269     sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, nSub, regRecord);
  1241   1270   
  1242   1271     /* Check if this is the start of a new partition. If so, call the
  1243   1272     ** flush_partition sub-routine.  */
................................................................................
  1247   1276       int nPart = pPart->nExpr;
  1248   1277       int regNewPart = reg + pMWin->nBufferCol;
  1249   1278       KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);
  1250   1279   
  1251   1280       addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPart, pMWin->regPart,nPart);
  1252   1281       sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
  1253   1282       sqlite3VdbeAddOp3(v, OP_Jump, addr+2, addr+4, addr+2);
  1254         -    VdbeCoverage(v);
         1283  +    VdbeCoverageEqNe(v);
  1255   1284       sqlite3VdbeAddOp3(v, OP_Copy, regNewPart, pMWin->regPart, nPart-1);
  1256   1285       sqlite3VdbeAddOp2(v, OP_Gosub, regFlushPart, lblFlushPart);
  1257   1286       VdbeComment((v, "call flush_partition"));
  1258   1287     }
  1259   1288   
  1260   1289     /* Buffer the current row in the ephemeral table. */
  1261   1290     sqlite3VdbeAddOp2(v, OP_NewRowid, pMWin->iEphCsr, regRowid);
................................................................................
  1304   1333           sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+1,tmpReg);
  1305   1334           windowCheckIntValue(pParse, tmpReg, 2);
  1306   1335         }else{
  1307   1336           sqlite3VdbeAddOp2(v, OP_Integer, 1, tmpReg);
  1308   1337         }
  1309   1338         sqlite3VdbeAddOp3(v, OP_Add, tmpReg, pWin->regApp, tmpReg);
  1310   1339         sqlite3VdbeAddOp3(v, OP_Gt, pWin->regApp+1, lbl, tmpReg);
  1311         -      VdbeCoverage(v);
  1312         -      sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, lbl, tmpReg);
  1313         -      VdbeCoverage(v);
         1340  +      VdbeCoverageNeverNull(v);
         1341  +      sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, 0, tmpReg);
         1342  +      VdbeCoverageNeverTaken(v);
  1314   1343         sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
  1315   1344         sqlite3VdbeResolveLabel(v, lbl);
  1316   1345         sqlite3ReleaseTempReg(pParse, tmpReg);
  1317   1346       }
  1318   1347       else if( pFunc->zName==leadName || pFunc->zName==lagName ){
  1319   1348         int nArg = pWin->pOwner->x.pList->nExpr;
  1320   1349         int iEph = pMWin->iEphCsr;
................................................................................
  1617   1646     **   }
  1618   1647     **   regEnd = regEnd - regStart;
  1619   1648     */
  1620   1649     if( pMWin->pEnd && pMWin->eStart==TK_FOLLOWING ){
  1621   1650       assert( pMWin->pStart!=0 );
  1622   1651       assert( pMWin->eEnd==TK_FOLLOWING );
  1623   1652       sqlite3VdbeAddOp3(v, OP_Ge, regStart, sqlite3VdbeCurrentAddr(v)+2, regEnd);
  1624         -    VdbeCoverage(v);
         1653  +    VdbeCoverageNeverNull(v);
  1625   1654       sqlite3VdbeAddOp2(v, OP_Copy, regSize, regStart);
  1626   1655       sqlite3VdbeAddOp3(v, OP_Subtract, regStart, regEnd, regEnd);
  1627   1656     }
  1628   1657   
  1629   1658     if( pMWin->pStart && pMWin->eEnd==TK_PRECEDING ){
  1630   1659       assert( pMWin->pEnd!=0 );
  1631   1660       assert( pMWin->eStart==TK_PRECEDING );
  1632   1661       sqlite3VdbeAddOp3(v, OP_Le, regStart, sqlite3VdbeCurrentAddr(v)+3, regEnd);
  1633         -    VdbeCoverage(v);
         1662  +    VdbeCoverageNeverNull(v);
  1634   1663       sqlite3VdbeAddOp2(v, OP_Copy, regSize, regStart);
  1635   1664       sqlite3VdbeAddOp2(v, OP_Copy, regSize, regEnd);
  1636   1665     }
  1637   1666   
  1638   1667     /* Initialize the accumulator register for each window function to NULL */
  1639   1668     regArg = windowInitAccum(pParse, pMWin);
  1640   1669   
................................................................................
  1698   1727       }
  1699   1728       if( pMWin->eStart==TK_FOLLOWING ){
  1700   1729         sqlite3VdbeAddOp2(v, OP_Next, csrStart, sqlite3VdbeCurrentAddr(v)+2);
  1701   1730         VdbeCoverage(v);
  1702   1731         sqlite3VdbeAddOp2(v, OP_Goto, 0, lblSkipInverse);
  1703   1732       }else{
  1704   1733         sqlite3VdbeAddOp2(v, OP_Next, csrStart, sqlite3VdbeCurrentAddr(v)+1);
  1705         -      VdbeCoverage(v);
         1734  +      VdbeCoverageAlwaysTaken(v);
  1706   1735       }
  1707   1736       windowAggStep(pParse, pMWin, csrStart, 1, regArg, regSize);
  1708   1737       sqlite3VdbeResolveLabel(v, lblSkipInverse);
  1709   1738     }
  1710   1739     if( pMWin->eEnd==TK_FOLLOWING ){
  1711   1740       sqlite3VdbeJumpHere(v, addrIfPos1);
  1712   1741     }
................................................................................
  2001   2030   
  2002   2031     if( pMWin->eEnd==TK_UNBOUNDED ){
  2003   2032       pOrderBy = 0;
  2004   2033     }
  2005   2034   
  2006   2035     pParse->nMem += nSub + 2;
  2007   2036   
  2008         -  /* Martial the row returned by the sub-select into an array of 
  2009         -  ** registers. */
         2037  +  /* Load the individual column values of the row returned by
         2038  +  ** the sub-select into an array of registers. */
  2010   2039     for(k=0; k<nSub; k++){
  2011   2040       sqlite3VdbeAddOp3(v, OP_Column, iSubCsr, k, reg+k);
  2012   2041     }
  2013   2042   
  2014   2043     /* Check if this is the start of a new partition or peer group. */
  2015   2044     if( pPart || pOrderBy ){
  2016   2045       int nPart = (pPart ? pPart->nExpr : 0);
................................................................................
  2020   2049   
  2021   2050       if( pPart ){
  2022   2051         int regNewPart = reg + pMWin->nBufferCol;
  2023   2052         KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);
  2024   2053         addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPart, pMWin->regPart,nPart);
  2025   2054         sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
  2026   2055         addrJump = sqlite3VdbeAddOp3(v, OP_Jump, addr+2, 0, addr+2);
  2027         -      VdbeCoverage(v);
         2056  +      VdbeCoverageEqNe(v);
  2028   2057         windowAggFinal(pParse, pMWin, 1);
  2029   2058         if( pOrderBy ){
  2030   2059           addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
  2031   2060         }
  2032   2061       }
  2033   2062   
  2034   2063       if( pOrderBy ){
................................................................................
  2179   2208     ** windowCodeDefaultStep() is the only one of the three functions that
  2180   2209     ** does not cache each partition in a temp table before beginning to
  2181   2210     ** return rows.
  2182   2211     */
  2183   2212     if( pMWin->eType==TK_ROWS 
  2184   2213      && (pMWin->eStart!=TK_UNBOUNDED||pMWin->eEnd!=TK_CURRENT||!pMWin->pOrderBy)
  2185   2214     ){
         2215  +    VdbeModuleComment((pParse->pVdbe, "Begin RowExprStep()"));
  2186   2216       windowCodeRowExprStep(pParse, p, pWInfo, regGosub, addrGosub);
  2187   2217     }else{
  2188   2218       Window *pWin;
  2189   2219       int bCache = 0;               /* True to use CacheStep() */
  2190   2220   
  2191   2221       if( pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_UNBOUNDED ){
  2192   2222         bCache = 1;
................................................................................
  2203   2233             break;
  2204   2234           }
  2205   2235         }
  2206   2236       }
  2207   2237   
  2208   2238       /* Otherwise, call windowCodeDefaultStep().  */
  2209   2239       if( bCache ){
         2240  +      VdbeModuleComment((pParse->pVdbe, "Begin CacheStep()"));
  2210   2241         windowCodeCacheStep(pParse, p, pWInfo, regGosub, addrGosub);
  2211   2242       }else{
         2243  +      VdbeModuleComment((pParse->pVdbe, "Begin DefaultStep()"));
  2212   2244         windowCodeDefaultStep(pParse, p, pWInfo, regGosub, addrGosub);
  2213   2245       }
  2214   2246     }
  2215   2247   }
  2216   2248   
  2217   2249   #endif /* SQLITE_OMIT_WINDOWFUNC */

Changes to test/pg_common.tcl.

    67     67     puts $::fd ""
    68     68   }
    69     69   
    70     70   # Same as [execsql_test], except coerce all results to floating point values
    71     71   # with two decimal points.
    72     72   #
    73     73   proc execsql_float_test {tn sql} {
    74         -  set F "%.2f"
           74  +  set F "%.4f"
           75  +  set T 0.0001
    75     76     set res [execsql $sql]
    76     77     set res2 [list]
    77     78     foreach r $res { 
    78     79       if {$r != ""} { set r [format $F $r] }
    79     80       lappend res2 $r
    80     81     }
    81     82   
    82         -  puts $::fd "do_test $tn {"
    83         -  puts $::fd "  set myres {}"
    84         -  puts $::fd "  foreach r \[db eval {[string trim $sql]}\] {"
    85         -  puts $::fd "    lappend myres \[format $F \[set r\]\]"
    86         -  puts $::fd "  }"
    87         -  puts $::fd "  set myres"
    88         -  puts $::fd "} {$res2}"
    89         -  puts $::fd ""
           83  +  set sql [string trim $sql]
           84  +puts $::fd [subst -nocommands {
           85  +do_test $tn {
           86  +  set myres {}
           87  +  foreach r [db eval {$sql}] {
           88  +    lappend myres [format $F [set r]]
           89  +  }
           90  +  set res2 {$res2}
           91  +  foreach r [set myres] r2 [set res2] {
           92  +    if {[set r]<([set r2]-$T) || [set r]>([set r2]+$T)} {
           93  +      error "list element [set i] does not match: got=[set r] expected=[set r2]"
           94  +    }
           95  +  }
           96  +  set {} {}
           97  +} {}
           98  +}]
    90     99   }
    91    100   
    92    101   proc start_test {name date} {
    93    102     set dir [file dirname $::argv0]
    94    103     set output [file join $dir $name.test]
    95    104     set ::fd [open $output w]
    96    105   puts $::fd [string trimleft "

Changes to test/resetdb.test.

   171    171        PRAGMA page_count;
   172    172        PRAGMA page_size;
   173    173        PRAGMA journal_mode;
   174    174        PRAGMA quick_check;
   175    175     } db2
   176    176   } {0 {1 8192 wal ok}}
   177    177   db2 close
          178  +
          179  +#-------------------------------------------------------------------------
          180  +reset_db
          181  +sqlite3 db2 test.db
          182  +do_execsql_test 600 {
          183  +  PRAGMA journal_mode = wal;
          184  +  CREATE TABLE t1(a);
          185  +  INSERT INTO t1 VALUES(1), (2), (3), (4);
          186  +} {wal}
          187  +
          188  +do_execsql_test -db db2 610 {
          189  +  SELECT * FROM t1
          190  +} {1 2 3 4}
          191  +
          192  +do_test 620 {
          193  +  set res [list]
          194  +  db2 eval {SELECT a FROM t1} {
          195  +    lappend res $a
          196  +    if {$a==3} {
          197  +      sqlite3_db_config db RESET_DB 1
          198  +      db eval VACUUM
          199  +      sqlite3_db_config db RESET_DB 0
          200  +    }
          201  +  }
          202  +
          203  +  set res
          204  +} {1 2 3 4}
          205  +
          206  +do_execsql_test -db db2 630 {
          207  +  SELECT * FROM sqlite_master
          208  +} {}
   178    209   
   179    210   finish_test
   180    211   

Changes to test/selectD.test.

   165    165     SELECT * 
   166    166      FROM t41
   167    167      LEFT JOIN (SELECT count(*) AS cnt, x1.d
   168    168                   FROM (t42 INNER JOIN t43 ON d=g) AS x1
   169    169                  WHERE x1.d>5
   170    170                  GROUP BY x1.d) AS x2
   171    171                     ON t41.b=x2.d;
   172         -} {/*SEARCH SUBQUERY 0x* AS x2 USING AUTOMATIC*/}
          172  +} {/*SEARCH SUBQUERY * AS x2 USING AUTOMATIC*/}
   173    173   
   174    174   finish_test

Changes to test/skipscan1.test.

   333    333     ANALYZE sqlite_master;
   334    334     INSERT INTO sqlite_stat1 VALUES('t9a','t9a_ab','1000000 250000 1');
   335    335     ANALYZE sqlite_master;
   336    336     EXPLAIN QUERY PLAN
   337    337     SELECT * FROM t9a WHERE b IN (SELECT x FROM t9b WHERE y!=5);
   338    338   } {/USING INDEX t9a_ab .ANY.a. AND b=./}
   339    339   
          340  +
          341  +optimization_control db skip-scan 0
          342  +do_execsql_test skipscan1-9.3 {
          343  +  EXPLAIN QUERY PLAN
          344  +  SELECT  * FROM t9a WHERE b IN (SELECT x FROM t9b WHERE y!=5);
          345  +} {/{SCAN TABLE t9a}/}
          346  +optimization_control db skip-scan 1
          347  +
   340    348   finish_test

Changes to test/tester.tcl.

   970    970   proc query_plan_graph {sql} {
   971    971     db eval "EXPLAIN QUERY PLAN $sql" {
   972    972       set dx($id) $detail
   973    973       lappend cx($parent) $id
   974    974     }
   975    975     set a "\n  QUERY PLAN\n"
   976    976     append a [append_graph "  " dx cx 0]
   977         -  return [regsub -all { 0x[A-F0-9]+\y} $a { xxxxxx}]
          977  +  regsub -all { 0x[A-F0-9]+\y} $a { xxxxxx} a
          978  +  regsub -all {(MATERIALIZE|CO-ROUTINE|SUBQUERY) \d+\y} $a {\1 xxxxxx} a
          979  +  return $a
   978    980   }
   979    981   
   980    982   # Helper routine for [query_plan_graph SQL]:
   981    983   #
   982    984   # Output rows of the graph that are children of $level.
   983    985   #
   984    986   #   prefix:  Prepend to every output line

Changes to test/upsert1.test.

   107    107   do_execsql_test upsert1-500 {
   108    108     DROP TABLE t1;
   109    109     CREATE TABLE t1(x INTEGER PRIMARY KEY, y INT UNIQUE);
   110    110     INSERT INTO t1(x,y) SELECT 1,2 WHERE true
   111    111       ON CONFLICT(x) DO UPDATE SET y=max(t1.y,excluded.y) AND true;
   112    112     SELECT * FROM t1;
   113    113   } {1 2}
          114  +
          115  +# 2018-07-11
          116  +# Ticket https://sqlite.org/src/tktview/79cad5e4b2e219dd197242e9e5f4
          117  +# UPSERT leads to a corrupt index.
          118  +#
          119  +do_execsql_test upsert1-600 {
          120  +  DROP TABLE t1;
          121  +  CREATE TABLE t1(b UNIQUE, a INT PRIMARY KEY) WITHOUT ROWID;
          122  +  INSERT OR IGNORE INTO t1(a) VALUES('1') ON CONFLICT(a) DO NOTHING;
          123  +  PRAGMA integrity_check;
          124  +} {ok}
          125  +do_execsql_test upsert1-610 {
          126  +  DELETE FROM t1;
          127  +  INSERT OR IGNORE INTO t1(a) VALUES('1'),(1) ON CONFLICT(a) DO NOTHING;
          128  +  PRAGMA integrity_check;
          129  +} {ok}
   114    130   
   115    131   finish_test

Changes to test/window3.test.

cannot compute difference between binary files

Changes to test/window6.test.

   306    306   } {
   307    307     do_execsql_test 10.2.$tn "
   308    308       WITH t1(a,b) AS ( VALUES(1, 2), (2, 3), (3, 4) )
   309    309       $stmt
   310    310     " $res
   311    311   }
   312    312   
          313  +
          314  +#-------------------------------------------------------------------------
          315  +#
          316  +reset_db
          317  +do_execsql_test 11.0 {
          318  +  CREATE TABLE t1(a INT);
          319  +  INSERT INTO t1 VALUES(10),(15),(20),(20),(25),(30),(30),(50);
          320  +  CREATE TABLE t3(x INT, y VARCHAR);
          321  +  INSERT INTO t3(x,y) VALUES(10,'ten'),('15','fifteen'),(30,'thirty');
          322  +}
          323  +
          324  +do_execsql_test 11.1 {
          325  +  SELECT a, (SELECT y FROM t3 WHERE x=a) FROM t1 ORDER BY a;
          326  +} {
          327  +  10 ten 15 fifteen 20 {} 20 {} 25 {} 30 thirty 30 thirty 50 {}
          328  +}
          329  +
          330  +do_execsql_test 11.2 {
          331  +  SELECT a, (SELECT y FROM t3 WHERE x=a), sum(a) OVER (ORDER BY a)
          332  +    FROM t1 ORDER BY a;
          333  +} {
          334  +  10 ten 10   15 fifteen 25   20 {} 65        20 {} 65   
          335  +  25 {} 90    30 thirty 150   30 thirty 150   50 {} 200
          336  +}
          337  +
   313    338   finish_test
          339  +