/ Check-in [20eeccf1]
Login

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

Overview
Comment:Minor problems in the high-speed NGQP fixed.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | nextgen-query-plan-fast
Files: files | file ages | folders
SHA1: 20eeccf1f24dd762f1bee9c3fe628c70ff01627f
User & Date: drh 2013-06-10 12:15:47
Context
2013-06-10
12:17
Add a high-speed bypass for the NGQP for the common case of a simply query with quality constraints that outputs a single row. check-in: 8d1ba309 user: drh tags: nextgen-query-plan-exp
12:15
Minor problems in the high-speed NGQP fixed. Closed-Leaf check-in: 20eeccf1 user: drh tags: nextgen-query-plan-fast
2013-06-09
17:21
High-speed version of NGQP. Still has some minor problems. check-in: db2415fa user: drh tags: nextgen-query-plan-fast
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  4276   4276       if( pExpr->iTable==iCursor ){
  4277   4277         if( pExpr->iColumn==iCol ) return 1;
  4278   4278         return 0;
  4279   4279       }
  4280   4280     }
  4281   4281     return 0;
  4282   4282   }
         4283  +
         4284  +/*
         4285  +** Return a bitmask where 1s indicate that the corresponding column of
         4286  +** the table is used by an index.  Only the first 63 columns are considered.
         4287  +*/
         4288  +static Bitmask columnsUsedByIndex(Index *pIdx){
         4289  +  Bitmask m = 0;
         4290  +  int j;
         4291  +  for(j=pIdx->nColumn-1; j>=0; j--){
         4292  +    int x = pIdx->aiColumn[j];
         4293  +    if( x<BMS-1 ) m |= MASKBIT(x);
         4294  +  }
         4295  +  return m;
         4296  +}
         4297  +
  4283   4298   
  4284   4299   /*
  4285   4300   ** Add all WhereLoop objects a single table of the join were the table
  4286   4301   ** is idenfied by pBuilder->pNew->iTab.  That table is guaranteed to be
  4287   4302   ** a b-tree table, not a virtual table.
  4288   4303   */
  4289   4304   static int whereLoopAddBtree(
................................................................................
  4384   4399         /* Full table scan */
  4385   4400         pNew->iSortIdx = b ? iSortIdx : 0;
  4386   4401         pNew->nOut = rSize;
  4387   4402         pNew->rRun = (rSize + rLogSize)*(3+b); /* 4x penalty for a full-scan */
  4388   4403         rc = whereLoopInsert(pBuilder, pNew);
  4389   4404         if( rc ) break;
  4390   4405       }else{
  4391         -      Bitmask m = pSrc->colUsed;
  4392         -      int j;
  4393         -      for(j=pProbe->nColumn-1; j>=0; j--){
  4394         -        int x = pProbe->aiColumn[j];
  4395         -        if( x<BMS-1 ){
  4396         -          m &= ~MASKBIT(x);
  4397         -        }
  4398         -      }
         4406  +      Bitmask m = pSrc->colUsed & ~columnsUsedByIndex(pProbe);
  4399   4407         pNew->wsFlags = (m==0) ? (WHERE_IDX_ONLY|WHERE_INDEXED) : WHERE_INDEXED;
  4400   4408   
  4401   4409         /* Full scan via index */
  4402   4410         if( (m==0 || b)
  4403   4411          && pProbe->bUnordered==0
  4404   4412          && (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0
  4405   4413          && sqlite3GlobalConfig.bUseCis
................................................................................
  5182   5190   static int whereSimpleFastCase(WhereLoopBuilder *pBuilder){
  5183   5191     WhereInfo *pWInfo;
  5184   5192     struct SrcList_item *pItem;
  5185   5193     WhereClause *pWC;
  5186   5194     WhereTerm *pTerm;
  5187   5195     WhereLoop *pLoop;
  5188   5196     int iCur;
  5189         -  int i, j;
         5197  +  int j;
  5190   5198     int nOrderBy;
  5191   5199     Table *pTab;
  5192   5200     Index *pIdx;
  5193   5201     
  5194   5202     pWInfo = pBuilder->pWInfo;
  5195   5203     assert( pWInfo->pTabList->nSrc>=1 );
  5196   5204     pItem = pWInfo->pTabList->a;
................................................................................
  5198   5206     if( IsVirtual(pTab) ) return 0;
  5199   5207     if( pItem->zIndex ) return 0;
  5200   5208     iCur = pItem->iCursor;
  5201   5209     pWC = &pWInfo->sWC;
  5202   5210     pLoop = pBuilder->pNew;
  5203   5211     pWInfo->a[0].pWLoop = pLoop;
  5204   5212     pLoop->wsFlags = 0;
         5213  +  pLoop->maskSelf = getMask(&pWInfo->sMaskSet, iCur);
         5214  +  pWInfo->a[0].iTabCur = iCur;
         5215  +#ifdef SQLITE_DEBUG
         5216  +  pLoop->cId = '0';
         5217  +#endif
  5205   5218     nOrderBy = pWInfo->pOrderBy ? pWInfo->pOrderBy->nExpr : 0;
  5206   5219     pTerm = findTerm(pWC, iCur, -1, 1, WO_EQ, 0);
  5207   5220     if( pTerm ){
  5208   5221       pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW;
  5209   5222       pLoop->aLTerm[0] = pTerm;
  5210   5223       pLoop->nLTerm = 1;
  5211   5224       pLoop->u.btree.nEq = 1;
................................................................................
  5219   5232         for(j=0; j<pIdx->nColumn; j++){
  5220   5233           pTerm = findTerm(pWC, iCur, pIdx->aiColumn[j], 1, WO_EQ, pIdx);
  5221   5234           if( pTerm==0 ) break;
  5222   5235           whereLoopResize(pWInfo->pParse->db, pLoop, j);
  5223   5236           pLoop->aLTerm[j] = pTerm;
  5224   5237         }
  5225   5238         if( j!=pIdx->nColumn ) continue;
  5226         -      pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_ONEROW;
         5239  +      pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_ONEROW|WHERE_INDEXED;
         5240  +      if( (pItem->colUsed & ~columnsUsedByIndex(pIdx))==0 ){
         5241  +        pLoop->wsFlags |= WHERE_IDX_ONLY;
         5242  +      }
  5227   5243         pLoop->nLTerm = j;
  5228   5244         pLoop->u.btree.nEq = j;
  5229   5245         pLoop->u.btree.pIndex = pIdx;
  5230   5246         pLoop->rRun = (WhereCost)15;
  5231   5247         pLoop->nOut = (WhereCost)1;
  5232   5248         pWInfo->nRowOut = 1;
  5233   5249         pWInfo->nOBSat = nOrderBy;