1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

Optimize simple min() and max() queries. (CVS 382)

FossilOrigin-Name: cc5abfe392bdb8c3ed00e0610bc2b41851bfc9d7
This commit is contained in:
drh
2002-02-19 15:00:07 +00:00
parent aaab5725db
commit 9562b55115
7 changed files with 287 additions and 130 deletions

View File

@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.53 2002/02/19 13:39:22 drh Exp $
** $Id: btree.c,v 1.54 2002/02/19 15:00:07 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
@@ -1325,6 +1325,30 @@ int sqliteBtreeFirst(BtCursor *pCur, int *pRes){
return rc;
}
/* Move the cursor to the last entry in the table. Return SQLITE_OK
** on success. Set *pRes to 0 if the cursor actually points to something
** or set *pRes to 1 if the table is empty and there is no first element.
*/
int sqliteBtreeLast(BtCursor *pCur, int *pRes){
int rc;
Pgno pgno;
if( pCur->pPage==0 ) return SQLITE_ABORT;
rc = moveToRoot(pCur);
if( rc ) return rc;
if( pCur->pPage->nCell==0 ){
*pRes = 1;
return SQLITE_OK;
}
*pRes = 0;
while( (pgno = pCur->pPage->u.hdr.rightChild)!=0 ){
rc = moveToChild(pCur, pgno);
if( rc ) return rc;
}
pCur->idx = pCur->pPage->nCell-1;
pCur->bSkipNext = 0;
return rc;
}
/* Move the cursor so that it points to an entry near pKey.
** Return a success code.
**