From: drh Date: Sat, 7 Jan 2017 14:47:03 +0000 (+0000) Subject: Improvements to the iIdxNoSeek optimization of sqlite3GenerateRowDelete() X-Git-Tag: version-3.17.0~124 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=68116939ebe9319c400962c19e5901d4636ae7ed;p=thirdparty%2Fsqlite.git Improvements to the iIdxNoSeek optimization of sqlite3GenerateRowDelete() so that it is automatically disabled for BEFORE triggers but works in all other cases. FossilOrigin-Name: 3178ec4c27efc4ff84bcd17ddb17ec50a6ac96b3 --- diff --git a/manifest b/manifest index 769b92f991..ec76e312ce 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Critical\sfix\sto\sthe\sprevious\scheck-in\sso\sthat\sit\sworks\swhen\sthere\sare\nBEFORE\striggers\sthat\smove\sthe\scursor\sbefore\sthe\sOP_Delete\shas\sa\schance\sto\nbe\sapplied. -D 2017-01-07T14:26:28.809 +C Improvements\sto\sthe\siIdxNoSeek\soptimization\sof\ssqlite3GenerateRowDelete()\nso\sthat\sit\sis\sautomatically\sdisabled\sfor\sBEFORE\striggers\sbut\sworks\sin\sall\nother\scases. +D 2017-01-07T14:47:03.531 F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da @@ -340,7 +340,7 @@ F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 9f2296a4e5d26ebf0e0d95a0af4628f1ea694e7a F src/date.c dc3f1391d9297f8c748132813aaffcb117090d6e F src/dbstat.c 19ee7a4e89979d4df8e44cfac7a8f905ec89b77d -F src/delete.c 4220f4feee7fddefc1e73e5ade1ed82ffe8dc92a +F src/delete.c a84f6229ccb9448460c287248024ceb70e10baab F src/expr.c f06f41e5e5daca10fb090e70a2502dcc0dbc992b F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 2e9aabe1aee76273aff8a84ee92c464e095400ae @@ -350,7 +350,7 @@ F src/hash.c 63d0ee752a3b92d4695b2b1f5259c4621b2cfebd F src/hash.h ab34c5c54a9e9de2e790b24349ba5aab3dbb4fd4 F src/hwtime.h 747c1bbe9df21a92e9c50f3bbec1de841dc5e5da F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 3b7fbb149ef249269bfbedabbe8fd706ef9a2317 +F src/insert.c ad2a0b2757a23b6f9297ee414eeab22b52fbde75 F src/legacy.c 75d3023be8f0d2b99d60f905090341a03358c58e F src/loadext.c 5d6642d141c07d366e43d359e94ec9de47add41d F src/main.c e207b81542d13b9f13d61e78ca441f9781f055b0 @@ -1543,7 +1543,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 f0495c5133d0dc04d63521136d6b9ca440792cdf -R 21f1a5c5760681e8d66bbbeed4342953 +P db2c0960ffb3b396b20e0441d3edb812254c82bc +R 7bbc97d23d01181c7fdd8aa9c81894e1 U drh -Z 06625003bcd408124313c9f36986c7f6 +Z 5c5df114c2b0c58ce035451bb180f71f diff --git a/manifest.uuid b/manifest.uuid index ce6b8d600a..c040ce2769 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -db2c0960ffb3b396b20e0441d3edb812254c82bc \ No newline at end of file +3178ec4c27efc4ff84bcd17ddb17ec50a6ac96b3 \ No newline at end of file diff --git a/src/delete.c b/src/delete.c index db00803996..1a5edb59d8 100644 --- a/src/delete.c +++ b/src/delete.c @@ -519,9 +519,8 @@ void sqlite3DeleteFrom( #endif { int count = (pParse->nested==0); /* True to count changes */ - int iIdxNoSeek = bComplex ? -1 : aiCurOnePass[1]; sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, - iKey, nKey, count, OE_Default, eOnePass, iIdxNoSeek); + iKey, nKey, count, OE_Default, eOnePass, aiCurOnePass[1]); } /* End of the loop over all rowids/primary-keys. */ @@ -610,6 +609,8 @@ delete_from_cleanup: ** If iIdxNoSeek is a valid cursor number (>=0) not equal to iDataCur, ** then it identifies an index cursor (from within array of cursors ** starting at iIdxCur) that already points to the index entry to be deleted. +** Except, this optimization is disabled if there are BEFORE triggers since +** the trigger body might have moved the cursor. */ void sqlite3GenerateRowDelete( Parse *pParse, /* Parsing context */ @@ -682,11 +683,16 @@ void sqlite3GenerateRowDelete( ** row to be deleted again. It may be that the BEFORE triggers moved ** the cursor or already deleted the row that the cursor was ** pointing to. + ** + ** Also disable the iIdxNoSeek optimization since the BEFORE trigger + ** may have moved that cursor. */ if( addrStart=0 ); + iIdxNoSeek = -1; } /* Do FK processing. This call checks that any FK constraints that diff --git a/src/insert.c b/src/insert.c index 4f407a2cbd..e55ea2d9fb 100644 --- a/src/insert.c +++ b/src/insert.c @@ -1651,8 +1651,7 @@ void sqlite3GenerateConstraintChecks( } sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, regR, nPkField, 0, OE_Replace, - (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), - (pTrigger ? -1 : iThisCur)); + (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), iThisCur); seenReplace = 1; break; }