Fix a problem causing incorrect code to be generated for IN constraints like "a IN (1, 2, 3)" where column "a" is a rowid column with an extra UNIQUE index created on it. Ticket [0eab1ac759].

FossilOrigin-Name: a92aee5520cfaf85ae896365a7e42bdd981f828d
This commit is contained in:
dan 2016-09-16 16:30:57 +00:00
parent 72d5003ed8
commit edc3537c61
4 changed files with 32 additions and 14 deletions

View File

@ -1,5 +1,5 @@
C Replace\sa\sfaulty\sassert()\swith\sa\stestcase()\sto\sassure\sthe\scondition\sis\ntested.
D 2016-09-16T15:42:17.759
C Fix\sa\sproblem\scausing\sincorrect\scode\sto\sbe\sgenerated\sfor\sIN\sconstraints\slike\s"a\sIN\s(1,\s2,\s3)"\swhere\scolumn\s"a"\sis\sa\srowid\scolumn\swith\san\sextra\sUNIQUE\sindex\screated\son\sit.\sTicket\s[0eab1ac759].
D 2016-09-16T16:30:57.249
F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc e1aa788e84f926e42239ee167c53f785bedacacd
@ -469,7 +469,7 @@ F src/wal.h 6dd221ed384afdc204bc61e25c23ef7fd5a511f2
F src/walker.c 2d2cc7fb0f320f7f415215d7247f3c584141ac09
F src/where.c d0ca1b5e1c56249e7725cea66ce4e172c5845dec
F src/whereInt.h 14dd243e13b81cbb0a66063d38b70f93a7d6e613
F src/wherecode.c c23f9b26fbcdf3f1e3ff2bcd4377057ffc14e063
F src/wherecode.c e412e09abad1eea213d85594cf46db9f877db56d
F src/whereexpr.c e3db778ed205e982f31960896db71c50612ae009
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd
@ -831,7 +831,7 @@ F test/in.test 20c5529986998949908f889c8208b2cd894b2cc9
F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75
F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0
F test/in4.test d2b38cba404bc4320f4fe1b595b3d163f212c068
F test/in5.test acc710c12af118df5f8645eaba9479f5619eed81
F test/in5.test 6c006e0bcd7351b69350ef566e65f244023489e9
F test/incrblob.test c9b96afc292aeff43d6687bcb09b0280aa599822
F test/incrblob2.test a5ce5ed1d0b01e2ed347245a21170372528af0a5
F test/incrblob3.test d8d036fde015d4a159cd3cbae9d29003b37227a4
@ -1525,7 +1525,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 e7653decdcee161d379ced40aa1b27246337b000
R ba1360097229bdefefc2984ae83db820
U drh
Z 4ae8145ebc191fbb330e31aa85de1aa5
P a49bc0a8244feb08b83e716d81c2a9512c184539
R 6f0469103fd0ee7eefefaa24af917500
U dan
Z 752f0595c26528c23b738c8e2fc1f9ad

View File

@ -1 +1 @@
a49bc0a8244feb08b83e716d81c2a9512c184539
a92aee5520cfaf85ae896365a7e42bdd981f828d

View File

@ -525,14 +525,13 @@ static int codeEqualityTerm(
int iMap = 0; /* Index in aiMap[] */
pIn += i;
for(i=iEq;i<pLoop->nLTerm; i++){
int iOut = iReg;
if( pLoop->aLTerm[i]->pExpr==pX ){
int iOut = iReg + i - iEq;
if( eType==IN_INDEX_ROWID ){
testcase( nEq>1 ); /* Happens with a UNIQUE index on ROWID */
pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iOut);
}else{
int iCol = aiMap ? aiMap[iMap++] : 0;
iOut = iReg + i - iEq;
pIn->addrInTop = sqlite3VdbeAddOp3(v,OP_Column,iTab, iCol, iOut);
}
sqlite3VdbeAddOp1(v, OP_IsNull, iOut); VdbeCoverage(v);

View File

@ -214,8 +214,27 @@ do_execsql_test 7.3.2 {
SELECT a FROM y1 WHERE b IN (SELECT a FROM y2);
} {two}
finish_test
#-------------------------------------------------------------------------
# Tests to confirm that indexes on the rowid column do not confuse
# the query planner. See ticket [0eab1ac7591f511d].
#
do_execsql_test 8.0 {
CREATE TABLE n1(a INTEGER PRIMARY KEY, b VARCHAR(500));
CREATE UNIQUE INDEX n1a ON n1(a);
}
do_execsql_test 8.1 {
SELECT count(*) FROM n1 WHERE a IN (1, 2, 3)
} 0
do_execsql_test 8.2 {
SELECT count(*) FROM n1 WHERE a IN (SELECT +a FROM n1)
} 0
do_execsql_test 8.3 {
INSERT INTO n1 VALUES(1, NULL), (2, NULL), (3, NULL);
SELECT count(*) FROM n1 WHERE a IN (1, 2, 3)
} 3
do_execsql_test 8.4 {
SELECT count(*) FROM n1 WHERE a IN (SELECT +a FROM n1)
} 3
finish_test