aboutsummaryrefslogtreecommitdiff
path: root/src/select.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2020-01-08 04:36:01 +0000
committerdrh <drh@noemail.net>2020-01-08 04:36:01 +0000
commitf8f76d672b78b77e7d79ebaf0e9ab55c8bb0b14d (patch)
tree83df440e7bb1c3fbfd4bb9707c2bdb43c6b07873 /src/select.c
parentc9301e6e7c03d876be80b415783f99cf50f83ec8 (diff)
downloadsqlite-f8f76d672b78b77e7d79ebaf0e9ab55c8bb0b14d.tar.gz
sqlite-f8f76d672b78b77e7d79ebaf0e9ab55c8bb0b14d.zip
Simplification of the logic in the constant-propagation optimization.
FossilOrigin-Name: 1c3e5c20a9e6f501befa2bf6241a1b5190872bd83b765dac67065d252d04ea4f
Diffstat (limited to 'src/select.c')
-rw-r--r--src/select.c45
1 files changed, 25 insertions, 20 deletions
diff --git a/src/select.c b/src/select.c
index 4826d65f4..2ec131b3a 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);
}
}