Fossil SCM
Pull the latest SQLite from upstream for testing purposes.
Commit
50c534ee530d0e5f229e0b99384d3648acd76c9c
Parent
cc746fc66c79351…
2 files changed
+84
-12
+2
-1
+84
-12
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -673,11 +673,11 @@ | ||
| 673 | 673 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 674 | 674 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 675 | 675 | */ |
| 676 | 676 | #define SQLITE_VERSION "3.7.15" |
| 677 | 677 | #define SQLITE_VERSION_NUMBER 3007015 |
| 678 | -#define SQLITE_SOURCE_ID "2012-10-30 18:09:46 9dca18f5fea84afbecb314ee1cdfb98430656af3" | |
| 678 | +#define SQLITE_SOURCE_ID "2012-11-09 21:40:02 5a3b07f0f5dfae7eea870303f52f37d6a17f1da2" | |
| 679 | 679 | |
| 680 | 680 | /* |
| 681 | 681 | ** CAPI3REF: Run-Time Library Version Numbers |
| 682 | 682 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 683 | 683 | ** |
| @@ -1038,10 +1038,11 @@ | ||
| 1038 | 1038 | #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) |
| 1039 | 1039 | #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) |
| 1040 | 1040 | #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) |
| 1041 | 1041 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
| 1042 | 1042 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 1043 | +#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) | |
| 1043 | 1044 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 1044 | 1045 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1045 | 1046 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 1046 | 1047 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 1047 | 1048 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| @@ -11008,10 +11009,11 @@ | ||
| 11008 | 11009 | int addrInTop; /* Top of the IN loop */ |
| 11009 | 11010 | } *aInLoop; /* Information about each nested IN operator */ |
| 11010 | 11011 | } in; /* Used when plan.wsFlags&WHERE_IN_ABLE */ |
| 11011 | 11012 | Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */ |
| 11012 | 11013 | } u; |
| 11014 | + double rOptCost; /* "Optimal" cost for this level */ | |
| 11013 | 11015 | |
| 11014 | 11016 | /* The following field is really not part of the current level. But |
| 11015 | 11017 | ** we need a place to cache virtual table index information for each |
| 11016 | 11018 | ** virtual table in the FROM clause and the WhereLevel structure is |
| 11017 | 11019 | ** a convenient place since there is one WhereLevel for each FROM clause |
| @@ -13716,10 +13718,11 @@ | ||
| 13716 | 13718 | int nByte = 0; /* Used to accumulate return value */ |
| 13717 | 13719 | |
| 13718 | 13720 | db->pnBytesFreed = &nByte; |
| 13719 | 13721 | for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){ |
| 13720 | 13722 | sqlite3VdbeClearObject(db, pVdbe); |
| 13723 | + sqlite3DbFree(db, pVdbe); | |
| 13721 | 13724 | } |
| 13722 | 13725 | db->pnBytesFreed = 0; |
| 13723 | 13726 | |
| 13724 | 13727 | *pHighwater = 0; |
| 13725 | 13728 | *pCurrent = nByte; |
| @@ -28219,12 +28222,17 @@ | ||
| 28219 | 28222 | int dirSync /* If true, fsync() directory after deleting file */ |
| 28220 | 28223 | ){ |
| 28221 | 28224 | int rc = SQLITE_OK; |
| 28222 | 28225 | UNUSED_PARAMETER(NotUsed); |
| 28223 | 28226 | SimulateIOError(return SQLITE_IOERR_DELETE); |
| 28224 | - if( osUnlink(zPath)==(-1) && errno!=ENOENT ){ | |
| 28225 | - return unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath); | |
| 28227 | + if( osUnlink(zPath)==(-1) ){ | |
| 28228 | + if( errno==ENOENT ){ | |
| 28229 | + rc = SQLITE_IOERR_DELETE_NOENT; | |
| 28230 | + }else{ | |
| 28231 | + rc = unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath); | |
| 28232 | + } | |
| 28233 | + return rc; | |
| 28226 | 28234 | } |
| 28227 | 28235 | #ifndef SQLITE_DISABLE_DIRSYNC |
| 28228 | 28236 | if( (dirSync & 1)!=0 ){ |
| 28229 | 28237 | int fd; |
| 28230 | 28238 | rc = osOpenDirectory(zPath, &fd); |
| @@ -40388,10 +40396,11 @@ | ||
| 40388 | 40396 | |
| 40389 | 40397 | rc = pagerPagecount(pPager, &nPage); |
| 40390 | 40398 | if( rc ) return rc; |
| 40391 | 40399 | if( nPage==0 ){ |
| 40392 | 40400 | rc = sqlite3OsDelete(pPager->pVfs, pPager->zWal, 0); |
| 40401 | + if( rc==SQLITE_IOERR_DELETE_NOENT ) rc = SQLITE_OK; | |
| 40393 | 40402 | isWal = 0; |
| 40394 | 40403 | }else{ |
| 40395 | 40404 | rc = sqlite3OsAccess( |
| 40396 | 40405 | pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &isWal |
| 40397 | 40406 | ); |
| @@ -77655,12 +77664,14 @@ | ||
| 77655 | 77664 | */ |
| 77656 | 77665 | assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) ); |
| 77657 | 77666 | ExprSetIrreducible(pExpr); |
| 77658 | 77667 | pExpr->iAgg = (i16)i; |
| 77659 | 77668 | pExpr->pAggInfo = pAggInfo; |
| 77669 | + return WRC_Prune; | |
| 77670 | + }else{ | |
| 77671 | + return WRC_Continue; | |
| 77660 | 77672 | } |
| 77661 | - return WRC_Prune; | |
| 77662 | 77673 | } |
| 77663 | 77674 | } |
| 77664 | 77675 | return WRC_Continue; |
| 77665 | 77676 | } |
| 77666 | 77677 | static int analyzeAggregatesInSelect(Walker *pWalker, Select *pSelect){ |
| @@ -77668,13 +77679,14 @@ | ||
| 77668 | 77679 | UNUSED_PARAMETER(pSelect); |
| 77669 | 77680 | return WRC_Continue; |
| 77670 | 77681 | } |
| 77671 | 77682 | |
| 77672 | 77683 | /* |
| 77673 | -** Analyze the given expression looking for aggregate functions and | |
| 77674 | -** for variables that need to be added to the pParse->aAgg[] array. | |
| 77675 | -** Make additional entries to the pParse->aAgg[] array as necessary. | |
| 77684 | +** Analyze the pExpr expression looking for aggregate functions and | |
| 77685 | +** for variables that need to be added to AggInfo object that pNC->pAggInfo | |
| 77686 | +** points to. Additional entries are made on the AggInfo object as | |
| 77687 | +** necessary. | |
| 77676 | 77688 | ** |
| 77677 | 77689 | ** This routine should only be called after the expression has been |
| 77678 | 77690 | ** analyzed by sqlite3ResolveExprNames(). |
| 77679 | 77691 | */ |
| 77680 | 77692 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){ |
| @@ -85700,10 +85712,59 @@ | ||
| 85700 | 85712 | sqlite3_result_double(context, rVal); |
| 85701 | 85713 | break; |
| 85702 | 85714 | } |
| 85703 | 85715 | } |
| 85704 | 85716 | } |
| 85717 | + | |
| 85718 | +/* | |
| 85719 | +** Implementation of the instr() function. | |
| 85720 | +** | |
| 85721 | +** instr(haystack,needle) finds the first occurrence of needle | |
| 85722 | +** in haystack and returns the number of previous characters plus 1, | |
| 85723 | +** or 0 if needle does not occur within haystack. | |
| 85724 | +** | |
| 85725 | +** If both haystack and needle are BLOBs, then the result is one more than | |
| 85726 | +** the number of bytes in haystack prior to the first occurrence of needle, | |
| 85727 | +** or 0 if needle never occurs in haystack. | |
| 85728 | +*/ | |
| 85729 | +static void instrFunc( | |
| 85730 | + sqlite3_context *context, | |
| 85731 | + int argc, | |
| 85732 | + sqlite3_value **argv | |
| 85733 | +){ | |
| 85734 | + const unsigned char *zHaystack; | |
| 85735 | + const unsigned char *zNeedle; | |
| 85736 | + int nHaystack; | |
| 85737 | + int nNeedle; | |
| 85738 | + int typeHaystack, typeNeedle; | |
| 85739 | + int N = 1; | |
| 85740 | + int isText; | |
| 85741 | + | |
| 85742 | + typeHaystack = sqlite3_value_type(argv[0]); | |
| 85743 | + typeNeedle = sqlite3_value_type(argv[1]); | |
| 85744 | + if( typeHaystack==SQLITE_NULL || typeNeedle==SQLITE_NULL ) return; | |
| 85745 | + nHaystack = sqlite3_value_bytes(argv[0]); | |
| 85746 | + nNeedle = sqlite3_value_bytes(argv[1]); | |
| 85747 | + if( typeHaystack==SQLITE_BLOB && typeNeedle==SQLITE_BLOB ){ | |
| 85748 | + zHaystack = sqlite3_value_blob(argv[0]); | |
| 85749 | + zNeedle = sqlite3_value_blob(argv[1]); | |
| 85750 | + isText = 0; | |
| 85751 | + }else{ | |
| 85752 | + zHaystack = sqlite3_value_text(argv[0]); | |
| 85753 | + zNeedle = sqlite3_value_text(argv[1]); | |
| 85754 | + isText = 1; | |
| 85755 | + } | |
| 85756 | + while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){ | |
| 85757 | + N++; | |
| 85758 | + do{ | |
| 85759 | + nHaystack--; | |
| 85760 | + zHaystack++; | |
| 85761 | + }while( isText && (zHaystack[0]&0xc0)==0x80 ); | |
| 85762 | + } | |
| 85763 | + if( nNeedle>nHaystack ) N = 0; | |
| 85764 | + sqlite3_result_int(context, N); | |
| 85765 | +} | |
| 85705 | 85766 | |
| 85706 | 85767 | /* |
| 85707 | 85768 | ** Implementation of the substr() function. |
| 85708 | 85769 | ** |
| 85709 | 85770 | ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1. |
| @@ -87069,10 +87130,11 @@ | ||
| 87069 | 87130 | FUNCTION(max, -1, 1, 1, minmaxFunc ), |
| 87070 | 87131 | FUNCTION(max, 0, 1, 1, 0 ), |
| 87071 | 87132 | AGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize ), |
| 87072 | 87133 | FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), |
| 87073 | 87134 | FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), |
| 87135 | + FUNCTION(instr, 2, 0, 0, instrFunc ), | |
| 87074 | 87136 | FUNCTION(substr, 2, 0, 0, substrFunc ), |
| 87075 | 87137 | FUNCTION(substr, 3, 0, 0, substrFunc ), |
| 87076 | 87138 | FUNCTION(abs, 1, 0, 0, absFunc ), |
| 87077 | 87139 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 87078 | 87140 | FUNCTION(round, 1, 0, 0, roundFunc ), |
| @@ -107298,19 +107360,32 @@ | ||
| 107298 | 107360 | || sWBI.cost.plan.u.pIdx==sWBI.pSrc->pIndex ); |
| 107299 | 107361 | |
| 107300 | 107362 | if( isOptimal && (sWBI.cost.plan.wsFlags & WHERE_NOT_FULLSCAN)==0 ){ |
| 107301 | 107363 | notIndexed |= m; |
| 107302 | 107364 | } |
| 107365 | + if( isOptimal ){ | |
| 107366 | + pWInfo->a[j].rOptCost = sWBI.cost.rCost; | |
| 107367 | + }else if( iFrom<nTabList-1 ){ | |
| 107368 | + /* If two or more tables have nearly the same outer loop cost, | |
| 107369 | + ** very different inner loop (optimal) cost, we want to choose | |
| 107370 | + ** for the outer loop that table which benefits the least from | |
| 107371 | + ** being in the inner loop. The following code scales the | |
| 107372 | + ** outer loop cost estimate to accomplish that. */ | |
| 107373 | + WHERETRACE((" scaling cost from %.1f to %.1f\n", | |
| 107374 | + sWBI.cost.rCost, | |
| 107375 | + sWBI.cost.rCost/pWInfo->a[j].rOptCost)); | |
| 107376 | + sWBI.cost.rCost /= pWInfo->a[j].rOptCost; | |
| 107377 | + } | |
| 107303 | 107378 | |
| 107304 | 107379 | /* Conditions under which this table becomes the best so far: |
| 107305 | 107380 | ** |
| 107306 | 107381 | ** (1) The table must not depend on other tables that have not |
| 107307 | 107382 | ** yet run. (In other words, it must not depend on tables |
| 107308 | 107383 | ** in inner loops.) |
| 107309 | 107384 | ** |
| 107310 | - ** (2) A full-table-scan plan cannot supercede indexed plan unless | |
| 107311 | - ** the full-table-scan is an "optimal" plan as defined above. | |
| 107385 | + ** (2) (This rule was removed on 2012-11-09. The scaling of the | |
| 107386 | + ** cost using the optimal scan cost made this rule obsolete.) | |
| 107312 | 107387 | ** |
| 107313 | 107388 | ** (3) All tables have an INDEXED BY clause or this table lacks an |
| 107314 | 107389 | ** INDEXED BY clause or this table uses the specific |
| 107315 | 107390 | ** index specified by its INDEXED BY clause. This rule ensures |
| 107316 | 107391 | ** that a best-so-far is always selected even if an impossible |
| @@ -107321,13 +107396,10 @@ | ||
| 107321 | 107396 | ** |
| 107322 | 107397 | ** (4) The plan cost must be lower than prior plans, where "cost" |
| 107323 | 107398 | ** is defined by the compareCost() function above. |
| 107324 | 107399 | */ |
| 107325 | 107400 | if( (sWBI.cost.used&sWBI.notValid)==0 /* (1) */ |
| 107326 | - && (bestJ<0 || (notIndexed&m)!=0 /* (2) */ | |
| 107327 | - || (bestPlan.plan.wsFlags & WHERE_NOT_FULLSCAN)==0 | |
| 107328 | - || (sWBI.cost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0) | |
| 107329 | 107401 | && (nUnconstrained==0 || sWBI.pSrc->pIndex==0 /* (3) */ |
| 107330 | 107402 | || NEVER((sWBI.cost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0)) |
| 107331 | 107403 | && (bestJ<0 || compareCost(&sWBI.cost, &bestPlan)) /* (4) */ |
| 107332 | 107404 | ){ |
| 107333 | 107405 | WHERETRACE((" === table %d (%s) is best so far\n" |
| 107334 | 107406 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -673,11 +673,11 @@ | |
| 673 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 674 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 675 | */ |
| 676 | #define SQLITE_VERSION "3.7.15" |
| 677 | #define SQLITE_VERSION_NUMBER 3007015 |
| 678 | #define SQLITE_SOURCE_ID "2012-10-30 18:09:46 9dca18f5fea84afbecb314ee1cdfb98430656af3" |
| 679 | |
| 680 | /* |
| 681 | ** CAPI3REF: Run-Time Library Version Numbers |
| 682 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 683 | ** |
| @@ -1038,10 +1038,11 @@ | |
| 1038 | #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) |
| 1039 | #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) |
| 1040 | #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) |
| 1041 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
| 1042 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 1043 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 1044 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1045 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 1046 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 1047 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| @@ -11008,10 +11009,11 @@ | |
| 11008 | int addrInTop; /* Top of the IN loop */ |
| 11009 | } *aInLoop; /* Information about each nested IN operator */ |
| 11010 | } in; /* Used when plan.wsFlags&WHERE_IN_ABLE */ |
| 11011 | Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */ |
| 11012 | } u; |
| 11013 | |
| 11014 | /* The following field is really not part of the current level. But |
| 11015 | ** we need a place to cache virtual table index information for each |
| 11016 | ** virtual table in the FROM clause and the WhereLevel structure is |
| 11017 | ** a convenient place since there is one WhereLevel for each FROM clause |
| @@ -13716,10 +13718,11 @@ | |
| 13716 | int nByte = 0; /* Used to accumulate return value */ |
| 13717 | |
| 13718 | db->pnBytesFreed = &nByte; |
| 13719 | for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){ |
| 13720 | sqlite3VdbeClearObject(db, pVdbe); |
| 13721 | } |
| 13722 | db->pnBytesFreed = 0; |
| 13723 | |
| 13724 | *pHighwater = 0; |
| 13725 | *pCurrent = nByte; |
| @@ -28219,12 +28222,17 @@ | |
| 28219 | int dirSync /* If true, fsync() directory after deleting file */ |
| 28220 | ){ |
| 28221 | int rc = SQLITE_OK; |
| 28222 | UNUSED_PARAMETER(NotUsed); |
| 28223 | SimulateIOError(return SQLITE_IOERR_DELETE); |
| 28224 | if( osUnlink(zPath)==(-1) && errno!=ENOENT ){ |
| 28225 | return unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath); |
| 28226 | } |
| 28227 | #ifndef SQLITE_DISABLE_DIRSYNC |
| 28228 | if( (dirSync & 1)!=0 ){ |
| 28229 | int fd; |
| 28230 | rc = osOpenDirectory(zPath, &fd); |
| @@ -40388,10 +40396,11 @@ | |
| 40388 | |
| 40389 | rc = pagerPagecount(pPager, &nPage); |
| 40390 | if( rc ) return rc; |
| 40391 | if( nPage==0 ){ |
| 40392 | rc = sqlite3OsDelete(pPager->pVfs, pPager->zWal, 0); |
| 40393 | isWal = 0; |
| 40394 | }else{ |
| 40395 | rc = sqlite3OsAccess( |
| 40396 | pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &isWal |
| 40397 | ); |
| @@ -77655,12 +77664,14 @@ | |
| 77655 | */ |
| 77656 | assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) ); |
| 77657 | ExprSetIrreducible(pExpr); |
| 77658 | pExpr->iAgg = (i16)i; |
| 77659 | pExpr->pAggInfo = pAggInfo; |
| 77660 | } |
| 77661 | return WRC_Prune; |
| 77662 | } |
| 77663 | } |
| 77664 | return WRC_Continue; |
| 77665 | } |
| 77666 | static int analyzeAggregatesInSelect(Walker *pWalker, Select *pSelect){ |
| @@ -77668,13 +77679,14 @@ | |
| 77668 | UNUSED_PARAMETER(pSelect); |
| 77669 | return WRC_Continue; |
| 77670 | } |
| 77671 | |
| 77672 | /* |
| 77673 | ** Analyze the given expression looking for aggregate functions and |
| 77674 | ** for variables that need to be added to the pParse->aAgg[] array. |
| 77675 | ** Make additional entries to the pParse->aAgg[] array as necessary. |
| 77676 | ** |
| 77677 | ** This routine should only be called after the expression has been |
| 77678 | ** analyzed by sqlite3ResolveExprNames(). |
| 77679 | */ |
| 77680 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){ |
| @@ -85700,10 +85712,59 @@ | |
| 85700 | sqlite3_result_double(context, rVal); |
| 85701 | break; |
| 85702 | } |
| 85703 | } |
| 85704 | } |
| 85705 | |
| 85706 | /* |
| 85707 | ** Implementation of the substr() function. |
| 85708 | ** |
| 85709 | ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1. |
| @@ -87069,10 +87130,11 @@ | |
| 87069 | FUNCTION(max, -1, 1, 1, minmaxFunc ), |
| 87070 | FUNCTION(max, 0, 1, 1, 0 ), |
| 87071 | AGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize ), |
| 87072 | FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), |
| 87073 | FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), |
| 87074 | FUNCTION(substr, 2, 0, 0, substrFunc ), |
| 87075 | FUNCTION(substr, 3, 0, 0, substrFunc ), |
| 87076 | FUNCTION(abs, 1, 0, 0, absFunc ), |
| 87077 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 87078 | FUNCTION(round, 1, 0, 0, roundFunc ), |
| @@ -107298,19 +107360,32 @@ | |
| 107298 | || sWBI.cost.plan.u.pIdx==sWBI.pSrc->pIndex ); |
| 107299 | |
| 107300 | if( isOptimal && (sWBI.cost.plan.wsFlags & WHERE_NOT_FULLSCAN)==0 ){ |
| 107301 | notIndexed |= m; |
| 107302 | } |
| 107303 | |
| 107304 | /* Conditions under which this table becomes the best so far: |
| 107305 | ** |
| 107306 | ** (1) The table must not depend on other tables that have not |
| 107307 | ** yet run. (In other words, it must not depend on tables |
| 107308 | ** in inner loops.) |
| 107309 | ** |
| 107310 | ** (2) A full-table-scan plan cannot supercede indexed plan unless |
| 107311 | ** the full-table-scan is an "optimal" plan as defined above. |
| 107312 | ** |
| 107313 | ** (3) All tables have an INDEXED BY clause or this table lacks an |
| 107314 | ** INDEXED BY clause or this table uses the specific |
| 107315 | ** index specified by its INDEXED BY clause. This rule ensures |
| 107316 | ** that a best-so-far is always selected even if an impossible |
| @@ -107321,13 +107396,10 @@ | |
| 107321 | ** |
| 107322 | ** (4) The plan cost must be lower than prior plans, where "cost" |
| 107323 | ** is defined by the compareCost() function above. |
| 107324 | */ |
| 107325 | if( (sWBI.cost.used&sWBI.notValid)==0 /* (1) */ |
| 107326 | && (bestJ<0 || (notIndexed&m)!=0 /* (2) */ |
| 107327 | || (bestPlan.plan.wsFlags & WHERE_NOT_FULLSCAN)==0 |
| 107328 | || (sWBI.cost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0) |
| 107329 | && (nUnconstrained==0 || sWBI.pSrc->pIndex==0 /* (3) */ |
| 107330 | || NEVER((sWBI.cost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0)) |
| 107331 | && (bestJ<0 || compareCost(&sWBI.cost, &bestPlan)) /* (4) */ |
| 107332 | ){ |
| 107333 | WHERETRACE((" === table %d (%s) is best so far\n" |
| 107334 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -673,11 +673,11 @@ | |
| 673 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 674 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 675 | */ |
| 676 | #define SQLITE_VERSION "3.7.15" |
| 677 | #define SQLITE_VERSION_NUMBER 3007015 |
| 678 | #define SQLITE_SOURCE_ID "2012-11-09 21:40:02 5a3b07f0f5dfae7eea870303f52f37d6a17f1da2" |
| 679 | |
| 680 | /* |
| 681 | ** CAPI3REF: Run-Time Library Version Numbers |
| 682 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 683 | ** |
| @@ -1038,10 +1038,11 @@ | |
| 1038 | #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) |
| 1039 | #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) |
| 1040 | #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) |
| 1041 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
| 1042 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 1043 | #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) |
| 1044 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 1045 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1046 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 1047 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 1048 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| @@ -11008,10 +11009,11 @@ | |
| 11009 | int addrInTop; /* Top of the IN loop */ |
| 11010 | } *aInLoop; /* Information about each nested IN operator */ |
| 11011 | } in; /* Used when plan.wsFlags&WHERE_IN_ABLE */ |
| 11012 | Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */ |
| 11013 | } u; |
| 11014 | double rOptCost; /* "Optimal" cost for this level */ |
| 11015 | |
| 11016 | /* The following field is really not part of the current level. But |
| 11017 | ** we need a place to cache virtual table index information for each |
| 11018 | ** virtual table in the FROM clause and the WhereLevel structure is |
| 11019 | ** a convenient place since there is one WhereLevel for each FROM clause |
| @@ -13716,10 +13718,11 @@ | |
| 13718 | int nByte = 0; /* Used to accumulate return value */ |
| 13719 | |
| 13720 | db->pnBytesFreed = &nByte; |
| 13721 | for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){ |
| 13722 | sqlite3VdbeClearObject(db, pVdbe); |
| 13723 | sqlite3DbFree(db, pVdbe); |
| 13724 | } |
| 13725 | db->pnBytesFreed = 0; |
| 13726 | |
| 13727 | *pHighwater = 0; |
| 13728 | *pCurrent = nByte; |
| @@ -28219,12 +28222,17 @@ | |
| 28222 | int dirSync /* If true, fsync() directory after deleting file */ |
| 28223 | ){ |
| 28224 | int rc = SQLITE_OK; |
| 28225 | UNUSED_PARAMETER(NotUsed); |
| 28226 | SimulateIOError(return SQLITE_IOERR_DELETE); |
| 28227 | if( osUnlink(zPath)==(-1) ){ |
| 28228 | if( errno==ENOENT ){ |
| 28229 | rc = SQLITE_IOERR_DELETE_NOENT; |
| 28230 | }else{ |
| 28231 | rc = unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath); |
| 28232 | } |
| 28233 | return rc; |
| 28234 | } |
| 28235 | #ifndef SQLITE_DISABLE_DIRSYNC |
| 28236 | if( (dirSync & 1)!=0 ){ |
| 28237 | int fd; |
| 28238 | rc = osOpenDirectory(zPath, &fd); |
| @@ -40388,10 +40396,11 @@ | |
| 40396 | |
| 40397 | rc = pagerPagecount(pPager, &nPage); |
| 40398 | if( rc ) return rc; |
| 40399 | if( nPage==0 ){ |
| 40400 | rc = sqlite3OsDelete(pPager->pVfs, pPager->zWal, 0); |
| 40401 | if( rc==SQLITE_IOERR_DELETE_NOENT ) rc = SQLITE_OK; |
| 40402 | isWal = 0; |
| 40403 | }else{ |
| 40404 | rc = sqlite3OsAccess( |
| 40405 | pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &isWal |
| 40406 | ); |
| @@ -77655,12 +77664,14 @@ | |
| 77664 | */ |
| 77665 | assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) ); |
| 77666 | ExprSetIrreducible(pExpr); |
| 77667 | pExpr->iAgg = (i16)i; |
| 77668 | pExpr->pAggInfo = pAggInfo; |
| 77669 | return WRC_Prune; |
| 77670 | }else{ |
| 77671 | return WRC_Continue; |
| 77672 | } |
| 77673 | } |
| 77674 | } |
| 77675 | return WRC_Continue; |
| 77676 | } |
| 77677 | static int analyzeAggregatesInSelect(Walker *pWalker, Select *pSelect){ |
| @@ -77668,13 +77679,14 @@ | |
| 77679 | UNUSED_PARAMETER(pSelect); |
| 77680 | return WRC_Continue; |
| 77681 | } |
| 77682 | |
| 77683 | /* |
| 77684 | ** Analyze the pExpr expression looking for aggregate functions and |
| 77685 | ** for variables that need to be added to AggInfo object that pNC->pAggInfo |
| 77686 | ** points to. Additional entries are made on the AggInfo object as |
| 77687 | ** necessary. |
| 77688 | ** |
| 77689 | ** This routine should only be called after the expression has been |
| 77690 | ** analyzed by sqlite3ResolveExprNames(). |
| 77691 | */ |
| 77692 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){ |
| @@ -85700,10 +85712,59 @@ | |
| 85712 | sqlite3_result_double(context, rVal); |
| 85713 | break; |
| 85714 | } |
| 85715 | } |
| 85716 | } |
| 85717 | |
| 85718 | /* |
| 85719 | ** Implementation of the instr() function. |
| 85720 | ** |
| 85721 | ** instr(haystack,needle) finds the first occurrence of needle |
| 85722 | ** in haystack and returns the number of previous characters plus 1, |
| 85723 | ** or 0 if needle does not occur within haystack. |
| 85724 | ** |
| 85725 | ** If both haystack and needle are BLOBs, then the result is one more than |
| 85726 | ** the number of bytes in haystack prior to the first occurrence of needle, |
| 85727 | ** or 0 if needle never occurs in haystack. |
| 85728 | */ |
| 85729 | static void instrFunc( |
| 85730 | sqlite3_context *context, |
| 85731 | int argc, |
| 85732 | sqlite3_value **argv |
| 85733 | ){ |
| 85734 | const unsigned char *zHaystack; |
| 85735 | const unsigned char *zNeedle; |
| 85736 | int nHaystack; |
| 85737 | int nNeedle; |
| 85738 | int typeHaystack, typeNeedle; |
| 85739 | int N = 1; |
| 85740 | int isText; |
| 85741 | |
| 85742 | typeHaystack = sqlite3_value_type(argv[0]); |
| 85743 | typeNeedle = sqlite3_value_type(argv[1]); |
| 85744 | if( typeHaystack==SQLITE_NULL || typeNeedle==SQLITE_NULL ) return; |
| 85745 | nHaystack = sqlite3_value_bytes(argv[0]); |
| 85746 | nNeedle = sqlite3_value_bytes(argv[1]); |
| 85747 | if( typeHaystack==SQLITE_BLOB && typeNeedle==SQLITE_BLOB ){ |
| 85748 | zHaystack = sqlite3_value_blob(argv[0]); |
| 85749 | zNeedle = sqlite3_value_blob(argv[1]); |
| 85750 | isText = 0; |
| 85751 | }else{ |
| 85752 | zHaystack = sqlite3_value_text(argv[0]); |
| 85753 | zNeedle = sqlite3_value_text(argv[1]); |
| 85754 | isText = 1; |
| 85755 | } |
| 85756 | while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){ |
| 85757 | N++; |
| 85758 | do{ |
| 85759 | nHaystack--; |
| 85760 | zHaystack++; |
| 85761 | }while( isText && (zHaystack[0]&0xc0)==0x80 ); |
| 85762 | } |
| 85763 | if( nNeedle>nHaystack ) N = 0; |
| 85764 | sqlite3_result_int(context, N); |
| 85765 | } |
| 85766 | |
| 85767 | /* |
| 85768 | ** Implementation of the substr() function. |
| 85769 | ** |
| 85770 | ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1. |
| @@ -87069,10 +87130,11 @@ | |
| 87130 | FUNCTION(max, -1, 1, 1, minmaxFunc ), |
| 87131 | FUNCTION(max, 0, 1, 1, 0 ), |
| 87132 | AGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize ), |
| 87133 | FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), |
| 87134 | FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), |
| 87135 | FUNCTION(instr, 2, 0, 0, instrFunc ), |
| 87136 | FUNCTION(substr, 2, 0, 0, substrFunc ), |
| 87137 | FUNCTION(substr, 3, 0, 0, substrFunc ), |
| 87138 | FUNCTION(abs, 1, 0, 0, absFunc ), |
| 87139 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 87140 | FUNCTION(round, 1, 0, 0, roundFunc ), |
| @@ -107298,19 +107360,32 @@ | |
| 107360 | || sWBI.cost.plan.u.pIdx==sWBI.pSrc->pIndex ); |
| 107361 | |
| 107362 | if( isOptimal && (sWBI.cost.plan.wsFlags & WHERE_NOT_FULLSCAN)==0 ){ |
| 107363 | notIndexed |= m; |
| 107364 | } |
| 107365 | if( isOptimal ){ |
| 107366 | pWInfo->a[j].rOptCost = sWBI.cost.rCost; |
| 107367 | }else if( iFrom<nTabList-1 ){ |
| 107368 | /* If two or more tables have nearly the same outer loop cost, |
| 107369 | ** very different inner loop (optimal) cost, we want to choose |
| 107370 | ** for the outer loop that table which benefits the least from |
| 107371 | ** being in the inner loop. The following code scales the |
| 107372 | ** outer loop cost estimate to accomplish that. */ |
| 107373 | WHERETRACE((" scaling cost from %.1f to %.1f\n", |
| 107374 | sWBI.cost.rCost, |
| 107375 | sWBI.cost.rCost/pWInfo->a[j].rOptCost)); |
| 107376 | sWBI.cost.rCost /= pWInfo->a[j].rOptCost; |
| 107377 | } |
| 107378 | |
| 107379 | /* Conditions under which this table becomes the best so far: |
| 107380 | ** |
| 107381 | ** (1) The table must not depend on other tables that have not |
| 107382 | ** yet run. (In other words, it must not depend on tables |
| 107383 | ** in inner loops.) |
| 107384 | ** |
| 107385 | ** (2) (This rule was removed on 2012-11-09. The scaling of the |
| 107386 | ** cost using the optimal scan cost made this rule obsolete.) |
| 107387 | ** |
| 107388 | ** (3) All tables have an INDEXED BY clause or this table lacks an |
| 107389 | ** INDEXED BY clause or this table uses the specific |
| 107390 | ** index specified by its INDEXED BY clause. This rule ensures |
| 107391 | ** that a best-so-far is always selected even if an impossible |
| @@ -107321,13 +107396,10 @@ | |
| 107396 | ** |
| 107397 | ** (4) The plan cost must be lower than prior plans, where "cost" |
| 107398 | ** is defined by the compareCost() function above. |
| 107399 | */ |
| 107400 | if( (sWBI.cost.used&sWBI.notValid)==0 /* (1) */ |
| 107401 | && (nUnconstrained==0 || sWBI.pSrc->pIndex==0 /* (3) */ |
| 107402 | || NEVER((sWBI.cost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0)) |
| 107403 | && (bestJ<0 || compareCost(&sWBI.cost, &bestPlan)) /* (4) */ |
| 107404 | ){ |
| 107405 | WHERETRACE((" === table %d (%s) is best so far\n" |
| 107406 |
+2
-1
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -107,11 +107,11 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.7.15" |
| 111 | 111 | #define SQLITE_VERSION_NUMBER 3007015 |
| 112 | -#define SQLITE_SOURCE_ID "2012-10-30 18:09:46 9dca18f5fea84afbecb314ee1cdfb98430656af3" | |
| 112 | +#define SQLITE_SOURCE_ID "2012-11-09 21:40:02 5a3b07f0f5dfae7eea870303f52f37d6a17f1da2" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -472,10 +472,11 @@ | ||
| 472 | 472 | #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) |
| 473 | 473 | #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) |
| 474 | 474 | #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) |
| 475 | 475 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
| 476 | 476 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 477 | +#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) | |
| 477 | 478 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 478 | 479 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 479 | 480 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 480 | 481 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 481 | 482 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 482 | 483 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.7.15" |
| 111 | #define SQLITE_VERSION_NUMBER 3007015 |
| 112 | #define SQLITE_SOURCE_ID "2012-10-30 18:09:46 9dca18f5fea84afbecb314ee1cdfb98430656af3" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -472,10 +472,11 @@ | |
| 472 | #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) |
| 473 | #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) |
| 474 | #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) |
| 475 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
| 476 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 477 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 478 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 479 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 480 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 481 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 482 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.7.15" |
| 111 | #define SQLITE_VERSION_NUMBER 3007015 |
| 112 | #define SQLITE_SOURCE_ID "2012-11-09 21:40:02 5a3b07f0f5dfae7eea870303f52f37d6a17f1da2" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -472,10 +472,11 @@ | |
| 472 | #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) |
| 473 | #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) |
| 474 | #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) |
| 475 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
| 476 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 477 | #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) |
| 478 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 479 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 480 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 481 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 482 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 483 |