aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2025-07-01 15:13:37 +0000
committerdrh <>2025-07-01 15:13:37 +0000
commite1910ed1d293616aa72e8252e4f7d0242fba1e1f (patch)
treec5bd0ff88501e43f1cbcd8a4f45e74bcd981b765 /src
parent3d21dcc924fb1049c7e0cbc42a21ebfe17d472b6 (diff)
parentd82c6a2cf7394354ed1a17ad26d42b02766bb0d2 (diff)
downloadsqlite-e1910ed1d293616aa72e8252e4f7d0242fba1e1f.tar.gz
sqlite-e1910ed1d293616aa72e8252e4f7d0242fba1e1f.zip
Merge trunk fixes into the empty-table-optimizations branch.
FossilOrigin-Name: 63306e447efb3ac17e789a331ed3bb65459eb8b79d66e9c185ba3bd852f34ce3
Diffstat (limited to 'src')
-rw-r--r--src/expr.c2
-rw-r--r--src/parse.y19
2 files changed, 15 insertions, 6 deletions
diff --git a/src/expr.c b/src/expr.c
index 6cb9c2aa1..9ed0a121e 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -1144,7 +1144,7 @@ Expr *sqlite3ExprAnd(Parse *pParse, Expr *pLeft, Expr *pRight){
return pLeft;
}else{
u32 f = pLeft->flags | pRight->flags;
- if( (f&(EP_OuterON|EP_InnerON|EP_IsFalse))==EP_IsFalse
+ if( (f&(EP_OuterON|EP_InnerON|EP_IsFalse|EP_HasFunc))==EP_IsFalse
&& !IN_RENAME_OBJECT
){
sqlite3ExprDeferredDelete(pParse, pLeft);
diff --git a/src/parse.y b/src/parse.y
index a5691cad4..617eb7303 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -1429,12 +1429,21 @@ expr(A) ::= expr(A) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
** expr1 IN ()
** expr1 NOT IN ()
**
- ** simplify to constants 0 (false) and 1 (true), respectively,
- ** regardless of the value of expr1.
+ ** simplify to constants 0 (false) and 1 (true), respectively.
+ **
+ ** Except, do not apply this optimization if expr1 contains a function
+ ** because that function might be an aggregate (we don't know yet whether
+ ** it is or not) and if it is an aggregate, that could change the meaning
+ ** of the whole query.
*/
- sqlite3ExprUnmapAndDelete(pParse, A);
- A = sqlite3Expr(pParse->db, TK_STRING, N ? "true" : "false");
- if( A ) sqlite3ExprIdToTrueFalse(A);
+ Expr *pB = sqlite3Expr(pParse->db, TK_STRING, N ? "true" : "false");
+ if( pB ) sqlite3ExprIdToTrueFalse(pB);
+ if( !ExprHasProperty(A, EP_HasFunc) ){
+ sqlite3ExprUnmapAndDelete(pParse, A);
+ A = pB;
+ }else{
+ A = sqlite3PExpr(pParse, N ? TK_OR : TK_AND, pB, A);
+ }
}else{
Expr *pRHS = Y->a[0].pExpr;
if( Y->nExpr==1 && sqlite3ExprIsConstant(pParse,pRHS) && A->op!=TK_VECTOR ){