diff options
author | drh <> | 2025-07-03 20:51:08 +0000 |
---|---|---|
committer | drh <> | 2025-07-03 20:51:08 +0000 |
commit | 1e3a862b79ebf4314f0d61674f9382913a653a68 (patch) | |
tree | 1ac97af24485a54e91e8537a6138f861c6eb0f2c /src/expr.c | |
parent | debc8f7bb7b62fb865251e140510d853b138b88b (diff) | |
parent | bd05edd98f44e3430a8ecfecfdead510897e7582 (diff) | |
download | sqlite-1e3a862b79ebf4314f0d61674f9382913a653a68.tar.gz sqlite-1e3a862b79ebf4314f0d61674f9382913a653a68.zip |
Merge the latest trunk fixes and enhancements into the empty-table-optimizations branch
FossilOrigin-Name: d4f47e04f5880e99a53089e2dd5cde64a7ea44f059d9906b5d11324896546714
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/expr.c b/src/expr.c index c8dfd3af3..ebac654a2 100644 --- a/src/expr.c +++ b/src/expr.c @@ -3896,17 +3896,23 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){ VdbeComment((v, "Init EXISTS result")); } if( pSel->pLimit ){ - /* The subquery already has a limit. If the pre-existing limit is X - ** then make the new limit X<>0 so that the new limit is either 1 or 0 */ - sqlite3 *db = pParse->db; - pLimit = sqlite3Expr(db, TK_INTEGER, "0"); - if( pLimit ){ - pLimit->affExpr = SQLITE_AFF_NUMERIC; - pLimit = sqlite3PExpr(pParse, TK_NE, - sqlite3ExprDup(db, pSel->pLimit->pLeft, 0), pLimit); - } - sqlite3ExprDeferredDelete(pParse, pSel->pLimit->pLeft); - pSel->pLimit->pLeft = pLimit; + /* The subquery already has a limit. If the pre-existing limit X is + ** not already integer value 1 or 0, then make the new limit X<>0 so that + ** the new limit is either 1 or 0 */ + Expr *pLeft = pSel->pLimit->pLeft; + if( ExprHasProperty(pLeft, EP_IntValue)==0 + || (pLeft->u.iValue!=1 && pLeft->u.iValue!=0) + ){ + sqlite3 *db = pParse->db; + pLimit = sqlite3Expr(db, TK_INTEGER, "0"); + if( pLimit ){ + pLimit->affExpr = SQLITE_AFF_NUMERIC; + pLimit = sqlite3PExpr(pParse, TK_NE, + sqlite3ExprDup(db, pLeft, 0), pLimit); + } + sqlite3ExprDeferredDelete(pParse, pLeft); + pSel->pLimit->pLeft = pLimit; + } }else{ /* If there is no pre-existing limit add a limit of 1 */ pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1"); |