Fix where.c so that the primary key values appended to every index entry on a WITHOUT ROWID table may be used when useful.
FossilOrigin-Name: 6624a61d16e47ad691c4195ca8a1d68b7348118d
This commit is contained in:
parent
971fd07135
commit
39129ce8d9
16
manifest
16
manifest
@ -1,5 +1,5 @@
|
||||
C Omit\snon-primary-key\scolumns\sfrom\sthe\sSTAT4\ssamples\sfor\sWITHOUT\sROWID\stables.\nIndexes,\sboth\srowid\sand\swithout-rowid,\sstill\shold\san\sexact\scopy\nof\sthe\sindex\sentry.
|
||||
D 2014-06-30T13:56:34.968
|
||||
C Fix\swhere.c\sso\sthat\sthe\sprimary\skey\svalues\sappended\sto\severy\sindex\sentry\son\sa\sWITHOUT\sROWID\stable\smay\sbe\sused\swhen\suseful.
|
||||
D 2014-06-30T15:23:57.908
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in 1732320ecac3fee229d560d7ef2afa34681d1815
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@ -296,7 +296,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd
|
||||
F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a
|
||||
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
|
||||
F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45
|
||||
F src/where.c 7b9e13cff91a2f14ac61e6a1bc3a83b5113e6298
|
||||
F src/where.c da15506cd52de8717836921da8ebd9109228f94e
|
||||
F src/whereInt.h 929c1349b5355fd44f22cee5c14d72b3329c58a6
|
||||
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
||||
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
||||
@ -1122,7 +1122,7 @@ F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d
|
||||
F test/with1.test 268081a6b14817a262ced4d0ee34d4d2a1dd2068
|
||||
F test/with2.test ee227a663586aa09771cafd4fa269c5217eaf775
|
||||
F test/withM.test e97f2a8c506ab3ea9eab94e6f6072f6cc924c991
|
||||
F test/without_rowid1.test e00a0a9dc9f0be651f011d61e8a32b7add5afb30
|
||||
F test/without_rowid1.test 7862e605753c8d25329f665fa09072e842183151
|
||||
F test/without_rowid2.test af260339f79d13cb220288b67cd287fbcf81ad99
|
||||
F test/without_rowid3.test eac3d5c8a1924725b58503a368f2cbd24fd6c8a0
|
||||
F test/without_rowid4.test 4e08bcbaee0399f35d58b5581881e7a6243d458a
|
||||
@ -1181,7 +1181,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
|
||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||
P 8cb43eddab83c68b2163441df70e0e9496d5fa33
|
||||
R 76a8cf4e27cd1a26fe3722da49c987a3
|
||||
U drh
|
||||
Z d18fb0d5c10defb46f6f8aaff06ea5cb
|
||||
P de826c31589258f0906f87d65796944103e36d5b
|
||||
R 8442f880f57a242b77225992393b657c
|
||||
U dan
|
||||
Z 6c9f8a4d0a3c007f8c2ac1857a8d9913
|
||||
|
@ -1 +1 @@
|
||||
de826c31589258f0906f87d65796944103e36d5b
|
||||
6624a61d16e47ad691c4195ca8a1d68b7348118d
|
20
src/where.c
20
src/where.c
@ -544,7 +544,7 @@ static WhereTerm *whereScanInit(
|
||||
if( pIdx && iColumn>=0 ){
|
||||
pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
|
||||
for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
|
||||
if( NEVER(j>=pIdx->nKeyCol) ) return 0;
|
||||
if( NEVER(j>pIdx->nColumn) ) return 0;
|
||||
}
|
||||
pScan->zCollName = pIdx->azColl[j];
|
||||
}else{
|
||||
@ -2645,7 +2645,7 @@ static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
|
||||
txt.db = db;
|
||||
sqlite3StrAccumAppend(&txt, " (", 2);
|
||||
for(i=0; i<nEq; i++){
|
||||
char *z = (i==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[i]].zName;
|
||||
char *z = aiColumn[i] < 0 ? "rowid" : aCol[aiColumn[i]].zName;
|
||||
if( i>=nSkip ){
|
||||
explainAppendTerm(&txt, i, z, "=");
|
||||
}else{
|
||||
@ -2658,11 +2658,11 @@ static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
|
||||
|
||||
j = i;
|
||||
if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
|
||||
char *z = (j==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[j]].zName;
|
||||
char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
|
||||
explainAppendTerm(&txt, i++, z, ">");
|
||||
}
|
||||
if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
|
||||
char *z = (j==pIndex->nKeyCol ) ? "rowid" : aCol[aiColumn[j]].zName;
|
||||
char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
|
||||
explainAppendTerm(&txt, i, z, "<");
|
||||
}
|
||||
sqlite3StrAccumAppend(&txt, ")", 1);
|
||||
@ -4164,12 +4164,9 @@ static int whereLoopAddBtreeIndex(
|
||||
}
|
||||
if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
|
||||
|
||||
assert( pNew->u.btree.nEq<=pProbe->nKeyCol );
|
||||
if( pNew->u.btree.nEq < pProbe->nKeyCol ){
|
||||
iCol = pProbe->aiColumn[pNew->u.btree.nEq];
|
||||
}else{
|
||||
iCol = -1;
|
||||
}
|
||||
assert( pNew->u.btree.nEq<pProbe->nColumn );
|
||||
iCol = pProbe->aiColumn[pNew->u.btree.nEq];
|
||||
|
||||
pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
|
||||
opMask, pProbe);
|
||||
saved_nEq = pNew->u.btree.nEq;
|
||||
@ -4359,7 +4356,7 @@ static int whereLoopAddBtreeIndex(
|
||||
}
|
||||
|
||||
if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
|
||||
&& pNew->u.btree.nEq<(pProbe->nKeyCol + (pProbe->zName!=0))
|
||||
&& pNew->u.btree.nEq<pProbe->nColumn
|
||||
){
|
||||
whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
|
||||
}
|
||||
@ -4506,6 +4503,7 @@ static int whereLoopAddBtree(
|
||||
Index *pFirst; /* First of real indices on the table */
|
||||
memset(&sPk, 0, sizeof(Index));
|
||||
sPk.nKeyCol = 1;
|
||||
sPk.nColumn = 1;
|
||||
sPk.aiColumn = &aiColumnPk;
|
||||
sPk.aiRowLogEst = aiRowEstPk;
|
||||
sPk.onError = OE_Replace;
|
||||
|
@ -213,5 +213,69 @@ do_execsql_test 4.1 {
|
||||
do_execsql_test 4.2 {
|
||||
SELECT t42.rowid FROM t42, t41;
|
||||
} {1}
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# The following tests verify that the trailing PK fields added to each
|
||||
# entry in an index on a WITHOUT ROWID table are used correctly.
|
||||
#
|
||||
do_execsql_test 5.0 {
|
||||
CREATE TABLE t45(a PRIMARY KEY, b, c) WITHOUT ROWID;
|
||||
CREATE INDEX i45 ON t45(b);
|
||||
|
||||
INSERT INTO t45 VALUES(2, 'one', 'x');
|
||||
INSERT INTO t45 VALUES(4, 'one', 'x');
|
||||
INSERT INTO t45 VALUES(6, 'one', 'x');
|
||||
INSERT INTO t45 VALUES(8, 'one', 'x');
|
||||
INSERT INTO t45 VALUES(10, 'one', 'x');
|
||||
|
||||
INSERT INTO t45 VALUES(1, 'two', 'x');
|
||||
INSERT INTO t45 VALUES(3, 'two', 'x');
|
||||
INSERT INTO t45 VALUES(5, 'two', 'x');
|
||||
INSERT INTO t45 VALUES(7, 'two', 'x');
|
||||
INSERT INTO t45 VALUES(9, 'two', 'x');
|
||||
}
|
||||
|
||||
do_eqp_test 5.1 {
|
||||
SELECT * FROM t45 WHERE b=? AND a>?
|
||||
} {/*USING INDEX i45 (b=? AND a>?)*/}
|
||||
|
||||
do_execsql_test 5.2 {
|
||||
SELECT * FROM t45 WHERE b='two' AND a>4
|
||||
} {5 two x 7 two x 9 two x}
|
||||
|
||||
do_execsql_test 5.3 {
|
||||
SELECT * FROM t45 WHERE b='one' AND a<8
|
||||
} { 2 one x 4 one x 6 one x }
|
||||
|
||||
do_execsql_test 5.4 {
|
||||
CREATE TABLE t46(a, b, c, d, PRIMARY KEY(a, b)) WITHOUT ROWID;
|
||||
WITH r(x) AS (
|
||||
SELECT 1 UNION ALL SELECT x+1 FROM r WHERE x<100
|
||||
)
|
||||
INSERT INTO t46 SELECT x / 20, x % 20, x % 10, x FROM r;
|
||||
}
|
||||
|
||||
set queries {
|
||||
1 2 "c = 5 AND a = 1" {/*i46 (c=? AND a=?)*/}
|
||||
2 6 "c = 4 AND a < 3" {/*i46 (c=? AND a<?)*/}
|
||||
3 4 "c = 2 AND a >= 3" {/*i46 (c=? AND a>?)*/}
|
||||
4 1 "c = 2 AND a = 1 AND b<10" {/*i46 (c=? AND a=? AND b<?)*/}
|
||||
5 1 "c = 0 AND a = 0 AND b>5" {/*i46 (c=? AND a=? AND b>?)*/}
|
||||
}
|
||||
|
||||
foreach {tn cnt where eqp} $queries {
|
||||
do_execsql_test 5.5.$tn.1 "SELECT count(*) FROM t46 WHERE $where" $cnt
|
||||
}
|
||||
|
||||
do_execsql_test 5.6 {
|
||||
CREATE INDEX i46 ON t46(c);
|
||||
}
|
||||
|
||||
foreach {tn cnt where eqp} $queries {
|
||||
do_execsql_test 5.7.$tn.1 "SELECT count(*) FROM t46 WHERE $where" $cnt
|
||||
do_eqp_test 5.7.$tn.2 "SELECT count(*) FROM t46 WHERE $where" $eqp
|
||||
}
|
||||
|
||||
|
||||
finish_test
|
||||
|
Loading…
x
Reference in New Issue
Block a user