Merge the vdbesort.c optimization from trunk.

FossilOrigin-Name: e4bfffb988283c077778c60696be0d285ad66c3c
This commit is contained in:
drh
2014-03-19 23:42:51 +00:00
3 changed files with 54 additions and 13 deletions
+6 -6
View File
@@ -1,5 +1,5 @@
C Fix\squery\splanner\sweights\sassociated\swith\schoosing\sblock-sorting.\s\sFix\nblock\ssorting\sof\stables\swith\scollating\sfunctions.\s\sFix\svarious\stest\scases.\nAll\s"veryquick"\stests\sare\snow\spassing,\sthough\smore\stests\sneed\sto\sbe\sadded.
D 2014-03-19T23:24:49.240
C Merge\sthe\svdbesort.c\soptimization\sfrom\strunk.
D 2014-03-19T23:42:51.606
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -285,7 +285,7 @@ F src/vdbeapi.c 0ed6053f947edd0b30f64ce5aeb811872a3450a4
F src/vdbeaux.c 5078ca7de4fd5ba4535bd17fe44d5b56c2d3294c
F src/vdbeblob.c 15377abfb59251bccedd5a9c7d014a895f0c04aa
F src/vdbemem.c 6fc77594c60f6155404f3f8d71bf36d1fdeb4447
F src/vdbesort.c 553537f632e8925bb8a2563692d0ee6e2175018c
F src/vdbesort.c 17336685efeef61170485b273cb14b3f1c68130e
F src/vdbetrace.c 6f52bc0c51e144b7efdcfb2a8f771167a8816767
F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd
F src/wal.c 76e7fc6de229bea8b30bb2539110f03a494dc3a8
@@ -1156,7 +1156,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
P 7ce2daafd39a117041bfdd0a7132e2764fe7a74b
R f3bf694b0186fa15aaedfb1a5982c72f
P 01afbf97c0ff29667806e9a7c4d74ca717819de5 707ea170b3e26965b7e3982f7554d122d130b9a6
R 8822581e4a84d2f390bdca26ebdb6cc0
U drh
Z 15ce545d4c6482a35d82cbe6b958fe2e
Z db1037b5faa49e6de7af132643ccdf5b
+1 -1
View File
@@ -1 +1 @@
01afbf97c0ff29667806e9a7c4d74ca717819de5
e4bfffb988283c077778c60696be0d285ad66c3c
+47 -6
View File
@@ -973,14 +973,55 @@ int sqlite3VdbeSorterNext(sqlite3 *db, const VdbeCursor *pCsr, int *pbEof){
if( pSorter->aTree ){
int iPrev = pSorter->aTree[1];/* Index of iterator to advance */
int i; /* Index of aTree[] to recalculate */
rc = vdbeSorterIterNext(db, &pSorter->aIter[iPrev]);
for(i=(pSorter->nTree+iPrev)/2; rc==SQLITE_OK && i>0; i=i/2){
rc = vdbeSorterDoCompare(pCsr, i);
}
if( rc==SQLITE_OK ){
int i; /* Index of aTree[] to recalculate */
VdbeSorterIter *pIter1; /* First iterator to compare */
VdbeSorterIter *pIter2; /* Second iterator to compare */
u8 *pKey2; /* To pIter2->aKey, or 0 if record cached */
*pbEof = (pSorter->aIter[pSorter->aTree[1]].pFile==0);
/* Find the first two iterators to compare. The one that was just
** advanced (iPrev) and the one next to it in the array. */
pIter1 = &pSorter->aIter[(iPrev & 0xFFFE)];
pIter2 = &pSorter->aIter[(iPrev | 0x0001)];
pKey2 = pIter2->aKey;
for(i=(pSorter->nTree+iPrev)/2; i>0; i=i/2){
/* Compare pIter1 and pIter2. Store the result in variable iRes. */
int iRes;
if( pIter1->pFile==0 ){
iRes = +1;
}else if( pIter2->pFile==0 ){
iRes = -1;
}else{
vdbeSorterCompare(pCsr, 0,
pIter1->aKey, pIter1->nKey, pKey2, pIter2->nKey, &iRes
);
}
/* If pIter1 contained the smaller value, set aTree[i] to its index.
** Then set pIter2 to the next iterator to compare to pIter1. In this
** case there is no cache of pIter2 in pSorter->pUnpacked, so set
** pKey2 to point to the record belonging to pIter2.
**
** Alternatively, if pIter2 contains the smaller of the two values,
** 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 ){
pSorter->aTree[i] = (pIter1 - pSorter->aIter);
pIter2 = &pSorter->aIter[ pSorter->aTree[i ^ 0x0001] ];
pKey2 = pIter2->aKey;
}else{
if( pIter1->pFile ) pKey2 = 0;
pSorter->aTree[i] = (pIter2 - pSorter->aIter);
pIter1 = &pSorter->aIter[ pSorter->aTree[i ^ 0x0001] ];
}
}
*pbEof = (pSorter->aIter[pSorter->aTree[1]].pFile==0);
}
}else{
SorterRecord *pFree = pSorter->pRecord;
pSorter->pRecord = pFree->pNext;