/ Check-in [cbef38c2]
Login

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

Overview
Comment:Minor performance tuning of the NGQP.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | nextgen-query-plan-exp
Files: files | file ages | folders
SHA1: cbef38c2d123e7d5a02c2a2450e8b329e3e96ee9
User & Date: drh 2013-06-05 16:19:59
Context
2013-06-05
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
12:47
Performance tweak to whereLoopInsert(). check-in: 1c4a7880 user: drh tags: nextgen-query-plan-exp
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/where.c.

   748    748     int iCur,               /* Cursor to scan for */
   749    749     int iColumn,            /* Column to scan for */
   750    750     u32 opMask,             /* Operator(s) to scan for */
   751    751     Index *pIdx             /* Must be compatible with this index */
   752    752   ){
   753    753     int j;
   754    754   
   755         -  memset(pScan, 0, sizeof(*pScan));
          755  +  /* memset(pScan, 0, sizeof(*pScan)); */
          756  +  pScan->pCurrent = 0;
   756    757     pScan->pOrigWC = pWC;
   757    758     pScan->pWC = pWC;
   758    759     if( pIdx && iColumn>=0 ){
   759    760       pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
   760    761       for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
   761    762         if( NEVER(j>=pIdx->nColumn) ) return 0;
   762    763       }
   763    764       pScan->zCollName = pIdx->azColl[j];
          765  +  }else{
          766  +    pScan->idxaff = 0;
          767  +    pScan->zCollName = 0;
   764    768     }
   765    769     pScan->opMask = opMask;
          770  +  pScan->k = 0;
   766    771     pScan->aEquiv[0] = iCur;
   767    772     pScan->aEquiv[1] = iColumn;
   768    773     pScan->nEquiv = 2;
   769    774     pScan->iEquiv = 2;
   770    775     return whereScanNext(pScan);
   771    776   }
   772    777   
................................................................................
  4778   4783   ** attempts to find the lowest cost path that visits each WhereLoop
  4779   4784   ** once.  This path is then loaded into the pWInfo->a[].pWLoop fields.
  4780   4785   **
  4781   4786   ** Return SQLITE_OK on success or SQLITE_NOMEM of a memory allocation
  4782   4787   ** error occurs.
  4783   4788   */
  4784   4789   static int wherePathSolver(WhereInfo *pWInfo, double nRowEst){
  4785         -  const int mxChoice = 10;  /* Maximum number of simultaneous paths tracked */
         4790  +  int mxChoice = 10;        /* Maximum number of simultaneous paths tracked */
  4786   4791     int nLoop;                /* Number of terms in the join */
  4787   4792     sqlite3 *db;              /* The database connection */
  4788   4793     int iLoop;                /* Loop counter over the terms of the join */
  4789   4794     int ii, jj;               /* Loop counters */
  4790   4795     double rCost;             /* Cost of a path */
  4791   4796     double mxCost;            /* Maximum cost of a set of paths */
  4792   4797     double rSortCost;         /* Cost to do a sort */
................................................................................
  4797   4802     WherePath *pTo;           /* An element of aTo[] that we are working on */
  4798   4803     WhereLoop *pWLoop;        /* One of the WhereLoop objects */
  4799   4804     WhereLoop **pX;           /* Used to divy up the pSpace memory */
  4800   4805     char *pSpace;             /* Temporary memory used by this routine */
  4801   4806   
  4802   4807     db = pWInfo->pParse->db;
  4803   4808     nLoop = pWInfo->nLevel;
         4809  +  mxChoice = (nLoop==1) ? 1 : (nLoop==2 ? 5 : 10);
  4804   4810     assert( nLoop<=pWInfo->pTabList->nSrc );
  4805   4811   #ifdef WHERETRACE_ENABLED
  4806   4812     if( sqlite3WhereTrace>=2 ) sqlite3DebugPrintf("---- begin solver\n");
  4807   4813   #endif
  4808   4814   
  4809   4815     /* Allocate and initialize space for aTo and aFrom */
  4810   4816     ii = (sizeof(WherePath)+sizeof(WhereLoop*)*nLoop)*mxChoice*2;
  4811   4817     pSpace = sqlite3DbMallocRaw(db, ii);
  4812   4818     if( pSpace==0 ) return SQLITE_NOMEM;
  4813   4819     aTo = (WherePath*)pSpace;
  4814   4820     aFrom = aTo+mxChoice;
  4815   4821     memset(aFrom, 0, sizeof(aFrom[0]));
  4816   4822     pX = (WhereLoop**)(aFrom+mxChoice);
  4817         -  for(ii=0, pFrom=aTo; ii<mxChoice*2; ii++, pFrom++, pX += nLoop){
         4823  +  for(ii=mxChoice*2, pFrom=aTo; ii>0; ii--, pFrom++, pX += nLoop){
  4818   4824       pFrom->aLoop = pX;
  4819   4825     }
  4820   4826   
  4821   4827     /* Seed the search with a single WherePath containing zero WhereLoops */
  4822   4828     aFrom[0].nRow = (double)1;
  4823   4829     nFrom = 1;
  4824   4830