In the WHERE generator, when building code for a DELETE operation, make sure

that seeks to the main table are not deferred.
This is a better fix for the [16c9801ceba49] bug than the previous.

FossilOrigin-Name: 150dd09ebd7b17234a79e1811a0fae8b0a7a40d5
This commit is contained in:
drh 2016-05-06 16:06:59 +00:00
parent 70077d1733
commit bcf6884afd
7 changed files with 27 additions and 18 deletions

View File

@ -1,5 +1,5 @@
C Do\snot\sscan\sindexes\sthat\shave\sthe\sinteger\sprimary\skey\sas\stheir\sleft-most\ncolumn.\s\sThis\sfixes\sthe\scrash\sof\sticket\s[16c9801ceba]\sbut\sit\sseems\slike\nthe\swrong\sfix.\s\sMore\sinvestigation\sneeded.
D 2016-05-06T11:31:10.902
C In\sthe\sWHERE\sgenerator,\swhen\sbuilding\scode\sfor\sa\sDELETE\soperation,\smake\ssure\nthat\sseeks\sto\sthe\smain\stable\sare\snot\sdeferred.\nThis\sis\sa\sbetter\sfix\sfor\sthe\s[16c9801ceba49]\sbug\sthan\sthe\sprevious.
D 2016-05-06T16:06:59.602
F Makefile.in 9eda6e1c90d05c199c3ec8a7069b0682ad307657
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc db82b35aef27f412fef14d8534afc022138bcdfd
@ -330,7 +330,7 @@ F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
F src/ctime.c 60e135af364d777a9ab41c97e5e89cd224da6198
F src/date.c 1cc9fb516ec9932c6fd4d2a0d2f8bc4480145c39
F src/dbstat.c c845548d4346e606e2f2b7d2e714ace2b8a7dd1b
F src/delete.c 912908dea57778737d4bab632f00e48b550d10ea
F src/delete.c 4aba4214a377ce8ddde2d2e609777bcc8235200f
F src/expr.c 8796c0739b2ad091e6779253f62aad6e767e2be1
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
F src/fkey.c 4c0bd09e602b8ae8d36d81e31e4872d0b53c87bb
@ -382,7 +382,7 @@ F src/shell.c 14ff7f660530a52b117d110ba3390b7b2eb719b6
F src/sqlite.h.in 9984129d86243424b765fcb3f147c697bd20bb54
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 98f72cbfe00169c39089115427d06ea05fe4b4a2
F src/sqliteInt.h c8483dd77894a72d38a76b6251a4ac949a37d6e8
F src/sqliteInt.h 4ab5884aa7dd1cfbb1a34f60d8a919f6584c4aa1
F src/sqliteLimit.h c0373387c287c8d0932510b5547ecde31b5da247
F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba
F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9
@ -457,9 +457,9 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
F src/wal.c 4db22ed7e77bcf672b1a685d6ddeffba8d5be302
F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c
F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354
F src/where.c a7ce00ffd7844495582af957a222602e517b14de
F src/where.c 019e5b10dedcf54ef077ce23dd8fce38d614dcf4
F src/whereInt.h 3b1fc240e322613ba4e9dc857ca9c7c3390acc74
F src/wherecode.c 28951741be3974701186281ced0564e9586a0db3
F src/wherecode.c 6e2da2449d5589b2ce988afae125a61cad665c86
F src/whereexpr.c eacc0e60d029a082b4fc0cc42ea98544add1319e
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd
@ -847,7 +847,7 @@ F test/insert5.test 394f96728d1258f406fe5f5aeb0aaf29487c39a6
F test/instr.test 737bbf80685232033f3abedc6ae92f75860b5dd2
F test/intarray.test 066b7d7ac38d25bf96f87f1b017bfc687551cdd4
F test/interrupt.test dfe9a67a94b0b2d8f70545ba1a6cca10780d71cc
F test/intpkey.test 18ec1f3f39a18ed51d2dbd9ce184cc421191ff70
F test/intpkey.test bd82146463500ecb5e793b5ea2865eaa1c7bdfb6
F test/io.test f95bca1783b01ea7761671560d023360d2dfa4cc
F test/ioerr.test 2a24bd6ed5a8b062e64bfe1f6cf94fb25e92210d
F test/ioerr2.test 2593563599e2cc6b6b4fcf5878b177bdd5d8df26
@ -1487,10 +1487,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 69d11447f4b1a8c536c3b6573d2a3419da870412
R 88ac4ed286db19382d4843a346c44c60
T *branch * ticket-16c9801ce
T *sym-ticket-16c9801ce *
T -sym-trunk *
P 50312273ffaf1bd4bfdc73865fa0b19166968429
R 0aaabe1d44ff452855f4b1d0d09524f8
U drh
Z a8fa257e80e1a139c1678ae44101daf6
Z 9200ae75c074ea360e36df5da26c6a08

