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

Allow subqueries on the right-hand side of a LEFT JOIN to be flattened even

if they contain a GROUP BY clause.

FossilOrigin-Name: 816da9a893ae97a21463562479edb419a8b511ae731d86eccee3fa6e3e7dc96e
This commit is contained in:
drh
2022-07-25 15:54:23 +00:00
parent 6b6d6c6bd2
commit ee37302095
4 changed files with 31 additions and 24 deletions

View File

@@ -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 */