1
0
mirror of https://github.com/sqlite/sqlite.git synced 2026-01-06 08:01:16 +03:00

Eliminate some more cases of redundant sorting in window-function queries.

FossilOrigin-Name: 8158d2aca68c5a253054376fdf1b8eaab2db874f4b93524742be7340e9c50dd5
This commit is contained in:
dan
2019-08-07 17:45:37 +00:00
parent 74c490e045
commit 0e3c50c5dc
4 changed files with 39 additions and 10 deletions

View File

@@ -934,11 +934,14 @@ int sqlite3WindowRewrite(Parse *pParse, Select *p){
** redundant, remove the ORDER BY from the parent SELECT. */
pSort = sqlite3ExprListDup(db, pMWin->pPartition, 0);
pSort = exprListAppendList(pParse, pSort, pMWin->pOrderBy, 1);
if( pSort && p->pOrderBy ){
if( pSort && p->pOrderBy && p->pOrderBy->nExpr<=pSort->nExpr ){
int nSave = pSort->nExpr;
pSort->nExpr = p->pOrderBy->nExpr;
if( sqlite3ExprListCompare(pSort, p->pOrderBy, -1)==0 ){
sqlite3ExprListDelete(db, p->pOrderBy);
p->pOrderBy = 0;
}
pSort->nExpr = nSave;
}
/* Assign a cursor number for the ephemeral table used to buffer rows.