SQLite

Check-in [33b1f584ef]
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
Timelines: family | ancestors | descendants | both | wal
Files: files | file ages | folders
SHA1: 33b1f584ef712625c4df8e2aefe895fa89f6a795
User & Date: drh 2010-04-15 12:36:07.000
References
2010-04-15
13:29
The query planner fix of check-in [33b1f584ef] should have been on the trunk. (check-in: f538d759be user: drh tags: trunk)
Context
2010-04-15
13:33
Merge two leaves on the WAL branch. (check-in: c9ed66cc39 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: 33b1f584ef user: drh tags: wal)
02:37
Bring over the recent query planner enhancements from the trunk. (check-in: 82969f27e5 user: drh tags: wal)
Changes
Unified Diff Show Whitespace Changes Patch
Changes to src/where.c.
2733
2734
2735
2736
2737
2738
2739









2740
2741
2742
2743
2744


2745
2746
2747
2748
2749
2750
2751
2752

    /* If there are additional constraints on this table that cannot
    ** be used with the current index, but which might lower the number
    ** of output rows, adjust the nRow value accordingly.  This only 
    ** matters if the current index is the least costly, so do not bother
    ** with this step if we already know this index will not be chosen.
    ** Also, never reduce the output row count below 2 using this step.









    */
    if( nRow>2 && cost<=pCost->rCost ){
      int k;
      int nSkipEq = nEq;
      int nSkipRange = nBound;


      Bitmask thisTab = getMask(pWC->pMaskSet, iCur);
      for(pTerm=pWC->a, k=pWC->nTerm; nRow>2 && k; k--, pTerm++){
        if( pTerm->wtFlags & TERM_VIRTUAL ) continue;
        if( (pTerm->prereqAll & notReady)!=thisTab ) continue;
        if( pTerm->eOperator & (WO_EQ|WO_IN|WO_ISNULL) ){
          if( nSkipEq ){
            /* Ignore the first nEq equality matches since the index
            ** has already accounted for these */







>
>
>
>
>
>
>
>
>

|
|
|
|
>
>
|







2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763

    /* If there are additional constraints on this table that cannot
    ** be used with the current index, but which might lower the number
    ** of output rows, adjust the nRow value accordingly.  This only 
    ** matters if the current index is the least costly, so do not bother
    ** with this step if we already know this index will not be chosen.
    ** Also, never reduce the output row count below 2 using this step.
    **
    ** Do not reduce the output row count if pSrc is the only table that
    ** is notReady; if notReady is a power of two.  This will be the case
    ** when the main sqlite3WhereBegin() loop is scanning for a table with
    ** and "optimal" index, and on such a scan the output row count
    ** reduction is not valid because it does not update the "pCost->used"
    ** bitmap.  The notReady bitmap will also be a power of two when we
    ** are scanning for the last table in a 64-way join.  We are willing
    ** to bypass this optimization in that corner case.
    */
    if( nRow>2 && cost<=pCost->rCost && (notReady & (notReady-1))!=0 ){
      int k;                       /* Loop counter */
      int nSkipEq = nEq;           /* Number of == constraints to skip */
      int nSkipRange = nBound;     /* Number of < constraints to skip */
      Bitmask thisTab;             /* Bitmap for pSrc */

      thisTab = getMask(pWC->pMaskSet, iCur);
      for(pTerm=pWC->a, k=pWC->nTerm; nRow>2 && k; k--, pTerm++){
        if( pTerm->wtFlags & TERM_VIRTUAL ) continue;
        if( (pTerm->prereqAll & notReady)!=thisTab ) continue;
        if( pTerm->eOperator & (WO_EQ|WO_IN|WO_ISNULL) ){
          if( nSkipEq ){
            /* Ignore the first nEq equality matches since the index
            ** has already accounted for these */