/ Check-in [a51d8c92]
Login

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

Overview
Comment:Incremental check-in with various NGQP fixes. Many tests still fail.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | nextgen-query-plan-exp
Files: files | file ages | folders
SHA1: a51d8c92496436488e1a6eabd85785e8fedf2736
User & Date: drh 2013-05-30 22:27:09
Context
2013-05-30
23:21
Improvements to the ORDER BY suppressor in the NGQP. check-in: 24a2e9dd user: drh tags: nextgen-query-plan-exp
22:27
Incremental check-in with various NGQP fixes. Many tests still fail. check-in: a51d8c92 user: drh tags: nextgen-query-plan-exp
19:29
Futher simplifications to the NGQP. Fix some test cases to use EXPLAIN QUERY PLAN rather than the (now obsolete) sqlite_query_plan global variable. check-in: ae985db4 user: drh tags: nextgen-query-plan-exp
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  3179   3179       if( testOp!=OP_Noop ){
  3180   3180         iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
  3181   3181         sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
  3182   3182         sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
  3183   3183         sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
  3184   3184         sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
  3185   3185       }
  3186         -  }else if( pLoop->wsFlags & (WHERE_COLUMN_RANGE | WHERE_COLUMN_NULL |
  3187         -                              WHERE_COLUMN_EQ | WHERE_IDX_ONLY) ){
         3186  +  }else if( pLoop->wsFlags & WHERE_INDEXED ){
  3188   3187       /* Case 4: A scan using an index.
  3189   3188       **
  3190   3189       **         The WHERE clause may contain zero or more equality 
  3191   3190       **         terms ("==" or "IN" operators) that refer to the N
  3192   3191       **         left-most columns of the index. It may also contain
  3193   3192       **         inequality constraints (>, <, >= or <=) on the indexed
  3194   3193       **         column that immediately follows the N equalities. Only 
................................................................................
  3421   3420         pLevel->op = OP_Noop;
  3422   3421       }else if( bRev ){
  3423   3422         pLevel->op = OP_Prev;
  3424   3423       }else{
  3425   3424         pLevel->op = OP_Next;
  3426   3425       }
  3427   3426       pLevel->p1 = iIdxCur;
  3428         -    if( pLoop->wsFlags & WHERE_COVER_SCAN ){
         3427  +    if( (pLoop->wsFlags & (WHERE_COLUMN_EQ | WHERE_COLUMN_RANGE | 
         3428  +                          WHERE_COLUMN_NULL | WHERE_COLUMN_IN))==0 ){
  3429   3429         pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
  3430   3430       }else{
  3431   3431         assert( pLevel->p5==0 );
  3432   3432       }
  3433   3433     }else
  3434   3434   
  3435   3435   #ifndef SQLITE_OMIT_OR_OPTIMIZATION
................................................................................
  3871   3871     }
  3872   3872   
  3873   3873     /* Search for an existing WhereLoop to overwrite, or which takes
  3874   3874     ** priority over pTemplate.
  3875   3875     */
  3876   3876     for(ppPrev=&pWInfo->pLoops, p=*ppPrev; p; ppPrev=&p->pNextLoop, p=*ppPrev){
  3877   3877       if( p->iTab!=pTemplate->iTab || p->iSortIdx!=pTemplate->iSortIdx ) continue;
         3878  +    if( p->nTerm<pTemplate->nTerm
         3879  +     && (p->wsFlags & WHERE_INDEXED)!=0
         3880  +     && (pTemplate->wsFlags & WHERE_INDEXED)!=0
         3881  +     && p->u.btree.pIndex==pTemplate->u.btree.pIndex
         3882  +     && p->prereq==pTemplate->prereq
         3883  +    ){
         3884  +      /* Overwrite an existing WhereLoop with an similar one that uses
         3885  +      ** more terms of the index */
         3886  +      pNext = p->pNextLoop;
         3887  +      whereLoopClear(db, p);
         3888  +      break;
         3889  +    }
  3878   3890       if( (p->prereq & pTemplate->prereq)==p->prereq
  3879   3891        && p->rSetup<=pTemplate->rSetup
  3880   3892        && p->rRun<=pTemplate->rRun
  3881   3893       ){
  3882   3894         /* Already holding an equal or better WhereLoop.
  3883   3895         ** Return without changing or adding anything */
  3884   3896         return SQLITE_OK;
................................................................................
  4586   4598           revIdx = pIndex->aSortOrder[j];
  4587   4599           if( iColumn==pIndex->pTable->iPKey ) iColumn = -1;
  4588   4600         }else{
  4589   4601           /* The ROWID column at the end */
  4590   4602           iColumn = -1;
  4591   4603           revIdx = 0;
  4592   4604         }
  4593         -      if( pOBExpr->iColumn!=iColumn ) return 0;
         4605  +      if( pOBExpr->iColumn!=iColumn ){
         4606  +        if( j<pLoop->u.btree.nEq ){ nUsed--; continue; }
         4607  +        return 0;
         4608  +      }
  4594   4609         if( iColumn>=0 ){
  4595   4610           pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[nUsed].pExpr);
  4596   4611           if( !pColl ) pColl = db->pDfltColl;
  4597   4612           if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) return 0;
  4598   4613         }
  4599   4614         if( revSet ){
  4600   4615           if( (rev ^ revIdx)!=pOrderBy->a[nUsed].sortOrder ) return 0;