Fix the EXPLAIN QUERY PLAN output for row value range constaints that use an index.

FossilOrigin-Name: bb60651163553c5e46bf7b2805490570cea647b8
This commit is contained in:
dan 2016-08-08 18:42:08 +00:00
parent adeb970da2
commit 1d9bc9b7a0
4 changed files with 80 additions and 28 deletions

View File

@ -1,5 +1,5 @@
C Merge\strunk\schanges\swith\sthis\sbranch.
D 2016-08-08T16:52:11.472
C Fix\sthe\sEXPLAIN\sQUERY\sPLAN\soutput\sfor\srow\svalue\srange\sconstaints\sthat\suse\san\sindex.
D 2016-08-08T18:42:08.741
F Makefile.in cfd8fb987cd7a6af046daa87daa146d5aad0e088
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc d66d0395c38571aab3804f8db0fa20707ae4609a
@ -465,7 +465,7 @@ F src/wal.h 6dd221ed384afdc204bc61e25c23ef7fd5a511f2
F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354
F src/where.c f60310d9fa2dd275698f3a768d2c63917353f22d
F src/whereInt.h 14dd243e13b81cbb0a66063d38b70f93a7d6e613
F src/wherecode.c c2392fa30bcb0c555a8ae402d646b357ca428ad6
F src/wherecode.c c24645572eba538c04c5ff8b8f6e9c0278107563
F src/whereexpr.c 4a8cefc7c122132ac9f3ed125c61629a0e3de094
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd
@ -1021,7 +1021,7 @@ F test/rowid.test 5b7509f384f4f6fae1af3c8c104c8ca299fea18d
F test/rowvalue.test 56b34d31d91340a6e922e753b798880170cc1aa7
F test/rowvalue2.test 8d5dfe75b8f4d1868a2f91f0356f20d36cba64ff
F test/rowvalue3.test dbe935260851b197dfbbbcb0ac2a15cb5f324fd4
F test/rowvalue4.test 1f0fa2d6e4485c2c35cdb997ba57f572fd9919e0
F test/rowvalue4.test 8d3b26c7ab26314b625cd2b113d782b011b91851
F test/rowvaluefault.test 7b16485e3f2b371f3e3d05455b8ded6d0c090244
F test/rtree.test 0c8d9dd458d6824e59683c19ab2ffa9ef946f798
F test/run-wordcount.sh 891e89c4c2d16e629cd45951d4ed899ad12afc09
@ -1514,7 +1514,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 3c2f908f5b7312570cfa74afcf4252a857cb5237 d5e98057028abcf7217d0d2b2e29bbbcdf09d6de
R e29053a139f99493b32e4ec805317c91
P 0e927a7e0250a65fd8e97b322cd69e93fadd13f0
R c87cf26a8b83e76d6d485dba242f3437
U dan
Z c05c70937976285652f33ed04f5e8c75
Z eb833a77a96d41ac0d9eabbd9e7d8788

View File

@ -1 +1 @@
0e927a7e0250a65fd8e97b322cd69e93fadd13f0
bb60651163553c5e46bf7b2805490570cea647b8

View File

