1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Fix EXPLAIN QUERY PLAN output for indexed-expressions. Fix another

obscure fault in the WHERE term scanner.

FossilOrigin-Name: 73d361ce9e4d72c943def8b0b3caa227f9199aed
This commit is contained in:
drh
2015-08-27 20:33:38 +00:00
parent 29d03f6517
commit c7c4680ffd
4 changed files with 22 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
C Fix\sproblems\sin\sthe\sindexed-expression\shandling\sin\sthe\soptimizer. C Fix\sEXPLAIN\sQUERY\sPLAN\soutput\sfor\sindexed-expressions.\s\sFix\sanother\nobscure\sfault\sin\sthe\sWHERE\sterm\sscanner.
D 2015-08-27T19:56:49.408 D 2015-08-27T20:33:38.975
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in e2218eb228374422969de7b1680eda6864affcef F Makefile.in e2218eb228374422969de7b1680eda6864affcef
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -414,9 +414,9 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb
F src/wal.c 6fb6b68969e4692593c2552c4e7bff5882de2cb8 F src/wal.c 6fb6b68969e4692593c2552c4e7bff5882de2cb8
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
F src/walker.c 2e14d17f592d176b6dc879c33fbdec4fbccaa2ba F src/walker.c 2e14d17f592d176b6dc879c33fbdec4fbccaa2ba
F src/where.c fcdded4bf274bf527020436e8895b33d575f18f6 F src/where.c b22b416694905555a0cbbd7d8881179392a56aba
F src/whereInt.h 292d3ac90da4eab1e03ac8452f1add746bcafaa1 F src/whereInt.h 292d3ac90da4eab1e03ac8452f1add746bcafaa1
F src/wherecode.c 3d9113cc307ffeed58db41fe9f2d807c94787ab5 F src/wherecode.c b0bf45ca49e62fde68ba2e2ad2939d9cdeb4e409
F src/whereexpr.c 990ed42b5940d4000e7e61887a4bbed412c80488 F src/whereexpr.c 990ed42b5940d4000e7e61887a4bbed412c80488
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd
@@ -1380,7 +1380,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 42f93f582eccd8a778189aa6c113874f995ab751 P 03375017691d5b480e73d712c4318632e835060c
R 475d6e7258921a9c57642e7cd0e82c9c R 8aa1e38f792c255d32b6cb36a0f80565
U drh U drh
Z 29a0c57d5a3080634424e9023a9fd1e9 Z dc558ff8656aec58d6de7d38d850c48a

View File

@@ -1 +1 @@
03375017691d5b480e73d712c4318632e835060c 73d361ce9e4d72c943def8b0b3caa227f9199aed

View File

@@ -191,10 +191,9 @@ static WhereTerm *whereScanNext(WhereScan *pScan){
){ ){
if( (pTerm->eOperator & WO_EQUIV)!=0 if( (pTerm->eOperator & WO_EQUIV)!=0
&& pScan->nEquiv<ArraySize(pScan->aiCur) && pScan->nEquiv<ArraySize(pScan->aiCur)
&& (pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight))->op==TK_COLUMN
){ ){
int j; int j;
pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight);
assert( pX->op==TK_COLUMN );
for(j=0; j<pScan->nEquiv; j++){ for(j=0; j<pScan->nEquiv; j++){
if( pScan->aiCur[j]==pX->iTable if( pScan->aiCur[j]==pX->iTable
&& pScan->aiColumn[j]==pX->iColumn ){ && pScan->aiColumn[j]==pX->iColumn ){

View File

@@ -41,6 +41,16 @@ static void explainAppendTerm(
sqlite3StrAccumAppend(pStr, "?", 1); sqlite3StrAccumAppend(pStr, "?", 1);
} }
/*
** Return the name of the i-th column of the pIdx index.
*/
static const char *explainIndexColumnName(Index *pIdx, int i){
i = pIdx->aiColumn[i];
if( i==(-2) ) return "<expr>";
if( i==(-1) ) return "rowid";
return pIdx->pTable->aCol[i].zName;
}
/* /*
** Argument pLevel describes a strategy for scanning table pTab. This ** Argument pLevel describes a strategy for scanning table pTab. This
** function appends text to pStr that describes the subset of table ** function appends text to pStr that describes the subset of table
@@ -60,13 +70,11 @@ static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
u16 nEq = pLoop->u.btree.nEq; u16 nEq = pLoop->u.btree.nEq;
u16 nSkip = pLoop->nSkip; u16 nSkip = pLoop->nSkip;
int i, j; int i, j;
Column *aCol = pTab->aCol;
i16 *aiColumn = pIndex->aiColumn;
if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return; if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
sqlite3StrAccumAppend(pStr, " (", 2); sqlite3StrAccumAppend(pStr, " (", 2);
for(i=0; i<nEq; i++){ for(i=0; i<nEq; i++){
char *z = aiColumn[i] < 0 ? "rowid" : aCol[aiColumn[i]].zName; const char *z = explainIndexColumnName(pIndex, i);
if( i>=nSkip ){ if( i>=nSkip ){
explainAppendTerm(pStr, i, z, "="); explainAppendTerm(pStr, i, z, "=");
}else{ }else{
@@ -77,11 +85,11 @@ static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
j = i; j = i;
if( pLoop->wsFlags&WHERE_BTM_LIMIT ){ if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName; const char *z = explainIndexColumnName(pIndex, i);
explainAppendTerm(pStr, i++, z, ">"); explainAppendTerm(pStr, i++, z, ">");
} }
if( pLoop->wsFlags&WHERE_TOP_LIMIT ){ if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName; const char *z = explainIndexColumnName(pIndex, j);
explainAppendTerm(pStr, i, z, "<"); explainAppendTerm(pStr, i, z, "<");
} }
sqlite3StrAccumAppend(pStr, ")", 1); sqlite3StrAccumAppend(pStr, ")", 1);