/ Check-in [3ce7eb02]
Login

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

Overview
Comment:Revise the patch to make it easier to understand.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | desc-orderby-fix-1
Files: files | file ages | folders
SHA1: 3ce7eb0265b5be4e23264ae41332b947011ff1ad
User & Date: drh 2013-03-12 18:49:25
Context
2013-03-12
20:38
Fix the ORDER BY optimization with IN constraints when the RHS of the IN constraint is a descending index. check-in: 62316eba user: drh tags: desc-orderby-fix-1
18:49
Revise the patch to make it easier to understand. check-in: 3ce7eb02 user: drh tags: desc-orderby-fix-1
18:44
Add test cases for [4dd95f6943]. check-in: 723c144c user: dan tags: desc-orderby-fix-1
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  3790   3790       iReg = iTarget;
  3791   3791       sqlite3VdbeAddOp2(v, OP_Null, 0, iReg);
  3792   3792   #ifndef SQLITE_OMIT_SUBQUERY
  3793   3793     }else{
  3794   3794       int eType;
  3795   3795       int iTab;
  3796   3796       struct InLoop *pIn;
  3797         -    u8 bRev;
         3797  +    u8 bRev = (pLevel->plan.wsFlags & WHERE_REVERSE)!=0;
  3798   3798   
  3799         -    if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
  3800         -      bRev = pLevel->plan.u.pIdx->aSortOrder[iEq];
  3801         -    }else{
  3802         -      bRev = 0;
         3799  +    if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 
         3800  +      && pLevel->plan.u.pIdx->aSortOrder[iEq]
         3801  +    ){
         3802  +      bRev = 1 - bRev;
  3803   3803       }
  3804         -    if( pLevel->plan.wsFlags & WHERE_REVERSE ) bRev = 1 - bRev;
  3805   3804       assert( pX->op==TK_IN );
  3806   3805       iReg = iTarget;
  3807   3806       eType = sqlite3FindInIndex(pParse, pX, 0);
  3808   3807       iTab = pX->iTable;
  3809   3808       sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
  3810   3809       assert( pLevel->plan.wsFlags & WHERE_IN_ABLE );
  3811   3810       if( pLevel->u.in.nIn==0 ){