From: drh Date: Sat, 7 Nov 2015 01:19:00 +0000 (+0000) Subject: The OPFLAG_SEEKEQ optimization is only applicable to equality comparisons X-Git-Tag: version-3.10.0~159 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d6b7946c32ec1cf4b77f51ab82db553cf466c488;p=thirdparty%2Fsqlite.git The OPFLAG_SEEKEQ optimization is only applicable to equality comparisons against an index, not against a rowid table. FossilOrigin-Name: 0f5b147d1fe83c34d0fbeacc7422be94d8441bc1 --- diff --git a/manifest b/manifest index 495696b9a2..782863019b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sharmless\ssanitizer\swarning\sin\sthe\sieee754\sextension. -D 2015-11-07T00:51:15.328 +C The\sOPFLAG_SEEKEQ\soptimization\sis\sonly\sapplicable\sto\sequality\scomparisons\nagainst\san\sindex,\snot\sagainst\sa\srowid\stable. +D 2015-11-07T01:19:00.997 F Makefile.in 3a705bb4bd12e194212ddbdbf068310d17153cdb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 702d3e98f3afc6587a78481257f3c4c900efc3a4 @@ -403,7 +403,7 @@ F src/update.c 40e51cd0883cb5bfd6abb7d8a7cd8aa47fab2945 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c fc612367108b74573c5fd13a85d0a23027f438bd F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 -F src/vdbe.c a9b0ec9f8df86a805d593b625d1f21a8e71dcda5 +F src/vdbe.c 7a9b18027414368d800716e6319e2acd699c70db F src/vdbe.h efb7a8c1459e31f3ea4377824c6a7e4cb5068637 F src/vdbeInt.h 33403622c6a8feaaac5f0f3f17f5d1bf6df42286 F src/vdbeapi.c 020681b943e77766b32ae1cddf86d7831b7374ca @@ -1400,7 +1400,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P d741e1ccdce96e6142e294fbdd20a0282296dcea -R 09ac306f39fb272ed95e60baefe78a45 +P dd9a26ecdeaef7b0b9cbf4ff70448ab13a276b4e +R 37fd8f25666e5cc61c467cdb94b7bb71 U drh -Z d2d47fc2f78320b8e866fa5d7ad2519b +Z b3bf4f06c783a2156de71d3cb1963976 diff --git a/manifest.uuid b/manifest.uuid index e3b122df6d..f7a057f393 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dd9a26ecdeaef7b0b9cbf4ff70448ab13a276b4e \ No newline at end of file +0f5b147d1fe83c34d0fbeacc7422be94d8441bc1 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index bfbb7e0195..d13655d9c1 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3681,7 +3681,7 @@ case OP_SeekGT: { /* jump, in3 */ UnpackedRecord r; /* The key to seek for */ int nField; /* Number of columns or fields in the key */ i64 iKey; /* The rowid we are to seek to */ - int eqOnly = 0; /* Only interested in == results */ + int eqOnly; /* Only interested in == results */ assert( pOp->p1>=0 && pOp->p1nCursor ); assert( pOp->p2!=0 ); @@ -3694,26 +3694,16 @@ case OP_SeekGT: { /* jump, in3 */ assert( pC->isOrdered ); assert( pC->pCursor!=0 ); oc = pOp->opcode; + eqOnly = 0; pC->nullRow = 0; #ifdef SQLITE_DEBUG pC->seekOp = pOp->opcode; #endif - /* For a cursor with the BTREE_SEEK_EQ hint, only the OP_SeekGE and - ** OP_SeekLE opcodes are allowed, and these must be immediately followed - ** by an OP_IdxGT or OP_IdxLT opcode, respectively, with the same key. - */ - if( sqlite3BtreeCursorHasHint(pC->pCursor, BTREE_SEEK_EQ) ){ - eqOnly = 1; - assert( pOp->opcode==OP_SeekGE || pOp->opcode==OP_SeekLE ); - assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT ); - assert( pOp[1].p1==pOp[0].p1 ); - assert( pOp[1].p2==pOp[0].p2 ); - assert( pOp[1].p3==pOp[0].p3 ); - assert( pOp[1].p4.i==pOp[0].p4.i ); - } - if( pC->isTable ){ + /* The BTREE_SEEK_EQ flag is only set on index cursors */ + assert( sqlite3BtreeCursorHasHint(pC->pCursor, BTREE_SEEK_EQ)==0 ); + /* The input value in P3 might be of any type: integer, real, string, ** blob, or NULL. But it needs to be an integer before we can do ** the seek, so convert it. */ @@ -3761,8 +3751,21 @@ case OP_SeekGT: { /* jump, in3 */ if( rc!=SQLITE_OK ){ goto abort_due_to_error; } - if( eqOnly && res ) goto seek_not_found; }else{ + /* For a cursor with the BTREE_SEEK_EQ hint, only the OP_SeekGE and + ** OP_SeekLE opcodes are allowed, and these must be immediately followed + ** by an OP_IdxGT or OP_IdxLT opcode, respectively, with the same key. + */ + if( sqlite3BtreeCursorHasHint(pC->pCursor, BTREE_SEEK_EQ) ){ + eqOnly = 1; + assert( pOp->opcode==OP_SeekGE || pOp->opcode==OP_SeekLE ); + assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT ); + assert( pOp[1].p1==pOp[0].p1 ); + assert( pOp[1].p2==pOp[0].p2 ); + assert( pOp[1].p3==pOp[0].p3 ); + assert( pOp[1].p4.i==pOp[0].p4.i ); + } + nField = pOp->p4.i; assert( pOp->p4type==P4_INT32 ); assert( nField>0 );