| | @@ -670,11 +670,11 @@ |
| 670 | 670 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 671 | 671 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 672 | 672 | */ |
| 673 | 673 | #define SQLITE_VERSION "3.8.0" |
| 674 | 674 | #define SQLITE_VERSION_NUMBER 3008000 |
| 675 | | -#define SQLITE_SOURCE_ID "2013-06-28 23:55:45 338826ef3f8a209b14f8d42370855cab9ac9ed45" |
| 675 | +#define SQLITE_SOURCE_ID "2013-07-09 03:04:32 52a49cbc1621094b2fe2b021209b768d29e0426b" |
| 676 | 676 | |
| 677 | 677 | /* |
| 678 | 678 | ** CAPI3REF: Run-Time Library Version Numbers |
| 679 | 679 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 680 | 680 | ** |
| | @@ -19954,12 +19954,12 @@ |
| 19954 | 19954 | if( xtype==etEXP ){ |
| 19955 | 19955 | e2 = 0; |
| 19956 | 19956 | }else{ |
| 19957 | 19957 | e2 = exp; |
| 19958 | 19958 | } |
| 19959 | | - if( e2+precision+width > etBUFSIZE - 15 ){ |
| 19960 | | - bufpt = zExtra = sqlite3Malloc( e2+precision+width+15 ); |
| 19959 | + if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){ |
| 19960 | + bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 ); |
| 19961 | 19961 | if( bufpt==0 ){ |
| 19962 | 19962 | pAccum->mallocFailed = 1; |
| 19963 | 19963 | return; |
| 19964 | 19964 | } |
| 19965 | 19965 | } |
| | @@ -40075,10 +40075,11 @@ |
| 40075 | 40075 | assert( !MEMDB ); |
| 40076 | 40076 | pager_reset(pPager); |
| 40077 | 40077 | pPager->changeCountDone = pPager->tempFile; |
| 40078 | 40078 | pPager->eState = PAGER_OPEN; |
| 40079 | 40079 | pPager->errCode = SQLITE_OK; |
| 40080 | + if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0); |
| 40080 | 40081 | } |
| 40081 | 40082 | |
| 40082 | 40083 | pPager->journalOff = 0; |
| 40083 | 40084 | pPager->journalHdr = 0; |
| 40084 | 40085 | pPager->setMaster = 0; |
| | @@ -41641,14 +41642,14 @@ |
| 41641 | 41642 | ** Invoke SQLITE_FCNTL_MMAP_SIZE based on the current value of szMmap. |
| 41642 | 41643 | */ |
| 41643 | 41644 | static void pagerFixMaplimit(Pager *pPager){ |
| 41644 | 41645 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 41645 | 41646 | sqlite3_file *fd = pPager->fd; |
| 41646 | | - if( isOpen(fd) ){ |
| 41647 | + if( isOpen(fd) && fd->pMethods->iVersion>=3 ){ |
| 41647 | 41648 | sqlite3_int64 sz; |
| 41648 | | - pPager->bUseFetch = (fd->pMethods->iVersion>=3) && pPager->szMmap>0; |
| 41649 | 41649 | sz = pPager->szMmap; |
| 41650 | + pPager->bUseFetch = (sz>0); |
| 41650 | 41651 | sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_SIZE, &sz); |
| 41651 | 41652 | } |
| 41652 | 41653 | #endif |
| 41653 | 41654 | } |
| 41654 | 41655 | |
| | @@ -60297,11 +60298,11 @@ |
| 60297 | 60298 | p->bIsReader = 1; |
| 60298 | 60299 | }else if( opcode==OP_AutoCommit || opcode==OP_Savepoint ){ |
| 60299 | 60300 | p->bIsReader = 1; |
| 60300 | 60301 | }else if( opcode==OP_Vacuum |
| 60301 | 60302 | || opcode==OP_JournalMode |
| 60302 | | -#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 60303 | +#ifndef SQLITE_OMIT_WAL |
| 60303 | 60304 | || opcode==OP_Checkpoint |
| 60304 | 60305 | #endif |
| 60305 | 60306 | ){ |
| 60306 | 60307 | p->readOnly = 0; |
| 60307 | 60308 | p->bIsReader = 1; |
| | @@ -104504,11 +104505,11 @@ |
| 104504 | 104505 | |
| 104505 | 104506 | /* |
| 104506 | 104507 | ** Each instance of this object holds a sequence of WhereLoop objects |
| 104507 | 104508 | ** that implement some or all of a query plan. |
| 104508 | 104509 | ** |
| 104509 | | -** Think of each WhereLoop objects as a node in a graph, which arcs |
| 104510 | +** Think of each WhereLoop object as a node in a graph with arcs |
| 104510 | 104511 | ** showing dependences and costs for travelling between nodes. (That is |
| 104511 | 104512 | ** not a completely accurate description because WhereLoop costs are a |
| 104512 | 104513 | ** vector, not a scalar, and because dependences are many-to-one, not |
| 104513 | 104514 | ** one-to-one as are graph nodes. But it is a useful visualization aid.) |
| 104514 | 104515 | ** Then a WherePath object is a path through the graph that visits some |
| | @@ -104774,11 +104775,11 @@ |
| 104774 | 104775 | /* |
| 104775 | 104776 | ** These are definitions of bits in the WhereLoop.wsFlags field. |
| 104776 | 104777 | ** The particular combination of bits in each WhereLoop help to |
| 104777 | 104778 | ** determine the algorithm that WhereLoop represents. |
| 104778 | 104779 | */ |
| 104779 | | -#define WHERE_COLUMN_EQ 0x00000001 /* x=EXPR or x IN (...) or x IS NULL */ |
| 104780 | +#define WHERE_COLUMN_EQ 0x00000001 /* x=EXPR */ |
| 104780 | 104781 | #define WHERE_COLUMN_RANGE 0x00000002 /* x<EXPR and/or x>EXPR */ |
| 104781 | 104782 | #define WHERE_COLUMN_IN 0x00000004 /* x IN (...) */ |
| 104782 | 104783 | #define WHERE_COLUMN_NULL 0x00000008 /* x IS NULL */ |
| 104783 | 104784 | #define WHERE_CONSTRAINT 0x0000000f /* Any of the WHERE_COLUMN_xxx values */ |
| 104784 | 104785 | #define WHERE_TOP_LIMIT 0x00000010 /* x<EXPR or x<=EXPR constraint */ |
| | @@ -105167,11 +105168,11 @@ |
| 105167 | 105168 | /* |
| 105168 | 105169 | ** Advance to the next WhereTerm that matches according to the criteria |
| 105169 | 105170 | ** established when the pScan object was initialized by whereScanInit(). |
| 105170 | 105171 | ** Return NULL if there are no more matching WhereTerms. |
| 105171 | 105172 | */ |
| 105172 | | -WhereTerm *whereScanNext(WhereScan *pScan){ |
| 105173 | +static WhereTerm *whereScanNext(WhereScan *pScan){ |
| 105173 | 105174 | int iCur; /* The cursor on the LHS of the term */ |
| 105174 | 105175 | int iColumn; /* The column on the LHS of the term. -1 for IPK */ |
| 105175 | 105176 | Expr *pX; /* An expression being tested */ |
| 105176 | 105177 | WhereClause *pWC; /* Shorthand for pScan->pWC */ |
| 105177 | 105178 | WhereTerm *pTerm; /* The term being tested */ |
| | @@ -105254,11 +105255,11 @@ |
| 105254 | 105255 | ** but is enough to handle most commonly occurring SQL statements. |
| 105255 | 105256 | ** |
| 105256 | 105257 | ** If X is not the INTEGER PRIMARY KEY then X must be compatible with |
| 105257 | 105258 | ** index pIdx. |
| 105258 | 105259 | */ |
| 105259 | | -WhereTerm *whereScanInit( |
| 105260 | +static WhereTerm *whereScanInit( |
| 105260 | 105261 | WhereScan *pScan, /* The WhereScan object being initialized */ |
| 105261 | 105262 | WhereClause *pWC, /* The WHERE clause to be scanned */ |
| 105262 | 105263 | int iCur, /* Cursor to scan for */ |
| 105263 | 105264 | int iColumn, /* Column to scan for */ |
| 105264 | 105265 | u32 opMask, /* Operator(s) to scan for */ |
| | @@ -107680,14 +107681,15 @@ |
| 107680 | 107681 | }; |
| 107681 | 107682 | assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */ |
| 107682 | 107683 | assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */ |
| 107683 | 107684 | assert( TK_GE==TK_GT+3 ); /* ... is correcct. */ |
| 107684 | 107685 | |
| 107686 | + assert( (pStart->wtFlags & TERM_VNULL)==0 ); |
| 107685 | 107687 | testcase( pStart->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */ |
| 107686 | 107688 | pX = pStart->pExpr; |
| 107687 | 107689 | assert( pX!=0 ); |
| 107688 | | - assert( pStart->leftCursor==iCur ); |
| 107690 | + testcase( pStart->leftCursor!=iCur ); /* transitive constraints */ |
| 107689 | 107691 | r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp); |
| 107690 | 107692 | sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1); |
| 107691 | 107693 | VdbeComment((v, "pk")); |
| 107692 | 107694 | sqlite3ExprCacheAffinityChange(pParse, r1, 1); |
| 107693 | 107695 | sqlite3ReleaseTempReg(pParse, rTemp); |
| | @@ -107697,11 +107699,12 @@ |
| 107697 | 107699 | } |
| 107698 | 107700 | if( pEnd ){ |
| 107699 | 107701 | Expr *pX; |
| 107700 | 107702 | pX = pEnd->pExpr; |
| 107701 | 107703 | assert( pX!=0 ); |
| 107702 | | - assert( pEnd->leftCursor==iCur ); |
| 107704 | + assert( (pEnd->wtFlags & TERM_VNULL)==0 ); |
| 107705 | + testcase( pEnd->leftCursor!=iCur ); /* Transitive constraints */ |
| 107703 | 107706 | testcase( pEnd->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */ |
| 107704 | 107707 | memEndValue = ++pParse->nMem; |
| 107705 | 107708 | sqlite3ExprCode(pParse, pX->pRight, memEndValue); |
| 107706 | 107709 | if( pX->op==TK_LT || pX->op==TK_GT ){ |
| 107707 | 107710 | testOp = bRev ? OP_Le : OP_Ge; |
| | @@ -108232,10 +108235,11 @@ |
| 108232 | 108235 | WhereTerm *pAlt; |
| 108233 | 108236 | Expr sEq; |
| 108234 | 108237 | if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue; |
| 108235 | 108238 | if( pTerm->eOperator!=(WO_EQUIV|WO_EQ) ) continue; |
| 108236 | 108239 | if( pTerm->leftCursor!=iCur ) continue; |
| 108240 | + if( pLevel->iLeftJoin ) continue; |
| 108237 | 108241 | pE = pTerm->pExpr; |
| 108238 | 108242 | assert( !ExprHasProperty(pE, EP_FromJoin) ); |
| 108239 | 108243 | assert( (pTerm->prereqRight & newNotReady)!=0 ); |
| 108240 | 108244 | pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0); |
| 108241 | 108245 | if( pAlt==0 ) continue; |
| | @@ -108626,10 +108630,15 @@ |
| 108626 | 108630 | pNew->rSetup = 0; |
| 108627 | 108631 | rLogSize = estLog(whereCost(pProbe->aiRowEst[0])); |
| 108628 | 108632 | for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){ |
| 108629 | 108633 | int nIn = 0; |
| 108630 | 108634 | if( pTerm->prereqRight & pNew->maskSelf ) continue; |
| 108635 | +#ifdef SQLITE_ENABLE_STAT3 |
| 108636 | + if( (pTerm->wtFlags & TERM_VNULL)!=0 && pSrc->pTab->aCol[iCol].notNull ){ |
| 108637 | + continue; /* skip IS NOT NULL constraints on a NOT NULL column */ |
| 108638 | + } |
| 108639 | +#endif |
| 108631 | 108640 | pNew->wsFlags = saved_wsFlags; |
| 108632 | 108641 | pNew->u.btree.nEq = saved_nEq; |
| 108633 | 108642 | pNew->nLTerm = saved_nLTerm; |
| 108634 | 108643 | if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */ |
| 108635 | 108644 | pNew->aLTerm[pNew->nLTerm++] = pTerm; |
| | @@ -108773,11 +108782,11 @@ |
| 108773 | 108782 | return m; |
| 108774 | 108783 | } |
| 108775 | 108784 | |
| 108776 | 108785 | |
| 108777 | 108786 | /* |
| 108778 | | -** Add all WhereLoop objects a single table of the join were the table |
| 108787 | +** Add all WhereLoop objects for a single table of the join where the table |
| 108779 | 108788 | ** is idenfied by pBuilder->pNew->iTab. That table is guaranteed to be |
| 108780 | 108789 | ** a b-tree table, not a virtual table. |
| 108781 | 108790 | */ |
| 108782 | 108791 | static int whereLoopAddBtree( |
| 108783 | 108792 | WhereLoopBuilder *pBuilder, /* WHERE clause information */ |
| | @@ -109237,16 +109246,23 @@ |
| 109237 | 109246 | } |
| 109238 | 109247 | |
| 109239 | 109248 | /* |
| 109240 | 109249 | ** Examine a WherePath (with the addition of the extra WhereLoop of the 5th |
| 109241 | 109250 | ** parameters) to see if it outputs rows in the requested ORDER BY |
| 109242 | | -** (or GROUP BY) without requiring a separate source operation. Return: |
| 109251 | +** (or GROUP BY) without requiring a separate sort operation. Return: |
| 109243 | 109252 | ** |
| 109244 | 109253 | ** 0: ORDER BY is not satisfied. Sorting required |
| 109245 | 109254 | ** 1: ORDER BY is satisfied. Omit sorting |
| 109246 | 109255 | ** -1: Unknown at this time |
| 109247 | 109256 | ** |
| 109257 | +** Note that processing for WHERE_GROUPBY and WHERE_DISTINCTBY is not as |
| 109258 | +** strict. With GROUP BY and DISTINCT the only requirement is that |
| 109259 | +** equivalent rows appear immediately adjacent to one another. GROUP BY |
| 109260 | +** and DISTINT do not require rows to appear in any particular order as long |
| 109261 | +** as equivelent rows are grouped together. Thus for GROUP BY and DISTINCT |
| 109262 | +** the pOrderBy terms can be matched in any order. With ORDER BY, the |
| 109263 | +** pOrderBy terms must be matched in strict left-to-right order. |
| 109248 | 109264 | */ |
| 109249 | 109265 | static int wherePathSatisfiesOrderBy( |
| 109250 | 109266 | WhereInfo *pWInfo, /* The WHERE clause */ |
| 109251 | 109267 | ExprList *pOrderBy, /* ORDER BY or GROUP BY or DISTINCT clause to check */ |
| 109252 | 109268 | WherePath *pPath, /* The WherePath to check */ |
| | @@ -109490,11 +109506,11 @@ |
| 109490 | 109506 | } |
| 109491 | 109507 | #endif |
| 109492 | 109508 | |
| 109493 | 109509 | |
| 109494 | 109510 | /* |
| 109495 | | -** Given the list of WhereLoop objects on pWInfo->pLoops, this routine |
| 109511 | +** Given the list of WhereLoop objects at pWInfo->pLoops, this routine |
| 109496 | 109512 | ** attempts to find the lowest cost path that visits each WhereLoop |
| 109497 | 109513 | ** once. This path is then loaded into the pWInfo->a[].pWLoop fields. |
| 109498 | 109514 | ** |
| 109499 | 109515 | ** Assume that the total number of output rows that will need to be sorted |
| 109500 | 109516 | ** will be nRowEst (in the 10*log2 representation). Or, ignore sorting |
| | @@ -109907,11 +109923,12 @@ |
| 109907 | 109923 | ** fi |
| 109908 | 109924 | ** end |
| 109909 | 109925 | ** |
| 109910 | 109926 | ** ORDER BY CLAUSE PROCESSING |
| 109911 | 109927 | ** |
| 109912 | | -** pOrderBy is a pointer to the ORDER BY clause of a SELECT statement, |
| 109928 | +** pOrderBy is a pointer to the ORDER BY clause (or the GROUP BY clause |
| 109929 | +** if the WHERE_GROUPBY flag is set in wctrlFlags) of a SELECT statement |
| 109913 | 109930 | ** if there is one. If there is no ORDER BY clause or if this routine |
| 109914 | 109931 | ** is called from an UPDATE or DELETE statement, then pOrderBy is NULL. |
| 109915 | 109932 | */ |
| 109916 | 109933 | SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( |
| 109917 | 109934 | Parse *pParse, /* The parser context */ |
| | @@ -109999,10 +110016,11 @@ |
| 109999 | 110016 | */ |
| 110000 | 110017 | initMaskSet(pMaskSet); |
| 110001 | 110018 | whereClauseInit(&pWInfo->sWC, pWInfo); |
| 110002 | 110019 | sqlite3ExprCodeConstants(pParse, pWhere); |
| 110003 | 110020 | whereSplit(&pWInfo->sWC, pWhere, TK_AND); /* IMP: R-15842-53296 */ |
| 110021 | + sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */ |
| 110004 | 110022 | |
| 110005 | 110023 | /* Special case: a WHERE clause that is constant. Evaluate the |
| 110006 | 110024 | ** expression and either jump over all of the code or fall thru. |
| 110007 | 110025 | */ |
| 110008 | 110026 | if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){ |
| | @@ -110193,17 +110211,15 @@ |
| 110193 | 110211 | } |
| 110194 | 110212 | |
| 110195 | 110213 | /* Open all tables in the pTabList and any indices selected for |
| 110196 | 110214 | ** searching those tables. |
| 110197 | 110215 | */ |
| 110198 | | - sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */ |
| 110199 | 110216 | notReady = ~(Bitmask)0; |
| 110200 | 110217 | for(ii=0, pLevel=pWInfo->a; ii<nTabList; ii++, pLevel++){ |
| 110201 | 110218 | Table *pTab; /* Table to open */ |
| 110202 | 110219 | int iDb; /* Index of database containing table/index */ |
| 110203 | 110220 | struct SrcList_item *pTabItem; |
| 110204 | | - WhereLoop *pLoop; |
| 110205 | 110221 | |
| 110206 | 110222 | pTabItem = &pTabList->a[pLevel->iFrom]; |
| 110207 | 110223 | pTab = pTabItem->pTab; |
| 110208 | 110224 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 110209 | 110225 | pLoop = pLevel->pWLoop; |
| | @@ -120698,11 +120714,11 @@ |
| 120698 | 120714 | nName = (int)strlen(argv[2]) + 1; |
| 120699 | 120715 | |
| 120700 | 120716 | nByte = sizeof(const char *) * (argc-2); |
| 120701 | 120717 | aCol = (const char **)sqlite3_malloc(nByte); |
| 120702 | 120718 | if( aCol ){ |
| 120703 | | - memset(aCol, 0, nByte); |
| 120719 | + memset((void*)aCol, 0, nByte); |
| 120704 | 120720 | azNotindexed = (char **)sqlite3_malloc(nByte); |
| 120705 | 120721 | } |
| 120706 | 120722 | if( azNotindexed ){ |
| 120707 | 120723 | memset(azNotindexed, 0, nByte); |
| 120708 | 120724 | } |
| | @@ -120949,11 +120965,11 @@ |
| 120949 | 120965 | assert( zCsr <= &((char *)p)[nByte] ); |
| 120950 | 120966 | } |
| 120951 | 120967 | |
| 120952 | 120968 | /* Fill in the abNotindexed array */ |
| 120953 | 120969 | for(iCol=0; iCol<nCol; iCol++){ |
| 120954 | | - int n = strlen(p->azColumn[iCol]); |
| 120970 | + int n = (int)strlen(p->azColumn[iCol]); |
| 120955 | 120971 | for(i=0; i<nNotindexed; i++){ |
| 120956 | 120972 | char *zNot = azNotindexed[i]; |
| 120957 | 120973 | if( zNot && 0==sqlite3_strnicmp(p->azColumn[iCol], zNot, n) ){ |
| 120958 | 120974 | p->abNotindexed[iCol] = 1; |
| 120959 | 120975 | sqlite3_free(zNot); |
| 120960 | 120976 | |