1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-10 01:02:56 +03:00

When translating arguments of aggregate functions into references to

expression indexes, make sure to only translate them for the current
aggregate when there are nested aggregates.
[forum/forumpost/409ebc7368|Forum post 409ebc7368].

FossilOrigin-Name: 898bfa1afd8260eaaf2aa6db94e74d99ebf4e8a6dc02cf21d20cd981393609a5
This commit is contained in:
drh
2023-04-03 23:49:00 +00:00
parent f61bf3dbe8
commit 39b07f1afc
5 changed files with 32 additions and 12 deletions

View File

@@ -6288,7 +6288,7 @@ static int agginfoPersistExprCb(Walker *pWalker, Expr *pExpr){
sqlite3 *db = pParse->db;
assert( iAgg>=0 );
if( pExpr->op!=TK_AGG_FUNCTION ){
if( iAgg<pAggInfo->nColumn
if( ALWAYS(iAgg<pAggInfo->nColumn)
&& pAggInfo->aCol[iAgg].pCExpr==pExpr
){
pExpr = sqlite3ExprDup(db, pExpr, 0);
@@ -6441,6 +6441,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
default: {
IndexedExpr *pIEpr;
Expr tmp;
int i;
assert( pParse->iSelfTab==0 );
if( (pNC->ncFlags & NC_InAggFunc)==0 ) break;
if( pParse->pIdxEpr==0 ) break;
@@ -6451,7 +6452,11 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
}
if( pIEpr==0 ) break;
if( NEVER(!ExprUseYTab(pExpr)) ) break;
if( pExpr->pAggInfo!=0 ) break; /* Already resolved by outer context */
for(i=0; i<pSrcList->nSrc; i++){
if( pSrcList->a[0].iCursor==pIEpr->iDataCur ) break;
}
if( i>=pSrcList->nSrc ) break;
if( NEVER(pExpr->pAggInfo!=0) ) break; /* Resolved by outer context */
if( pParse->nErr ){ return WRC_Abort; }
/* If we reach this point, it means that expression pExpr can be