1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-06 15:49:35 +03:00

Add more bits to the bit vector that is used to disable optimizations for

built-in test.  Add specific bit patterns to disable ORDER BY using an
index in general and for joins.  Use macros to test for bits in the 
disabled-optimization bit vector, in order to make the code clearer.

FossilOrigin-Name: d2fcba1e143beca8c45724d2108870657c269e17
This commit is contained in:
drh
2012-09-27 15:05:54 +00:00
parent 32634d270c
commit 7e5418e4a4
9 changed files with 77 additions and 63 deletions

View File

@@ -1,5 +1,5 @@
C Enable\sORDER\sBY\sclauses\sthat\sspan\sjoins\sto\sbe\soptimized\sout. C Add\smore\sbits\sto\sthe\sbit\svector\sthat\sis\sused\sto\sdisable\soptimizations\sfor\nbuilt-in\stest.\s\sAdd\sspecific\sbit\spatterns\sto\sdisable\sORDER\sBY\susing\san\nindex\sin\sgeneral\sand\sfor\sjoins.\s\sUse\smacros\sto\stest\sfor\sbits\sin\sthe\s\ndisabled-optimization\sbit\svector,\sin\sorder\sto\smake\sthe\scode\sclearer.
D 2012-09-27T14:11:36.514 D 2012-09-27T15:05:54.735
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 5f4f26109f9d80829122e0e09f9cda008fa065fb F Makefile.in 5f4f26109f9d80829122e0e09f9cda008fa065fb
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -129,8 +129,8 @@ F src/callback.c 0cb4228cdcd827dcc5def98fb099edcc9142dbcd
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
F src/ctime.c 72a70dcfda75d3a1f81041ce4573e7afddcd8e4e F src/ctime.c 72a70dcfda75d3a1f81041ce4573e7afddcd8e4e
F src/date.c 067a81c9942c497aafd2c260e13add8a7d0c7dd4 F src/date.c 067a81c9942c497aafd2c260e13add8a7d0c7dd4
F src/delete.c 335f36750dc6ac88d580aa36a6487459be9889de F src/delete.c 4f7d773ec44b7db22b30ec9144f58a69154e09b7
F src/expr.c 4d1cef0fae6f3cf3c754773fd413f3e221021003 F src/expr.c 4de967b85f577ba00a7cdcb53d22070def6198db
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
F src/fkey.c c82a04e7a92bb728f9ab972b76590403283be2af F src/fkey.c c82a04e7a92bb728f9ab972b76590403283be2af
F src/func.c cbb90dc84b22eea25caf39528d342279e61b8898 F src/func.c cbb90dc84b22eea25caf39528d342279e61b8898
@@ -143,7 +143,7 @@ F src/journal.c 552839e54d1bf76fb8f7abe51868b66acacf6a0e
F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f
F src/lempar.c 0ee69fca0be54cd93939df98d2aca4ca46f44416 F src/lempar.c 0ee69fca0be54cd93939df98d2aca4ca46f44416
F src/loadext.c f20382fbaeec832438a1ba7797bee3d3c8a6d51d F src/loadext.c f20382fbaeec832438a1ba7797bee3d3c8a6d51d
F src/main.c 97d13e749ae84fe62238a5940c5b46b2b22cd369 F src/main.c c5fec9814efaa64fa1de83497553f5904aa1bbec
F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6 F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa
@@ -174,17 +174,17 @@ F src/printf.c 4a9f882f1c1787a8b494a2987765acf9d97ac21f
F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
F src/resolve.c 9e28280ec98035f31900fdd1db01f86f68ca6c32 F src/resolve.c 9e28280ec98035f31900fdd1db01f86f68ca6c32
F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
F src/select.c a91b651652b43a8baaeec0ad13a6a6b290a4d0af F src/select.c 75c5e37cc882c468383c9d9e07496b9a16cfae3e
F src/shell.c 8ee5a3cb502e2d574f97b43972e6c1e275e7bec7 F src/shell.c 8ee5a3cb502e2d574f97b43972e6c1e275e7bec7
F src/sqlite.h.in cbe846facaba903654b4136c97e7f57b3ac0bac7 F src/sqlite.h.in cbe846facaba903654b4136c97e7f57b3ac0bac7
F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0
F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477 F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477
F src/sqliteInt.h cbcd2dd649338598a1a773a9adaf9f62e7256852 F src/sqliteInt.h 6ad55f4efbd1bb209711032e40b7c81c8855d634
F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
F src/status.c 35939e7e03abf1b7577ce311f48f682c40de3208 F src/status.c 35939e7e03abf1b7577ce311f48f682c40de3208
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
F src/tclsqlite.c e4de2458b3ef38fdd0498bc4e5ea5367a241b0f3 F src/tclsqlite.c e4de2458b3ef38fdd0498bc4e5ea5367a241b0f3
F src/test1.c bec5295347a7bc38a53ca955f01cfcaf116fdb88 F src/test1.c 9000293bfdcd67de05bf91d257343392c4b194f4
F src/test2.c 4178056dd1e7d70f954ad8a1e3edb71a2a784daf F src/test2.c 4178056dd1e7d70f954ad8a1e3edb71a2a784daf
F src/test3.c 3c3c2407fa6ec7a19e24ae23f7cb439d0275a60d F src/test3.c 3c3c2407fa6ec7a19e24ae23f7cb439d0275a60d
F src/test4.c bf9fa9bece01de08e6f5e02314e4af5c13590dfa F src/test4.c bf9fa9bece01de08e6f5e02314e4af5c13590dfa
@@ -249,7 +249,7 @@ F src/vtab.c d8020c0a0e8ccc490ca449d7e665311b6e9f3ba9
F src/wal.c 5acb3e7bbd31f10ba39acad9ce6b399055337a9d F src/wal.c 5acb3e7bbd31f10ba39acad9ce6b399055337a9d
F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6 F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6
F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b
F src/where.c 36af33a92ccbf8b5be3bc7eae08a7f022afb60d8 F src/where.c 4b837884c4747b022cf36bd00d9eddbb6b451241
F test/8_3_names.test 631ea964a3edb091cf73c3b540f6bcfdb36ce823 F test/8_3_names.test 631ea964a3edb091cf73c3b540f6bcfdb36ce823
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/aggnested.test 0be144b453e0622a085fae8665c32f5676708e00 F test/aggnested.test 0be144b453e0622a085fae8665c32f5676708e00
@@ -1016,7 +1016,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9
P 53efc10af990d3f293551f3cd8ef2f8be2d9d716 P c29538f9b1ee4d4869999570604c9618ca0d08ac
R d9d746ad3fd7e5c77ffbaf4f5251f6f8 R 112951e028390501419dede06d50cf2d
U drh U drh
Z 769b41d4cd58dfa3626d0858103449b9 Z 58d07d9f2619813e6ef0c2cb6bcd8ae9

