From: drh <> Date: Sun, 9 Feb 2025 20:23:29 +0000 (+0000) Subject: Performance optimization to the substr() SQL function. X-Git-Tag: major-release~309 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3efac4aa782fa58857de1018152305e3d7a7c3eb;p=thirdparty%2Fsqlite.git Performance optimization to the substr() SQL function. FossilOrigin-Name: ce228ce3d0132ad758b5b7464fcf22ae5976df3c02ec948280cc76290c79ed0b --- diff --git a/manifest b/manifest index 4b5d165af9..98df1c108a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Performance\sand\ssize\soptimization\sfor\sthe\ssqlite3ColumnIndex()\sroutine. -D 2025-02-09T19:49:46.297 +C Performance\soptimization\sto\sthe\ssubstr()\sSQL\sfunction. +D 2025-02-09T20:23:29.902 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md e108e1e69ae8e8a59e93c455654b8ac9356a11720d3345df2a4743e9590fb20d @@ -733,7 +733,7 @@ F src/delete.c 03a77ba20e54f0f42ebd8eddf15411ed6bdb06a2c472ac4b6b336521bf7cea42 F src/expr.c 15fabfb67261e298a39fe61457f3cfa24148d9ca8d02f4dff385feb5cf523ea7 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 928ed2517e8732113d2b9821aa37af639688d752f4ea9ac6e0e393d713eeb76f -F src/func.c 0712a5b03fdfc8af0cda6d076bfe231b66388d3d5a28b46dc1a94b90d41cac6a +F src/func.c b2fb33139972d7d65640b27ea962a49f1616265428001090cab39fcf270228e1 F src/global.c a19e4b1ca1335f560e9560e590fc13081e21f670643367f99cb9e8f9dc7d615b F src/hash.c 73934a7f7ab1cb110614a9388cb516893b0cf5b7b69e4fd1a0780ac4ce166be7 F src/hash.h 46b92795a95bfefb210f52f0c316e9d7cdbcdd7e7fcfb0d8be796d3a5767cddf @@ -2209,8 +2209,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P f3a35fdc9113ad5f1fed6a2f474aee670e1793d355475a7971d376bf33823cc4 -R 07cb4b330390fc770f5d5e73fded3930 +P a93e3fe0ee8f98a7ec0dfb2e1abf432cc9d5f9d3ad345b5db261475215d43df9 +R 6458c5e9c4d2d7940a949acd5df2c6a3 U drh -Z 8439106cb5dd02e83a92bb726a395093 +Z 384512ae3dd3c9dcc3fa9d0daadac731 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index bd2f91ec8d..468eacb582 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a93e3fe0ee8f98a7ec0dfb2e1abf432cc9d5f9d3ad345b5db261475215d43df9 +ce228ce3d0132ad758b5b7464fcf22ae5976df3c02ec948280cc76290c79ed0b diff --git a/src/func.c b/src/func.c index e8cd174e42..52462b4682 100644 --- a/src/func.c +++ b/src/func.c @@ -356,11 +356,6 @@ static void substrFunc( i64 p1, p2; assert( argc==3 || argc==2 ); - if( sqlite3_value_type(argv[1])==SQLITE_NULL - || (argc==3 && sqlite3_value_type(argv[2])==SQLITE_NULL) - ){ - return; - } p0type = sqlite3_value_type(argv[0]); p1 = sqlite3_value_int64(argv[1]); if( p0type==SQLITE_BLOB ){ @@ -378,19 +373,23 @@ static void substrFunc( } } } -#ifdef SQLITE_SUBSTR_COMPATIBILITY - /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as - ** as substr(X,1,N) - it returns the first N characters of X. This - ** is essentially a back-out of the bug-fix in check-in [5fc125d362df4b8] - ** from 2009-02-02 for compatibility of applications that exploited the - ** old buggy behavior. */ - if( p1==0 ) p1 = 1; /* */ -#endif if( argc==3 ){ p2 = sqlite3_value_int64(argv[2]); + if( p2==0 && sqlite3_value_type(argv[2])==SQLITE_NULL ) return; }else{ p2 = sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH]; } + if( p1==0 ){ +#ifdef SQLITE_SUBSTR_COMPATIBILITY + /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as + ** as substr(X,1,N) - it returns the first N characters of X. This + ** is essentially a back-out of the bug-fix in check-in [5fc125d362df4b8] + ** from 2009-02-02 for compatibility of applications that exploited the + ** old buggy behavior. */ + p1 = 1; /* */ +#endif + if( sqlite3_value_type(argv[1])==SQLITE_NULL ) return; + } if( p1<0 ){ p1 += len; if( p1<0 ){