Skip to content

Commit

Permalink
Make sure that the KeyInfo.nXField value of ephermeral tables used for
Browse files Browse the repository at this point in the history
ORDER BY and GROUP BY is set correctly, so that the correct comparison
function can be choosen by sqlite3VdbeFindCompare().
  • Loading branch information
D. Richard Hipp committed Jan 19, 2015
1 parent 8497c39 commit 27be884
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ static KeyInfo *keyInfoFromExprList(
int i;

nExpr = pList->nExpr;
pInfo = sqlite3KeyInfoAlloc(db, nExpr+nExtra-iStart, 1);
pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
if( pInfo ){
assert( sqlite3KeyInfoIsWriteable(pInfo) );
for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
Expand Down Expand Up @@ -4924,7 +4924,7 @@ int sqlite3Select(
*/
if( sSort.pOrderBy ){
KeyInfo *pKeyInfo;
pKeyInfo = keyInfoFromExprList(pParse, sSort.pOrderBy, 0, 0);
pKeyInfo = keyInfoFromExprList(pParse, sSort.pOrderBy, 0, pEList->nExpr);
sSort.iECursor = pParse->nTab++;
sSort.addrSortIndex =
sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
Expand Down Expand Up @@ -5098,7 +5098,7 @@ int sqlite3Select(
** will be converted into a Noop.
*/
sAggInfo.sortingIdx = pParse->nTab++;
pKeyInfo = keyInfoFromExprList(pParse, pGroupBy, 0, 0);
pKeyInfo = keyInfoFromExprList(pParse, pGroupBy, 0, sAggInfo.nColumn);
addrSortingIdx = sqlite3VdbeAddOp4(v, OP_SorterOpen,
sAggInfo.sortingIdx, sAggInfo.nSortingColumn,
0, (char*)pKeyInfo, P4_KEYINFO);
Expand Down

0 comments on commit 27be884

Please sign in to comment.