From: drh Date: Thu, 29 Jan 2015 15:53:19 +0000 (+0000) Subject: Improvements to the DELETE code generator for the one-pass case. Avoid X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c4811b124e8449e11b5074c71149abb408753d4c;p=thirdparty%2Fsqlite.git Improvements to the DELETE code generator for the one-pass case. Avoid some OP_Goto instructions. Read content from the index cursor if the index cursor is valid and was used to locate the row that is to be deleted. FossilOrigin-Name: 58cc257aeb3ce75b8d3811b568cb8a677f6730a2 --- diff --git a/manifest b/manifest index 98a9812dcb..b1b7743070 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\soverlength\scommand\slines\sin\sMakefile.msc\swhen\susing\sTOP=\swith\sa\slarge\ndirectory\sname. -D 2015-01-29T14:48:36.055 +C Improvements\sto\sthe\sDELETE\scode\sgenerator\sfor\sthe\sone-pass\scase.\s\sAvoid\nsome\sOP_Goto\sinstructions.\s\sRead\scontent\sfrom\sthe\sindex\scursor\sif\sthe\nindex\scursor\sis\svalid\sand\swas\sused\sto\slocate\sthe\srow\sthat\sis\sto\sbe\sdeleted. +D 2015-01-29T15:53:19.350 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -181,7 +181,7 @@ F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463 F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887 F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac -F src/delete.c 250aa3cfd37efd5e660abf0ed061356c1f97acea +F src/delete.c 66c10f83d3b0f37282f5b91f8a9192f4ce4a82c2 F src/expr.c abe930897ccafae3819fd2855cbc1b00c262fd12 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e0444b61bed271a76840cbe6182df93a9baa3f12 @@ -292,7 +292,7 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c 98a7627ca48ad3265b6940915a1d08355eb3fc7e F src/vacuum.c 9b30ec729337dd012ed88d4c292922c8ef9cf00c -F src/vdbe.c ddfc977981cd6324668aa6b114045eb1c677421a +F src/vdbe.c 55f4db96c3d2bee17c66f244e4fc51fb0f09fed2 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbeInt.h 9bb69ff2447c34b6ccc58b34ec35b615f86ead78 F src/vdbeapi.c 4bc511a46b9839392ae0e90844a71dc96d9dbd71 @@ -1237,7 +1237,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 2305411097c4985b61c5faf4361c4da8414101f2 -R 3630050c6c1dd97fb4a47db3b5491230 +P 0cdd59bf36aa4c2cad9a15bb7237643fb4222d55 +R 139902d9a4e02d98a72f3dedb9a073bc U drh -Z 6afbf0e41cb02db92c3354378ab76211 +Z ea315405c3cfce5f5aed8dbe7ead251e diff --git a/manifest.uuid b/manifest.uuid index dc70127e8f..66eddfe516 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0cdd59bf36aa4c2cad9a15bb7237643fb4222d55 \ No newline at end of file +58cc257aeb3ce75b8d3811b568cb8a677f6730a2 \ No newline at end of file diff --git a/src/delete.c b/src/delete.c index 1725484ed6..bf8a03d09d 100644 --- a/src/delete.c +++ b/src/delete.c @@ -247,7 +247,6 @@ void sqlite3DeleteFrom( int iRowSet = 0; /* Register for rowset of rows to delete */ int addrBypass = 0; /* Address of jump over the delete logic */ int addrLoop = 0; /* Top of the delete loop */ - int addrDelete = 0; /* Jump directly to the delete logic */ int addrEphOpen = 0; /* Instruction to open the Ephemeral table */ #ifndef SQLITE_OMIT_TRIGGER @@ -437,7 +436,6 @@ void sqlite3DeleteFrom( if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0; if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0; if( addrEphOpen ) sqlite3VdbeChangeToNoop(v, addrEphOpen); - addrDelete = sqlite3VdbeAddOp0(v, OP_Goto); /* Jump to DELETE logic */ }else if( pPk ){ /* Construct a composite key for the row to be deleted and remember it */ iKey = ++pParse->nMem; @@ -451,13 +449,11 @@ void sqlite3DeleteFrom( sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey); } - /* End of the WHERE loop */ - sqlite3WhereEnd(pWInfo); + /* End of the WHERE loop. */ if( okOnePass ){ - /* Bypass the delete logic below if the WHERE loop found zero rows */ addrBypass = sqlite3VdbeMakeLabel(v); - sqlite3VdbeAddOp2(v, OP_Goto, 0, addrBypass); - sqlite3VdbeJumpHere(v, addrDelete); + }else{ + sqlite3WhereEnd(pWInfo); } /* Unless this is a view, open cursors for the table we are @@ -513,6 +509,7 @@ void sqlite3DeleteFrom( /* End of the loop over all rowids/primary-keys. */ if( okOnePass ){ + sqlite3WhereEnd(pWInfo); sqlite3VdbeResolveLabel(v, addrBypass); }else if( pPk ){ sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v); diff --git a/src/vdbe.c b/src/vdbe.c index 1e0ff96af4..c289bfa248 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -4191,7 +4191,8 @@ case OP_Delete: { pC = p->apCsr[pOp->p1]; assert( pC!=0 ); assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */ - assert( pC->deferredMoveto==0 ); + rc = sqlite3VdbeCursorMoveto(pC); + if( rc ) goto abort_due_to_error; #ifdef SQLITE_DEBUG /* The seek operation that positioned the cursor prior to OP_Delete will