mirror of
				https://github.com/sqlite/sqlite.git
				synced 2025-11-03 16:53:36 +03:00 
			
		
		
		
	Avoid some unnecessary calls to sqlite3VdbeRecordUnpack() that were being made when merging data from two or more temp files together in vdbesort.c
FossilOrigin-Name: 707ea170b3e26965b7e3982f7554d122d130b9a6
This commit is contained in:
		
							
								
								
									
										14
									
								
								manifest
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								manifest
									
									
									
									
									
								
							@@ -1,5 +1,5 @@
 | 
			
		||||
C Clean\sup\ssome\sobsolete\s"register"\sdeclarations\sin\sprintf.c.
 | 
			
		||||
D 2014-03-17T15:06:57.359
 | 
			
		||||
C Avoid\ssome\sunnecessary\scalls\sto\ssqlite3VdbeRecordUnpack()\sthat\swere\sbeing\smade\swhen\smerging\sdata\sfrom\stwo\sor\smore\stemp\sfiles\stogether\sin\svdbesort.c
 | 
			
		||||
D 2014-03-19T20:01:25.712
 | 
			
		||||
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 e45e3f9daf38c5be3fd39e9aacc1c9066af57a06
 | 
			
		||||
F src/vdbeblob.c 15377abfb59251bccedd5a9c7d014a895f0c04aa
 | 
			
		||||
F src/vdbemem.c 6fc77594c60f6155404f3f8d71bf36d1fdeb4447
 | 
			
		||||
F src/vdbesort.c 46801acb342e5e4c07ba1777fe58880c143abb59
 | 
			
		||||
F src/vdbesort.c 0a9e5e63d7ce196651610d1a264eeb0b2152d3ba
 | 
			
		||||
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 eb071eb58cf675bd6cd9dd46aed9d57fbb7a77e8
 | 
			
		||||
R f35820126ad6a1c360258186873a2e79
 | 
			
		||||
U drh
 | 
			
		||||
Z b6382160ccdf74a44bc9653763bb82ef
 | 
			
		||||
P ecd9d3f9453be0bb8e312d8027fd1a9e55882f36
 | 
			
		||||
R 597feeb3c9b32d5be1e5c696f1b077da
 | 
			
		||||
U dan
 | 
			
		||||
Z 03e3772c0627172d43f05f231b29ede3
 | 
			
		||||
 
 | 
			
		||||
@@ -1 +1 @@
 | 
			
		||||
ecd9d3f9453be0bb8e312d8027fd1a9e55882f36
 | 
			
		||||
707ea170b3e26965b7e3982f7554d122d130b9a6
 | 
			
		||||
@@ -956,14 +956,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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user