1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Be more aggressive in optimizing constant conditional expressions.

FossilOrigin-Name: b7e39851a75b87ebca747b26a39989560fd6362b
This commit is contained in:
drh
2014-01-02 17:57:16 +00:00
parent b00d862139
commit 991a198511
3 changed files with 41 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
C Try\sto\sdetect\sprocess\sID\schanges\sdue\sto\sfork()\scalls\sin\sos_unix.c\sand\nreset\sthe\sPRNG\swhen\sa\sprocess\sID\schange\sis\sdetected.
D 2014-01-01T15:18:36.453
C Be\smore\saggressive\sin\soptimizing\sconstant\sconditional\sexpressions.
D 2014-01-02T17:57:16.874
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -175,7 +175,7 @@ F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
F src/ctime.c 77779efbe78dd678d84bfb4fc2e87b6b6ad8dccd
F src/date.c 593c744b2623971e45affd0bde347631bdfa4625
F src/delete.c 821da82527c24496bef0677ed4f61a53b44c27ee
F src/expr.c ffe4bc79c66f711f450a6113fbd1943b9b2380f7
F src/expr.c ca0959386f01d6e5d4dc67b362a4e4c912ebd054
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
F src/fkey.c 2ab0f5384b70594468ef3ac5c7ed8ca24bfd17d5
F src/func.c 6325ac2ec10833ccf4d5c36d323709221d37ea19
@@ -1147,7 +1147,7 @@ F tool/vdbe-compress.tcl 0cf56e9263a152b84da86e75a5c0cdcdb7a47891
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
P a221aa82bb5496885fd0bf76e4601443799511de
R 0b5cbfb8643918ccfe030368af8a9f9c
P e1eba1fb09d7db49d77928bd115b27b8002ae640
R 8c33ee4ecd82143d9dd9bc5270372c1d
U drh
Z 8d0b25dd26eff92b0e8709464c57dd81
Z 948115126ed1b38f36b2ba1121c24109

View File

@@ -1 +1 @@
e1eba1fb09d7db49d77928bd115b27b8002ae640
b7e39851a75b87ebca747b26a39989560fd6362b

View File

@@ -523,16 +523,25 @@ Expr *sqlite3PExpr(
}
/*
** Return 1 if an expression must be FALSE in all cases and 0 if the
** expression might be true. This is an optimization. If is OK to
** return 0 here even if the expression really is always false (a
** false negative). But it is a bug to return 1 if the expression
** might be true in some rare circumstances (a false positive.)
** If the expression is always either TRUE or FALSE (respectively),
** then return 1. If one cannot determine the truth value of the
** expression at compile-time return 0.
**
** This is an optimization. If is OK to return 0 here even if
** the expression really is always false or false (a false negative).
** But it is a bug to return 1 if the expression might have different
** boolean values in different circumstances (a false positive.)
**
** Note that if the expression is part of conditional for a
** LEFT JOIN, then we cannot determine at compile-time whether or not
** is it true or false, so always return 0.
*/
static int exprAlwaysTrue(Expr *p){
int v = 0;
if( ExprHasProperty(p, EP_FromJoin) ) return 0;
if( !sqlite3ExprIsInteger(p, &v) ) return 0;
return v!=0;
}
static int exprAlwaysFalse(Expr *p){
int v = 0;
if( ExprHasProperty(p, EP_FromJoin) ) return 0;
@@ -3614,10 +3623,16 @@ void sqlite3ExprIfTrue(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
}
#endif
default: {
if( exprAlwaysTrue(pExpr) ){
sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
}else if( exprAlwaysFalse(pExpr) ){
/* No-op */
}else{
r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
testcase( regFree1==0 );
testcase( jumpIfNull==0 );
}
break;
}
}
@@ -3759,10 +3774,16 @@ void sqlite3ExprIfFalse(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
}
#endif
default: {
if( exprAlwaysFalse(pExpr) ){
sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
}else if( exprAlwaysTrue(pExpr) ){
/* no-op */
}else{
r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
testcase( regFree1==0 );
testcase( jumpIfNull==0 );
}
break;
}
}