View File

@@ -1 +1 @@
c29538f9b1ee4d4869999570604c9618ca0d08ac d2fcba1e143beca8c45724d2108870657c269e17

View File

@@ -638,7 +638,9 @@ int sqlite3GenerateIndexKey(
} }
if( doMakeRec ){ if( doMakeRec ){
const char *zAff; const char *zAff;
if( pTab->pSelect || (pParse->db->flags & SQLITE_IdxRealAsInt)!=0 ){ if( pTab->pSelect
|| OptimizationDisabled(pParse->db, SQLITE_IdxRealAsInt)
){
zAff = 0; zAff = 0;
}else{ }else{
zAff = sqlite3IndexAffinityStr(v, pIdx); zAff = sqlite3IndexAffinityStr(v, pIdx);

View File

@@ -2066,7 +2066,7 @@ void sqlite3ExprCacheStore(Parse *pParse, int iTab, int iCol, int iReg){
** for testing only - to verify that SQLite always gets the same answer ** for testing only - to verify that SQLite always gets the same answer
** with and without the column cache. ** with and without the column cache.
*/ */
if( pParse->db->flags & SQLITE_ColumnCache ) return; if( OptimizationDisabled(pParse->db, SQLITE_ColumnCache) ) return;
/* First replace any existing entry. /* First replace any existing entry.
** **
@@ -3382,7 +3382,7 @@ static int evalConstExpr(Walker *pWalker, Expr *pExpr){
void sqlite3ExprCodeConstants(Parse *pParse, Expr *pExpr){ void sqlite3ExprCodeConstants(Parse *pParse, Expr *pExpr){
Walker w; Walker w;
if( pParse->cookieGoto ) return; if( pParse->cookieGoto ) return;
if( (pParse->db->flags & SQLITE_FactorOutConst)!=0 ) return; if( OptimizationDisabled(pParse->db, SQLITE_FactorOutConst) ) return;
w.xExprCallback = evalConstExpr; w.xExprCallback = evalConstExpr;
w.xSelectCallback = 0; w.xSelectCallback = 0;
w.pParse = pParse; w.pParse = pParse;

View File

@@ -3018,8 +3018,7 @@ int sqlite3_test_control(int op, ...){
*/ */
case SQLITE_TESTCTRL_OPTIMIZATIONS: { case SQLITE_TESTCTRL_OPTIMIZATIONS: {
sqlite3 *db = va_arg(ap, sqlite3*); sqlite3 *db = va_arg(ap, sqlite3*);
int x = va_arg(ap,int); db->dbOptFlags = (u16)(va_arg(ap, int) & 0xffff);
db->flags = (x & SQLITE_OptMask) | (db->flags & ~SQLITE_OptMask);
break; break;
} }

View File

@@ -2809,7 +2809,7 @@ static int flattenSubquery(
*/ */
assert( p!=0 ); assert( p!=0 );
assert( p->pPrior==0 ); /* Unable to flatten compound queries */ assert( p->pPrior==0 ); /* Unable to flatten compound queries */
if( db->flags & SQLITE_QueryFlattener ) return 0; if( OptimizationDisabled(db, SQLITE_QueryFlattener) ) return 0;
pSrc = p->pSrc; pSrc = p->pSrc;
assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc ); assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc );
pSubitem = &pSrc->a[iFrom]; pSubitem = &pSrc->a[iFrom];
@@ -4012,7 +4012,7 @@ int sqlite3Select(
** to disable this optimization for testing purposes. ** to disable this optimization for testing purposes.
*/ */
if( sqlite3ExprListCompare(p->pGroupBy, pOrderBy)==0 if( sqlite3ExprListCompare(p->pGroupBy, pOrderBy)==0
&& (db->flags & SQLITE_GroupByOrder)==0 ){ && OptimizationEnabled(db, SQLITE_GroupByOrder) ){
pOrderBy = 0; pOrderBy = 0;
} }

View File

@@ -827,6 +827,7 @@ struct sqlite3 {
unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
int errCode; /* Most recent error code (SQLITE_*) */ int errCode; /* Most recent error code (SQLITE_*) */
int errMask; /* & result codes with this before returning */ int errMask; /* & result codes with this before returning */
u16 dbOptFlags; /* Flags to enable/disable optimizations */
u8 autoCommit; /* The auto-commit flag. */ u8 autoCommit; /* The auto-commit flag. */
u8 temp_store; /* 1: file 2: memory 0: default */ u8 temp_store; /* 1: file 2: memory 0: default */
u8 mallocFailed; /* True if we have seen a malloc failure */ u8 mallocFailed; /* True if we have seen a malloc failure */
@@ -931,46 +932,59 @@ struct sqlite3 {
/* /*
** Possible values for the sqlite3.flags. ** Possible values for the sqlite3.flags.
*/ */
#define SQLITE_VdbeTrace 0x00000100 /* True to trace VDBE execution */ #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
#define SQLITE_InternChanges 0x00000200 /* Uncommitted Hash table changes */ #define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */
#define SQLITE_FullColNames 0x00000400 /* Show full column names on SELECT */ #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
#define SQLITE_ShortColNames 0x00000800 /* Show short columns names */ #define SQLITE_ShortColNames 0x00000008 /* Show short columns names */
#define SQLITE_CountRows 0x00001000 /* Count rows changed by INSERT, */ #define SQLITE_CountRows 0x00000010 /* Count rows changed by INSERT, */
/* DELETE, or UPDATE and return */ /* DELETE, or UPDATE and return */
/* the count using a callback. */ /* the count using a callback. */
#define SQLITE_NullCallback 0x00002000 /* Invoke the callback once if the */ #define SQLITE_NullCallback 0x00000020 /* Invoke the callback once if the */
/* result set is empty */ /* result set is empty */
#define SQLITE_SqlTrace 0x00004000 /* Debug print SQL as it executes */ #define SQLITE_SqlTrace 0x00000040 /* Debug print SQL as it executes */
#define SQLITE_VdbeListing 0x00008000 /* Debug listings of VDBE programs */ #define SQLITE_VdbeListing 0x00000080 /* Debug listings of VDBE programs */
#define SQLITE_WriteSchema 0x00010000 /* OK to update SQLITE_MASTER */ #define SQLITE_WriteSchema 0x00000100 /* OK to update SQLITE_MASTER */
/* 0x00020000 Unused */ /* 0x00000200 Unused */
#define SQLITE_IgnoreChecks 0x00040000 /* Do not enforce check constraints */ #define SQLITE_IgnoreChecks 0x00000400 /* Do not enforce check constraints */
#define SQLITE_ReadUncommitted 0x0080000 /* For shared-cache mode */ #define SQLITE_ReadUncommitted 0x0000800 /* For shared-cache mode */
#define SQLITE_LegacyFileFmt 0x00100000 /* Create new databases in format 1 */ #define SQLITE_LegacyFileFmt 0x00001000 /* Create new databases in format 1 */
#define SQLITE_FullFSync 0x00200000 /* Use full fsync on the backend */ #define SQLITE_FullFSync 0x00002000 /* Use full fsync on the backend */
#define SQLITE_CkptFullFSync 0x00400000 /* Use full fsync for checkpoint */ #define SQLITE_CkptFullFSync 0x00004000 /* Use full fsync for checkpoint */
#define SQLITE_RecoveryMode 0x00800000 /* Ignore schema errors */ #define SQLITE_RecoveryMode 0x00008000 /* Ignore schema errors */
#define SQLITE_ReverseOrder 0x01000000 /* Reverse unordered SELECTs */ #define SQLITE_ReverseOrder 0x00010000 /* Reverse unordered SELECTs */
#define SQLITE_RecTriggers 0x02000000 /* Enable recursive triggers */ #define SQLITE_RecTriggers 0x00020000 /* Enable recursive triggers */
#define SQLITE_ForeignKeys 0x04000000 /* Enforce foreign key constraints */ #define SQLITE_ForeignKeys 0x00040000 /* Enforce foreign key constraints */
#define SQLITE_AutoIndex 0x08000000 /* Enable automatic indexes */ #define SQLITE_AutoIndex 0x00080000 /* Enable automatic indexes */
#define SQLITE_PreferBuiltin 0x10000000 /* Preference to built-in funcs */ #define SQLITE_PreferBuiltin 0x00100000 /* Preference to built-in funcs */
#define SQLITE_LoadExtension 0x20000000 /* Enable load_extension */ #define SQLITE_LoadExtension 0x00200000 /* Enable load_extension */
#define SQLITE_EnableTrigger 0x40000000 /* True to enable triggers */ #define SQLITE_EnableTrigger 0x00400000 /* True to enable triggers */
/* /*
** Bits of the sqlite3.flags field that are used by the ** Bits of the sqlite3.dbOptFlags field that are used by the
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface. ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
** These must be the low-order bits of the flags field. ** selectively disable various optimizations.
*/ */
#define SQLITE_QueryFlattener 0x01 /* Disable query flattening */ #define SQLITE_QueryFlattener 0x0001 /* Query flattening */
#define SQLITE_ColumnCache 0x02 /* Disable the column cache */ #define SQLITE_ColumnCache 0x0002 /* Column cache */
#define SQLITE_GroupByOrder 0x04 /* Disable GROUPBY cover of ORDERBY */ #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */
#define SQLITE_FactorOutConst 0x08 /* Disable factoring out constants */ #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */
#define SQLITE_IdxRealAsInt 0x10 /* Store REAL as INT in indices */ #define SQLITE_IdxRealAsInt 0x0010 /* Store REAL as INT in indices */
#define SQLITE_DistinctOpt 0x20 /* DISTINCT using indexes */ #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
#define SQLITE_CoverIdxScan 0x40 /* Disable covering index scans */ #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
#define SQLITE_OptMask 0xff /* Mask of all disablable opts */ #define SQLITE_OrderByIdx 0x0180 /* ORDER BY using indices */
#define SQLITE_OrderByIdxJoin 0x0100 /* ORDER BY of joins via index */
#define SQLITE_AllOpts 0x01ff /* All optimizations */
/*
** Macros for testing whether or not optimizations are enabled or disabled.
*/
#ifndef SQLITE_OMIT_BUILTIN_TEST
#define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0)
#define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0)
#else
#define OptimizationDisabled(db, mask) 0
#define OptimizationEnabled(db, mask) 1
#endif
/* /*
** Possible values for the sqlite.magic field. ** Possible values for the sqlite.magic field.

View File

@@ -5933,7 +5933,7 @@ static int optimization_control(
const char *zOptName; const char *zOptName;
int mask; int mask;
} aOpt[] = { } aOpt[] = {
{ "all", SQLITE_OptMask }, { "all", SQLITE_AllOpts },
{ "query-flattener", SQLITE_QueryFlattener }, { "query-flattener", SQLITE_QueryFlattener },
{ "column-cache", SQLITE_ColumnCache }, { "column-cache", SQLITE_ColumnCache },
{ "groupby-order", SQLITE_GroupByOrder }, { "groupby-order", SQLITE_GroupByOrder },
@@ -5941,6 +5941,8 @@ static int optimization_control(
{ "real-as-int", SQLITE_IdxRealAsInt }, { "real-as-int", SQLITE_IdxRealAsInt },
{ "distinct-opt", SQLITE_DistinctOpt }, { "distinct-opt", SQLITE_DistinctOpt },
{ "cover-idx-scan", SQLITE_CoverIdxScan }, { "cover-idx-scan", SQLITE_CoverIdxScan },
{ "order-by-idx", SQLITE_OrderByIdx },
{ "order-by-idx-join",SQLITE_OrderByIdxJoin },
}; };
if( objc!=4 ){ if( objc!=4 ){

View File

@@ -1646,9 +1646,11 @@ static int isSortingIndex(
int nPriorSat; /* ORDER BY terms satisfied by outer loops */ int nPriorSat; /* ORDER BY terms satisfied by outer loops */
int seenRowid = 0; /* True if an ORDER BY rowid term is seen */ int seenRowid = 0; /* True if an ORDER BY rowid term is seen */
if( OptimizationDisabled(db, SQLITE_OrderByIdx) ) return 0;
if( p->i==0 ){ if( p->i==0 ){
nPriorSat = 0; nPriorSat = 0;
}else{ }else{
if( OptimizationDisabled(db, SQLITE_OrderByIdxJoin) ) return 0;
nPriorSat = p->aLevel[p->i-1].plan.nOBSat; nPriorSat = p->aLevel[p->i-1].plan.nOBSat;
} }
if( p->i>0 && nEqCol==0 /*&& !allOuterLoopsUnique(p)*/ ) return nPriorSat; if( p->i>0 && nEqCol==0 /*&& !allOuterLoopsUnique(p)*/ ) return nPriorSat;
@@ -2879,10 +2881,7 @@ static int isOrderedColumn(WhereBestIdx *p, int iTab, int iCol, int *pbRev){
u8 sortOrder; u8 sortOrder;
for(i=p->i-1; i>=0; i--, pLevel--){ for(i=p->i-1; i>=0; i--, pLevel--){
if( pLevel->iTabCur!=iTab ) continue; if( pLevel->iTabCur!=iTab ) continue;
if( (pLevel->plan.wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE))!=0 ){ if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
if( iCol!=(-1) ) return 0;
sortOrder = 0;
}else if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
pIdx = pLevel->plan.u.pIdx; pIdx = pLevel->plan.u.pIdx;
for(j=0; j<pIdx->nColumn; j++){ for(j=0; j<pIdx->nColumn; j++){
if( iCol==pIdx->aiColumn[j] ) break; if( iCol==pIdx->aiColumn[j] ) break;
@@ -3289,9 +3288,7 @@ static void bestBtreeIndex(WhereBestIdx *p){
if( wsFlags==WHERE_IDX_ONLY if( wsFlags==WHERE_IDX_ONLY
&& (pWC->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 && (pWC->wctrlFlags & WHERE_ONEPASS_DESIRED)==0
&& sqlite3GlobalConfig.bUseCis && sqlite3GlobalConfig.bUseCis
#ifndef SQLITE_OMIT_BUILTIN_TEST && OptimizationEnabled(pParse->db, SQLITE_CoverIdxScan)
&& (pParse->db->flags & SQLITE_CoverIdxScan)==0
#endif
){ ){
/* This index is not useful for indexing, but it is a covering index. /* This index is not useful for indexing, but it is a covering index.
** A full-scan of the index might be a little faster than a full-scan ** A full-scan of the index might be a little faster than a full-scan
@@ -4841,7 +4838,7 @@ WhereInfo *sqlite3WhereBegin(
/* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via /* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via
** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */ ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */
if( db->flags & SQLITE_DistinctOpt ) pDistinct = 0; if( OptimizationDisabled(db, SQLITE_DistinctOpt) ) pDistinct = 0;
/* Split the WHERE clause into separate subexpressions where each /* Split the WHERE clause into separate subexpressions where each
** subexpression is separated by an AND operator. ** subexpression is separated by an AND operator.