aboutsummaryrefslogtreecommitdiff
path: root/src/select.c
diff options
context:
space:
mode:
authordrh <>2022-07-25 15:54:23 +0000
committerdrh <>2022-07-25 15:54:23 +0000
commitee37302095f95b8692d835dc3dec4cbb398d9c3b (patch)
treeda7f2322c7732c92cb670bc49b4e3262fb1fdb1b /src/select.c
parent6b6d6c6bd2ca6b1dc19f61216ffe88e5cf734581 (diff)
downloadsqlite-ee37302095f95b8692d835dc3dec4cbb398d9c3b.tar.gz
sqlite-ee37302095f95b8692d835dc3dec4cbb398d9c3b.zip
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
Diffstat (limited to 'src/select.c')
-rw-r--r--src/select.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/select.c b/src/select.c
index 90ba47fa8..672461d44 100644
--- a/src/select.c
+++ b/src/select.c
@@ -4065,8 +4065,8 @@ static void renumberCursors(
** (3a) the subquery may not be a join and
** (3b) the FROM clause of the subquery may not contain a virtual
** table and
-** (3c) The outer query may not have a GROUP BY. (This limitation is
-** due to how TK_IF_NULL_ROW works. FIX ME!)
+** (**) Was: "The outer query may not have a GROUP BY." This case
+** is now managed correctly
** (3d) the outer query may not be DISTINCT.
** See also (26) for restrictions on RIGHT JOIN.
**
@@ -4284,7 +4284,6 @@ static int flattenSubquery(
if( pSubSrc->nSrc>1 /* (3a) */
|| IsVirtual(pSubSrc->a[0].pTab) /* (3b) */
|| (p->selFlags & SF_Distinct)!=0 /* (3d) */
- || (p->pGroupBy!=0) /* (3c) */
|| (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
){
return 0;
@@ -7541,15 +7540,15 @@ int sqlite3Select(
regBase = sqlite3GetTempRange(pParse, nCol);
sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
j = nGroupBy;
+ pAggInfo->directMode = 1;
for(i=0; i<pAggInfo->nColumn; i++){
struct AggInfo_col *pCol = &pAggInfo->aCol[i];
if( pCol->iSorterColumn>=j ){
- int r1 = j + regBase;
- sqlite3ExprCodeGetColumnOfTable(v,
- pCol->pTab, pCol->iTable, pCol->iColumn, r1);
+ sqlite3ExprCode(pParse, pCol->pCExpr, j + regBase);
j++;
}
}
+ pAggInfo->directMode = 0;
regRecord = sqlite3GetTempReg(pParse);
sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regRecord);
sqlite3VdbeAddOp2(v, OP_SorterInsert, pAggInfo->sortingIdx, regRecord);