From: drh Date: Wed, 28 Jun 2017 21:47:16 +0000 (+0000) Subject: Alternative implementation of exprCompareVariable(). Need to run tests on X-Git-Tag: version-3.20.0~167^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c080422642c7b32873cd16aedfd4d356b75e5350;p=thirdparty%2Fsqlite.git Alternative implementation of exprCompareVariable(). Need to run tests on both this branch and the original to see which one to go with. FossilOrigin-Name: b959c6297c151150ea2dca24aa1f68f3bd76dd6620eb6c03f8dfa59fdd5c13b2 --- diff --git a/manifest b/manifest index c71f873790..9c0d6e0773 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sthe\squery\splanners\suse\sof\spartial\sindexes\sbased\son\sbound\svariables\nresponsive\sto\sthe\sSQLITE_DBCONFIG_ENABLE_QPSG\ssetting. -D 2017-06-28T18:25:03.706 +C Alternative\simplementation\sof\sexprCompareVariable().\s\sNeed\sto\srun\stests\son\nboth\sthis\sbranch\sand\sthe\soriginal\sto\ssee\swhich\sone\sto\sgo\swith. +D 2017-06-28T21:47:16.657 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 8eeb80162074004e906b53d7340a12a14c471a83743aab975947e95ce061efcc @@ -359,7 +359,7 @@ F src/ctime.c e9a6db1321c2353fe922533f202b85abb3084cdf569450abcabf55e21e104550 F src/date.c cc42a41c7422389860d40419a5e3bce5eaf6e7835c3ba2677751dc653550a5c7 F src/dbstat.c 19ee7a4e89979d4df8e44cfac7a8f905ec89b77d F src/delete.c 3213547e97b676c6fa79948b7a9ede4801ea04a01a2043241deafedf132ecf5d -F src/expr.c 9aea9dbac1169c5cda3ee5d288b9e6c25de597a38023f8104406e0312145ca8d +F src/expr.c 8281b9e5b88862176862c614acda20fdeb85c20143c5125cee4efd2893c1a64e F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 5ff2c895fe087756d8085dc1a9bc229b5670e2a65c3929dd87c71e43649af333 F src/func.c 9d52522cc8ae7f5cdadfe14594262f1618bc1f86083c4cd6da861b4cf5af6174 @@ -1585,7 +1585,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 8f63c5863231eba7f853f9587b58a81102c31708402fa9962a6e91aa622fad13 -R c0bca5815e0b14a60d8900b0ad5f06a7 +P a934dd14ac55177ac541423f4a077484bb3b461b60c9c2e88d067cca922fa2bc +R d8af740d34bab1193c95ada6cd028712 +T *branch * partial-index-variables-v2 +T *sym-partial-index-variables-v2 * +T -sym-partial-index-variables * U drh -Z afcf7a655c64b8f5d4a7cb72e9e49496 +Z 929717708efb4b9fc1714d496de51de5 diff --git a/manifest.uuid b/manifest.uuid index 59255b606a..e1a8d56d9b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a934dd14ac55177ac541423f4a077484bb3b461b60c9c2e88d067cca922fa2bc \ No newline at end of file +b959c6297c151150ea2dca24aa1f68f3bd76dd6620eb6c03f8dfa59fdd5c13b2 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 89a4adddb8..0443195640 100644 --- a/src/expr.c +++ b/src/expr.c @@ -4675,29 +4675,19 @@ void sqlite3ExprIfFalseDup(Parse *pParse, Expr *pExpr, int dest,int jumpIfNull){ */ static int exprCompareVariable(Parse *pParse, Expr *pVar, Expr *pExpr){ int res = 0; - int iVar = pVar->iColumn; - Expr *p = pExpr; - - while( p->op==TK_UMINUS ) p = p->pLeft; - if( p->op==TK_NULL || p->op==TK_INTEGER - || p->op==TK_FLOAT || p->op==TK_STRING - || p->op==TK_BLOB - ){ + int iVar; + sqlite3_value *pL, *pR = 0; + + sqlite3ValueFromExpr(pParse->db, pExpr, SQLITE_UTF8, SQLITE_AFF_BLOB, &pR); + if( pR ){ + iVar = pVar->iColumn; sqlite3VdbeSetVarmask(pParse->pVdbe, iVar); - sqlite3_value *pL; pL = sqlite3VdbeGetBoundValue(pParse->pReprepare, iVar, SQLITE_AFF_BLOB); - if( pL ){ - sqlite3_value *pR = 0; - sqlite3ValueFromExpr(pParse->db, pExpr, SQLITE_UTF8, SQLITE_AFF_BLOB,&pR); - assert( pR || pParse->db->mallocFailed ); - if( pR && 0==sqlite3MemCompare(pL, pR, 0) ){ - res = 1; - } - sqlite3ValueFree(pR); - sqlite3ValueFree(pL); - }else if( p->op==TK_NULL ){ + if( pL && 0==sqlite3MemCompare(pL, pR, 0) ){ res = 1; } + sqlite3ValueFree(pR); + sqlite3ValueFree(pL); } return res; @@ -4725,11 +4715,12 @@ static int exprCompareVariable(Parse *pParse, Expr *pVar, Expr *pExpr){ ** just might result in some slightly slower code. But returning ** an incorrect 0 or 1 could lead to a malfunction. ** -** Argument pParse should normally be NULL. If it is not NULL and -** expression pA contains SQL variable references, then the values -** currently bound to those variable references may be compared to -** simple SQL values in pB. See comments above function exprCompareVariable() -** for details. +** If pParse is not NULL then TK_VARIABLE terms in pA with bindings in +** pParse->pReprepare can be matched against literals in pB. The +** pParse->pVdbe->expmask bitmask is updated for each variable referenced. +** If pParse is NULL (the normal case) then any TK_VARIABLE term in +** Argument pParse should normally be NULL. If it is not NULL and pA or +** pB causes a return value of 2. */ int sqlite3ExprCompare(Parse *pParse, Expr *pA, Expr *pB, int iTab){ u32 combinedFlags; @@ -4833,6 +4824,11 @@ int sqlite3ExprCompareSkip(Expr *pA, Expr *pB, int iTab){ ** When comparing TK_COLUMN nodes between pE1 and pE2, if pE2 has ** Expr.iTable<0 then assume a table number given by iTab. ** +** If pParse is not NULL, then the values of bound variables in pE1 are +** compared against literal values in pE2 and pParse->pVdbe->expmask is +** modified to record which bound variables are referenced. If pParse +** is NULL, then false will be returned if pE1 contains any bound variables. +** ** When in doubt, return false. Returning true might give a performance ** improvement. Returning false might cause a performance reduction, but ** it will always give the correct answer and is hence always safe.