/ Check-in [eec8c0df]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove redundant parameter from vdbeSorterInitMerge() in vdbesort.c.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1: eec8c0df075d3a54ad71a2854b170f3ed307d068
User & Date: dan 2011-08-08 19:26:13
Context
2011-08-12
11:59
Add tests to improve coverage of vdbesort.c. check-in: 87a15917 user: dan tags: experimental
2011-08-08
19:26
Remove redundant parameter from vdbeSorterInitMerge() in vdbesort.c. check-in: eec8c0df user: dan tags: experimental
16:44
Add fault-injection and other tests (and fixes) to improve coverage of vdbesort.c. check-in: 0e6defa6 user: dan tags: experimental
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbesort.c.

   170    170   
   171    171     pIter->iReadOff += iOff+nRec;
   172    172     pIter->nKey = nRec;
   173    173     pIter->aKey = &pIter->aAlloc[iOff];
   174    174     return rc;
   175    175   }
   176    176   
          177  +/*
          178  +** Write a single varint, value iVal, to file-descriptor pFile. Return
          179  +** SQLITE_OK if successful, or an SQLite error code if some error occurs.
          180  +**
          181  +** The value of *piOffset when this function is called is used as the byte
          182  +** offset in file pFile to write to. Before returning, *piOffset is 
          183  +** incremented by the number of bytes written.
          184  +*/
   177    185   static int vdbeSorterWriteVarint(
   178    186     sqlite3_file *pFile, 
   179    187     i64 iVal, 
   180    188     i64 *piOffset
   181    189   ){
   182    190     u8 aVarint[9];                  /* Buffer large enough for a varint */
   183    191     int nVarint;                    /* Number of used bytes in varint */
................................................................................
   186    194     nVarint = sqlite3PutVarint(aVarint, iVal);
   187    195     rc = sqlite3OsWrite(pFile, aVarint, nVarint, *piOffset);
   188    196     *piOffset += nVarint;
   189    197   
   190    198     return rc;
   191    199   }
   192    200   
          201  +/*
          202  +** Read a single varint from file-descriptor pFile. Return SQLITE_OK if
          203  +** successful, or an SQLite error code if some error occurs.
          204  +**
          205  +** The value of *piOffset when this function is called is used as the
          206  +** byte offset in file pFile from whence to read the varint. If successful
          207  +** (i.e. if no IO error occurs), then *piOffset is set to the offset of
          208  +** the first byte past the end of the varint before returning. *piVal is
          209  +** set to the integer value read. If an error occurs, the final values of
          210  +** both *piOffset and *piVal are undefined.
          211  +*/
   193    212   static int vdbeSorterReadVarint(
   194    213     sqlite3_file *pFile, 
   195    214     i64 iEof,                       /* Total number of bytes in file */
   196    215     i64 *piOffset,                  /* IN/OUT: Read offset */
   197    216     i64 *piVal                      /* OUT: Value read from file */
   198    217   ){
   199    218     u8 aVarint[9];                  /* Buffer large enough for a varint */
................................................................................
   483    502   
   484    503       pSorter->nBtree += sqlite3VarintLen(nKey) + nKey;
   485    504     }
   486    505     return rc;
   487    506   }
   488    507   
   489    508   /*
   490         -** Helper function for sqlite3VdbeSorterRewind().
          509  +** Helper function for sqlite3VdbeSorterRewind(). 
   491    510   */
   492    511   static int vdbeSorterInitMerge(
   493         -  sqlite3 *db,
   494         -  VdbeCursor *pCsr,
   495         -  int iFirst,
          512  +  sqlite3 *db,                    /* Database handle */
          513  +  VdbeCursor *pCsr,               /* Cursor handle for this sorter */
   496    514     i64 *pnByte                     /* Sum of bytes in all opened PMAs */
   497    515   ){
   498    516     VdbeSorter *pSorter = pCsr->pSorter;
   499         -  int rc = SQLITE_OK;
   500         -  int i;
   501         -  i64 nByte = 0;
          517  +  int rc = SQLITE_OK;             /* Return code */
          518  +  int i;                          /* Used to iterator through aIter[] */
          519  +  i64 nByte = 0;                  /* Total bytes in all opened PMAs */
   502    520   
   503         -  /* Initialize as many iterators as possible. */
   504         -  for(i=iFirst; 
   505         -      rc==SQLITE_OK && i<pSorter->nPMA && (i-iFirst)<SORTER_MAX_MERGE_COUNT; 
   506         -      i++
   507         -  ){
   508         -    VdbeSorterIter *pIter = &pSorter->aIter[i - iFirst];
          521  +  /* Initialize the iterators. */
          522  +  for(i=0; rc==SQLITE_OK && i<SORTER_MAX_MERGE_COUNT; i++){
          523  +    VdbeSorterIter *pIter = &pSorter->aIter[i];
   509    524       rc = vdbeSorterIterInit(db, pSorter, pSorter->iReadOff, pIter, &nByte);
   510    525       pSorter->iReadOff = pIter->iEof;
          526  +    assert( pSorter->iReadOff<=pSorter->iWriteOff );
          527  +    if( pSorter->iReadOff>=pSorter->iWriteOff ) break;
   511    528     }
   512         -  assert( i>iFirst );
   513    529   
   514         -  /* Populate the aTree[] array. */
          530  +  /* Initialize the aTree[] array. */
   515    531     for(i=pSorter->nTree-1; rc==SQLITE_OK && i>0; i--){
   516    532       rc = vdbeSorterDoCompare(pCsr, i);
   517    533     }
   518    534   
   519    535     *pnByte = nByte;
   520    536     return rc;
   521    537   }
................................................................................
   569    585         ** These iterators will be incrementally merged as the VDBE layer calls
   570    586         ** sqlite3VdbeSorterNext().
   571    587         **
   572    588         ** Otherwise, if pTemp1 contains more than SORTER_MAX_MERGE_COUNT PMAs,
   573    589         ** initialize interators for SORTER_MAX_MERGE_COUNT of them. These PMAs
   574    590         ** are merged into a single PMA that is written to file pTemp2.
   575    591         */
   576         -      rc = vdbeSorterInitMerge(db, pCsr, iNew*SORTER_MAX_MERGE_COUNT, &nWrite);
          592  +      rc = vdbeSorterInitMerge(db, pCsr, &nWrite);
   577    593         assert( rc!=SQLITE_OK || pSorter->aIter[ pSorter->aTree[1] ].pFile );
   578    594         if( rc!=SQLITE_OK || pSorter->nPMA<=SORTER_MAX_MERGE_COUNT ){
   579    595           break;
   580    596         }
   581    597   
   582    598         /* Open the second temp file, if it is not already open. */
   583    599         if( pTemp2==0 ){