From: drh Date: Wed, 8 Jan 2020 04:36:01 +0000 (+0000) Subject: Simplification of the logic in the constant-propagation optimization. X-Git-Tag: version-3.31.0~52 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f8f76d672b78b77e7d79ebaf0e9ab55c8bb0b14d;p=thirdparty%2Fsqlite.git Simplification of the logic in the constant-propagation optimization. FossilOrigin-Name: 1c3e5c20a9e6f501befa2bf6241a1b5190872bd83b765dac67065d252d04ea4f --- diff --git a/manifest b/manifest index a1540b419e..8491b1b6cb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sconstant\spropagation\soptimization\sso\sthat\sit\sdoes\snot\stry\sto\npropagate\sconstant\sexpressions\sthat\shave\saffinity.\s\sTicket\s[82ac75ba0093e5dc] -D 2020-01-08T01:43:47.581 +C Simplification\sof\sthe\slogic\sin\sthe\sconstant-propagation\soptimization. +D 2020-01-08T04:36:01.255 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -528,7 +528,7 @@ F src/printf.c 9be6945837c839ba57837b4bc3af349eba630920fa5532aa518816defe42a7d4 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 31dc20837034491e5a043f411425a507b306ceedf40d666af5fc87b13020ff3d F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93 -F src/select.c 63ef2d193f343def2209d5f40446050de5830b22e4a828e4fc4651e943635c28 +F src/select.c de96e8a24dd273c472a9b4d89ba06014e81a218533a8b82fb8bbe2b3a94f6824 F src/shell.c.in 90b002bf0054399cbbfac62dd752a9b05770427ba141bcba75eefbb0098f4280 F src/sqlite.h.in 51f69c62ba3e980aca1e39badcaf9ad13f008774fe1bb8e7f57e3e456c656670 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -1853,7 +1853,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ee0bc7ede0fbf3e54bb934c0d580c62d7393c984cbc374ece6d57fe9211dac26 -R ea4155636112b44bcb6c0bf5fe64c996 +P 6db1c3498f6bfa01bb460e62b802b63ec4bf43577a17a94e1e2fa0ecc1e64960 +R 908e9b415e0afc1e46568c64091702de U drh -Z 66f314899ba361254dfbe9f436764edb +Z 5f7619ce8d00e18add0895da7f50a1e5 diff --git a/manifest.uuid b/manifest.uuid index 501a8795f4..c57f94365b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6db1c3498f6bfa01bb460e62b802b63ec4bf43577a17a94e1e2fa0ecc1e64960 \ No newline at end of file +1c3e5c20a9e6f501befa2bf6241a1b5190872bd83b765dac67065d252d04ea4f \ No newline at end of file diff --git a/src/select.c b/src/select.c index 4826d65f45..2ec131b3ad 100644 --- a/src/select.c +++ b/src/select.c @@ -4146,15 +4146,28 @@ struct WhereConst { /* ** Add a new entry to the pConst object. Except, do not add duplicate -** pColumn entires. +** pColumn entires. Also, do not add if doing so would not be appropriate. +** +** The caller guarantees the pColumn is a column and pValue is a constant. +** This routine has to do some additional checks before completing the +** insert. */ static void constInsert( - WhereConst *pConst, /* The WhereConst into which we are inserting */ - Expr *pColumn, /* The COLUMN part of the constraint */ - Expr *pValue /* The VALUE part of the constraint */ + WhereConst *pConst, /* The WhereConst into which we are inserting */ + Expr *pColumn, /* The COLUMN part of the constraint */ + Expr *pValue, /* The VALUE part of the constraint */ + Expr *pExpr /* Overall expression: COLUMN=VALUE or VALUE=COLUMN */ ){ int i; assert( pColumn->op==TK_COLUMN ); + assert( sqlite3ExprIsConstant(pValue) ); + + if( !ExprHasProperty(pValue, EP_FixedCol) && sqlite3ExprAffinity(pValue)!=0 ){ + return; + } + if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) ){ + return; + } /* 2018-10-25 ticket [cf5ed20f] ** Make sure the same pColumn is not inserted more than once */ @@ -4174,7 +4187,9 @@ static void constInsert( if( pConst->apExpr==0 ){ pConst->nConst = 0; }else{ - if( ExprHasProperty(pValue, EP_FixedCol) ) pValue = pValue->pLeft; + if( ExprHasProperty(pValue, EP_FixedCol) ){ + pValue = pValue->pLeft; + } pConst->apExpr[pConst->nConst*2-2] = pColumn; pConst->apExpr[pConst->nConst*2-1] = pValue; } @@ -4200,21 +4215,11 @@ static void findConstInWhere(WhereConst *pConst, Expr *pExpr){ pLeft = pExpr->pLeft; assert( pRight!=0 ); assert( pLeft!=0 ); - if( pRight->op==TK_COLUMN - && !ExprHasProperty(pRight, EP_FixedCol) - && sqlite3ExprIsConstant(pLeft) - && sqlite3ExprAffinity(pLeft)==0 - && sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) - ){ - constInsert(pConst, pRight, pLeft); - }else - if( pLeft->op==TK_COLUMN - && !ExprHasProperty(pLeft, EP_FixedCol) - && sqlite3ExprIsConstant(pRight) - && sqlite3ExprAffinity(pRight)==0 - && sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) - ){ - constInsert(pConst, pLeft, pRight); + if( pRight->op==TK_COLUMN && sqlite3ExprIsConstant(pLeft) ){ + constInsert(pConst,pRight,pLeft,pExpr); + } + if( pLeft->op==TK_COLUMN && sqlite3ExprIsConstant(pRight) ){ + constInsert(pConst,pLeft,pRight,pExpr); } }