| | @@ -135,11 +135,11 @@ |
| 135 | 135 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 136 | 136 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 137 | 137 | */ |
| 138 | 138 | #define SQLITE_VERSION "3.8.1" |
| 139 | 139 | #define SQLITE_VERSION_NUMBER 3008001 |
| 140 | | -#define SQLITE_SOURCE_ID "2013-10-11 13:27:26 03593817ab5abdd4bbaa5e47e2e4745eef025af9" |
| 140 | +#define SQLITE_SOURCE_ID "2013-10-14 13:21:00 1660efbe46439734c7dc1674994ceb86a9b41d1a" |
| 141 | 141 | |
| 142 | 142 | /* |
| 143 | 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 144 | 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 145 | 145 | ** |
| | @@ -1643,31 +1643,31 @@ |
| 1643 | 1643 | ** supplied by the application must not invoke any SQLite interface. |
| 1644 | 1644 | ** In a multi-threaded application, the application-defined logger |
| 1645 | 1645 | ** function must be threadsafe. </dd> |
| 1646 | 1646 | ** |
| 1647 | 1647 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 1648 | | -** <dd> This option takes a single argument of type int. If non-zero, then |
| 1648 | +** <dd>^(This option takes a single argument of type int. If non-zero, then |
| 1649 | 1649 | ** URI handling is globally enabled. If the parameter is zero, then URI handling |
| 1650 | | -** is globally disabled. If URI handling is globally enabled, all filenames |
| 1650 | +** is globally disabled.)^ ^If URI handling is globally enabled, all filenames |
| 1651 | 1651 | ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or |
| 1652 | 1652 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 1653 | 1653 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 1654 | | -** connection is opened. If it is globally disabled, filenames are |
| 1654 | +** connection is opened. ^If it is globally disabled, filenames are |
| 1655 | 1655 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 1656 | | -** database connection is opened. By default, URI handling is globally |
| 1656 | +** database connection is opened. ^(By default, URI handling is globally |
| 1657 | 1657 | ** disabled. The default value may be changed by compiling with the |
| 1658 | | -** [SQLITE_USE_URI] symbol defined. |
| 1658 | +** [SQLITE_USE_URI] symbol defined.)^ |
| 1659 | 1659 | ** |
| 1660 | 1660 | ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN |
| 1661 | | -** <dd> This option takes a single integer argument which is interpreted as |
| 1661 | +** <dd>^This option takes a single integer argument which is interpreted as |
| 1662 | 1662 | ** a boolean in order to enable or disable the use of covering indices for |
| 1663 | | -** full table scans in the query optimizer. The default setting is determined |
| 1663 | +** full table scans in the query optimizer. ^The default setting is determined |
| 1664 | 1664 | ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" |
| 1665 | 1665 | ** if that compile-time option is omitted. |
| 1666 | 1666 | ** The ability to disable the use of covering indices for full table scans |
| 1667 | 1667 | ** is because some incorrectly coded legacy applications might malfunction |
| 1668 | | -** malfunction when the optimization is enabled. Providing the ability to |
| 1668 | +** when the optimization is enabled. Providing the ability to |
| 1669 | 1669 | ** disable the optimization allows the older, buggy application code to work |
| 1670 | 1670 | ** without change even with newer versions of SQLite. |
| 1671 | 1671 | ** |
| 1672 | 1672 | ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]] |
| 1673 | 1673 | ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE |
| | @@ -1692,20 +1692,20 @@ |
| 1692 | 1692 | ** configuration option can be seen in the "test_sqllog.c" source file in |
| 1693 | 1693 | ** the canonical SQLite source tree.</dd> |
| 1694 | 1694 | ** |
| 1695 | 1695 | ** [[SQLITE_CONFIG_MMAP_SIZE]] |
| 1696 | 1696 | ** <dt>SQLITE_CONFIG_MMAP_SIZE |
| 1697 | | -** <dd>SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values |
| 1697 | +** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values |
| 1698 | 1698 | ** that are the default mmap size limit (the default setting for |
| 1699 | 1699 | ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit. |
| 1700 | | -** The default setting can be overridden by each database connection using |
| 1700 | +** ^The default setting can be overridden by each database connection using |
| 1701 | 1701 | ** either the [PRAGMA mmap_size] command, or by using the |
| 1702 | | -** [SQLITE_FCNTL_MMAP_SIZE] file control. The maximum allowed mmap size |
| 1702 | +** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size |
| 1703 | 1703 | ** cannot be changed at run-time. Nor may the maximum allowed mmap size |
| 1704 | 1704 | ** exceed the compile-time maximum mmap size set by the |
| 1705 | | -** [SQLITE_MAX_MMAP_SIZE] compile-time option. |
| 1706 | | -** If either argument to this option is negative, then that argument is |
| 1705 | +** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^ |
| 1706 | +** ^If either argument to this option is negative, then that argument is |
| 1707 | 1707 | ** changed to its compile-time default. |
| 1708 | 1708 | ** </dl> |
| 1709 | 1709 | */ |
| 1710 | 1710 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1711 | 1711 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| | @@ -14430,10 +14430,14 @@ |
| 14430 | 14430 | ** is available. This routine returns 0 on success and |
| 14431 | 14431 | ** non-zero on any kind of error. |
| 14432 | 14432 | ** |
| 14433 | 14433 | ** If the sqlite3GlobalConfig.bLocaltimeFault variable is true then this |
| 14434 | 14434 | ** routine will always fail. |
| 14435 | +** |
| 14436 | +** EVIDENCE-OF: R-62172-00036 In this implementation, the standard C |
| 14437 | +** library function localtime_r() is used to assist in the calculation of |
| 14438 | +** local time. |
| 14435 | 14439 | */ |
| 14436 | 14440 | static int osLocaltime(time_t *t, struct tm *pTm){ |
| 14437 | 14441 | int rc; |
| 14438 | 14442 | #if (!defined(HAVE_LOCALTIME_R) || !HAVE_LOCALTIME_R) \ |
| 14439 | 14443 | && (!defined(HAVE_LOCALTIME_S) || !HAVE_LOCALTIME_S) |
| | @@ -14486,10 +14490,15 @@ |
| 14486 | 14490 | memset(&sLocal, 0, sizeof(sLocal)); |
| 14487 | 14491 | |
| 14488 | 14492 | x = *p; |
| 14489 | 14493 | computeYMD_HMS(&x); |
| 14490 | 14494 | if( x.Y<1971 || x.Y>=2038 ){ |
| 14495 | + /* EVIDENCE-OF: R-55269-29598 The localtime_r() C function normally only |
| 14496 | + ** works for years between 1970 and 2037. For dates outside this range, |
| 14497 | + ** SQLite attempts to map the year into an equivalent year within this |
| 14498 | + ** range, do the calculation, then map the year back. |
| 14499 | + */ |
| 14491 | 14500 | x.Y = 2000; |
| 14492 | 14501 | x.M = 1; |
| 14493 | 14502 | x.D = 1; |
| 14494 | 14503 | x.h = 0; |
| 14495 | 14504 | x.m = 0; |
| | @@ -60299,11 +60308,13 @@ |
| 60299 | 60308 | } |
| 60300 | 60309 | |
| 60301 | 60310 | pRec->nField = p->iVal+1; |
| 60302 | 60311 | return &pRec->aMem[p->iVal]; |
| 60303 | 60312 | } |
| 60304 | | -#endif |
| 60313 | +#else |
| 60314 | + UNUSED_PARAMETER(p); |
| 60315 | +#endif /* defined(SQLITE_ENABLE_STAT3_OR_STAT4) */ |
| 60305 | 60316 | return sqlite3ValueNew(db); |
| 60306 | 60317 | } |
| 60307 | 60318 | |
| 60308 | 60319 | /* |
| 60309 | 60320 | ** Extract a value from the supplied expression in the manner described |
| | @@ -60313,11 +60324,11 @@ |
| 60313 | 60324 | ** If pCtx is NULL and an error occurs after the sqlite3_value object |
| 60314 | 60325 | ** has been allocated, it is freed before returning. Or, if pCtx is not |
| 60315 | 60326 | ** NULL, it is assumed that the caller will free any allocated object |
| 60316 | 60327 | ** in all cases. |
| 60317 | 60328 | */ |
| 60318 | | -int valueFromExpr( |
| 60329 | +static int valueFromExpr( |
| 60319 | 60330 | sqlite3 *db, /* The database connection */ |
| 60320 | 60331 | Expr *pExpr, /* The expression to evaluate */ |
| 60321 | 60332 | u8 enc, /* Encoding to use */ |
| 60322 | 60333 | u8 affinity, /* Affinity to use */ |
| 60323 | 60334 | sqlite3_value **ppVal, /* Write the new value here */ |
| | @@ -60470,10 +60481,11 @@ |
| 60470 | 60481 | int nVal; /* Bytes of space required for argv[0] */ |
| 60471 | 60482 | int nRet; |
| 60472 | 60483 | sqlite3 *db; |
| 60473 | 60484 | u8 *aRet; |
| 60474 | 60485 | |
| 60486 | + UNUSED_PARAMETER( argc ); |
| 60475 | 60487 | iSerial = sqlite3VdbeSerialType(argv[0], file_format); |
| 60476 | 60488 | nSerial = sqlite3VarintLen(iSerial); |
| 60477 | 60489 | nVal = sqlite3VdbeSerialTypeLen(iSerial); |
| 60478 | 60490 | db = sqlite3_context_db_handle(context); |
| 60479 | 60491 | |
| | @@ -75410,10 +75422,14 @@ |
| 75410 | 75422 | sqlite3ErrorMsg(pParse, "second argument to likelihood() must be a " |
| 75411 | 75423 | "constant between 0.0 and 1.0"); |
| 75412 | 75424 | pNC->nErr++; |
| 75413 | 75425 | } |
| 75414 | 75426 | }else{ |
| 75427 | + /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is equivalent to |
| 75428 | + ** likelihood(X, 0.0625). |
| 75429 | + ** EVIDENCE-OF: R-35738-39582 The unlikely(X) fucntion is short-hand for |
| 75430 | + ** likelihood(X,0.0625). */ |
| 75415 | 75431 | pExpr->iTable = 62; /* TUNING: Default 2nd arg to unlikely() is 0.0625 */ |
| 75416 | 75432 | } |
| 75417 | 75433 | } |
| 75418 | 75434 | } |
| 75419 | 75435 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| | @@ -81696,11 +81712,11 @@ |
| 81696 | 81712 | } |
| 81697 | 81713 | |
| 81698 | 81714 | /* |
| 81699 | 81715 | ** Copy the contents of object (*pFrom) into (*pTo). |
| 81700 | 81716 | */ |
| 81701 | | -void sampleCopy(Stat4Accum *p, Stat4Sample *pTo, Stat4Sample *pFrom){ |
| 81717 | +static void sampleCopy(Stat4Accum *p, Stat4Sample *pTo, Stat4Sample *pFrom){ |
| 81702 | 81718 | pTo->iRowid = pFrom->iRowid; |
| 81703 | 81719 | pTo->isPSample = pFrom->isPSample; |
| 81704 | 81720 | pTo->iCol = pFrom->iCol; |
| 81705 | 81721 | pTo->iHash = pFrom->iHash; |
| 81706 | 81722 | memcpy(pTo->anEq, pFrom->anEq, sizeof(tRowcnt)*p->nCol); |
| | @@ -81841,10 +81857,15 @@ |
| 81841 | 81857 | ){ |
| 81842 | 81858 | sampleInsert(p, &p->current, 0); |
| 81843 | 81859 | } |
| 81844 | 81860 | } |
| 81845 | 81861 | #endif |
| 81862 | + |
| 81863 | +#ifndef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 81864 | + UNUSED_PARAMETER( p ); |
| 81865 | + UNUSED_PARAMETER( iChng ); |
| 81866 | +#endif |
| 81846 | 81867 | } |
| 81847 | 81868 | |
| 81848 | 81869 | /* |
| 81849 | 81870 | ** Implementation of the stat_push SQL function: stat_push(P,R,C) |
| 81850 | 81871 | ** Arguments: |
| | @@ -81866,10 +81887,12 @@ |
| 81866 | 81887 | |
| 81867 | 81888 | /* The three function arguments */ |
| 81868 | 81889 | Stat4Accum *p = (Stat4Accum*)sqlite3_value_blob(argv[0]); |
| 81869 | 81890 | int iChng = sqlite3_value_int(argv[1]); |
| 81870 | 81891 | |
| 81892 | + UNUSED_PARAMETER( argc ); |
| 81893 | + UNUSED_PARAMETER( context ); |
| 81871 | 81894 | assert( p->nCol>1 ); /* Includes rowid field */ |
| 81872 | 81895 | assert( iChng<p->nCol ); |
| 81873 | 81896 | |
| 81874 | 81897 | if( p->nRow==0 ){ |
| 81875 | 81898 | /* This is the first call to this function. Do initialization. */ |
| | @@ -82051,10 +82074,13 @@ |
| 82051 | 82074 | sqlite3_result_text(context, zRet, -1, sqlite3_free); |
| 82052 | 82075 | } |
| 82053 | 82076 | } |
| 82054 | 82077 | } |
| 82055 | 82078 | #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */ |
| 82079 | +#ifndef SQLITE_DEBUG |
| 82080 | + UNUSED_PARAMETER( argc ); |
| 82081 | +#endif |
| 82056 | 82082 | } |
| 82057 | 82083 | static const FuncDef statGetFuncdef = { |
| 82058 | 82084 | 1+IsStat34, /* nArg */ |
| 82059 | 82085 | SQLITE_UTF8, /* funcFlags */ |
| 82060 | 82086 | 0, /* pUserData */ |
| | @@ -82069,12 +82095,14 @@ |
| 82069 | 82095 | |
| 82070 | 82096 | static void callStatGet(Vdbe *v, int regStat4, int iParam, int regOut){ |
| 82071 | 82097 | assert( regOut!=regStat4 && regOut!=regStat4+1 ); |
| 82072 | 82098 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 82073 | 82099 | sqlite3VdbeAddOp2(v, OP_Integer, iParam, regStat4+1); |
| 82074 | | -#else |
| 82100 | +#elif SQLITE_DEBUG |
| 82075 | 82101 | assert( iParam==STAT_GET_STAT1 ); |
| 82102 | +#else |
| 82103 | + UNUSED_PARAMETER( iParam ); |
| 82076 | 82104 | #endif |
| 82077 | 82105 | sqlite3VdbeAddOp3(v, OP_Function, 0, regStat4, regOut); |
| 82078 | 82106 | sqlite3VdbeChangeP4(v, -1, (char*)&statGetFuncdef, P4_FUNCDEF); |
| 82079 | 82107 | sqlite3VdbeChangeP5(v, 1 + IsStat34); |
| 82080 | 82108 | } |
| | @@ -84833,11 +84861,11 @@ |
| 84833 | 84861 | *pszEst = 1; /* default size is approx 4 bytes */ |
| 84834 | 84862 | if( aff<=SQLITE_AFF_NONE ){ |
| 84835 | 84863 | if( zChar ){ |
| 84836 | 84864 | while( zChar[0] ){ |
| 84837 | 84865 | if( sqlite3Isdigit(zChar[0]) ){ |
| 84838 | | - int v; |
| 84866 | + int v = 0; |
| 84839 | 84867 | sqlite3GetInt32(zChar, &v); |
| 84840 | 84868 | v = v/4 + 1; |
| 84841 | 84869 | if( v>255 ) v = 255; |
| 84842 | 84870 | *pszEst = v; /* BLOB(k), VARCHAR(k), CHAR(k) -> r=(k/4+1) */ |
| 84843 | 84871 | break; |
| | @@ -91144,11 +91172,11 @@ |
| 91144 | 91172 | ** generating any VDBE code. If one can be found, then jump over |
| 91145 | 91173 | ** the entire DELETE if there are no outstanding deferred constraints |
| 91146 | 91174 | ** when this statement is run. */ |
| 91147 | 91175 | FKey *p; |
| 91148 | 91176 | for(p=pTab->pFKey; p; p=p->pNextFrom){ |
| 91149 | | - if( p->isDeferred ) break; |
| 91177 | + if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break; |
| 91150 | 91178 | } |
| 91151 | 91179 | if( !p ) return; |
| 91152 | 91180 | iSkip = sqlite3VdbeMakeLabel(v); |
| 91153 | 91181 | sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); |
| 91154 | 91182 | } |
| | @@ -91158,15 +91186,22 @@ |
| 91158 | 91186 | pParse->disableTriggers = 0; |
| 91159 | 91187 | |
| 91160 | 91188 | /* If the DELETE has generated immediate foreign key constraint |
| 91161 | 91189 | ** violations, halt the VDBE and return an error at this point, before |
| 91162 | 91190 | ** any modifications to the schema are made. This is because statement |
| 91163 | | - ** transactions are not able to rollback schema changes. */ |
| 91164 | | - sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2); |
| 91165 | | - sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY, |
| 91166 | | - OE_Abort, "foreign key constraint failed", P4_STATIC |
| 91167 | | - ); |
| 91191 | + ** transactions are not able to rollback schema changes. |
| 91192 | + ** |
| 91193 | + ** If the SQLITE_DeferFKs flag is set, then this is not required, as |
| 91194 | + ** the statement transaction will not be rolled back even if FK |
| 91195 | + ** constraints are violated. |
| 91196 | + */ |
| 91197 | + if( (db->flags & SQLITE_DeferFKs)==0 ){ |
| 91198 | + sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2); |
| 91199 | + sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY, |
| 91200 | + OE_Abort, "foreign key constraint failed", P4_STATIC |
| 91201 | + ); |
| 91202 | + } |
| 91168 | 91203 | |
| 91169 | 91204 | if( iSkip ){ |
| 91170 | 91205 | sqlite3VdbeResolveLabel(v, iSkip); |
| 91171 | 91206 | } |
| 91172 | 91207 | } |
| | @@ -95164,22 +95199,23 @@ |
| 95164 | 95199 | #define PragTyp_MMAP_SIZE 23 |
| 95165 | 95200 | #define PragTyp_PAGE_SIZE 24 |
| 95166 | 95201 | #define PragTyp_SECURE_DELETE 25 |
| 95167 | 95202 | #define PragTyp_SHRINK_MEMORY 26 |
| 95168 | 95203 | #define PragTyp_SOFT_HEAP_LIMIT 27 |
| 95169 | | -#define PragTyp_SYNCHRONOUS 28 |
| 95170 | | -#define PragTyp_TABLE_INFO 29 |
| 95171 | | -#define PragTyp_TEMP_STORE 30 |
| 95172 | | -#define PragTyp_TEMP_STORE_DIRECTORY 31 |
| 95173 | | -#define PragTyp_WAL_AUTOCHECKPOINT 32 |
| 95174 | | -#define PragTyp_WAL_CHECKPOINT 33 |
| 95175 | | -#define PragTyp_ACTIVATE_EXTENSIONS 34 |
| 95176 | | -#define PragTyp_HEXKEY 35 |
| 95177 | | -#define PragTyp_KEY 36 |
| 95178 | | -#define PragTyp_REKEY 37 |
| 95179 | | -#define PragTyp_LOCK_STATUS 38 |
| 95180 | | -#define PragTyp_PARSER_TRACE 39 |
| 95204 | +#define PragTyp_STATS 28 |
| 95205 | +#define PragTyp_SYNCHRONOUS 29 |
| 95206 | +#define PragTyp_TABLE_INFO 30 |
| 95207 | +#define PragTyp_TEMP_STORE 31 |
| 95208 | +#define PragTyp_TEMP_STORE_DIRECTORY 32 |
| 95209 | +#define PragTyp_WAL_AUTOCHECKPOINT 33 |
| 95210 | +#define PragTyp_WAL_CHECKPOINT 34 |
| 95211 | +#define PragTyp_ACTIVATE_EXTENSIONS 35 |
| 95212 | +#define PragTyp_HEXKEY 36 |
| 95213 | +#define PragTyp_KEY 37 |
| 95214 | +#define PragTyp_REKEY 38 |
| 95215 | +#define PragTyp_LOCK_STATUS 39 |
| 95216 | +#define PragTyp_PARSER_TRACE 40 |
| 95181 | 95217 | #define PragFlag_NeedSchema 0x01 |
| 95182 | 95218 | static const struct sPragmaNames { |
| 95183 | 95219 | const char *const zName; /* Name of pragma */ |
| 95184 | 95220 | u8 ePragTyp; /* PragTyp_XXX value */ |
| 95185 | 95221 | u8 mPragFlag; /* Zero or more PragFlag_XXX values */ |
| | @@ -95466,10 +95502,16 @@ |
| 95466 | 95502 | #if defined(SQLITE_DEBUG) |
| 95467 | 95503 | { /* zName: */ "sql_trace", |
| 95468 | 95504 | /* ePragTyp: */ PragTyp_FLAG, |
| 95469 | 95505 | /* ePragFlag: */ 0, |
| 95470 | 95506 | /* iArg: */ SQLITE_SqlTrace }, |
| 95507 | +#endif |
| 95508 | +#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 95509 | + { /* zName: */ "stats", |
| 95510 | + /* ePragTyp: */ PragTyp_STATS, |
| 95511 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95512 | + /* iArg: */ 0 }, |
| 95471 | 95513 | #endif |
| 95472 | 95514 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 95473 | 95515 | { /* zName: */ "synchronous", |
| 95474 | 95516 | /* ePragTyp: */ PragTyp_SYNCHRONOUS, |
| 95475 | 95517 | /* ePragFlag: */ PragFlag_NeedSchema, |
| | @@ -95528,11 +95570,11 @@ |
| 95528 | 95570 | { /* zName: */ "writable_schema", |
| 95529 | 95571 | /* ePragTyp: */ PragTyp_FLAG, |
| 95530 | 95572 | /* ePragFlag: */ 0, |
| 95531 | 95573 | /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode }, |
| 95532 | 95574 | }; |
| 95533 | | -/* Number of pragmas: 55 on by default, 67 total. */ |
| 95575 | +/* Number of pragmas: 56 on by default, 68 total. */ |
| 95534 | 95576 | /* End of the automatically generated pragma table. |
| 95535 | 95577 | ***************************************************************************/ |
| 95536 | 95578 | |
| 95537 | 95579 | /* |
| 95538 | 95580 | ** Interpret the given string as a safety level. Return 0 for OFF, |
| | @@ -96532,10 +96574,40 @@ |
| 96532 | 96574 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6); |
| 96533 | 96575 | } |
| 96534 | 96576 | } |
| 96535 | 96577 | } |
| 96536 | 96578 | break; |
| 96579 | + |
| 96580 | + case PragTyp_STATS: { |
| 96581 | + Index *pIdx; |
| 96582 | + HashElem *i; |
| 96583 | + v = sqlite3GetVdbe(pParse); |
| 96584 | + sqlite3VdbeSetNumCols(v, 4); |
| 96585 | + pParse->nMem = 4; |
| 96586 | + sqlite3CodeVerifySchema(pParse, iDb); |
| 96587 | + sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC); |
| 96588 | + sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "index", SQLITE_STATIC); |
| 96589 | + sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "width", SQLITE_STATIC); |
| 96590 | + sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "height", SQLITE_STATIC); |
| 96591 | + for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){ |
| 96592 | + Table *pTab = sqliteHashData(i); |
| 96593 | + sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, pTab->zName, 0); |
| 96594 | + sqlite3VdbeAddOp2(v, OP_Null, 0, 2); |
| 96595 | + sqlite3VdbeAddOp2(v, OP_Integer, |
| 96596 | + (int)sqlite3LogEstToInt(pTab->szTabRow), 3); |
| 96597 | + sqlite3VdbeAddOp2(v, OP_Integer, (int)pTab->nRowEst, 4); |
| 96598 | + sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); |
| 96599 | + for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 96600 | + sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0); |
| 96601 | + sqlite3VdbeAddOp2(v, OP_Integer, |
| 96602 | + (int)sqlite3LogEstToInt(pIdx->szIdxRow), 3); |
| 96603 | + sqlite3VdbeAddOp2(v, OP_Integer, (int)pIdx->aiRowEst[0], 4); |
| 96604 | + sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); |
| 96605 | + } |
| 96606 | + } |
| 96607 | + } |
| 96608 | + break; |
| 96537 | 96609 | |
| 96538 | 96610 | case PragTyp_INDEX_INFO: if( zRight ){ |
| 96539 | 96611 | Index *pIdx; |
| 96540 | 96612 | Table *pTab; |
| 96541 | 96613 | pIdx = sqlite3FindIndex(db, zRight, zDb); |
| | @@ -96565,30 +96637,21 @@ |
| 96565 | 96637 | Table *pTab; |
| 96566 | 96638 | int i; |
| 96567 | 96639 | pTab = sqlite3FindTable(db, zRight, zDb); |
| 96568 | 96640 | if( pTab ){ |
| 96569 | 96641 | v = sqlite3GetVdbe(pParse); |
| 96570 | | - sqlite3VdbeSetNumCols(v, 4); |
| 96571 | | - pParse->nMem = 4; |
| 96642 | + sqlite3VdbeSetNumCols(v, 3); |
| 96643 | + pParse->nMem = 3; |
| 96572 | 96644 | sqlite3CodeVerifySchema(pParse, iDb); |
| 96573 | 96645 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); |
| 96574 | 96646 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); |
| 96575 | 96647 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC); |
| 96576 | | - sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "avgrowsize", SQLITE_STATIC); |
| 96577 | | - sqlite3VdbeAddOp2(v, OP_Integer, 0, 1); |
| 96578 | | - sqlite3VdbeAddOp2(v, OP_Null, 0, 2); |
| 96579 | | - sqlite3VdbeAddOp2(v, OP_Integer, 1, 3); |
| 96580 | | - sqlite3VdbeAddOp2(v, OP_Integer, |
| 96581 | | - (int)sqlite3LogEstToInt(pTab->szTabRow), 4); |
| 96582 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); |
| 96583 | | - for(pIdx=pTab->pIndex, i=1; pIdx; pIdx=pIdx->pNext, i++){ |
| 96648 | + for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){ |
| 96584 | 96649 | sqlite3VdbeAddOp2(v, OP_Integer, i, 1); |
| 96585 | 96650 | sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0); |
| 96586 | 96651 | sqlite3VdbeAddOp2(v, OP_Integer, pIdx->onError!=OE_None, 3); |
| 96587 | | - sqlite3VdbeAddOp2(v, OP_Integer, |
| 96588 | | - (int)sqlite3LogEstToInt(pIdx->szIdxRow), 4); |
| 96589 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); |
| 96652 | + sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); |
| 96590 | 96653 | } |
| 96591 | 96654 | } |
| 96592 | 96655 | } |
| 96593 | 96656 | break; |
| 96594 | 96657 | |
| | @@ -108909,10 +108972,13 @@ |
| 108909 | 108972 | int iMin = 0; /* Smallest sample not yet tested */ |
| 108910 | 108973 | int i = pIdx->nSample; /* Smallest sample larger than or equal to pRec */ |
| 108911 | 108974 | int iTest; /* Next sample to test */ |
| 108912 | 108975 | int res; /* Result of comparison operation */ |
| 108913 | 108976 | |
| 108977 | +#ifndef SQLITE_DEBUG |
| 108978 | + UNUSED_PARAMETER( pParse ); |
| 108979 | +#endif |
| 108914 | 108980 | assert( pRec!=0 || pParse->db->mallocFailed ); |
| 108915 | 108981 | if( pRec==0 ) return; |
| 108916 | 108982 | iCol = pRec->nField - 1; |
| 108917 | 108983 | assert( pIdx->nSample>0 ); |
| 108918 | 108984 | assert( pRec->nField>0 && iCol<pIdx->nSampleCol ); |
| | @@ -109026,15 +109092,15 @@ |
| 109026 | 109092 | WhereTerm *pUpper, /* Upper bound on the range. ex: "x<455" Might be NULL */ |
| 109027 | 109093 | WhereLoop *pLoop /* Modify the .nOut and maybe .rRun fields */ |
| 109028 | 109094 | ){ |
| 109029 | 109095 | int rc = SQLITE_OK; |
| 109030 | 109096 | int nOut = pLoop->nOut; |
| 109031 | | - int nEq = pLoop->u.btree.nEq; |
| 109032 | 109097 | LogEst nNew; |
| 109033 | 109098 | |
| 109034 | 109099 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 109035 | 109100 | Index *p = pLoop->u.btree.pIndex; |
| 109101 | + int nEq = pLoop->u.btree.nEq; |
| 109036 | 109102 | |
| 109037 | 109103 | if( p->nSample>0 |
| 109038 | 109104 | && nEq==pBuilder->nRecValid |
| 109039 | 109105 | && nEq<p->nSampleCol |
| 109040 | 109106 | && OptimizationEnabled(pParse->db, SQLITE_Stat3) |
| | @@ -110754,11 +110820,11 @@ |
| 110754 | 110820 | ** |
| 110755 | 110821 | ** In the current implementation, the first extra WHERE clause term reduces |
| 110756 | 110822 | ** the number of output rows by a factor of 10 and each additional term |
| 110757 | 110823 | ** reduces the number of output rows by sqrt(2). |
| 110758 | 110824 | */ |
| 110759 | | -static void whereLoopOutputAdjust(WhereClause *pWC, WhereLoop *pLoop, int iCur){ |
| 110825 | +static void whereLoopOutputAdjust(WhereClause *pWC, WhereLoop *pLoop){ |
| 110760 | 110826 | WhereTerm *pTerm, *pX; |
| 110761 | 110827 | Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf); |
| 110762 | 110828 | int i, j; |
| 110763 | 110829 | |
| 110764 | 110830 | if( !OptimizationEnabled(pWC->pWInfo->pParse->db, SQLITE_AdjustOutEst) ){ |
| | @@ -110929,12 +110995,12 @@ |
| 110929 | 110995 | && !ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 110930 | 110996 | rc = whereInScanEst(pParse, pBuilder, pExpr->x.pList, &nOut); |
| 110931 | 110997 | } |
| 110932 | 110998 | assert( nOut==0 || rc==SQLITE_OK ); |
| 110933 | 110999 | if( nOut ){ |
| 110934 | | - nOut = sqlite3LogEst(nOut); |
| 110935 | | - pNew->nOut = MIN(nOut, saved_nOut); |
| 111000 | + pNew->nOut = sqlite3LogEst(nOut); |
| 111001 | + if( pNew->nOut>saved_nOut ) pNew->nOut = saved_nOut; |
| 110936 | 111002 | } |
| 110937 | 111003 | } |
| 110938 | 111004 | #endif |
| 110939 | 111005 | if( (pNew->wsFlags & (WHERE_IDX_ONLY|WHERE_IPK))==0 ){ |
| 110940 | 111006 | /* Each row involves a step of the index, then a binary search of |
| | @@ -110941,11 +111007,11 @@ |
| 110941 | 111007 | ** the main table */ |
| 110942 | 111008 | pNew->rRun = sqlite3LogEstAdd(pNew->rRun,rLogSize>27 ? rLogSize-17 : 10); |
| 110943 | 111009 | } |
| 110944 | 111010 | /* Step cost for each output row */ |
| 110945 | 111011 | pNew->rRun = sqlite3LogEstAdd(pNew->rRun, pNew->nOut); |
| 110946 | | - whereLoopOutputAdjust(pBuilder->pWC, pNew, pSrc->iCursor); |
| 111012 | + whereLoopOutputAdjust(pBuilder->pWC, pNew); |
| 110947 | 111013 | rc = whereLoopInsert(pBuilder, pNew); |
| 110948 | 111014 | if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 |
| 110949 | 111015 | && pNew->u.btree.nEq<(pProbe->nColumn + (pProbe->zName!=0)) |
| 110950 | 111016 | ){ |
| 110951 | 111017 | whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn); |
| | @@ -111145,11 +111211,11 @@ |
| 111145 | 111211 | pNew->iSortIdx = b ? iSortIdx : 0; |
| 111146 | 111212 | /* TUNING: Cost of full table scan is 3*(N + log2(N)). |
| 111147 | 111213 | ** + The extra 3 factor is to encourage the use of indexed lookups |
| 111148 | 111214 | ** over full scans. FIXME */ |
| 111149 | 111215 | pNew->rRun = sqlite3LogEstAdd(rSize,rLogSize) + 16; |
| 111150 | | - whereLoopOutputAdjust(pWC, pNew, pSrc->iCursor); |
| 111216 | + whereLoopOutputAdjust(pWC, pNew); |
| 111151 | 111217 | rc = whereLoopInsert(pBuilder, pNew); |
| 111152 | 111218 | pNew->nOut = rSize; |
| 111153 | 111219 | if( rc ) break; |
| 111154 | 111220 | }else{ |
| 111155 | 111221 | Bitmask m = pSrc->colUsed & ~columnsInIndex(pProbe); |
| | @@ -111178,11 +111244,11 @@ |
| 111178 | 111244 | assert( b!=0 ); |
| 111179 | 111245 | /* TUNING: Cost of scanning a non-covering index is (N+1)*log2(N) |
| 111180 | 111246 | ** which we will simplify to just N*log2(N) */ |
| 111181 | 111247 | pNew->rRun = rSize + rLogSize; |
| 111182 | 111248 | } |
| 111183 | | - whereLoopOutputAdjust(pWC, pNew, pSrc->iCursor); |
| 111249 | + whereLoopOutputAdjust(pWC, pNew); |
| 111184 | 111250 | rc = whereLoopInsert(pBuilder, pNew); |
| 111185 | 111251 | pNew->nOut = rSize; |
| 111186 | 111252 | if( rc ) break; |
| 111187 | 111253 | } |
| 111188 | 111254 | } |
| | @@ -126258,11 +126324,11 @@ |
| 126258 | 126324 | assert( p->nToken<=MAX_INCR_PHRASE_TOKENS ); |
| 126259 | 126325 | assert( p->iDoclistToken<MAX_INCR_PHRASE_TOKENS ); |
| 126260 | 126326 | |
| 126261 | 126327 | while( bEof==0 ){ |
| 126262 | 126328 | int bMaxSet = 0; |
| 126263 | | - sqlite3_int64 iMax; /* Largest docid for all iterators */ |
| 126329 | + sqlite3_int64 iMax = 0; /* Largest docid for all iterators */ |
| 126264 | 126330 | int i; /* Used to iterate through tokens */ |
| 126265 | 126331 | |
| 126266 | 126332 | /* Advance the iterator for each token in the phrase once. */ |
| 126267 | 126333 | for(i=0; rc==SQLITE_OK && i<p->nToken; i++){ |
| 126268 | 126334 | rc = incrPhraseTokenNext(pTab, p, i, &a[i], &bEof); |
| | @@ -126301,11 +126367,11 @@ |
| 126301 | 126367 | char *pR = aDoclist; |
| 126302 | 126368 | char *pOut = aDoclist; |
| 126303 | 126369 | int nDist = p->nToken-1-i; |
| 126304 | 126370 | int res = fts3PoslistPhraseMerge(&pOut, nDist, 0, 1, &pL, &pR); |
| 126305 | 126371 | if( res==0 ) break; |
| 126306 | | - nList = (pOut - aDoclist); |
| 126372 | + nList = (int)(pOut - aDoclist); |
| 126307 | 126373 | } |
| 126308 | 126374 | } |
| 126309 | 126375 | if( i==(p->nToken-1) ){ |
| 126310 | 126376 | pDL->iDocid = iMax; |
| 126311 | 126377 | pDL->pList = aDoclist; |
| 126312 | 126378 | |