| | @@ -1165,11 +1165,11 @@ |
| 1165 | 1165 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1166 | 1166 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1167 | 1167 | */ |
| 1168 | 1168 | #define SQLITE_VERSION "3.30.0" |
| 1169 | 1169 | #define SQLITE_VERSION_NUMBER 3030000 |
| 1170 | | -#define SQLITE_SOURCE_ID "2019-09-21 17:31:03 8ea1dc727d391b15d0c4fa858ff68d5b8a63dde46408f24027dac8d28f044cbd" |
| 1170 | +#define SQLITE_SOURCE_ID "2019-09-26 16:57:42 49073b7003330027303c4c776e9f85112f8b99b89f848fec3f953eba501d7505" |
| 1171 | 1171 | |
| 1172 | 1172 | /* |
| 1173 | 1173 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1174 | 1174 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1175 | 1175 | ** |
| | @@ -19349,11 +19349,10 @@ |
| 19349 | 19349 | #ifndef SQLITE_AMALGAMATION |
| 19350 | 19350 | SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[]; |
| 19351 | 19351 | SQLITE_PRIVATE const char sqlite3StrBINARY[]; |
| 19352 | 19352 | SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[]; |
| 19353 | 19353 | SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[]; |
| 19354 | | -SQLITE_PRIVATE const Token sqlite3IntTokens[]; |
| 19355 | 19354 | SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config; |
| 19356 | 19355 | SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions; |
| 19357 | 19356 | #ifndef SQLITE_OMIT_WSD |
| 19358 | 19357 | SQLITE_PRIVATE int sqlite3PendingByte; |
| 19359 | 19358 | #endif |
| | @@ -20020,18 +20019,10 @@ |
| 20020 | 20019 | ** database connections. After initialization, this table is |
| 20021 | 20020 | ** read-only. |
| 20022 | 20021 | */ |
| 20023 | 20022 | SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions; |
| 20024 | 20023 | |
| 20025 | | -/* |
| 20026 | | -** Constant tokens for values 0 and 1. |
| 20027 | | -*/ |
| 20028 | | -SQLITE_PRIVATE const Token sqlite3IntTokens[] = { |
| 20029 | | - { "0", 1 }, |
| 20030 | | - { "1", 1 } |
| 20031 | | -}; |
| 20032 | | - |
| 20033 | 20024 | #ifdef VDBE_PROFILE |
| 20034 | 20025 | /* |
| 20035 | 20026 | ** The following performance counter can be used in place of |
| 20036 | 20027 | ** sqlite3Hwtime() for profiling. This is a no-op on standard builds. |
| 20037 | 20028 | */ |
| | @@ -38509,11 +38500,11 @@ |
| 38509 | 38500 | ** as the associated database file. |
| 38510 | 38501 | ** |
| 38511 | 38502 | ** If the SQLITE_ENABLE_8_3_NAMES option is enabled, then the |
| 38512 | 38503 | ** original filename is unavailable. But 8_3_NAMES is only used for |
| 38513 | 38504 | ** FAT filesystems and permissions do not matter there, so just use |
| 38514 | | -** the default permissions. |
| 38505 | +** the default permissions. In 8_3_NAMES mode, leave *pMode set to zero. |
| 38515 | 38506 | */ |
| 38516 | 38507 | static int findCreateFileMode( |
| 38517 | 38508 | const char *zPath, /* Path of file (possibly) being created */ |
| 38518 | 38509 | int flags, /* Flags passed as 4th argument to xOpen() */ |
| 38519 | 38510 | mode_t *pMode, /* OUT: Permissions to open file with */ |
| | @@ -38744,15 +38735,23 @@ |
| 38744 | 38735 | int rc2 = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName); |
| 38745 | 38736 | if( rc==SQLITE_OK ) rc = rc2; |
| 38746 | 38737 | goto open_finished; |
| 38747 | 38738 | } |
| 38748 | 38739 | |
| 38749 | | - /* If this process is running as root and if creating a new rollback |
| 38750 | | - ** journal or WAL file, set the ownership of the journal or WAL to be |
| 38751 | | - ** the same as the original database. |
| 38740 | + /* The owner of the rollback journal or WAL file should always be the |
| 38741 | + ** same as the owner of the database file. Try to ensure that this is |
| 38742 | + ** the case. The chown() system call will be a no-op if the current |
| 38743 | + ** process lacks root privileges, be we should at least try. Without |
| 38744 | + ** this step, if a root process opens a database file, it can leave |
| 38745 | + ** behinds a journal/WAL that is owned by root and hence make the |
| 38746 | + ** database inaccessible to unprivileged processes. |
| 38747 | + ** |
| 38748 | + ** If openMode==0, then that means uid and gid are not set correctly |
| 38749 | + ** (probably because SQLite is configured to use 8+3 filename mode) and |
| 38750 | + ** in that case we do not want to attempt the chown(). |
| 38752 | 38751 | */ |
| 38753 | | - if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){ |
| 38752 | + if( openMode && (flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL))!=0 ){ |
| 38754 | 38753 | robustFchown(fd, uid, gid); |
| 38755 | 38754 | } |
| 38756 | 38755 | } |
| 38757 | 38756 | assert( fd>=0 ); |
| 38758 | 38757 | if( pOutFlags ){ |
| | @@ -95757,10 +95756,17 @@ |
| 95757 | 95756 | memcpy(pExpr, pDup, sizeof(*pExpr)); |
| 95758 | 95757 | if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){ |
| 95759 | 95758 | assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 ); |
| 95760 | 95759 | pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken); |
| 95761 | 95760 | pExpr->flags |= EP_MemToken; |
| 95761 | + } |
| 95762 | + if( ExprHasProperty(pExpr, EP_WinFunc) ){ |
| 95763 | + if( pExpr->y.pWin!=0 ){ |
| 95764 | + pExpr->y.pWin->pOwner = pExpr; |
| 95765 | + }else{ |
| 95766 | + assert( db->mallocFailed ); |
| 95767 | + } |
| 95762 | 95768 | } |
| 95763 | 95769 | sqlite3DbFree(db, pDup); |
| 95764 | 95770 | } |
| 95765 | 95771 | ExprSetProperty(pExpr, EP_Alias); |
| 95766 | 95772 | } |
| | @@ -98388,11 +98394,11 @@ |
| 98388 | 98394 | }else if( pRight==0 ){ |
| 98389 | 98395 | return pLeft; |
| 98390 | 98396 | }else if( ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight) ){ |
| 98391 | 98397 | sqlite3ExprUnmapAndDelete(pParse, pLeft); |
| 98392 | 98398 | sqlite3ExprUnmapAndDelete(pParse, pRight); |
| 98393 | | - return sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0); |
| 98399 | + return sqlite3Expr(db, TK_INTEGER, "0"); |
| 98394 | 98400 | }else{ |
| 98395 | 98401 | return sqlite3PExpr(pParse, TK_AND, pLeft, pRight); |
| 98396 | 98402 | } |
| 98397 | 98403 | } |
| 98398 | 98404 | |
| | @@ -100442,15 +100448,25 @@ |
| 100442 | 100448 | }else{ |
| 100443 | 100449 | dest.eDest = SRT_Exists; |
| 100444 | 100450 | sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm); |
| 100445 | 100451 | VdbeComment((v, "Init EXISTS result")); |
| 100446 | 100452 | } |
| 100447 | | - pLimit = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[1], 0); |
| 100448 | 100453 | if( pSel->pLimit ){ |
| 100449 | | - sqlite3ExprDelete(pParse->db, pSel->pLimit->pLeft); |
| 100454 | + /* The subquery already has a limit. If the pre-existing limit is X |
| 100455 | + ** then make the new limit X<>0 so that the new limit is either 1 or 0 */ |
| 100456 | + sqlite3 *db = pParse->db; |
| 100457 | + pLimit = sqlite3Expr(db, TK_INTEGER, "0"); |
| 100458 | + if( pLimit ){ |
| 100459 | + pLimit->affExpr = SQLITE_AFF_NUMERIC; |
| 100460 | + pLimit = sqlite3PExpr(pParse, TK_NE, |
| 100461 | + sqlite3ExprDup(db, pSel->pLimit->pLeft, 0), pLimit); |
| 100462 | + } |
| 100463 | + sqlite3ExprDelete(db, pSel->pLimit->pLeft); |
| 100450 | 100464 | pSel->pLimit->pLeft = pLimit; |
| 100451 | 100465 | }else{ |
| 100466 | + /* If there is no pre-existing limit add a limit of 1 */ |
| 100467 | + pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1"); |
| 100452 | 100468 | pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0); |
| 100453 | 100469 | } |
| 100454 | 100470 | pSel->iLimit = 0; |
| 100455 | 100471 | if( sqlite3Select(pParse, pSel, &dest) ){ |
| 100456 | 100472 | return 0; |
| | @@ -131029,11 +131045,11 @@ |
| 131029 | 131045 | static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){ |
| 131030 | 131046 | if( pExpr->op!=TK_AND ){ |
| 131031 | 131047 | Select *pS = pWalker->u.pSelect; |
| 131032 | 131048 | if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, pS->pGroupBy) ){ |
| 131033 | 131049 | sqlite3 *db = pWalker->pParse->db; |
| 131034 | | - Expr *pNew = sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[1], 0); |
| 131050 | + Expr *pNew = sqlite3Expr(db, TK_INTEGER, "1"); |
| 131035 | 131051 | if( pNew ){ |
| 131036 | 131052 | Expr *pWhere = pS->pWhere; |
| 131037 | 131053 | SWAP(Expr, *pNew, *pExpr); |
| 131038 | 131054 | pNew = sqlite3ExprAnd(pWalker->pParse, pWhere, pNew); |
| 131039 | 131055 | pS->pWhere = pNew; |
| | @@ -147627,11 +147643,11 @@ |
| 147627 | 147643 | ** that pSublist is still NULL here. Add a constant expression here to |
| 147628 | 147644 | ** keep everything legal in this case. |
| 147629 | 147645 | */ |
| 147630 | 147646 | if( pSublist==0 ){ |
| 147631 | 147647 | pSublist = sqlite3ExprListAppend(pParse, 0, |
| 147632 | | - sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0) |
| 147648 | + sqlite3Expr(db, TK_INTEGER, "0") |
| 147633 | 147649 | ); |
| 147634 | 147650 | } |
| 147635 | 147651 | |
| 147636 | 147652 | pSub = sqlite3SelectNew( |
| 147637 | 147653 | pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0 |
| | @@ -148044,124 +148060,10 @@ |
| 148044 | 148060 | static int windowArgCount(Window *pWin){ |
| 148045 | 148061 | ExprList *pList = pWin->pOwner->x.pList; |
| 148046 | 148062 | return (pList ? pList->nExpr : 0); |
| 148047 | 148063 | } |
| 148048 | 148064 | |
| 148049 | | -/* |
| 148050 | | -** Generate VM code to invoke either xStep() (if bInverse is 0) or |
| 148051 | | -** xInverse (if bInverse is non-zero) for each window function in the |
| 148052 | | -** linked list starting at pMWin. Or, for built-in window functions |
| 148053 | | -** that do not use the standard function API, generate the required |
| 148054 | | -** inline VM code. |
| 148055 | | -** |
| 148056 | | -** If argument csr is greater than or equal to 0, then argument reg is |
| 148057 | | -** the first register in an array of registers guaranteed to be large |
| 148058 | | -** enough to hold the array of arguments for each function. In this case |
| 148059 | | -** the arguments are extracted from the current row of csr into the |
| 148060 | | -** array of registers before invoking OP_AggStep or OP_AggInverse |
| 148061 | | -** |
| 148062 | | -** Or, if csr is less than zero, then the array of registers at reg is |
| 148063 | | -** already populated with all columns from the current row of the sub-query. |
| 148064 | | -** |
| 148065 | | -** If argument regPartSize is non-zero, then it is a register containing the |
| 148066 | | -** number of rows in the current partition. |
| 148067 | | -*/ |
| 148068 | | -static void windowAggStep( |
| 148069 | | - Parse *pParse, |
| 148070 | | - Window *pMWin, /* Linked list of window functions */ |
| 148071 | | - int csr, /* Read arguments from this cursor */ |
| 148072 | | - int bInverse, /* True to invoke xInverse instead of xStep */ |
| 148073 | | - int reg /* Array of registers */ |
| 148074 | | -){ |
| 148075 | | - Vdbe *v = sqlite3GetVdbe(pParse); |
| 148076 | | - Window *pWin; |
| 148077 | | - for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ |
| 148078 | | - FuncDef *pFunc = pWin->pFunc; |
| 148079 | | - int regArg; |
| 148080 | | - int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin); |
| 148081 | | - int i; |
| 148082 | | - |
| 148083 | | - assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED ); |
| 148084 | | - |
| 148085 | | - for(i=0; i<nArg; i++){ |
| 148086 | | - if( i!=1 || pFunc->zName!=nth_valueName ){ |
| 148087 | | - sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i); |
| 148088 | | - }else{ |
| 148089 | | - sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+i, reg+i); |
| 148090 | | - } |
| 148091 | | - } |
| 148092 | | - regArg = reg; |
| 148093 | | - |
| 148094 | | - if( pMWin->regStartRowid==0 |
| 148095 | | - && (pFunc->funcFlags & SQLITE_FUNC_MINMAX) |
| 148096 | | - && (pWin->eStart!=TK_UNBOUNDED) |
| 148097 | | - ){ |
| 148098 | | - int addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regArg); |
| 148099 | | - VdbeCoverage(v); |
| 148100 | | - if( bInverse==0 ){ |
| 148101 | | - sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1, 1); |
| 148102 | | - sqlite3VdbeAddOp2(v, OP_SCopy, regArg, pWin->regApp); |
| 148103 | | - sqlite3VdbeAddOp3(v, OP_MakeRecord, pWin->regApp, 2, pWin->regApp+2); |
| 148104 | | - sqlite3VdbeAddOp2(v, OP_IdxInsert, pWin->csrApp, pWin->regApp+2); |
| 148105 | | - }else{ |
| 148106 | | - sqlite3VdbeAddOp4Int(v, OP_SeekGE, pWin->csrApp, 0, regArg, 1); |
| 148107 | | - VdbeCoverageNeverTaken(v); |
| 148108 | | - sqlite3VdbeAddOp1(v, OP_Delete, pWin->csrApp); |
| 148109 | | - sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2); |
| 148110 | | - } |
| 148111 | | - sqlite3VdbeJumpHere(v, addrIsNull); |
| 148112 | | - }else if( pWin->regApp ){ |
| 148113 | | - assert( pFunc->zName==nth_valueName |
| 148114 | | - || pFunc->zName==first_valueName |
| 148115 | | - ); |
| 148116 | | - assert( bInverse==0 || bInverse==1 ); |
| 148117 | | - sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1); |
| 148118 | | - }else if( pFunc->xSFunc!=noopStepFunc ){ |
| 148119 | | - int addrIf = 0; |
| 148120 | | - if( pWin->pFilter ){ |
| 148121 | | - int regTmp; |
| 148122 | | - assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr ); |
| 148123 | | - assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 ); |
| 148124 | | - regTmp = sqlite3GetTempReg(pParse); |
| 148125 | | - sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp); |
| 148126 | | - addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1); |
| 148127 | | - VdbeCoverage(v); |
| 148128 | | - sqlite3ReleaseTempReg(pParse, regTmp); |
| 148129 | | - } |
| 148130 | | - if( pWin->bExprArgs ){ |
| 148131 | | - int iStart = sqlite3VdbeCurrentAddr(v); |
| 148132 | | - VdbeOp *pOp, *pEnd; |
| 148133 | | - |
| 148134 | | - nArg = pWin->pOwner->x.pList->nExpr; |
| 148135 | | - regArg = sqlite3GetTempRange(pParse, nArg); |
| 148136 | | - sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0); |
| 148137 | | - |
| 148138 | | - pEnd = sqlite3VdbeGetOp(v, -1); |
| 148139 | | - for(pOp=sqlite3VdbeGetOp(v, iStart); pOp<=pEnd; pOp++){ |
| 148140 | | - if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){ |
| 148141 | | - pOp->p1 = csr; |
| 148142 | | - } |
| 148143 | | - } |
| 148144 | | - } |
| 148145 | | - if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 148146 | | - CollSeq *pColl; |
| 148147 | | - assert( nArg>0 ); |
| 148148 | | - pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr); |
| 148149 | | - sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ); |
| 148150 | | - } |
| 148151 | | - sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep, |
| 148152 | | - bInverse, regArg, pWin->regAccum); |
| 148153 | | - sqlite3VdbeAppendP4(v, pFunc, P4_FUNCDEF); |
| 148154 | | - sqlite3VdbeChangeP5(v, (u8)nArg); |
| 148155 | | - if( pWin->bExprArgs ){ |
| 148156 | | - sqlite3ReleaseTempRange(pParse, regArg, nArg); |
| 148157 | | - } |
| 148158 | | - if( addrIf ) sqlite3VdbeJumpHere(v, addrIf); |
| 148159 | | - } |
| 148160 | | - } |
| 148161 | | -} |
| 148162 | | - |
| 148163 | 148065 | typedef struct WindowCodeArg WindowCodeArg; |
| 148164 | 148066 | typedef struct WindowCsrAndReg WindowCsrAndReg; |
| 148165 | 148067 | |
| 148166 | 148068 | /* |
| 148167 | 148069 | ** See comments above struct WindowCodeArg. |
| | @@ -148238,17 +148140,10 @@ |
| 148238 | 148140 | WindowCsrAndReg start; |
| 148239 | 148141 | WindowCsrAndReg current; |
| 148240 | 148142 | WindowCsrAndReg end; |
| 148241 | 148143 | }; |
| 148242 | 148144 | |
| 148243 | | -/* |
| 148244 | | -** Values that may be passed as the second argument to windowCodeOp(). |
| 148245 | | -*/ |
| 148246 | | -#define WINDOW_RETURN_ROW 1 |
| 148247 | | -#define WINDOW_AGGINVERSE 2 |
| 148248 | | -#define WINDOW_AGGSTEP 3 |
| 148249 | | - |
| 148250 | 148145 | /* |
| 148251 | 148146 | ** Generate VM code to read the window frames peer values from cursor csr into |
| 148252 | 148147 | ** an array of registers starting at reg. |
| 148253 | 148148 | */ |
| 148254 | 148149 | static void windowReadPeerValues( |
| | @@ -148267,10 +148162,137 @@ |
| 148267 | 148162 | sqlite3VdbeAddOp3(v, OP_Column, csr, iColOff+i, reg+i); |
| 148268 | 148163 | } |
| 148269 | 148164 | } |
| 148270 | 148165 | } |
| 148271 | 148166 | |
| 148167 | +/* |
| 148168 | +** Generate VM code to invoke either xStep() (if bInverse is 0) or |
| 148169 | +** xInverse (if bInverse is non-zero) for each window function in the |
| 148170 | +** linked list starting at pMWin. Or, for built-in window functions |
| 148171 | +** that do not use the standard function API, generate the required |
| 148172 | +** inline VM code. |
| 148173 | +** |
| 148174 | +** If argument csr is greater than or equal to 0, then argument reg is |
| 148175 | +** the first register in an array of registers guaranteed to be large |
| 148176 | +** enough to hold the array of arguments for each function. In this case |
| 148177 | +** the arguments are extracted from the current row of csr into the |
| 148178 | +** array of registers before invoking OP_AggStep or OP_AggInverse |
| 148179 | +** |
| 148180 | +** Or, if csr is less than zero, then the array of registers at reg is |
| 148181 | +** already populated with all columns from the current row of the sub-query. |
| 148182 | +** |
| 148183 | +** If argument regPartSize is non-zero, then it is a register containing the |
| 148184 | +** number of rows in the current partition. |
| 148185 | +*/ |
| 148186 | +static void windowAggStep( |
| 148187 | + WindowCodeArg *p, |
| 148188 | + Window *pMWin, /* Linked list of window functions */ |
| 148189 | + int csr, /* Read arguments from this cursor */ |
| 148190 | + int bInverse, /* True to invoke xInverse instead of xStep */ |
| 148191 | + int reg /* Array of registers */ |
| 148192 | +){ |
| 148193 | + Parse *pParse = p->pParse; |
| 148194 | + Vdbe *v = sqlite3GetVdbe(pParse); |
| 148195 | + Window *pWin; |
| 148196 | + for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ |
| 148197 | + FuncDef *pFunc = pWin->pFunc; |
| 148198 | + int regArg; |
| 148199 | + int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin); |
| 148200 | + int i; |
| 148201 | + |
| 148202 | + assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED ); |
| 148203 | + |
| 148204 | + /* All OVER clauses in the same window function aggregate step must |
| 148205 | + ** be the same. */ |
| 148206 | + assert( pWin==pMWin || sqlite3WindowCompare(pParse,pWin,pMWin,0)==0 ); |
| 148207 | + |
| 148208 | + for(i=0; i<nArg; i++){ |
| 148209 | + if( i!=1 || pFunc->zName!=nth_valueName ){ |
| 148210 | + sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i); |
| 148211 | + }else{ |
| 148212 | + sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+i, reg+i); |
| 148213 | + } |
| 148214 | + } |
| 148215 | + regArg = reg; |
| 148216 | + |
| 148217 | + if( pMWin->regStartRowid==0 |
| 148218 | + && (pFunc->funcFlags & SQLITE_FUNC_MINMAX) |
| 148219 | + && (pWin->eStart!=TK_UNBOUNDED) |
| 148220 | + ){ |
| 148221 | + int addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regArg); |
| 148222 | + VdbeCoverage(v); |
| 148223 | + if( bInverse==0 ){ |
| 148224 | + sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1, 1); |
| 148225 | + sqlite3VdbeAddOp2(v, OP_SCopy, regArg, pWin->regApp); |
| 148226 | + sqlite3VdbeAddOp3(v, OP_MakeRecord, pWin->regApp, 2, pWin->regApp+2); |
| 148227 | + sqlite3VdbeAddOp2(v, OP_IdxInsert, pWin->csrApp, pWin->regApp+2); |
| 148228 | + }else{ |
| 148229 | + sqlite3VdbeAddOp4Int(v, OP_SeekGE, pWin->csrApp, 0, regArg, 1); |
| 148230 | + VdbeCoverageNeverTaken(v); |
| 148231 | + sqlite3VdbeAddOp1(v, OP_Delete, pWin->csrApp); |
| 148232 | + sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2); |
| 148233 | + } |
| 148234 | + sqlite3VdbeJumpHere(v, addrIsNull); |
| 148235 | + }else if( pWin->regApp ){ |
| 148236 | + assert( pFunc->zName==nth_valueName |
| 148237 | + || pFunc->zName==first_valueName |
| 148238 | + ); |
| 148239 | + assert( bInverse==0 || bInverse==1 ); |
| 148240 | + sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1); |
| 148241 | + }else if( pFunc->xSFunc!=noopStepFunc ){ |
| 148242 | + int addrIf = 0; |
| 148243 | + if( pWin->pFilter ){ |
| 148244 | + int regTmp; |
| 148245 | + assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr ); |
| 148246 | + assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 ); |
| 148247 | + regTmp = sqlite3GetTempReg(pParse); |
| 148248 | + sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp); |
| 148249 | + addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1); |
| 148250 | + VdbeCoverage(v); |
| 148251 | + sqlite3ReleaseTempReg(pParse, regTmp); |
| 148252 | + } |
| 148253 | + |
| 148254 | + if( pWin->bExprArgs ){ |
| 148255 | + int iStart = sqlite3VdbeCurrentAddr(v); |
| 148256 | + VdbeOp *pOp, *pEnd; |
| 148257 | + |
| 148258 | + nArg = pWin->pOwner->x.pList->nExpr; |
| 148259 | + regArg = sqlite3GetTempRange(pParse, nArg); |
| 148260 | + sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0); |
| 148261 | + |
| 148262 | + pEnd = sqlite3VdbeGetOp(v, -1); |
| 148263 | + for(pOp=sqlite3VdbeGetOp(v, iStart); pOp<=pEnd; pOp++){ |
| 148264 | + if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){ |
| 148265 | + pOp->p1 = csr; |
| 148266 | + } |
| 148267 | + } |
| 148268 | + } |
| 148269 | + if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 148270 | + CollSeq *pColl; |
| 148271 | + assert( nArg>0 ); |
| 148272 | + pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr); |
| 148273 | + sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ); |
| 148274 | + } |
| 148275 | + sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep, |
| 148276 | + bInverse, regArg, pWin->regAccum); |
| 148277 | + sqlite3VdbeAppendP4(v, pFunc, P4_FUNCDEF); |
| 148278 | + sqlite3VdbeChangeP5(v, (u8)nArg); |
| 148279 | + if( pWin->bExprArgs ){ |
| 148280 | + sqlite3ReleaseTempRange(pParse, regArg, nArg); |
| 148281 | + } |
| 148282 | + if( addrIf ) sqlite3VdbeJumpHere(v, addrIf); |
| 148283 | + } |
| 148284 | + } |
| 148285 | +} |
| 148286 | + |
| 148287 | +/* |
| 148288 | +** Values that may be passed as the second argument to windowCodeOp(). |
| 148289 | +*/ |
| 148290 | +#define WINDOW_RETURN_ROW 1 |
| 148291 | +#define WINDOW_AGGINVERSE 2 |
| 148292 | +#define WINDOW_AGGSTEP 3 |
| 148293 | + |
| 148272 | 148294 | /* |
| 148273 | 148295 | ** Generate VM code to invoke either xValue() (bFin==0) or xFinalize() |
| 148274 | 148296 | ** (bFin==1) for each window function in the linked list starting at |
| 148275 | 148297 | ** pMWin. Or, for built-in window-functions that do not use the standard |
| 148276 | 148298 | ** API, generate the equivalent VM code. |
| | @@ -148329,10 +148351,12 @@ |
| 148329 | 148351 | int lblNext; |
| 148330 | 148352 | int lblBrk; |
| 148331 | 148353 | int addrNext; |
| 148332 | 148354 | int csr; |
| 148333 | 148355 | |
| 148356 | + VdbeModuleComment((v, "windowFullScan begin")); |
| 148357 | + |
| 148334 | 148358 | assert( pMWin!=0 ); |
| 148335 | 148359 | csr = pMWin->csrApp; |
| 148336 | 148360 | nPeer = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0); |
| 148337 | 148361 | |
| 148338 | 148362 | lblNext = sqlite3VdbeMakeLabel(pParse); |
| | @@ -148385,11 +148409,11 @@ |
| 148385 | 148409 | sqlite3VdbeAddOp2(v, OP_Goto, 0, lblNext); |
| 148386 | 148410 | } |
| 148387 | 148411 | if( addrEq ) sqlite3VdbeJumpHere(v, addrEq); |
| 148388 | 148412 | } |
| 148389 | 148413 | |
| 148390 | | - windowAggStep(pParse, pMWin, csr, 0, p->regArg); |
| 148414 | + windowAggStep(p, pMWin, csr, 0, p->regArg); |
| 148391 | 148415 | |
| 148392 | 148416 | sqlite3VdbeResolveLabel(v, lblNext); |
| 148393 | 148417 | sqlite3VdbeAddOp2(v, OP_Next, csr, addrNext); |
| 148394 | 148418 | VdbeCoverage(v); |
| 148395 | 148419 | sqlite3VdbeJumpHere(v, addrNext-1); |
| | @@ -148400,10 +148424,11 @@ |
| 148400 | 148424 | sqlite3ReleaseTempRange(pParse, regPeer, nPeer); |
| 148401 | 148425 | sqlite3ReleaseTempRange(pParse, regCPeer, nPeer); |
| 148402 | 148426 | } |
| 148403 | 148427 | |
| 148404 | 148428 | windowAggFinal(p, 1); |
| 148429 | + VdbeModuleComment((v, "windowFullScan end")); |
| 148405 | 148430 | } |
| 148406 | 148431 | |
| 148407 | 148432 | /* |
| 148408 | 148433 | ** Invoke the sub-routine at regGosub (generated by code in select.c) to |
| 148409 | 148434 | ** return the current row of Window.iEphCsr. If all window functions are |
| | @@ -148730,13 +148755,11 @@ |
| 148730 | 148755 | int csr, reg; |
| 148731 | 148756 | Parse *pParse = p->pParse; |
| 148732 | 148757 | Window *pMWin = p->pMWin; |
| 148733 | 148758 | int ret = 0; |
| 148734 | 148759 | Vdbe *v = p->pVdbe; |
| 148735 | | - int addrIf = 0; |
| 148736 | 148760 | int addrContinue = 0; |
| 148737 | | - int addrGoto = 0; |
| 148738 | 148761 | int bPeer = (pMWin->eFrmType!=TK_ROWS); |
| 148739 | 148762 | |
| 148740 | 148763 | int lblDone = sqlite3VdbeMakeLabel(pParse); |
| 148741 | 148764 | int addrNextRange = 0; |
| 148742 | 148765 | |
| | @@ -148765,19 +148788,38 @@ |
| 148765 | 148788 | windowCodeRangeTest( |
| 148766 | 148789 | p, OP_Gt, p->end.csr, regCountdown, p->current.csr, lblDone |
| 148767 | 148790 | ); |
| 148768 | 148791 | } |
| 148769 | 148792 | }else{ |
| 148770 | | - addrIf = sqlite3VdbeAddOp3(v, OP_IfPos, regCountdown, 0, 1); |
| 148793 | + sqlite3VdbeAddOp3(v, OP_IfPos, regCountdown, lblDone, 1); |
| 148771 | 148794 | VdbeCoverage(v); |
| 148772 | 148795 | } |
| 148773 | 148796 | } |
| 148774 | 148797 | |
| 148775 | 148798 | if( op==WINDOW_RETURN_ROW && pMWin->regStartRowid==0 ){ |
| 148776 | 148799 | windowAggFinal(p, 0); |
| 148777 | 148800 | } |
| 148778 | 148801 | addrContinue = sqlite3VdbeCurrentAddr(v); |
| 148802 | + |
| 148803 | + /* If this is a (RANGE BETWEEN a FOLLOWING AND b FOLLOWING) or |
| 148804 | + ** (RANGE BETWEEN b PRECEDING AND a PRECEDING) frame, ensure the |
| 148805 | + ** start cursor does not advance past the end cursor within the |
| 148806 | + ** temporary table. It otherwise might, if (a>b). */ |
| 148807 | + if( pMWin->eStart==pMWin->eEnd && regCountdown |
| 148808 | + && pMWin->eFrmType==TK_RANGE && op==WINDOW_AGGINVERSE |
| 148809 | + ){ |
| 148810 | + int regRowid1 = sqlite3GetTempReg(pParse); |
| 148811 | + int regRowid2 = sqlite3GetTempReg(pParse); |
| 148812 | + sqlite3VdbeAddOp2(v, OP_Rowid, p->start.csr, regRowid1); |
| 148813 | + sqlite3VdbeAddOp2(v, OP_Rowid, p->end.csr, regRowid2); |
| 148814 | + sqlite3VdbeAddOp3(v, OP_Ge, regRowid2, lblDone, regRowid1); |
| 148815 | + VdbeCoverage(v); |
| 148816 | + sqlite3ReleaseTempReg(pParse, regRowid1); |
| 148817 | + sqlite3ReleaseTempReg(pParse, regRowid2); |
| 148818 | + assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING ); |
| 148819 | + } |
| 148820 | + |
| 148779 | 148821 | switch( op ){ |
| 148780 | 148822 | case WINDOW_RETURN_ROW: |
| 148781 | 148823 | csr = p->current.csr; |
| 148782 | 148824 | reg = p->current.reg; |
| 148783 | 148825 | windowReturnOneRow(p); |
| | @@ -148788,11 +148830,11 @@ |
| 148788 | 148830 | reg = p->start.reg; |
| 148789 | 148831 | if( pMWin->regStartRowid ){ |
| 148790 | 148832 | assert( pMWin->regEndRowid ); |
| 148791 | 148833 | sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regStartRowid, 1); |
| 148792 | 148834 | }else{ |
| 148793 | | - windowAggStep(pParse, pMWin, csr, 1, p->regArg); |
| 148835 | + windowAggStep(p, pMWin, csr, 1, p->regArg); |
| 148794 | 148836 | } |
| 148795 | 148837 | break; |
| 148796 | 148838 | |
| 148797 | 148839 | default: |
| 148798 | 148840 | assert( op==WINDOW_AGGSTEP ); |
| | @@ -148800,11 +148842,11 @@ |
| 148800 | 148842 | reg = p->end.reg; |
| 148801 | 148843 | if( pMWin->regStartRowid ){ |
| 148802 | 148844 | assert( pMWin->regEndRowid ); |
| 148803 | 148845 | sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regEndRowid, 1); |
| 148804 | 148846 | }else{ |
| 148805 | | - windowAggStep(pParse, pMWin, csr, 0, p->regArg); |
| 148847 | + windowAggStep(p, pMWin, csr, 0, p->regArg); |
| 148806 | 148848 | } |
| 148807 | 148849 | break; |
| 148808 | 148850 | } |
| 148809 | 148851 | |
| 148810 | 148852 | if( op==p->eDelete ){ |
| | @@ -148818,11 +148860,11 @@ |
| 148818 | 148860 | ret = sqlite3VdbeAddOp0(v, OP_Goto); |
| 148819 | 148861 | }else{ |
| 148820 | 148862 | sqlite3VdbeAddOp2(v, OP_Next, csr, sqlite3VdbeCurrentAddr(v)+1+bPeer); |
| 148821 | 148863 | VdbeCoverage(v); |
| 148822 | 148864 | if( bPeer ){ |
| 148823 | | - addrGoto = sqlite3VdbeAddOp0(v, OP_Goto); |
| 148865 | + sqlite3VdbeAddOp2(v, OP_Goto, 0, lblDone); |
| 148824 | 148866 | } |
| 148825 | 148867 | } |
| 148826 | 148868 | |
| 148827 | 148869 | if( bPeer ){ |
| 148828 | 148870 | int nReg = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0); |
| | @@ -148834,12 +148876,10 @@ |
| 148834 | 148876 | |
| 148835 | 148877 | if( addrNextRange ){ |
| 148836 | 148878 | sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNextRange); |
| 148837 | 148879 | } |
| 148838 | 148880 | sqlite3VdbeResolveLabel(v, lblDone); |
| 148839 | | - if( addrGoto ) sqlite3VdbeJumpHere(v, addrGoto); |
| 148840 | | - if( addrIf ) sqlite3VdbeJumpHere(v, addrIf); |
| 148841 | 148881 | return ret; |
| 148842 | 148882 | } |
| 148843 | 148883 | |
| 148844 | 148884 | |
| 148845 | 148885 | /* |
| | @@ -149188,11 +149228,11 @@ |
| 149188 | 149228 | ** if( first row of partition ){ |
| 149189 | 149229 | ** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent) |
| 149190 | 149230 | ** regEnd = <expr2> |
| 149191 | 149231 | ** regStart = <expr1> |
| 149192 | 149232 | ** }else{ |
| 149193 | | -** if( (csrEnd.key + regEnd) <= csrCurrent.key ){ |
| 149233 | +** while( (csrEnd.key + regEnd) <= csrCurrent.key ){ |
| 149194 | 149234 | ** AGGSTEP |
| 149195 | 149235 | ** } |
| 149196 | 149236 | ** while( (csrStart.key + regStart) < csrCurrent.key ){ |
| 149197 | 149237 | ** AGGINVERSE |
| 149198 | 149238 | ** } |
| | @@ -149261,20 +149301,20 @@ |
| 149261 | 149301 | int iInput; /* To iterate through sub cols */ |
| 149262 | 149302 | int addrNe; /* Address of OP_Ne */ |
| 149263 | 149303 | int addrGosubFlush = 0; /* Address of OP_Gosub to flush: */ |
| 149264 | 149304 | int addrInteger = 0; /* Address of OP_Integer */ |
| 149265 | 149305 | int addrEmpty; /* Address of OP_Rewind in flush: */ |
| 149266 | | - int regStart = 0; /* Value of <expr> PRECEDING */ |
| 149267 | | - int regEnd = 0; /* Value of <expr> FOLLOWING */ |
| 149268 | 149306 | int regNew; /* Array of registers holding new input row */ |
| 149269 | 149307 | int regRecord; /* regNew array in record form */ |
| 149270 | 149308 | int regRowid; /* Rowid for regRecord in eph table */ |
| 149271 | 149309 | int regNewPeer = 0; /* Peer values for new row (part of regNew) */ |
| 149272 | 149310 | int regPeer = 0; /* Peer values for current row */ |
| 149273 | 149311 | int regFlushPart = 0; /* Register for "Gosub flush_partition" */ |
| 149274 | 149312 | WindowCodeArg s; /* Context object for sub-routines */ |
| 149275 | 149313 | int lblWhereEnd; /* Label just before sqlite3WhereEnd() code */ |
| 149314 | + int regStart = 0; /* Value of <expr> PRECEDING */ |
| 149315 | + int regEnd = 0; /* Value of <expr> FOLLOWING */ |
| 149276 | 149316 | |
| 149277 | 149317 | assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_CURRENT |
| 149278 | 149318 | || pMWin->eStart==TK_FOLLOWING || pMWin->eStart==TK_UNBOUNDED |
| 149279 | 149319 | ); |
| 149280 | 149320 | assert( pMWin->eEnd==TK_FOLLOWING || pMWin->eEnd==TK_CURRENT |
| | @@ -149401,15 +149441,15 @@ |
| 149401 | 149441 | /* This block is run for the first row of each partition */ |
| 149402 | 149442 | s.regArg = windowInitAccum(pParse, pMWin); |
| 149403 | 149443 | |
| 149404 | 149444 | if( regStart ){ |
| 149405 | 149445 | sqlite3ExprCode(pParse, pMWin->pStart, regStart); |
| 149406 | | - windowCheckValue(pParse, regStart, 0 + (pMWin->eFrmType==TK_RANGE ? 3 : 0)); |
| 149446 | + windowCheckValue(pParse, regStart, 0 + (pMWin->eFrmType==TK_RANGE?3:0)); |
| 149407 | 149447 | } |
| 149408 | 149448 | if( regEnd ){ |
| 149409 | 149449 | sqlite3ExprCode(pParse, pMWin->pEnd, regEnd); |
| 149410 | | - windowCheckValue(pParse, regEnd, 1 + (pMWin->eFrmType==TK_RANGE ? 3 : 0)); |
| 149450 | + windowCheckValue(pParse, regEnd, 1 + (pMWin->eFrmType==TK_RANGE?3:0)); |
| 149411 | 149451 | } |
| 149412 | 149452 | |
| 149413 | 149453 | if( pMWin->eFrmType!=TK_RANGE && pMWin->eStart==pMWin->eEnd && regStart ){ |
| 149414 | 149454 | int op = ((pMWin->eStart==TK_FOLLOWING) ? OP_Ge : OP_Le); |
| 149415 | 149455 | int addrGe = sqlite3VdbeAddOp3(v, op, regStart, 0, regEnd); |
| | @@ -153724,11 +153764,11 @@ |
| 153724 | 153764 | ** |
| 153725 | 153765 | ** simplify to constants 0 (false) and 1 (true), respectively, |
| 153726 | 153766 | ** regardless of the value of expr1. |
| 153727 | 153767 | */ |
| 153728 | 153768 | sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy46); |
| 153729 | | - yymsp[-4].minor.yy46 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy32],1); |
| 153769 | + yymsp[-4].minor.yy46 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy32 ? "1" : "0"); |
| 153730 | 153770 | }else{ |
| 153731 | 153771 | yymsp[-4].minor.yy46 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy46, 0); |
| 153732 | 153772 | if( yymsp[-4].minor.yy46 ){ |
| 153733 | 153773 | yymsp[-4].minor.yy46->x.pList = yymsp[-1].minor.yy138; |
| 153734 | 153774 | sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy46); |
| | @@ -220196,11 +220236,11 @@ |
| 220196 | 220236 | int nArg, /* Number of args */ |
| 220197 | 220237 | sqlite3_value **apUnused /* Function arguments */ |
| 220198 | 220238 | ){ |
| 220199 | 220239 | assert( nArg==0 ); |
| 220200 | 220240 | UNUSED_PARAM2(nArg, apUnused); |
| 220201 | | - sqlite3_result_text(pCtx, "fts5: 2019-09-21 17:31:03 8ea1dc727d391b15d0c4fa858ff68d5b8a63dde46408f24027dac8d28f044cbd", -1, SQLITE_TRANSIENT); |
| 220241 | + sqlite3_result_text(pCtx, "fts5: 2019-09-25 18:44:49 36d35dbd5a80dc4a149ed7409cc4b43712622fc4c6a8915b4fbb62fd1d6b7763", -1, SQLITE_TRANSIENT); |
| 220202 | 220242 | } |
| 220203 | 220243 | |
| 220204 | 220244 | /* |
| 220205 | 220245 | ** Return true if zName is the extension on one of the shadow tables used |
| 220206 | 220246 | ** by this module. |
| | @@ -224964,12 +225004,12 @@ |
| 224964 | 225004 | } |
| 224965 | 225005 | #endif /* SQLITE_CORE */ |
| 224966 | 225006 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 224967 | 225007 | |
| 224968 | 225008 | /************** End of stmt.c ************************************************/ |
| 224969 | | -#if __LINE__!=224969 |
| 225009 | +#if __LINE__!=225009 |
| 224970 | 225010 | #undef SQLITE_SOURCE_ID |
| 224971 | | -#define SQLITE_SOURCE_ID "2019-09-21 17:31:03 8ea1dc727d391b15d0c4fa858ff68d5b8a63dde46408f24027dac8d28f04alt2" |
| 225011 | +#define SQLITE_SOURCE_ID "2019-09-26 16:57:42 49073b7003330027303c4c776e9f85112f8b99b89f848fec3f953eba501dalt2" |
| 224972 | 225012 | #endif |
| 224973 | 225013 | /* Return the source-id for this library */ |
| 224974 | 225014 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 224975 | 225015 | /************************** End of sqlite3.c ******************************/ |
| 224976 | 225016 | |