SQLite

Check-in [38298ef923]
Login

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

Overview
Comment:Increase the estimated cost of sorting when sorting wide results sets, to account for the extra storage space and I/O required for the external sort.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | apple-increased-sorting-cost
Files: files | file ages | folders
SHA1: 38298ef923c8dad6860385ac4a20849eeac2d174
User & Date: drh 2017-02-17 21:23:25.595
Context
2017-02-17
21:23
Increase the estimated cost of sorting when sorting wide results sets, to account for the extra storage space and I/O required for the external sort. (Leaf check-in: 38298ef923 user: drh tags: apple-increased-sorting-cost)
2017-02-16
21:29
Increase the estimated cost of sorting when sorting wide results sets, to account for the extra storage space and I/O required for the external sort. (check-in: aa0703e5ce user: drh tags: increased-sorting-cost)
2016-11-17
14:02
When opening the *-shm file for a readonly database, try to open it in read-write mode before falling back to readonly. This is in case some other read/write connection within the same process uses the same file descriptor. (check-in: a07c581e88 user: dan tags: apple-osx)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/where.c.
3786
3787
3788
3789
3790
3791
3792










3793
3794
3795
3796
3797
3798
3799
  **
  ** The (Y/X) term is implemented using stack variable rScale
  ** below.  */
  LogEst rScale, rSortCost;
  assert( nOrderBy>0 && 66==sqlite3LogEst(100) );
  rScale = sqlite3LogEst((nOrderBy-nSorted)*100/nOrderBy) - 66;
  rSortCost = nRow + rScale + 16;











  /* Multiple by log(M) where M is the number of output rows.
  ** Use the LIMIT for M if it is smaller */
  if( (pWInfo->wctrlFlags & WHERE_USE_LIMIT)!=0 && pWInfo->iLimit<nRow ){
    nRow = pWInfo->iLimit;
  }
  rSortCost += estLog(nRow);







>
>
>
>
>
>
>
>
>
>







3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
  **
  ** The (Y/X) term is implemented using stack variable rScale
  ** below.  */
  LogEst rScale, rSortCost;
  assert( nOrderBy>0 && 66==sqlite3LogEst(100) );
  rScale = sqlite3LogEst((nOrderBy-nSorted)*100/nOrderBy) - 66;
  rSortCost = nRow + rScale + 16;

  /* For wide sorts (many payload columns) increase the sorting cost
  ** to account for the additional I/O used by the external sorting
  ** algorithm when it flushes PMAs to disk.
  */
  if( pWInfo->pDistinctSet
   && pWInfo->pDistinctSet->nExpr>6
  ){
    rSortCost += sqlite3LogEst(pWInfo->pDistinctSet->nExpr) - 26;
  }

  /* Multiple by log(M) where M is the number of output rows.
  ** Use the LIMIT for M if it is smaller */
  if( (pWInfo->wctrlFlags & WHERE_USE_LIMIT)!=0 && pWInfo->iLimit<nRow ){
    nRow = pWInfo->iLimit;
  }
  rSortCost += estLog(nRow);