diff --git a/manifest b/manifest index 9ee146f83d..11b5b9c942 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C This\svariant\sto\sthe\sfix\sfor\sticket\s[e0c2ad1aa8a9c691]\suses\sfewer\sCPU\scycles. -D 2020-03-11T02:04:15.678 +C Do\snot\sfactor\sout\sconstant\sfunctions\sinto\sthe\sinitialization\ssection\sat\sthe\nend\sof\sthe\sprepared\sstatement,\sbe\scause\sif\sthey\sthrow\san\sexception,\sit\swill\nabort\sthe\sstatement\seven\sif\sthe\sfunction\sis\snever\scalled.\s\sBetter\sto\sput\nconstant\sfunctions\sin\san\sOP_Once\sblock. +D 2020-03-11T17:58:27.142 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -483,7 +483,7 @@ F src/date.c 6c408fdd2e9ddf6e8431aba76315a2d061bea2cec8fbb75e25d7c1ba08274712 F src/dbpage.c 8a01e865bf8bc6d7b1844b4314443a6436c07c3efe1d488ed89e81719047833a F src/dbstat.c 0f55297469d4244ab7df395849e1af98eb5e95816af7c661e7d2d8402dea23da F src/delete.c 11000121c4281c0bce4e41db29addfaea0038eaa127ece02557c9207bc3e541d -F src/expr.c cddb6c7ccdb856338c189c8cc15bd95dd60e596e4bb5a1c8ba86726b49857581 +F src/expr.c 137db48827025f68792824eaf8e4c66612dbd160cf5cafe6ae93b27eed101e12 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 4b575423b0a5d4898b1a7868ce985cf1a8ad91c741c9abbb108ff02536d20f41 F src/func.c 108577cebe8a50c86d849a93b99493a54e348dd0b846f00d13b52ca973d5baf4 @@ -612,7 +612,7 @@ F src/vdbeblob.c 253ed82894924c362a7fa3079551d3554cd1cdace39aa833da77d3bc67e7c1b F src/vdbemem.c 39b942ecca179f4f30a32b54579a85d74ccaefa5af2a0ad2700abe5ef0768b22 F src/vdbesort.c 2be76d26998ce2b3324cdcc9f6443728e54b6c7677c553ad909c7d7cfab587df F src/vdbetrace.c fa3bf238002f0bbbdfb66cc8afb0cea284ff9f148d6439bc1f6f2b4c3b7143f0 -F src/vtab.c 7b704a90515a239c6cdba6a66b1bb3a385e62326cceb5ecb05ec7a091d6b8515 +F src/vtab.c ad810f9b771cf66eee2762e18eb2b704c97c18ca4b4bf25af7f88ab1fb254d14 F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 697424314e40d99f93f548c7bfa526c10e87f4bdf64d5a76a96b999dd7133ebc F src/wal.h 606292549f5a7be50b6227bd685fa76e3a4affad71bb8ac5ce4cb5c79f6a176a @@ -1007,7 +1007,7 @@ F test/func.test b7f1a706d1bb8de103a24bd0c30c9e3dc3eedf0df24aabc54b0a4f6e0874262 F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f F test/func3.test 2bb0f31ab7baaed690b962a88544d7be6b34fa389364bc36a44e441ed3e3f1e6 F test/func4.test a94858a8c1f10a408b0b3db439c990b59dbb2349411d503de011ac4e2b5f27a6 -F test/func5.test cdd224400bc3e48d891827cc913a57051a426fa4 +F test/func5.test 863e6d1bd0013d09c17236f8a13ea34008dd857d87d85a13a673960e4c25d82a F test/func6.test 90e42b64c4f9fb6f04f44cb8a1da586c8542502e926b19c76504fe74ff2a9b7c F test/fuzz-oss1.test e58330d01cbbd8215ee636b17a03fe220b37dbfa F test/fuzz.test 96083052bf5765e4518c1ba686ce2bab785670d1 @@ -1860,7 +1860,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5f60b527b938c0778e8f725c635ce0dc5ed7a4e01fd6252aa2cdb64da2f625bc -R 37bce3d92e4cf86464a6bfb5a7dc2299 +P fb5a8a9edd0a4f979d6c30278d4ddc73c651f56ae989b4e5983fca36887c5ceb +R cf3e121998a086e24f73b7daa3777948 +T *branch * do-not-factor-functions +T *sym-do-not-factor-functions * +T -sym-trunk * U drh -Z 0b4099ba8ff5f2f0e887def300e748c2 +Z 4a780ea0d068b9c3f4aeae83f545f604 diff --git a/manifest.uuid b/manifest.uuid index 0b01cdc6f0..3625ef547a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fb5a8a9edd0a4f979d6c30278d4ddc73c651f56ae989b4e5983fca36887c5ceb \ No newline at end of file +97a18a5cd701848a9660385e31bffe2c397e3cfe57ccdb876f44d08c00d1d39a \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index cf52c5c754..8c0768bb7e 100644 --- a/src/expr.c +++ b/src/expr.c @@ -4532,15 +4532,29 @@ int sqlite3ExprCodeAtInit( } } } + if( regDest<0 ) regDest = ++pParse->nMem; pExpr = sqlite3ExprDup(pParse->db, pExpr, 0); - p = sqlite3ExprListAppend(pParse, p, pExpr); - if( p ){ - struct ExprList_item *pItem = &p->a[p->nExpr-1]; - pItem->reusable = regDest<0; - if( regDest<0 ) regDest = ++pParse->nMem; - pItem->u.iConstExprReg = regDest; + if( pExpr!=0 && ExprHasProperty(pExpr, EP_HasFunc) ){ + Vdbe *v = pParse->pVdbe; + int addr; + assert( v ); + addr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); + pParse->okConstFactor = 0; + if( !pParse->db->mallocFailed ){ + sqlite3ExprCode(pParse, pExpr, regDest); + } + pParse->okConstFactor = 1; + sqlite3ExprDelete(pParse->db, pExpr); + sqlite3VdbeJumpHere(v, addr); + }else{ + p = sqlite3ExprListAppend(pParse, p, pExpr); + if( p ){ + struct ExprList_item *pItem = &p->a[p->nExpr-1]; + pItem->reusable = regDest<0; + pItem->u.iConstExprReg = regDest; + } + pParse->pConstExpr = p; } - pParse->pConstExpr = p; return regDest; } diff --git a/src/vtab.c b/src/vtab.c index 013511cfb4..6a30f83a91 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -1113,7 +1113,7 @@ FuncDef *sqlite3VtabOverloadFunction( int rc = 0; /* Check to see the left operand is a column in a virtual table */ - if( NEVER(pExpr==0) ) return pDef; + if( pExpr==0 ) return pDef; if( pExpr->op!=TK_COLUMN ) return pDef; pTab = pExpr->y.pTab; if( pTab==0 ) return pDef; diff --git a/test/func5.test b/test/func5.test index bfd545b4e3..8c3dd05c60 100644 --- a/test/func5.test +++ b/test/func5.test @@ -53,9 +53,10 @@ do_execsql_test func5-2.2 { WHERE x+counter1('hello')=counter1('hello')+x ORDER BY +x; } {} +set cvalue [db one {SELECT counter2('hello')+1}] do_execsql_test func5-2.3 { SELECT x, y FROM t2 - WHERE x+counter2('hello')=counter2('hello')+x + WHERE x+counter2('hello')=$cvalue+x ORDER BY +x; } {1 2 3 4 5 6 7 8}