/ Check-in [ba2f492f]
Login

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

Overview
Comment:Fix an out-of-order memset() that occurs before all variable declarations are finished. Also fix a line that exceeds the 80-character line length limit.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ba2f492f957ab5556cd540e21a76ebb75efea725
User & Date: drh 2012-10-03 18:09:32
Context
2012-10-05
07:36
Rename a tool batch file subroutine to avoid confusion about its purpose. check-in: 43155b15 user: mistachkin tags: trunk
2012-10-04
19:33
Shared-cache mode fixes for views and virtual tables. check-in: 2b370dea user: dan tags: shared-cache-fix
12:10
Yet another refactoring of ORDER BY logic in the query planner. This particular check-in works mostly, but still has a few minor issues. check-in: 8f448745 user: drh tags: qp-enhancements
2012-10-03
20:25
Merge updates from trunk. check-in: 1138815c user: mistachkin tags: configReadOnly
18:09
Fix an out-of-order memset() that occurs before all variable declarations are finished. Also fix a line that exceeds the 80-character line length limit. check-in: ba2f492f user: drh tags: trunk
12:56
Update the query planner to recognize more cases where ORDER BY clauses can be optimized out. Add test cases to verify correct behavior of the ORDER BY optimization when the covering-index-scan optimization is disabled. Fix a harmless compiler warning in the TCL interface. check-in: 956e4d7f user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  3063   3063     /* Loop over all indices looking for the best one to use
  3064   3064     */
  3065   3065     for(; pProbe; pIdx=pProbe=pProbe->pNext){
  3066   3066       const tRowcnt * const aiRowEst = pProbe->aiRowEst;
  3067   3067       WhereCost pc;               /* Cost of using pProbe */
  3068   3068       double log10N = (double)1;  /* base-10 logarithm of nRow (inexact) */
  3069   3069       int bRev = 2;               /* 0=forward scan.  1=reverse.  2=undecided */
  3070         -    memset(&pc, 0, sizeof(pc));
  3071   3070   
  3072   3071       /* The following variables are populated based on the properties of
  3073   3072       ** index being evaluated. They are then used to determine the expected
  3074   3073       ** cost and number of rows returned.
  3075   3074       **
  3076   3075       **  pc.plan.nEq: 
  3077   3076       **    Number of equality terms that can be implemented using the index.
................................................................................
  3150   3149       int nPriorSat;                /* ORDER BY terms satisfied by outer loops */
  3151   3150       int nOrderBy;                 /* Number of ORDER BY terms */
  3152   3151       WhereTerm *pTerm;             /* A single term of the WHERE clause */
  3153   3152   #ifdef SQLITE_ENABLE_STAT3
  3154   3153       WhereTerm *pFirstTerm = 0;    /* First term matching the index */
  3155   3154   #endif
  3156   3155   
         3156  +    memset(&pc, 0, sizeof(pc));
  3157   3157       nOrderBy = p->pOrderBy ? p->pOrderBy->nExpr : 0;
  3158   3158       if( p->i ){
  3159   3159         nPriorSat = pc.plan.nOBSat = p->aLevel[p->i-1].plan.nOBSat;
  3160   3160         bSort = nPriorSat<nOrderBy;
  3161   3161         bDist = 0;
  3162   3162       }else{
  3163   3163         nPriorSat = pc.plan.nOBSat = 0;
................................................................................
  3182   3182           }else if( ALWAYS(pExpr->x.pList && pExpr->x.pList->nExpr) ){
  3183   3183             /* "x IN (value, value, ...)" */
  3184   3184             nInMul *= pExpr->x.pList->nExpr;
  3185   3185           }
  3186   3186         }else if( pTerm->eOperator & WO_ISNULL ){
  3187   3187           pc.plan.wsFlags |= WHERE_COLUMN_NULL;
  3188   3188           if( pc.plan.nEq==nOrdered ) nOrdered++;
  3189         -      }else if( bSort && pc.plan.nEq==nOrdered && isOrderedTerm(p, pTerm, &bRev) ){
         3189  +      }else if( bSort && pc.plan.nEq==nOrdered
         3190  +             && isOrderedTerm(p,pTerm,&bRev) ){
  3190   3191           nOrdered++;
  3191   3192         }
  3192   3193   #ifdef SQLITE_ENABLE_STAT3
  3193   3194         if( pc.plan.nEq==0 && pProbe->aSample ) pFirstTerm = pTerm;
  3194   3195   #endif
  3195   3196         pc.used |= pTerm->prereqRight;
  3196   3197       }