diff options
author | drh <drh@noemail.net> | 2018-07-27 16:57:11 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2018-07-27 16:57:11 +0000 |
commit | efad2e23668ea5cbd744b6abde43058de45fb53a (patch) | |
tree | a9b47f95d1da7ca005ed0e772d21fcc72b0efc32 /src/expr.c | |
parent | 7de7602eb7deac00e4bb5c2f44f82f5389cbcb83 (diff) | |
download | sqlite-efad2e23668ea5cbd744b6abde43058de45fb53a.tar.gz sqlite-efad2e23668ea5cbd744b6abde43058de45fb53a.zip |
Constant propagation is now restricted to just the WHERE clause. The
mechanism is changed to take affinity and collation into account. This
seems to give correct answers. But the search for constant propagation
costs 4 million cycles in the speed test.
FossilOrigin-Name: 82c67efb723dba387964f690cd459b420e59e3367d9589016597a76531596391
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/expr.c b/src/expr.c index 6e5100a22..69270959f 100644 --- a/src/expr.c +++ b/src/expr.c @@ -329,6 +329,15 @@ CollSeq *sqlite3BinaryCompareCollSeq( } /* +** Return true if CollSeq is the default built-in BINARY. +*/ +int sqlite3IsBinary(const CollSeq *p){ + if( p==0 ) return 1; + if( sqlite3_stricmp(p->zName,"BINARY")==0 ) return 1; + return 0; +} + +/* ** Generate code for a comparison operator. */ static int codeCompare( @@ -1839,6 +1848,9 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ testcase( pExpr->op==TK_COLUMN ); testcase( pExpr->op==TK_AGG_FUNCTION ); testcase( pExpr->op==TK_AGG_COLUMN ); + if( ExprHasProperty(pExpr, EP_FixedCol) ){ + return WRC_Continue; + } if( pWalker->eCode==3 && pExpr->iTable==pWalker->u.iCur ){ return WRC_Continue; } @@ -1927,7 +1939,7 @@ static int exprNodeIsConstantOrGroupBy(Walker *pWalker, Expr *pExpr){ Expr *p = pGroupBy->a[i].pExpr; if( sqlite3ExprCompare(0, pExpr, p, -1)<2 ){ CollSeq *pColl = sqlite3ExprNNCollSeq(pWalker->pParse, p); - if( sqlite3_stricmp("BINARY", pColl->zName)==0 ){ + if( sqlite3IsBinary(pColl) ){ return WRC_Prune; } } @@ -3581,6 +3593,10 @@ expr_code_doover: } case TK_COLUMN: { int iTab = pExpr->iTable; + if( ExprHasProperty(pExpr, EP_FixedCol) ){ + pExpr = pExpr->pLeft; + goto expr_code_doover; + } if( iTab<0 ){ if( pParse->iSelfTab<0 ){ /* Generating CHECK constraints or inserting into partial index */ @@ -4935,14 +4951,15 @@ int sqlite3ExprCompare(Parse *pParse, Expr *pA, Expr *pB, int iTab){ if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2; }else if( pA->op==TK_COLLATE ){ if( sqlite3_stricmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2; - }else if( pA->op!=TK_UPLUS && strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ + }else if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ return 2; } } if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2; if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){ if( combinedFlags & EP_xIsSelect ) return 2; - if( sqlite3ExprCompare(pParse, pA->pLeft, pB->pLeft, iTab) ) return 2; + if( (combinedFlags & EP_FixedCol)==0 + && sqlite3ExprCompare(pParse, pA->pLeft, pB->pLeft, iTab) ) return 2; if( sqlite3ExprCompare(pParse, pA->pRight, pB->pRight, iTab) ) return 2; if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2; assert( (combinedFlags & EP_Reduced)==0 ); |