diff options
author | drh <drh@noemail.net> | 2013-11-21 14:33:48 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2013-11-21 14:33:48 +0000 |
commit | b1fba2868b7e1c1932fe7985658ca409e8bbd6da (patch) | |
tree | 29990af239aec83f676ef1142896e7a0b3b17dab /src/expr.c | |
parent | e09f43f8b78369852773661c52df015b21ef3932 (diff) | |
download | sqlite-b1fba2868b7e1c1932fe7985658ca409e8bbd6da.tar.gz sqlite-b1fba2868b7e1c1932fe7985658ca409e8bbd6da.zip |
Add the ability to factor constant functions out of inner loops. But do
not factor out non-constant functions, like random().
FossilOrigin-Name: 1b0f779e19a5c0d51eddd2d88db50034d77d132c
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/expr.c b/src/expr.c index ce541ed8a..f0a419040 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1191,9 +1191,12 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ switch( pExpr->op ){ /* Consider functions to be constant if all their arguments are constant - ** and pWalker->u.i==2 */ + ** and either pWalker->u.i==2 or the function as the SQLITE_FUNC_CONST + ** flag. */ case TK_FUNCTION: - if( pWalker->u.i==2 ) return WRC_Continue; + if( pWalker->u.i==2 || ExprHasProperty(pExpr,EP_Constant) ){ + return WRC_Continue; + } /* Fall through */ case TK_ID: case TK_COLUMN: @@ -2697,9 +2700,9 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){ if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){ assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG ); assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG ); - testcase( (pDef->funcFlags&~SQLITE_FUNC_ENCMASK) - ==SQLITE_FUNC_LENGTH ); - pFarg->a[0].pExpr->op2 = pDef->funcFlags&~SQLITE_FUNC_ENCMASK; + testcase( pDef->funcFlags & OPFLAG_LENGTHARG ); + pFarg->a[0].pExpr->op2 = + pDef->funcFlags & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG); } } |