/ Check-in [33b1f584]
Login

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

Overview
Comment:Fix a problem in the result set size estimation logic of the query planner - a problem introduced by the two previous changes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wal
Files: files | file ages | folders
SHA1: 33b1f584ef712625c4df8e2aefe895fa89f6a795
User & Date: drh 2010-04-15 12:36:07
References
2010-04-15
13:29
The query planner fix of check-in [33b1f584ef] should have been on the trunk. check-in: f538d759 user: drh tags: trunk
Context
2010-04-15
13:33
Merge two leaves on the WAL branch. check-in: c9ed66cc user: dan tags: wal
12:36
Fix a problem in the result set size estimation logic of the query planner - a problem introduced by the two previous changes. check-in: 33b1f584 user: drh tags: wal
02:37
Bring over the recent query planner enhancements from the trunk. check-in: 82969f27 user: drh tags: wal
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  2733   2733   
  2734   2734       /* If there are additional constraints on this table that cannot
  2735   2735       ** be used with the current index, but which might lower the number
  2736   2736       ** of output rows, adjust the nRow value accordingly.  This only 
  2737   2737       ** matters if the current index is the least costly, so do not bother
  2738   2738       ** with this step if we already know this index will not be chosen.
  2739   2739       ** Also, never reduce the output row count below 2 using this step.
         2740  +    **
         2741  +    ** Do not reduce the output row count if pSrc is the only table that
         2742  +    ** is notReady; if notReady is a power of two.  This will be the case
         2743  +    ** when the main sqlite3WhereBegin() loop is scanning for a table with
         2744  +    ** and "optimal" index, and on such a scan the output row count
         2745  +    ** reduction is not valid because it does not update the "pCost->used"
         2746  +    ** bitmap.  The notReady bitmap will also be a power of two when we
         2747  +    ** are scanning for the last table in a 64-way join.  We are willing
         2748  +    ** to bypass this optimization in that corner case.
  2740   2749       */
  2741         -    if( nRow>2 && cost<=pCost->rCost ){
  2742         -      int k;
  2743         -      int nSkipEq = nEq;
  2744         -      int nSkipRange = nBound;
  2745         -      Bitmask thisTab = getMask(pWC->pMaskSet, iCur);
         2750  +    if( nRow>2 && cost<=pCost->rCost && (notReady & (notReady-1))!=0 ){
         2751  +      int k;                       /* Loop counter */
         2752  +      int nSkipEq = nEq;           /* Number of == constraints to skip */
         2753  +      int nSkipRange = nBound;     /* Number of < constraints to skip */
         2754  +      Bitmask thisTab;             /* Bitmap for pSrc */
         2755  +
         2756  +      thisTab = getMask(pWC->pMaskSet, iCur);
  2746   2757         for(pTerm=pWC->a, k=pWC->nTerm; nRow>2 && k; k--, pTerm++){
  2747   2758           if( pTerm->wtFlags & TERM_VIRTUAL ) continue;
  2748   2759           if( (pTerm->prereqAll & notReady)!=thisTab ) continue;
  2749   2760           if( pTerm->eOperator & (WO_EQ|WO_IN|WO_ISNULL) ){
  2750   2761             if( nSkipEq ){
  2751   2762               /* Ignore the first nEq equality matches since the index
  2752   2763               ** has already accounted for these */