aboutsummaryrefslogtreecommitdiff
path: root/src/where.c
diff options
context:
space:
mode:
authordrh <>2023-11-09 12:17:57 +0000
committerdrh <>2023-11-09 12:17:57 +0000
commitb18bb822dc4ae9ee1c44c6d8267ffc4a3fd3fcf4 (patch)
tree2190914f16530634f193fdb288355c06dc3bd0a8 /src/where.c
parent194b8d514bc8ba594e88c93cfaba66ff24d00ae8 (diff)
parent2cbe14098b156838153f194df1ea41d9b390935b (diff)
downloadsqlite-b18bb822dc4ae9ee1c44c6d8267ffc4a3fd3fcf4.tar.gz
sqlite-b18bb822dc4ae9ee1c44c6d8267ffc4a3fd3fcf4.zip
Do not replace expressions that return subtypes with values taken from an
index. FossilOrigin-Name: a35d13db09e32ee339f3983fe36b073714753ee3d39f577ae8d20596d7adc3eb
Diffstat (limited to 'src/where.c')
-rw-r--r--src/where.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/where.c b/src/where.c
index 05ae24f7b..448fe27c1 100644
--- a/src/where.c
+++ b/src/where.c
@@ -5810,6 +5810,20 @@ static SQLITE_NOINLINE void whereAddIndexedExpr(
continue;
}
if( sqlite3ExprIsConstant(pExpr) ) continue;
+ if( pExpr->op==TK_FUNCTION ){
+ /* Functions that might set a subtype should not be replaced by the
+ ** value taken from an expression index since the index omits the
+ ** subtype. https://sqlite.org/forum/forumpost/68d284c86b082c3e */
+ int n;
+ FuncDef *pDef;
+ sqlite3 *db = pParse->db;
+ assert( ExprUseXList(pExpr) );
+ n = pExpr->x.pList ? pExpr->x.pList->nExpr : 0;
+ pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0);
+ if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){
+ continue;
+ }
+ }
p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexedExpr));
if( p==0 ) break;
p->pIENext = pParse->pIdxEpr;