From: drh <> Date: Mon, 19 Jul 2021 20:52:31 +0000 (+0000) Subject: More precision in comparing integers and floating point values while X-Git-Tag: version-3.37.0~325 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=de3246176bcce89de803ae298afd455648a6a57f;p=thirdparty%2Fsqlite.git More precision in comparing integers and floating point values while processing the integer primary key for OP_SeekGE and similar. [forum:/forumpost/2bdb86a068|Forum post 2bdb86a068]. FossilOrigin-Name: f9c6426de3b413ff8fcf04a00931ca5f123f996c572b35181af114afa8d811d7 --- diff --git a/manifest b/manifest index c28c4a8667..7bb2b8c7ad 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Updates\sso\sthat\s"threadtest3[.exe]"\scan\sbe\sbuilt\sfor\swindows\swith\sMSVC. -D 2021-07-19T16:49:13.643 +C More\sprecision\sin\scomparing\sintegers\sand\sfloating\spoint\svalues\swhile\nprocessing\sthe\sinteger\sprimary\skey\sfor\sOP_SeekGE\sand\ssimilar.\n[forum:/forumpost/2bdb86a068|Forum\spost\s2bdb86a068]. +D 2021-07-19T20:52:31.773 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -616,11 +616,11 @@ F src/upsert.c df8f1727d62b5987c4fd302cd4d7c0c84ae57cd65683c5a34a740dfe24039235 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c 41c7a72da1df47864faa378a1c720b38adb288c6838cb6be5594511b6287a048 F src/vacuum.c 454973a59fb20bb982efc2df568a098616db6328a0491b6e84e2e07f7333db45 -F src/vdbe.c 27149413d6b09684b83746eb8f26210baf50eb23925b64261b6d93119a218435 +F src/vdbe.c b73a5ec9940185eb001ff8cff2cfd429bb438c7e89f2885e0bfdb56c3ff13386 F src/vdbe.h 25dabb25c7e157b84e59260cfb5b466c3ac103ede9f36f4db371332c47601abe -F src/vdbeInt.h 1fc1e3581afcd3f56bdbe930639edac84ee823c034f31da97f49c35522f4c8c2 +F src/vdbeInt.h 38206c8dd6b60ff03d9fd4f626b1b4fd0eef7cdc44f2fc2c1973b0f932a3f26b F src/vdbeapi.c aa5aaf2c37676b83af5724c6cd8207a3064ed46a217fd180957f75ac84f7a2a5 -F src/vdbeaux.c 23f9800742b11eb6d1d775fd332a88252e44e9f7ba94b826e211a5d9dbfe0ced +F src/vdbeaux.c 564622045316eb2eed1370714426e81ab96d86e7894a368e80a83e0baff23346 F src/vdbeblob.c c6b8db50b227f66fb404215732068df76485b5b433e5f9d4d9ac27410b218193 F src/vdbemem.c 53881aa0a7845922a075b3f375695588618098871a7a4120af4c297b80fa3e64 F src/vdbesort.c cd5130f683706c1a43e165a74187745fb3351cb56052cf9dc91de820634bbde2 @@ -1746,7 +1746,7 @@ F test/walthread.test 14b20fcfa6ae152f5d8e12f5dc8a8a724b7ef189f5d8ef1e2ceab79f2a F test/walvfs.test bccb3e0d235ef85e276f491d34db32c9ada1ea67be8d9f10aabe7b30319ec656 F test/wapp.tcl b440cd8cf57953d3a49e7ee81e6a18f18efdaf113b69f7d8482b0710a64566ec F test/wapptest.tcl 899594e25684861d5b0c0880fb012364def50ef8097041b8ddf74be5ba7fa270 x -F test/where.test 4f7a3939e5190845ef42142031a1819070f65e065e6a840a09adc54dccfef01f +F test/where.test 0be35396a509439d1c38919381feaed3d1e820e08254d246f96e499c5cbf8565 F test/where2.test 03c21a11e7b90e2845fc3c8b4002fc44cc2797fa74c86ee47d70bd7ea4f29ed6 F test/where3.test 5b4ffc0ac2ea0fe92f02b1244b7531522fe4d7bccf6fa8741d54e82c10e67753 F test/where4.test 4a371bfcc607f41d233701bdec33ac2972908ba8 @@ -1920,7 +1920,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 c8601d83fbecf84ca7991d339449b380deb5a7620dc84756a91c2880f030b423 -R e7c3798c4e8afbc59f637b8a384b4003 -U dan -Z 4507211c89102df26f9a64f266826b29 +P 4ce585fb07274284e3add6adcb66ed06e4b109584704d1ec7152bf43ca8d5d85 +R 000488406edbffc8806e75458a922494 +U drh +Z 26015d8f2da64898ae34fc3a47735d30 diff --git a/manifest.uuid b/manifest.uuid index 7723021063..bfd7a78e8b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4ce585fb07274284e3add6adcb66ed06e4b109584704d1ec7152bf43ca8d5d85 \ No newline at end of file +f9c6426de3b413ff8fcf04a00931ca5f123f996c572b35181af114afa8d811d7 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 5b42976a0e..cfcd62266a 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -4275,6 +4275,7 @@ case OP_SeekGT: { /* jump, in3, group */ /* If the P3 value could not be converted into an integer without ** loss of information, then special processing is required... */ if( (newType & (MEM_Int|MEM_IntReal))==0 ){ + int c; if( (newType & MEM_Real)==0 ){ if( (newType & MEM_Null) || oc>=OP_SeekGE ){ VdbeBranchTaken(1,2); @@ -4284,7 +4285,8 @@ case OP_SeekGT: { /* jump, in3, group */ if( rc!=SQLITE_OK ) goto abort_due_to_error; goto seek_not_found; } - }else + } + c = sqlite3IntFloatCompare(iKey, pIn3->u.r); /* If the approximation iKey is larger than the actual real search ** term, substitute >= for > and < for <=. e.g. if the search term @@ -4293,7 +4295,7 @@ case OP_SeekGT: { /* jump, in3, group */ ** (x > 4.9) -> (x >= 5) ** (x <= 4.9) -> (x < 5) */ - if( pIn3->u.r<(double)iKey ){ + if( c>0 ){ assert( OP_SeekGE==(OP_SeekGT-1) ); assert( OP_SeekLT==(OP_SeekLE-1) ); assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) ); @@ -4302,7 +4304,7 @@ case OP_SeekGT: { /* jump, in3, group */ /* If the approximation iKey is smaller than the actual real search ** term, substitute <= for < and > for >=. */ - else if( pIn3->u.r>(double)iKey ){ + else if( c<0 ){ assert( OP_SeekLE==(OP_SeekLT+1) ); assert( OP_SeekGT==(OP_SeekGE+1) ); assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) ); diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 4a41c43a52..763c4ed094 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -533,6 +533,7 @@ int sqlite3VdbeMemIsRowSet(const Mem*); int sqlite3VdbeMemSetRowSet(Mem*); int sqlite3VdbeMemMakeWriteable(Mem*); int sqlite3VdbeMemStringify(Mem*, u8, u8); +int sqlite3IntFloatCompare(i64,double); i64 sqlite3VdbeIntValue(Mem*); int sqlite3VdbeMemIntegerify(Mem*); double sqlite3VdbeRealValue(Mem*); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 7f08b5d25b..5c9ab11c7d 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -4285,7 +4285,7 @@ SQLITE_NOINLINE int sqlite3BlobCompare(const Mem *pB1, const Mem *pB2){ ** number. Return negative, zero, or positive if the first (i64) is less than, ** equal to, or greater than the second (double). */ -static int sqlite3IntFloatCompare(i64 i, double r){ +int sqlite3IntFloatCompare(i64 i, double r){ if( sizeof(LONGDOUBLE_TYPE)>8 ){ LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i; testcase( x=0 AND '-1'<=t1.c0 FROM t1; } {1} +# 2021-07-19 https://sqlite.org/forum/forumpost/2bdb86a068 +# Lose of precision when doing comparisons between integer and +# floating point values that are near 9223372036854775807 in the +# OP_SeekGE opcode (and similar). +# +reset_db +do_execsql_test where-27.1 { + CREATE TABLE t1(a INTEGER PRIMARY KEY); + INSERT INTO t1(a) VALUES(9223372036854775807); + SELECT 1 FROM t1 WHERE a>=(9223372036854775807+1); +} {} +do_execsql_test where-27.2 { + SELECT a>=9223372036854775807+1 FROM t1; +} {0} + finish_test