aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2024-03-16 17:04:08 +0000
committerdrh <>2024-03-16 17:04:08 +0000
commitbf4105d76851ba3fb4ad56190284f9ebc6decfd8 (patch)
tree3ab411da22d75c21336de0d0d1a2f584ddc58ee8 /src
parent40514dd1f661ad05b679cda3df90ed4efd0133fc (diff)
downloadsqlite-bf4105d76851ba3fb4ad56190284f9ebc6decfd8.tar.gz
sqlite-bf4105d76851ba3fb4ad56190284f9ebc6decfd8.zip
Extend the scope expr-is-constant for function to cover the IN-to-EQ
optimization. FossilOrigin-Name: dae669245c86021bcd28716aff6e316257cc8075d02081745d4b7de17f8ad553
Diffstat (limited to 'src')
-rw-r--r--src/parse.y2
-rw-r--r--src/test1.c21
2 files changed, 22 insertions, 1 deletions
diff --git a/src/parse.y b/src/parse.y
index 78404ce67..d22c8e6fc 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -1325,7 +1325,7 @@ expr(A) ::= expr(A) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
if( A ) sqlite3ExprIdToTrueFalse(A);
}else{
Expr *pRHS = Y->a[0].pExpr;
- if( Y->nExpr==1 && sqlite3ExprIsConstant(0,pRHS) && A->op!=TK_VECTOR ){
+ if( Y->nExpr==1 && sqlite3ExprIsConstant(pParse,pRHS) && A->op!=TK_VECTOR ){
Y->a[0].pExpr = 0;
sqlite3ExprListDelete(pParse->db, Y);
pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0);
diff --git a/src/test1.c b/src/test1.c
index 8faf5a397..a552c3f50 100644
--- a/src/test1.c
+++ b/src/test1.c
@@ -1025,6 +1025,23 @@ static void addRealTypeFunction(
}
/*
+** Implementation of the noop(X) SQL function.
+**
+** The result is just a copy of its argument. However, this function
+** does not have the SQLITE_FUNC_CONSTANT flag, so it is consider
+** non-constant by sqlite3ExprIsConstant().
+*/
+static void noopFunction(
+ sqlite3_context *context,
+ int argc,
+ sqlite3_value **argv
+){
+ (void)argc;
+ sqlite3_result_value(context, argv[0]);
+}
+
+
+/*
** SQL function: strtod(X)
**
** Use the C-library strtod() function to convert string X into a double.
@@ -1151,6 +1168,10 @@ static int SQLITE_TCLAPI test_create_function(
rc = sqlite3_create_function(db, "add_real_type", 1, SQLITE_UTF8,
0, addRealTypeFunction, 0, 0);
}
+ if( rc==SQLITE_OK ){
+ rc = sqlite3_create_function(db, "noop", 1, SQLITE_UTF8,
+ 0, noopFunction, 0, 0);
+ }
/* Functions strtod() and dtostr() work as in the shell. These routines
** use the standard C library to convert between floating point and