aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2015-08-27 20:33:38 +0000
committerdrh <drh@noemail.net>2015-08-27 20:33:38 +0000
commitc7c4680ffd727443c81c4b926e518b2552275d3f (patch)
treefedfc4d895afbd5d3083322eb3fefd92569daf6f /src
parent29d03f6517918b1e67f630e9984d1f8d726df401 (diff)
downloadsqlite-c7c4680ffd727443c81c4b926e518b2552275d3f.tar.gz
sqlite-c7c4680ffd727443c81c4b926e518b2552275d3f.zip
Fix EXPLAIN QUERY PLAN output for indexed-expressions. Fix another
obscure fault in the WHERE term scanner. FossilOrigin-Name: 73d361ce9e4d72c943def8b0b3caa227f9199aed
Diffstat (limited to 'src')
-rw-r--r--src/where.c3
-rw-r--r--src/wherecode.c18
2 files changed, 14 insertions, 7 deletions
diff --git a/src/where.c b/src/where.c
index c78563f1c..8d26cd4b4 100644
--- a/src/where.c
+++ b/src/where.c
@@ -191,10 +191,9 @@ static WhereTerm *whereScanNext(WhereScan *pScan){
){
if( (pTerm->eOperator & WO_EQUIV)!=0
&& pScan->nEquiv<ArraySize(pScan->aiCur)
+ && (pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight))->op==TK_COLUMN
){
int j;
- pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight);
- assert( pX->op==TK_COLUMN );
for(j=0; j<pScan->nEquiv; j++){
if( pScan->aiCur[j]==pX->iTable
&& pScan->aiColumn[j]==pX->iColumn ){
diff --git a/src/wherecode.c b/src/wherecode.c
index e5c0b40b1..0a9d7b35b 100644
--- a/src/wherecode.c
+++ b/src/wherecode.c
@@ -42,6 +42,16 @@ static void explainAppendTerm(
}
/*
+** 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
** function appends text to pStr that describes the subset of table
** rows scanned by the strategy in the form of an SQL expression.
@@ -60,13 +70,11 @@ static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
u16 nEq = pLoop->u.btree.nEq;
u16 nSkip = pLoop->nSkip;
int i, j;
- Column *aCol = pTab->aCol;
- i16 *aiColumn = pIndex->aiColumn;
if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
sqlite3StrAccumAppend(pStr, " (", 2);
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 ){
explainAppendTerm(pStr, i, z, "=");
}else{
@@ -77,11 +85,11 @@ static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
j = i;
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, ">");
}
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, "<");
}
sqlite3StrAccumAppend(pStr, ")", 1);