mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-19 21:43:15 +03:00
Allow tracing of whereLoopInsert() when the 0x8 bit is set on ".wheretrace".
Remove the use of sqlite_query_plan from where2.test. Fix a bug in the code generator for OR clause optimizations. FossilOrigin-Name: 707f0323264c35be14847a6adc49a0dc5eaf4ad2
This commit is contained in:
14
manifest
14
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Enhance\sthe\sshell\sto\sprovide\smore\sflexibility\swhen\sentering\snumeric\sarguments\non\sdot-commands.\s\sIn\sparticular,\sallow\shex\sarguments\sto\s.wheretrace.
|
C Allow\stracing\sof\swhereLoopInsert()\swhen\sthe\s0x8\sbit\sis\sset\son\s".wheretrace".\nRemove\sthe\suse\sof\ssqlite_query_plan\sfrom\swhere2.test.\s\sFix\sa\sbug\sin\sthe\ncode\sgenerator\sfor\sOR\sclause\soptimizations.
|
||||||
D 2013-05-31T14:31:11.784
|
D 2013-05-31T15:18:46.709
|
||||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||||
F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
|
F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
|
||||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||||
@@ -289,7 +289,7 @@ F src/vtab.c b05e5f1f4902461ba9f5fc49bb7eb7c3a0741a83
|
|||||||
F src/wal.c 436bfceb141b9423c45119e68e444358ee0ed35d
|
F src/wal.c 436bfceb141b9423c45119e68e444358ee0ed35d
|
||||||
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
|
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
|
||||||
F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73
|
F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73
|
||||||
F src/where.c 8e9922815b07290982cfc826497d128115ce358c
|
F src/where.c e120e28cb55cea658589ec2eca5764dcfa0396c2
|
||||||
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
||||||
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
||||||
F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
|
F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
|
||||||
@@ -1029,7 +1029,7 @@ F test/walshared.test 6dda2293880c300baf5d791c307f653094585761
|
|||||||
F test/walslow.test e7be6d9888f83aa5d3d3c7c08aa9b5c28b93609a
|
F test/walslow.test e7be6d9888f83aa5d3d3c7c08aa9b5c28b93609a
|
||||||
F test/walthread.test de8dbaf6d9e41481c460ba31ca61e163d7348f8e
|
F test/walthread.test de8dbaf6d9e41481c460ba31ca61e163d7348f8e
|
||||||
F test/where.test 054a6b6f7933c5a5f50d0bcd650b5eccb450cc81
|
F test/where.test 054a6b6f7933c5a5f50d0bcd650b5eccb450cc81
|
||||||
F test/where2.test 399b3178289925a0aa976b3d60ef139740540ecd
|
F test/where2.test f902f62d60f20b0257dd700f0c4a2945527fca8e
|
||||||
F test/where3.test 667e75642102c97a00bf9b23d3cb267db321d006
|
F test/where3.test 667e75642102c97a00bf9b23d3cb267db321d006
|
||||||
F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2
|
F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2
|
||||||
F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2
|
F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2
|
||||||
@@ -1093,7 +1093,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 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
|
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
|
||||||
P d8efa5f8b60bc4c8df8bfad077f87f76f7ee9bf6
|
P b9578c371ee569dca6a0964019959a93407c8ef9
|
||||||
R cab66f9edd3249c76db6815f19ee5773
|
R 10e84b9c96bf0dc4179bf10aeea4849d
|
||||||
U drh
|
U drh
|
||||||
Z 93073f371b16237bef628d122f206ede
|
Z 1f5041366a1e7c65f32184b30b5b84bc
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
b9578c371ee569dca6a0964019959a93407c8ef9
|
707f0323264c35be14847a6adc49a0dc5eaf4ad2
|
||||||
50
src/where.c
50
src/where.c
@@ -3758,6 +3758,7 @@ static void whereLoopPrint(WhereLoop *p, SrcList *pTabList){
|
|||||||
if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
|
if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
|
||||||
if( p->u.btree.pIndex ){
|
if( p->u.btree.pIndex ){
|
||||||
const char *zName = p->u.btree.pIndex->zName;
|
const char *zName = p->u.btree.pIndex->zName;
|
||||||
|
if( zName==0 ) zName = "ipk";
|
||||||
if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
|
if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
|
||||||
int i = sqlite3Strlen30(zName) - 1;
|
int i = sqlite3Strlen30(zName) - 1;
|
||||||
while( zName[i]!='_' ) i--;
|
while( zName[i]!='_' ) i--;
|
||||||
@@ -3865,16 +3866,22 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
|
|||||||
if( (p = pBuilder->pBest)!=0 ){
|
if( (p = pBuilder->pBest)!=0 ){
|
||||||
if( p->maskSelf!=0 ){
|
if( p->maskSelf!=0 ){
|
||||||
if( p->rRun+p->rSetup < pTemplate->rRun+pTemplate->rSetup ){
|
if( p->rRun+p->rSetup < pTemplate->rRun+pTemplate->rSetup ){
|
||||||
return SQLITE_OK;
|
goto whereLoopInsert_noop;
|
||||||
}
|
}
|
||||||
if( p->rRun+p->rSetup == pTemplate->rRun+pTemplate->rSetup
|
if( p->rRun+p->rSetup == pTemplate->rRun+pTemplate->rSetup
|
||||||
&& p->prereq <= pTemplate->prereq ){
|
&& p->prereq <= pTemplate->prereq ){
|
||||||
return SQLITE_OK;
|
goto whereLoopInsert_noop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*p = *pTemplate;
|
*p = *pTemplate;
|
||||||
p->aTerm = 0;
|
p->aTerm = 0;
|
||||||
p->u.vtab.needFree = 0;
|
p->u.vtab.needFree = 0;
|
||||||
|
#if WHERETRACE_ENABLED
|
||||||
|
if( sqlite3WhereTrace & 0x8 ){
|
||||||
|
sqlite3DebugPrintf("ins-best: ");
|
||||||
|
whereLoopPrint(pTemplate, pBuilder->pTabList);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3901,7 +3908,7 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
|
|||||||
){
|
){
|
||||||
/* Already holding an equal or better WhereLoop.
|
/* Already holding an equal or better WhereLoop.
|
||||||
** Return without changing or adding anything */
|
** Return without changing or adding anything */
|
||||||
return SQLITE_OK;
|
goto whereLoopInsert_noop;
|
||||||
}
|
}
|
||||||
if( (p->prereq & pTemplate->prereq)==pTemplate->prereq
|
if( (p->prereq & pTemplate->prereq)==pTemplate->prereq
|
||||||
&& p->rSetup>=pTemplate->rSetup
|
&& p->rSetup>=pTemplate->rSetup
|
||||||
@@ -3918,6 +3925,16 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
|
|||||||
** with pTemplate[] if p[] exists, or if p==NULL then allocate a new
|
** with pTemplate[] if p[] exists, or if p==NULL then allocate a new
|
||||||
** WhereLoop and insert it.
|
** WhereLoop and insert it.
|
||||||
*/
|
*/
|
||||||
|
#if WHERETRACE_ENABLED
|
||||||
|
if( sqlite3WhereTrace & 0x8 ){
|
||||||
|
if( p!=0 ){
|
||||||
|
sqlite3DebugPrintf("ins-del: ");
|
||||||
|
whereLoopPrint(p, pBuilder->pTabList);
|
||||||
|
}
|
||||||
|
sqlite3DebugPrintf("ins-new: ");
|
||||||
|
whereLoopPrint(pTemplate, pBuilder->pTabList);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if( p==0 ){
|
if( p==0 ){
|
||||||
p = pToFree = sqlite3DbMallocRaw(db, sizeof(WhereLoop));
|
p = pToFree = sqlite3DbMallocRaw(db, sizeof(WhereLoop));
|
||||||
if( p==0 ) return SQLITE_NOMEM;
|
if( p==0 ) return SQLITE_NOMEM;
|
||||||
@@ -3945,6 +3962,16 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
|
|||||||
pTemplate->u.vtab.needFree = 0;
|
pTemplate->u.vtab.needFree = 0;
|
||||||
}
|
}
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
|
|
||||||
|
/* Jump here if the insert is a no-op */
|
||||||
|
whereLoopInsert_noop:
|
||||||
|
#if WHERETRACE_ENABLED
|
||||||
|
if( sqlite3WhereTrace & 0x8 ){
|
||||||
|
sqlite3DebugPrintf("ins-noop: ");
|
||||||
|
whereLoopPrint(pTemplate, pBuilder->pTabList);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -4156,7 +4183,7 @@ static int whereLoopAddBtree(
|
|||||||
pNew->u.btree.pIndex = 0;
|
pNew->u.btree.pIndex = 0;
|
||||||
pNew->nTerm = 1;
|
pNew->nTerm = 1;
|
||||||
pNew->aTerm[0] = pTerm;
|
pNew->aTerm[0] = pTerm;
|
||||||
pNew->rSetup = 2*rLogSize*pSrc->pTab->nRowEst;
|
pNew->rSetup = 20*rLogSize*pSrc->pTab->nRowEst;
|
||||||
pNew->nOut = (double)10;
|
pNew->nOut = (double)10;
|
||||||
pNew->rRun = rLogSize + pNew->nOut;
|
pNew->rRun = rLogSize + pNew->nOut;
|
||||||
pNew->wsFlags = WHERE_TEMP_INDEX;
|
pNew->wsFlags = WHERE_TEMP_INDEX;
|
||||||
@@ -4773,8 +4800,8 @@ static int wherePathSolver(WhereInfo *pWInfo, double nRowEst){
|
|||||||
}
|
}
|
||||||
if( jj>=nTo ){
|
if( jj>=nTo ){
|
||||||
if( nTo>=mxChoice && rCost>=mxCost ){
|
if( nTo>=mxChoice && rCost>=mxCost ){
|
||||||
#ifdef WHERETRACE_ENABLE
|
#ifdef WHERETRACE_ENABLED
|
||||||
if( sqlite3WhereTrace>=3 ){
|
if( sqlite3WhereTrace&0x4 ){
|
||||||
sqlite3DebugPrintf("Skip %s cost=%-7.2g order=%c\n",
|
sqlite3DebugPrintf("Skip %s cost=%-7.2g order=%c\n",
|
||||||
wherePathName(pFrom, iLoop, pWLoop), rCost,
|
wherePathName(pFrom, iLoop, pWLoop), rCost,
|
||||||
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
|
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
|
||||||
@@ -4792,7 +4819,7 @@ static int wherePathSolver(WhereInfo *pWInfo, double nRowEst){
|
|||||||
}
|
}
|
||||||
pTo = &aTo[jj];
|
pTo = &aTo[jj];
|
||||||
#ifdef WHERETRACE_ENABLED
|
#ifdef WHERETRACE_ENABLED
|
||||||
if( sqlite3WhereTrace>=3 ){
|
if( sqlite3WhereTrace&0x4 ){
|
||||||
sqlite3DebugPrintf("New %s cost=%-7.2g order=%c\n",
|
sqlite3DebugPrintf("New %s cost=%-7.2g order=%c\n",
|
||||||
wherePathName(pFrom, iLoop, pWLoop), rCost,
|
wherePathName(pFrom, iLoop, pWLoop), rCost,
|
||||||
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
|
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
|
||||||
@@ -4801,7 +4828,7 @@ static int wherePathSolver(WhereInfo *pWInfo, double nRowEst){
|
|||||||
}else{
|
}else{
|
||||||
if( pTo->rCost<=rCost ){
|
if( pTo->rCost<=rCost ){
|
||||||
#ifdef WHERETRACE_ENABLED
|
#ifdef WHERETRACE_ENABLED
|
||||||
if( sqlite3WhereTrace>=3 ){
|
if( sqlite3WhereTrace&0x4 ){
|
||||||
sqlite3DebugPrintf(
|
sqlite3DebugPrintf(
|
||||||
"Skip %s cost=%-7.2g order=%c",
|
"Skip %s cost=%-7.2g order=%c",
|
||||||
wherePathName(pFrom, iLoop, pWLoop), rCost,
|
wherePathName(pFrom, iLoop, pWLoop), rCost,
|
||||||
@@ -4815,7 +4842,7 @@ static int wherePathSolver(WhereInfo *pWInfo, double nRowEst){
|
|||||||
}
|
}
|
||||||
/* A new and better score for a previously created equivalent path */
|
/* A new and better score for a previously created equivalent path */
|
||||||
#ifdef WHERETRACE_ENABLED
|
#ifdef WHERETRACE_ENABLED
|
||||||
if( sqlite3WhereTrace>=3 ){
|
if( sqlite3WhereTrace&0x4 ){
|
||||||
sqlite3DebugPrintf(
|
sqlite3DebugPrintf(
|
||||||
"Update %s cost=%-7.2g order=%c",
|
"Update %s cost=%-7.2g order=%c",
|
||||||
wherePathName(pFrom, iLoop, pWLoop), rCost,
|
wherePathName(pFrom, iLoop, pWLoop), rCost,
|
||||||
@@ -5239,9 +5266,8 @@ WhereInfo *sqlite3WhereBegin(
|
|||||||
if( pLoop->u.btree.pIndex!=0 ){
|
if( pLoop->u.btree.pIndex!=0 ){
|
||||||
Index *pIx = pLoop->u.btree.pIndex;
|
Index *pIx = pLoop->u.btree.pIndex;
|
||||||
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
|
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
|
||||||
/* FIXME: Might need to be the iIdxCur parameter. As an optimization
|
/* FIXME: As an optimization use pTabItem->iCursor if WHERE_IDX_ONLY */
|
||||||
** use pTabItem->iCursor if WHERE_IDX_ONLY */
|
int iIndexCur = pLevel->iIdxCur = iIdxCur ? iIdxCur : pParse->nTab++;
|
||||||
int iIndexCur = pLevel->iIdxCur = pParse->nTab++;
|
|
||||||
assert( pIx->pSchema==pTab->pSchema );
|
assert( pIx->pSchema==pTab->pSchema );
|
||||||
assert( iIndexCur>=0 );
|
assert( iIndexCur>=0 );
|
||||||
sqlite3VdbeAddOp4(v, OP_OpenRead, iIndexCur, pIx->tnum, iDb,
|
sqlite3VdbeAddOp4(v, OP_OpenRead, iIndexCur, pIx->tnum, iDb,
|
||||||
|
|||||||
@@ -73,7 +73,18 @@ proc queryplan {sql} {
|
|||||||
set data [execsql $sql]
|
set data [execsql $sql]
|
||||||
if {$::sqlite_sort_count} {set x sort} {set x nosort}
|
if {$::sqlite_sort_count} {set x sort} {set x nosort}
|
||||||
lappend data $x
|
lappend data $x
|
||||||
return [concat $data $::sqlite_query_plan]
|
set eqp [execsql "EXPLAIN QUERY PLAN $sql"]
|
||||||
|
# puts eqp=$eqp
|
||||||
|
foreach {a b c x} $eqp {
|
||||||
|
if {[regexp { TABLE (\w+ AS )?(\w+) USING.* INDEX (\w+)\W} \
|
||||||
|
$x all as tab idx]} {
|
||||||
|
lappend data $tab $idx
|
||||||
|
} elseif {[regexp { TABLE (\w+ AS )?(\w+)\W} $x all as tab]} {
|
||||||
|
lappend data $tab *
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $data
|
||||||
|
# return [concat $data $::sqlite_query_plan]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user