-C Remove\sthe\ssequence\svalues\sfrom\ssorter\srecords\sused\sby\sORDER\sBY\sas\swell.
-D 2014-03-25T15:04:07.777
+C Fix\sa\sproblem\sin\sthe\scode\sadded\sby\s[707ea170b3]\scausing\svdbesort.c\sto\ssort\sunstably.
+D 2014-03-25T17:07:48.821
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
F src/vdbeaux.c 5078ca7de4fd5ba4535bd17fe44d5b56c2d3294c
F src/vdbeblob.c 15377abfb59251bccedd5a9c7d014a895f0c04aa
F src/vdbemem.c 6fc77594c60f6155404f3f8d71bf36d1fdeb4447
-F src/vdbesort.c 46e50c6bc9300625cff144f8948381a2c53116bf
+F src/vdbesort.c 691f2186ae0943cd746ea7f5498cc9abebb7a7cc
F src/vdbetrace.c 6f52bc0c51e144b7efdcfb2a8f771167a8816767
F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd
F src/wal.c 76e7fc6de229bea8b30bb2539110f03a494dc3a8
F test/skipscan2.test 5a4db0799c338ddbacb154aaa5589c0254b36a8d
F test/soak.test 0b5b6375c9f4110c828070b826b3b4b0bb65cd5f
F test/softheap1.test 40562fe6cac6d9827b7b42b86d45aedf12c15e24
-F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5
+F test/sort.test cb76a6e9db897b6871ef4dbc206ebc6dbc033bf4
F test/speed1.test f2974a91d79f58507ada01864c0e323093065452
F test/speed1p.explain d841e650a04728b39e6740296b852dccdca9b2cb
F test/speed1p.test b180e98609c7677382cf618c0ec9b69f789033a8
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
-P 3f90abddc31ac20739778c235a834c33f7057997
-R 743d88a284437e5e0babc8e33ec37e61
+P c3ae3697832a00d4d5758988a8766bdbb691e6b8
+R eb749164f2115a0b3ef6dbb32fd74b6a
U dan
-Z 5024d9c780855d9abccbd4c6c23f3054
+Z ecf1eb93a5e3757595a49ddb23f9c671
-c3ae3697832a00d4d5758988a8766bdbb691e6b8
\ No newline at end of file
+d3e640afe611b6ae0b7f2cff5b00900d7e4d5ee3
\ No newline at end of file
/*
** Merge the two sorted lists p1 and p2 into a single list.
** Set *ppOut to the head of the new list.
+**
+** In cases where key values are equal, keys from list p1 are considered
+** to be smaller than list p2.
*/
static void vdbeSorterMerge(
const VdbeCursor *pCsr, /* For pKeyInfo */
** Sort the linked list of records headed at pCsr->pRecord. Return SQLITE_OK
** if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if an error
** occurs.
+**
+** The sort is required to be stable - if two elements compare as equal
+** then the one added to the sorter first is considered the smaller.
+** Currently, the list is sorted from newest to oldest - pSorter->pRecord
+** points to the most recently added sort key.
*/
static int vdbeSorterSort(const VdbeCursor *pCsr){
int i;
int i; /* Used to iterator through aIter[] */
i64 nByte = 0; /* Total bytes in all opened PMAs */
- /* Initialize the iterators. */
+ /* Initialize the iterators. Iterator 0 contains the oldest data. */
for(i=0; i<SORTER_MAX_MERGE_COUNT; i++){
VdbeSorterIter *pIter = &pSorter->aIter[i];
rc = vdbeSorterIterInit(db, pSorter, pSorter->iReadOff, pIter, &nByte);
** set aTree[i] to its index and update pIter1. If vdbeSorterCompare()
** was actually called above, then pSorter->pUnpacked now contains
** a value equivalent to pIter2. So set pKey2 to NULL to prevent
- ** vdbeSorterCompare() from decoding pIter2 again. */
- if( iRes<=0 ){
+ ** vdbeSorterCompare() from decoding pIter2 again.
+ **
+ ** If the two values were equal, then the value from the oldest
+ ** PMA should be considered smaller. The VdbeSorter.aIter[] array
+ ** is sorted from oldest to newest, so pIter1 contains older values
+ ** than pIter2 iff (pIter1<pIter2). */
+ if( iRes<0 || (iRes==0 && pIter1<pIter2) ){
pSorter->aTree[i] = (int)(pIter1 - pSorter->aIter);
pIter2 = &pSorter->aIter[ pSorter->aTree[i ^ 0x0001] ];
pKey2 = pIter2->aKey;
pSorter->aTree[i] = (int)(pIter2 - pSorter->aIter);
pIter1 = &pSorter->aIter[ pSorter->aTree[i ^ 0x0001] ];
}
-
}
*pbEof = (pSorter->aIter[pSorter->aTree[1]].pFile==0);
}
}
} {1 2 xxx 1 3 yyy 1 1 zzz}
+
+#-------------------------------------------------------------------------
+# Check that the sorter in vdbesort.c sorts in a stable fashion.
+#
+do_execsql_test sort-13.0 {
+ CREATE TABLE t10(a, b);
+}
+do_test sort-13.1 {
+ db transaction {
+ for {set i 0} {$i < 100000} {incr i} {
+ execsql { INSERT INTO t10 VALUES( $i/10, $i%10 ) }
+ }
+ }
+} {}
+do_execsql_test sort-13.2 {
+ SELECT a, b FROM t10 ORDER BY a;
+} [db eval {SELECT a, b FROM t10 ORDER BY a, b}]
+do_execsql_test sort-13.3 {
+ PRAGMA cache_size = 5;
+ SELECT a, b FROM t10 ORDER BY a;
+} [db eval {SELECT a, b FROM t10 ORDER BY a, b}]
+
+
finish_test