aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2025-06-02 18:34:17 +0000
committerdrh <>2025-06-02 18:34:17 +0000
commit342ef63e638e167ef16e8fff5bc109e2aa3de344 (patch)
tree919267b137adde6511741fc14ed33399ce989216 /src
parentd84bbac8be02e81c32a52765c02dd17996ac3841 (diff)
downloadsqlite-342ef63e638e167ef16e8fff5bc109e2aa3de344.tar.gz
sqlite-342ef63e638e167ef16e8fff5bc109e2aa3de344.zip
Improve the accuracy of affinity and collating sequence analysis for
NATURAL JOINs to the left of RIGHT JOINs where source tables are views or subqueries. Initial problem report in [forum:/forumpost/829306db47|forum post 829306db47]. FossilOrigin-Name: f184d1d236e47962658a4639d9533f67a525b74cfe0f06c93e9b85fdcd02a15f
Diffstat (limited to 'src')
-rw-r--r--src/expr.c8
-rw-r--r--src/select.c2
-rw-r--r--src/sqliteInt.h1
3 files changed, 8 insertions, 3 deletions
diff --git a/src/expr.c b/src/expr.c
index 12c94362f..606a4cd7e 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -73,7 +73,9 @@ char sqlite3ExprAffinity(const Expr *pExpr){
pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
);
}
- if( op==TK_VECTOR ){
+ if( op==TK_VECTOR
+ || (op==TK_FUNCTION && pExpr->affExpr==SQLITE_AFF_DEFER)
+ ){
assert( ExprUseXList(pExpr) );
return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
}
@@ -266,7 +268,9 @@ CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr){
p = p->pLeft;
continue;
}
- if( op==TK_VECTOR ){
+ if( op==TK_VECTOR
+ || (op==TK_FUNCTION && p->affExpr==SQLITE_AFF_DEFER)
+ ){
assert( ExprUseXList(p) );
p = p->x.pList->a[0].pExpr;
continue;
diff --git a/src/select.c b/src/select.c
index 1525a4640..6c0e7c92d 100644
--- a/src/select.c
+++ b/src/select.c
@@ -631,7 +631,7 @@ static int sqlite3ProcessJoin(Parse *pParse, Select *p){
pFuncArgs = sqlite3ExprListAppend(pParse, pFuncArgs, pE1);
pE1 = sqlite3ExprFunction(pParse, pFuncArgs, &tkCoalesce, 0);
if( pE1 ){
- pE1->affExpr = sqlite3ExprAffinity(pFuncArgs->a[0].pExpr);
+ pE1->affExpr = SQLITE_AFF_DEFER;
}
}
}else if( (pSrc->a[i+1].fg.jointype & JT_LEFT)!=0 && pParse->nErr==0 ){
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 951cd3d34..c65d159d1 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -2329,6 +2329,7 @@ struct CollSeq {
#define SQLITE_AFF_INTEGER 0x44 /* 'D' */
#define SQLITE_AFF_REAL 0x45 /* 'E' */
#define SQLITE_AFF_FLEXNUM 0x46 /* 'F' */
+#define SQLITE_AFF_DEFER 0x58 /* 'X' - defer computation until later */
#define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)