/ Check-in [8b2eb7a4]
Login

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

Overview
Comment:Revised fix for the DESC ORDER BY and IN constraint bug, ticket [4dd95f6943fbd18]. The previous check-in was incorrect.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | desc-orderby-fix-1
Files: files | file ages | folders
SHA1: 8b2eb7a43b4580f04c14ea8600cf080e0e7f384d
User & Date: drh 2013-03-12 18:40:20
Context
2013-03-12
18:44
Add test cases for [4dd95f6943]. check-in: 723c144c user: dan tags: desc-orderby-fix-1
18:40
Revised fix for the DESC ORDER BY and IN constraint bug, ticket [4dd95f6943fbd18]. The previous check-in was incorrect. check-in: 8b2eb7a4 user: drh tags: desc-orderby-fix-1
18:34
A proposed fix for the DESC ORDER BY bug of ticket [4dd95f6943fbd18]. Seems to work, but lots more testing is needed prior to moving to trunk. check-in: 614a038a user: drh tags: desc-orderby-fix-1
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/sqliteInt.h.

  1927   1927   ** is only used when wsFlags&WHERE_VIRTUALTABLE is true.  It is never the
  1928   1928   ** case that more than one of these conditions is true.
  1929   1929   */
  1930   1930   struct WherePlan {
  1931   1931     u32 wsFlags;                   /* WHERE_* flags that describe the strategy */
  1932   1932     u16 nEq;                       /* Number of == constraints */
  1933   1933     u16 nOBSat;                    /* Number of ORDER BY terms satisfied */
  1934         -  u16 iOBSat;                    /* First ORDER BY term satisfied */
  1935   1934     double nRow;                   /* Estimated number of rows (for EQP) */
  1936   1935     union {
  1937   1936       Index *pIdx;                   /* Index when WHERE_INDEXED is true */
  1938   1937       struct WhereTerm *pTerm;       /* WHERE clause term for OR-search */
  1939   1938       sqlite3_index_info *pVtabIdx;  /* Virtual table index to use */
  1940   1939     } u;
  1941   1940   };

Changes to src/where.c.

  1830   1830         ** of pCost. */
  1831   1831         WHERETRACE(("... multi-index OR cost=%.9g nrow=%.9g\n", rTotal, nRow));
  1832   1832         if( rTotal<p->cost.rCost ){
  1833   1833           p->cost.rCost = rTotal;
  1834   1834           p->cost.used = used;
  1835   1835           p->cost.plan.nRow = nRow;
  1836   1836           p->cost.plan.nOBSat = p->i ? p->aLevel[p->i-1].plan.nOBSat : 0;
  1837         -        p->cost.plan.iOBSat = p->cost.plan.nOBSat;
  1838   1837           p->cost.plan.wsFlags = flags;
  1839   1838           p->cost.plan.u.pTerm = pTerm;
  1840   1839         }
  1841   1840       }
  1842   1841     }
  1843   1842   #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
  1844   1843   }
................................................................................
  3794   3793     }else{
  3795   3794       int eType;
  3796   3795       int iTab;
  3797   3796       struct InLoop *pIn;
  3798   3797       u8 bRev;
  3799   3798   
  3800   3799       if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
  3801         -      Index *pIdx = pLevel->plan.u.pIdx;
  3802         -      bRev = pIdx->aSortOrder[iEq+pLevel->plan.iOBSat];
         3800  +      bRev = pLevel->plan.u.pIdx->aSortOrder[iEq];
  3803   3801       }else{
  3804   3802         bRev = 0;
  3805   3803       }
  3806   3804       if( pLevel->plan.wsFlags & WHERE_REVERSE ) bRev = 1 - bRev;
  3807   3805       assert( pX->op==TK_IN );
  3808   3806       iReg = iTarget;
  3809   3807       eType = sqlite3FindInIndex(pParse, pX, 0);