aboutsummaryrefslogtreecommitdiff
path: root/src/expr.c
diff options
context:
space:
mode:
authordrh <>2022-07-25 16:06:14 +0000
committerdrh <>2022-07-25 16:06:14 +0000
commit6aabb72618e1f8e5898dd408f01f7de8bdad2e2f (patch)
tree79584c0a6c8a163286475d37a5116c88a2033f72 /src/expr.c
parent8bd0b250b715802f3bddf46596841d18acffcdb4 (diff)
parentee37302095f95b8692d835dc3dec4cbb398d9c3b (diff)
downloadsqlite-6aabb72618e1f8e5898dd408f01f7de8bdad2e2f.tar.gz
sqlite-6aabb72618e1f8e5898dd408f01f7de8bdad2e2f.zip
Fix an error in the aggregate query LEFT JOIN flattening optimization from
[2cf373b10c9bc4cb] and further enhance that optimization so that it works even if there is a GROUP BY clause. FossilOrigin-Name: b52393ac28debe9867227f901d05cccf54f1b467272474500a549d956a5fb4d7
Diffstat (limited to 'src/expr.c')
-rw-r--r--src/expr.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/expr.c b/src/expr.c
index 8edab3298..c9c7c2e76 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -4670,6 +4670,21 @@ expr_code_doover:
case TK_IF_NULL_ROW: {
int addrINR;
u8 okConstFactor = pParse->okConstFactor;
+ AggInfo *pAggInfo = pExpr->pAggInfo;
+ if( pAggInfo ){
+ assert( pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn );
+ if( !pAggInfo->directMode ){
+ inReg = pAggInfo->aCol[pExpr->iAgg].iMem;
+ break;
+ }
+ if( pExpr->pAggInfo->useSortingIdx ){
+ sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab,
+ pAggInfo->aCol[pExpr->iAgg].iSorterColumn,
+ target);
+ inReg = target;
+ break;
+ }
+ }
addrINR = sqlite3VdbeAddOp1(v, OP_IfNullRow, pExpr->iTable);
/* Temporarily disable factoring of constant expressions, since
** even though expressions may appear to be constant, they are not
@@ -6175,10 +6190,12 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
assert( pNC->ncFlags & NC_UAggInfo );
switch( pExpr->op ){
+ case TK_IF_NULL_ROW:
case TK_AGG_COLUMN:
case TK_COLUMN: {
testcase( pExpr->op==TK_AGG_COLUMN );
testcase( pExpr->op==TK_COLUMN );
+ testcase( pExpr->op==TK_IF_NULL_ROW );
/* Check to see if the column is in one of the tables in the FROM
** clause of the aggregate query */
if( ALWAYS(pSrcList!=0) ){
@@ -6237,7 +6254,9 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
*/
ExprSetVVAProperty(pExpr, EP_NoReduce);
pExpr->pAggInfo = pAggInfo;
- pExpr->op = TK_AGG_COLUMN;
+ if( pExpr->op==TK_COLUMN ){
+ pExpr->op = TK_AGG_COLUMN;
+ }
pExpr->iAgg = (i16)k;
break;
} /* endif pExpr->iTable==pItem->iCursor */