@ -21,6 +21,17 @@
#include "whereInt.h"
#ifndef SQLITE_OMIT_EXPLAIN
/*
** 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==XN_EXPR ) return "<expr>";
if( i==XN_ROWID ) return "rowid";
return pIdx->pTable->aCol[i].zName;
}
/*
** This routine is a helper for explainIndexRange() below
**
@ -31,24 +42,32 @@
*/
static void explainAppendTerm(
StrAccum *pStr, /* The text expression being built */
int iTerm, /* Index of this term. First is zero */
const char *zColumn, /* Name of the column */
Index *pIdx, /* Index to read column names from */
int nTerm, /* Number of terms */
int iTerm, /* Zero-based index of first term. */
int bAnd, /* Non-zero to append " AND " */
const char *zOp /* Name of the operator */
){
if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5);
sqlite3StrAccumAppendAll(pStr, zColumn);
sqlite3StrAccumAppend(pStr, zOp, 1);
sqlite3StrAccumAppend(pStr, "?", 1);
}
int i;
/*
** 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==XN_EXPR ) return "<expr>";
if( i==XN_ROWID ) return "rowid";
return pIdx->pTable->aCol[i].zName;
assert( nTerm>=1 );
if( bAnd ) sqlite3StrAccumAppend(pStr, " AND ", 5);
if( nTerm>1 ) sqlite3StrAccumAppend(pStr, "(", 1);
for(i=0; i<nTerm; i++){
if( i ) sqlite3StrAccumAppend(pStr, ",", 1);
sqlite3StrAccumAppendAll(pStr, explainIndexColumnName(pIdx, iTerm+i));
}
if( nTerm>1 ) sqlite3StrAccumAppend(pStr, ")", 1);
sqlite3StrAccumAppend(pStr, zOp, 1);
if( nTerm>1 ) sqlite3StrAccumAppend(pStr, "(", 1);
for(i=0; i<nTerm; i++){
if( i ) sqlite3StrAccumAppend(pStr, ",", 1);
sqlite3StrAccumAppend(pStr, "?", 1);
}
if( nTerm>1 ) sqlite3StrAccumAppend(pStr, ")", 1);
}
/*
@ -81,12 +100,11 @@ static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop){
j = i;
if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
const char *z = explainIndexColumnName(pIndex, i);
explainAppendTerm(pStr, i++, z, ">");
explainAppendTerm(pStr, pIndex, pLoop->u.btree.nBtm, j, i, ">");
i = 1;
}
if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
const char *z = explainIndexColumnName(pIndex, j);
explainAppendTerm(pStr, i, z, "<");
explainAppendTerm(pStr, pIndex, pLoop->u.btree.nTop, j, i, "<");
}
sqlite3StrAccumAppend(pStr, ")", 1);
}

View File

@ -205,7 +205,7 @@ ifcapable stat4 {
0 0 0 {SEARCH TABLE c1 USING INDEX c1ab (a=?)}
}
do_eqp_test 3.2.5 { SELECT * FROM c1 WHERE a=1 AND (c, d)>(1, 'o') } {
0 0 0 {SEARCH TABLE c1 USING INDEX c1cd (c>?)}
0 0 0 {SEARCH TABLE c1 USING INDEX c1cd ((c,d)>(?,?))}
}
do_eqp_test 3.2.6 { SELECT * FROM c1 WHERE a=1 AND (c, +b)>(1, 'c') } {
0 0 0 {SEARCH TABLE c1 USING INDEX c1ab (a=?)}
@ -239,6 +239,40 @@ do_eqp_test 5.1 {
2 0 0 {SCAN TABLE d1}
}
do_execsql_test 6.0 {
CREATE TABLE e1(a, b, c, d, e);
CREATE INDEX e1ab ON e1(a, b);
CREATE INDEX e1cde ON e1(c, d, e);
}
do_eqp_test 6.1 {
SELECT * FROM e1 WHERE (a, b) > (?, ?)
} {
0 0 0 {SEARCH TABLE e1 USING INDEX e1ab ((a,b)>(?,?))}
}
do_eqp_test 6.2 {
SELECT * FROM e1 WHERE (a, b) < (?, ?)
} {
0 0 0 {SEARCH TABLE e1 USING INDEX e1ab ((a,b)<(?,?))}
}
do_eqp_test 6.3 {
SELECT * FROM e1 WHERE c = ? AND (d, e) > (?, ?)
} {
0 0 0 {SEARCH TABLE e1 USING INDEX e1cde (c=? AND (d,e)>(?,?))}
}
do_eqp_test 6.4 {
SELECT * FROM e1 WHERE c = ? AND (d, e) < (?, ?)
} {
0 0 0 {SEARCH TABLE e1 USING INDEX e1cde (c=? AND (d,e)<(?,?))}
}
do_eqp_test 6.5 {
SELECT * FROM e1 WHERE (d, e) BETWEEN (?, ?) AND (?, ?) AND c = ?
} {
0 0 0
{SEARCH TABLE e1 USING INDEX e1cde (c=? AND (d,e)>(?,?) AND (d,e)<(?,?))}
}
finish_test