diff options
author | drh <drh@noemail.net> | 2005-04-01 10:47:40 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2005-04-01 10:47:40 +0000 |
commit | 495c09a49aeb0e5ebd0c63c382562a4db4e9793e (patch) | |
tree | b515cba721e9235ef31881f2d8acbc3a5016980c /src | |
parent | 9a7e60865da5c3ecbff7b189a48a5bbfc4397d3c (diff) | |
download | sqlite-495c09a49aeb0e5ebd0c63c382562a4db4e9793e.tar.gz sqlite-495c09a49aeb0e5ebd0c63c382562a4db4e9793e.zip |
Make the ORDER BY clause return equal elements in the same order they were
seen (a stable sort). It was returning them in exactly the reverse order. (CVS 2439)
FossilOrigin-Name: e8391491a68018406e30c2a699a4cab9e0de092c
Diffstat (limited to 'src')
-rw-r--r-- | src/vdbe.c | 11 | ||||
-rw-r--r-- | src/vdbeInt.h | 1 | ||||
-rw-r--r-- | src/vdbeaux.c | 1 |
3 files changed, 10 insertions, 3 deletions
diff --git a/src/vdbe.c b/src/vdbe.c index c55dbbe62..d25ae75ab 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.464 2005/03/31 18:40:05 drh Exp $ +** $Id: vdbe.c,v 1.465 2005/04/01 10:47:40 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -4117,8 +4117,13 @@ case OP_SortPut: { /* no-push */ if( Dynamicify(pTos, db->enc) ) goto no_mem; pSorter = sqliteMallocRaw( sizeof(Sorter) ); if( pSorter==0 ) goto no_mem; - pSorter->pNext = p->pSort; - p->pSort = pSorter; + pSorter->pNext = 0; + if( p->pSortTail ){ + p->pSortTail->pNext = pSorter; + }else{ + p->pSort = pSorter; + } + p->pSortTail = pSorter; assert( pTos->flags & MEM_Dyn ); pSorter->nKey = pTos->n; pSorter->zKey = pTos->z; diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 37dada46d..23a65067c 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -314,6 +314,7 @@ struct Vdbe { int nCursor; /* Number of slots in apCsr[] */ Cursor **apCsr; /* One element of this array for each open cursor */ Sorter *pSort; /* A linked list of objects to be sorted */ + Sorter *pSortTail; /* Last element on the pSort list */ int nVar; /* Number of entries in aVar[] */ Mem *aVar; /* Values for the OP_Variable opcode. */ char **azVar; /* Name of variables */ diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 2866c3f9b..c4009eae0 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -779,6 +779,7 @@ void sqlite3VdbeSorterReset(Vdbe *p){ sqlite3VdbeMemRelease(&pSorter->data); sqliteFree(pSorter); } + p->pSortTail = 0; } /* |