From: drh Date: Mon, 5 Aug 2013 15:32:09 +0000 (+0000) Subject: Improve performance of sqlite3VdbeRecordCompare() by using an approximation X-Git-Tag: version-3.8.0~51 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=af5b2af77db148fb390a9423b70229e721c0d1ba;p=thirdparty%2Fsqlite.git Improve performance of sqlite3VdbeRecordCompare() by using an approximation that might give false negatives and only running the more expensive exact subexpression if the approximation fails. FossilOrigin-Name: 28979dcd16f53e0ddca8eed74b668834e2856f03 --- diff --git a/manifest b/manifest index b354557f64..14fc750b6f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\smissing\s'#include\s"tcl.h"'\sto\stest_rtree.c. -D 2013-08-05T12:31:41.375 +C Improve\sperformance\sof\ssqlite3VdbeRecordCompare()\sby\susing\san\sapproximation\nthat\smight\sgive\sfalse\snegatives\sand\sonly\srunning\sthe\smore\sexpensive\sexact\s\nsubexpression\sif\sthe\sapproximation\sfails. +D 2013-08-05T15:32:09.754 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -281,7 +281,7 @@ F src/vdbe.c d6048a720c197db2f0e7d618e918bd2e2eff0322 F src/vdbe.h 4f554b5627f26710c4c36d919110a3fc611ca5c4 F src/vdbeInt.h e9b7c6b165a31a4715c5aa97223d20d265515231 F src/vdbeapi.c 4d13580bd058b39623e8fcfc233b7df4b8191e8b -F src/vdbeaux.c 4389b3692969b4415fcfd00de36818a02f84df28 +F src/vdbeaux.c 1a149d406d812b767d70c932dfc472d586d04c45 F src/vdbeblob.c 5dc79627775bd9a9b494dd956e26297946417d69 F src/vdbemem.c 833005f1cbbf447289f1973dba2a0c2228c7b8ab F src/vdbesort.c 3937e06b2a0e354500e17dc206ef4c35770a5017 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 213020769f310aec1591d97756b53891d0b64005 -R 0448e5af5431e1ece697200cba67ff6c +P 4b8b426f10f8ae13bf553f7adf5ae09383fa0bd4 +R 338de61a71c3cd74b79152f7e9194e12 U drh -Z ddf1308995835ea195d91d2476e0f474 +Z 467c61e8c494116a000cdb09272cb823 diff --git a/manifest.uuid b/manifest.uuid index 2ba9bc5a79..caf82026b2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4b8b426f10f8ae13bf553f7adf5ae09383fa0bd4 \ No newline at end of file +28979dcd16f53e0ddca8eed74b668834e2856f03 \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 880a6299ca..de2de6a7f8 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -3023,7 +3023,18 @@ int sqlite3VdbeRecordCompare( /* Read the serial types for the next element in each key. */ idx1 += getVarint32( aKey1+idx1, serial_type1 ); - if( d1+sqlite3VdbeSerialTypeLen(serial_type1)>(u32)nKey1 ) break; + + /* Verify that there is enough key space remaining to avoid + ** a buffer overread. The "d1+serial_type1+2" subexpression will + ** always be greater than or equal to the amount of required key space. + ** Use that approximation to avoid the more expensive call to + ** sqlite3VdbeSerialTypeLen() in the common case. + */ + if( d1+serial_type1+2>(u32)nKey1 + && d1+sqlite3VdbeSerialTypeLen(serial_type1)>(u32)nKey1 + ){ + break; + } /* Extract the values to be compared. */