/ Check-in [9b1c4954]
Login

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

Overview
Comment:Performance improvement for the OR-clause analysis in the NGQP.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | nextgen-query-plan-exp
Files: files | file ages | folders
SHA1: 9b1c4954e468d0acfb5787e6bff56d50a3e7bc1a
User & Date: drh 2013-06-05 17:53:43
Context
2013-06-05
23:39
Move the definitions of the WhereLevel and WhereInfo objects out of sqliteInt.h and into where.c. This will facilitate future refactoring of the internal query planner data structures. check-in: 1574653b user: drh tags: nextgen-query-plan-exp
17:53
Performance improvement for the OR-clause analysis in the NGQP. check-in: 9b1c4954 user: drh tags: nextgen-query-plan-exp
16:19
Minor performance tuning of the NGQP. check-in: cbef38c2 user: drh tags: nextgen-query-plan-exp
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  4426   4426     struct SrcList_item *pItem;
  4427   4427     
  4428   4428   
  4429   4429     pWC = pBuilder->pWC;
  4430   4430     if( pWC->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK;
  4431   4431     pWCEnd = pWC->a + pWC->nTerm;
  4432   4432     pNew = pBuilder->pNew;
  4433         -  pItem = pBuilder->pTabList->a + pNew->iTab;
  4434         -  iCur = pItem->iCursor;
  4435         -  sSubBuild = *pBuilder;
  4436         -  sSubBuild.pOrderBy = 0;
  4437         -  sSubBuild.pBest = &sBest;
  4438         -  tempWC.pParse = pWC->pParse;
  4439         -  tempWC.pMaskSet = pWC->pMaskSet;
  4440         -  tempWC.pOuter = pWC;
  4441         -  tempWC.op = TK_AND;
  4442         -  tempWC.wctrlFlags = 0;
  4443         -  tempWC.nTerm = 1;
  4444   4433   
  4445   4434     for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){
  4446   4435       if( (pTerm->eOperator & WO_OR)!=0
  4447   4436        && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0 
  4448   4437       ){
  4449   4438         WhereClause * const pOrWC = &pTerm->u.pOrInfo->wc;
  4450   4439         WhereTerm * const pOrWCEnd = &pOrWC->a[pOrWC->nTerm];
  4451   4440         WhereTerm *pOrTerm;
  4452   4441         double rTotal = 0;
  4453   4442         double nRow = 0;
  4454   4443         Bitmask prereq = mExtra;
  4455         -
         4444  +    
         4445  +      pItem = pBuilder->pTabList->a + pNew->iTab;
         4446  +      iCur = pItem->iCursor;
         4447  +      sSubBuild = *pBuilder;
         4448  +      sSubBuild.pOrderBy = 0;
         4449  +      sSubBuild.pBest = &sBest;
  4456   4450   
  4457   4451         for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){
  4458         -        if( (pOrTerm->eOperator& WO_AND)!=0 ){
         4452  +        if( (pOrTerm->eOperator & WO_AND)!=0 ){
  4459   4453             sSubBuild.pWC = &pOrTerm->u.pAndInfo->wc;
  4460   4454           }else if( pOrTerm->leftCursor==iCur ){
         4455  +          tempWC.pParse = pWC->pParse;
         4456  +          tempWC.pMaskSet = pWC->pMaskSet;
         4457  +          tempWC.pOuter = pWC;
         4458  +          tempWC.op = TK_AND;
         4459  +          tempWC.wctrlFlags = 0;
         4460  +          tempWC.nTerm = 1;
  4461   4461             tempWC.a = pOrTerm;
  4462   4462             sSubBuild.pWC = &tempWC;
  4463   4463           }else{
  4464   4464             continue;
  4465   4465           }
  4466   4466           sBest.maskSelf = 0;
  4467   4467           if( IsVirtual(pItem->pTab) ){
................................................................................
  4783   4783   ** attempts to find the lowest cost path that visits each WhereLoop
  4784   4784   ** once.  This path is then loaded into the pWInfo->a[].pWLoop fields.
  4785   4785   **
  4786   4786   ** Return SQLITE_OK on success or SQLITE_NOMEM of a memory allocation
  4787   4787   ** error occurs.
  4788   4788   */
  4789   4789   static int wherePathSolver(WhereInfo *pWInfo, double nRowEst){
  4790         -  int mxChoice = 10;        /* Maximum number of simultaneous paths tracked */
         4790  +  int mxChoice;             /* Maximum number of simultaneous paths tracked */
  4791   4791     int nLoop;                /* Number of terms in the join */
  4792   4792     sqlite3 *db;              /* The database connection */
  4793   4793     int iLoop;                /* Loop counter over the terms of the join */
  4794   4794     int ii, jj;               /* Loop counters */
  4795   4795     double rCost;             /* Cost of a path */
  4796   4796     double mxCost;            /* Maximum cost of a set of paths */
  4797   4797     double rSortCost;         /* Cost to do a sort */