diff options
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/expr.c b/src/expr.c index 876b453f1..c9c7c2e76 100644 --- a/src/expr.c +++ b/src/expr.c @@ -4670,12 +4670,20 @@ expr_code_doover: case TK_IF_NULL_ROW: { int addrINR; u8 okConstFactor = pParse->okConstFactor; - if( pExpr->pAggInfo && !pExpr->pAggInfo->directMode ){ - struct AggInfo_col *pCol; - assert( pExpr->iAgg>=0 && pExpr->iAgg<pExpr->pAggInfo->nColumn ); - pCol = &pExpr->pAggInfo->aCol[pExpr->iAgg]; - inReg = pCol->iMem; - break; + 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 @@ -6187,6 +6195,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){ 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) ){ @@ -6245,7 +6254,9 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){ */ ExprSetVVAProperty(pExpr, EP_NoReduce); pExpr->pAggInfo = pAggInfo; - if( pExpr->op==TK_COLUMN ) 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 */ |