View File

@ -1 +1 @@
50312273ffaf1bd4bfdc73865fa0b19166968429
150dd09ebd7b17234a79e1811a0fae8b0a7a40d5

View File

@ -373,7 +373,7 @@ void sqlite3DeleteFrom(
}else
#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
{
u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK;
u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK|WHERE_SEEK_TABLE;
if( sNC.ncFlags & NC_VarSelect ) bComplex = 1;
wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
if( HasRowid(pTab) ){

View File

@ -2543,6 +2543,7 @@ struct SrcList {
#define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */
#define WHERE_ONEPASS_MULTIROW 0x2000 /* ONEPASS is ok with multiple rows */
#define WHERE_USE_LIMIT 0x4000 /* There is a constant LIMIT clause */
#define WHERE_SEEK_TABLE 0x8000 /* Always seek the main table */
/* Allowed return values from sqlite3WhereIsDistinct()
*/

View File

@ -289,7 +289,7 @@ static WhereTerm *whereScanInit(
j = iColumn;
iColumn = pIdx->aiColumn[j];
if( iColumn==XN_EXPR ) pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
if( iColumn==pIdx->pTable->iPKey && j>0 ) iColumn = XN_ROWID;
if( iColumn==pIdx->pTable->iPKey ) iColumn = XN_ROWID;
}
if( pIdx && iColumn>=0 ){
pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;

View File

@ -1324,7 +1324,9 @@ Bitmask sqlite3WhereCodeOneLoopStart(
if( omitTable ){
/* pIdx is a covering index. No need to access the main table. */
}else if( HasRowid(pIdx->pTable) ){
if( pWInfo->eOnePass!=ONEPASS_OFF ){
if( pWInfo->eOnePass!=ONEPASS_OFF
|| (pWInfo->wctrlFlags & WHERE_SEEK_TABLE)!=0
){
iRowidReg = ++pParse->nMem;
sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
@ -1520,7 +1522,8 @@ Bitmask sqlite3WhereCodeOneLoopStart(
wctrlFlags = WHERE_OMIT_OPEN_CLOSE
| WHERE_FORCE_TABLE
| WHERE_ONETABLE_ONLY
| WHERE_NO_AUTOINDEX;
| WHERE_NO_AUTOINDEX
| (pWInfo->wctrlFlags & WHERE_SEEK_TABLE);
for(ii=0; ii<pOrWc->nTerm; ii++){
WhereTerm *pOrTerm = &pOrWc->a[ii];
if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){

View File

@ -627,5 +627,13 @@ do_execsql_test intpkey-17.0 {
DELETE FROM t17 WHERE x=99 OR x<130;
SELECT * FROM t17;
} {248 giraffe}
do_execsql_test intpkey-17.1 {
DROP INDEX t17x;
DELETE FROM t17;
INSERT INTO t17(x,y) VALUES(123,'elephant'),(248,'giraffe');
CREATE INDEX t17x ON t17(abs(x));
DELETE FROM t17 WHERE abs(x) IS NULL OR abs(x)<130;
SELECT * FROM t17;
} {248 giraffe}
finish_test