From: drh <> Date: Sat, 16 Mar 2024 17:04:08 +0000 (+0000) Subject: Extend the scope expr-is-constant for function to cover the IN-to-EQ X-Git-Tag: version-3.46.0~123^2~10^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bf4105d76851ba3fb4ad56190284f9ebc6decfd8;p=thirdparty%2Fsqlite.git Extend the scope expr-is-constant for function to cover the IN-to-EQ optimization. FossilOrigin-Name: dae669245c86021bcd28716aff6e316257cc8075d02081745d4b7de17f8ad553 --- diff --git a/manifest b/manifest index 521628dfe1..bbfca938b7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sexprNodeIsConstantFunction()\sso\sthat\sit\sreturns\sWRC_Continue,\snot\sWRC_Abort,\sif\sthe\sfunction\sreally\sis\sconstant. -D 2024-03-16T14:27:10.517 +C Extend\sthe\sscope\sexpr-is-constant\sfor\sfunction\sto\scover\sthe\sIN-to-EQ\noptimization. +D 2024-03-16T17:04:08.435 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -739,7 +739,7 @@ F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a -F src/parse.y 004faaa6b6d6a88d9ec5e535281d7a203e1a03e83617ef8249f40e18bda23dc4 +F src/parse.y 5bcef16094213efcc365a9d4dc4e3131f09251dc8838dce4a9e5f9764bff5b82 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 @@ -760,7 +760,7 @@ F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 F src/tclsqlite.c ecbc3c99c0d0c3ed122a913f143026c26d38d57f33e06bb71185dd5c1efe37cd -F src/test1.c 310f43eb17a9252a7790726ca652e4ea3197da17c19eec93b8578863a49dc7b4 +F src/test1.c 5a67577fa7d93a19a72aa165b7013606a35e53f62d0de11587940aed5797d92d F src/test2.c 54520d0565ef2b9bf0f8f1dcac43dc4d06baf4ffe13d10905f8d8c3ad3e4b9ab F src/test3.c e5178558c41ff53236ae0271e9acb3d6885a94981d2eb939536ee6474598840e F src/test4.c 4533b76419e7feb41b40582554663ed3cd77aaa54e135cf76b3205098cd6e664 @@ -1271,7 +1271,7 @@ F test/imposter1.test c3f1db2d3db2c24611a6596a3fc0ffc14f1466c8 F test/in.test d1cad4ededd425568b2e39fb0c31fa9a3772311dd595801ff13ba3912b69bba6 F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75 F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 -F test/in4.test fdd1d8134da8376985c2edba6035a2de1f6c731524d2ffa651419e8fe2cd1c5a +F test/in4.test 176719161ba96c9386027891602700738aadac3419964f72b628f59d2071d53d F test/in5.test b32ce7f4a93f44c5dee94af16886d922cc16ebe33c8e1765c73d4049d0f4b40f F test/in6.test f5f40d6816a8bb7c784424b58a10ac38efb76ab29127a2c17399e0cbeeda0e4b F test/incrblob.test c9b96afc292aeff43d6687bcb09b0280aa599822 @@ -2179,8 +2179,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c9e0488c6c0135932b6e76b0f3f3acd69ef65327e0a54daa59777f35da1aef26 -R 073539ebd1c8b85d1f5a19f0731cb417 -U dan -Z afcb8a3f36080c6ea414186a5d7c11c8 +P d85dd4de2d0989127e0ae6a2eec9d83a577777f8d5ba40700084a0b498016634 +R ca429b76372fd82d8194dbd47566db28 +U drh +Z 9b82b5806afe1db311bd1eb3f3eb021c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 35e0b4aa0d..23dbdeae40 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d85dd4de2d0989127e0ae6a2eec9d83a577777f8d5ba40700084a0b498016634 \ No newline at end of file +dae669245c86021bcd28716aff6e316257cc8075d02081745d4b7de17f8ad553 \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index 78404ce673..d22c8e6fc2 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1325,7 +1325,7 @@ expr(A) ::= expr(A) between_op(N) expr(X) AND expr(Y). [BETWEEN] { if( A ) sqlite3ExprIdToTrueFalse(A); }else{ Expr *pRHS = Y->a[0].pExpr; - if( Y->nExpr==1 && sqlite3ExprIsConstant(0,pRHS) && A->op!=TK_VECTOR ){ + if( Y->nExpr==1 && sqlite3ExprIsConstant(pParse,pRHS) && A->op!=TK_VECTOR ){ Y->a[0].pExpr = 0; sqlite3ExprListDelete(pParse->db, Y); pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0); diff --git a/src/test1.c b/src/test1.c index 8faf5a397b..a552c3f509 100644 --- a/src/test1.c +++ b/src/test1.c @@ -1024,6 +1024,23 @@ static void addRealTypeFunction( sqlite3_result_value(context, argv[0]); } +/* +** Implementation of the noop(X) SQL function. +** +** The result is just a copy of its argument. However, this function +** does not have the SQLITE_FUNC_CONSTANT flag, so it is consider +** non-constant by sqlite3ExprIsConstant(). +*/ +static void noopFunction( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + (void)argc; + sqlite3_result_value(context, argv[0]); +} + + /* ** SQL function: strtod(X) ** @@ -1151,6 +1168,10 @@ static int SQLITE_TCLAPI test_create_function( rc = sqlite3_create_function(db, "add_real_type", 1, SQLITE_UTF8, 0, addRealTypeFunction, 0, 0); } + if( rc==SQLITE_OK ){ + rc = sqlite3_create_function(db, "noop", 1, SQLITE_UTF8, + 0, noopFunction, 0, 0); + } /* Functions strtod() and dtostr() work as in the shell. These routines ** use the standard C library to convert between floating point and diff --git a/test/in4.test b/test/in4.test index a3fe22e787..81f2b2840d 100644 --- a/test/in4.test +++ b/test/in4.test @@ -455,17 +455,18 @@ do_execsql_test 11.0 { INSERT INTO sqlite_stat1 VALUES('t1','t1abc','10000 5 00 2003 10'); ANALYZE sqlite_schema; } {} +sqlite3_create_function db do_execsql_test 11.1 { SELECT * FROM t1 WHERE b IN (345, (SELECT 1 FROM t1 - WHERE b IN (345 NOT GLOB 510) + WHERE b IN (noop(1)) AND c GLOB 'abc*xyz')) AND c BETWEEN 'abc' AND 'xyz'; } {xyz 1 abcdefxyz 99} do_execsql_test 11.2 { EXPLAIN SELECT * FROM t1 WHERE b IN (345, (SELECT 1 FROM t1 - WHERE b IN (345 NOT GLOB 510) + WHERE b IN (noop(1)) AND c GLOB 'abc*xyz')) AND c BETWEEN 'abc' AND 'xyz'; } {/ SeekScan /}