aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2023-03-25 23:52:05 +0000
committerdrh <>2023-03-25 23:52:05 +0000
commitb900f9e6e8571f266f6d5d2bc22518c598ea92bc (patch)
treebaa0f673ee53e2e338c39c232e06b93f34d17bcc /src
parent7bb842642c75b8b2664dd1c7b47df65bf4500e9e (diff)
parentdebc3202c6ac81a4baee951cddfad9a2087ed56e (diff)
downloadsqlite-b900f9e6e8571f266f6d5d2bc22518c598ea92bc.tar.gz
sqlite-b900f9e6e8571f266f6d5d2bc22518c598ea92bc.zip
When the left table of a RIGHT JOIN is used inside an aggregate function and the left table employs an index on expressions, then make sure the expressions evaluate to NULL for the cases where the left table should be NULL. Fix for
[forum:/forumpost/9b491e1deb|forum post 9b491e1deb]. FossilOrigin-Name: ffe23af73fcb324df988a00be343654ce7078b7208647c4eb779d666b8297e7c
Diffstat (limited to 'src')
-rw-r--r--src/expr.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/expr.c b/src/expr.c
index 9e2ae0ebd..cd09c0d71 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -4222,7 +4222,19 @@ expr_code_doover:
AggInfo *pAggInfo = pExpr->pAggInfo;
struct AggInfo_col *pCol;
assert( pAggInfo!=0 );
- assert( pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn );
+ assert( pExpr->iAgg>=0 );
+ if( pExpr->iAgg>=pAggInfo->nColumn ){
+ /* Happens when the left table of a RIGHT JOIN is null and
+ ** is using an expression index */
+ sqlite3VdbeAddOp2(v, OP_Null, 0, target);
+#ifdef SQLITE_VDBE_COVERAGE
+ /* Verify that the OP_Null above is exercised by tests
+ ** tag-20230325-2 */
+ sqlite3VdbeAddOp2(v, OP_NotNull, target, 1);
+ VdbeCoverageNeverTaken(v);
+#endif
+ break;
+ }
pCol = &pAggInfo->aCol[pExpr->iAgg];
if( !pAggInfo->directMode ){
return AggInfoColumnReg(pAggInfo, pExpr->iAgg);