diff options
author | drh <> | 2023-03-04 15:36:51 +0000 |
---|---|---|
committer | drh <> | 2023-03-04 15:36:51 +0000 |
commit | 89b3cbed6788f899d02b27d27f5199d777d53db3 (patch) | |
tree | 13dff1e0a82dbf59c08a3f2c5ab53bed9f5ae9fa /src | |
parent | c8c7243d6ee9c6231beadc73b572f10c6b4043e9 (diff) | |
download | sqlite-89b3cbed6788f899d02b27d27f5199d777d53db3.tar.gz sqlite-89b3cbed6788f899d02b27d27f5199d777d53db3.zip |
Fix to check-in [b9190d3da70c4171] - the agg-with-indexed-expr optimization
requested by ticket [99378177930f87bd] - that can cause an incorrect answer
if an aggregate subquery has a GROUP BY clause, and that GROUP BY contains a
term that is not in the result set, and the outer query makes use of expression
indexes. Problem reported by
[forum:/forumpost/a68313d054|forum post a68313d054].
FossilOrigin-Name: e06973876993926fd56181281d04b8dd504c689abf883fa21a5721cc1d478ea8
Diffstat (limited to 'src')
-rw-r--r-- | src/select.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/select.c b/src/select.c index 359dc8cf3..2906a4895 100644 --- a/src/select.c +++ b/src/select.c @@ -6439,10 +6439,12 @@ static void optimizeAggregateUseOfIndexedExpr( NameContext *pNC /* Name context used to resolve agg-func args */ ){ assert( pAggInfo->iFirstReg==0 ); + assert( pSelect!=0 ); + assert( pSelect->pGroupBy!=0 ); pAggInfo->nColumn = pAggInfo->nAccumulator; if( ALWAYS(pAggInfo->nSortingColumn>0) ){ if( pAggInfo->nColumn==0 ){ - pAggInfo->nSortingColumn = 0; + pAggInfo->nSortingColumn = pSelect->pGroupBy->nExpr; }else{ pAggInfo->nSortingColumn = pAggInfo->aCol[pAggInfo->nColumn-1].iSorterColumn+1; |