/ Check-in [02741d17]
Login

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

Overview
Comment:Further prepare-time performance improvements.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | nextgen-query-plan-exp
Files: files | file ages | folders
SHA1: 02741d177bfc2fca23bc99974cd899eba13cb59a
User & Date: drh 2013-06-07 00:29:23
Context
2013-06-07
02:04
Must faster computation of estimated logarithm. check-in: dfbca3ac user: drh tags: nextgen-query-plan-exp
00:29
Further prepare-time performance improvements. check-in: 02741d17 user: drh tags: nextgen-query-plan-exp
2013-06-06
23:44
Performance improvements. check-in: 9f8e84ab user: drh tags: nextgen-query-plan-exp
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

    95     95     Bitmask prereq;       /* Bitmask of other loops that must run first */
    96     96     Bitmask maskSelf;     /* Bitmask identifying table iTab */
    97     97   #ifdef SQLITE_DEBUG
    98     98     char cId;             /* Symbolic ID of this loop for debugging use */
    99     99   #endif
   100    100     u8 iTab;              /* Position in FROM clause of table for this loop */
   101    101     u8 iSortIdx;          /* Sorting index number.  0==None */
   102         -  u16 nLTerm;           /* Number of entries in aLTerm[] */
   103         -  u16 nLSlot;           /* Number of slots allocated for aLTerm[] */
   104         -  u32 wsFlags;          /* WHERE_* flags describing the plan */
   105    102     WhereCost rSetup;     /* One-time setup cost (ex: create transient index) */
   106    103     WhereCost rRun;       /* Cost of running each loop */
   107    104     WhereCost nOut;       /* Estimated number of output rows */
   108    105     union {
   109    106       struct {               /* Information for internal btree tables */
   110    107         int nEq;               /* Number of equality constraints */
   111    108         Index *pIndex;         /* Index used, or NULL */
................................................................................
   114    111         int idxNum;            /* Index number */
   115    112         u8 needFree;           /* True if sqlite3_free(idxStr) is needed */
   116    113         u8 isOrdered;          /* True if satisfies ORDER BY */
   117    114         u16 omitMask;          /* Terms that may be omitted */
   118    115         char *idxStr;          /* Index identifier string */
   119    116       } vtab;
   120    117     } u;
          118  +  u32 wsFlags;          /* WHERE_* flags describing the plan */
          119  +  u16 nLTerm;           /* Number of entries in aLTerm[] */
          120  +  /**** whereLoopXfer() copies fields above ***********************/
          121  +# define WHERE_LOOP_XFER_SZ offsetof(WhereLoop,nLSlot)
          122  +  u16 nLSlot;           /* Number of slots allocated for aLTerm[] */
   121    123     WhereTerm **aLTerm;   /* WhereTerms used */
   122    124     WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
   123    125     WhereTerm *aLTermSpace[4];  /* Initial aLTerm[] space */
   124    126   };
   125    127   
   126    128   /* Forward declaration of methods */
   127    129   static int whereLoopResize(sqlite3*, WhereLoop*, int);
................................................................................
  3923   3925   
  3924   3926   /*
  3925   3927   ** Transfer content from the second pLoop into the first.
  3926   3928   */
  3927   3929   static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
  3928   3930     if( whereLoopResize(db, pTo, pFrom->nLTerm) ) return SQLITE_NOMEM;
  3929   3931     whereLoopClearUnion(db, pTo);
  3930         -  pTo->prereq = pFrom->prereq;
  3931         -  pTo->maskSelf = pFrom->maskSelf;
  3932         -  pTo->iTab = pFrom->iTab;
  3933         -  pTo->iSortIdx = pFrom->iSortIdx;
  3934         -  pTo->nLTerm = pFrom->nLTerm;
  3935         -  pTo->rSetup = pFrom->rSetup;
  3936         -  pTo->rRun = pFrom->rRun;
  3937         -  pTo->nOut = pFrom->nOut;
  3938         -  if( pTo->nLTerm ){
  3939         -    memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
  3940         -  }
  3941         -  pTo->wsFlags = pFrom->wsFlags;
  3942         -  pTo->u = pFrom->u;
         3932  +  memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
         3933  +  memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
  3943   3934     if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){
  3944   3935       pFrom->u.vtab.needFree = 0;
  3945   3936     }else if( (pFrom->wsFlags & WHERE_TEMP_INDEX)!=0 ){
  3946   3937       pFrom->u.btree.pIndex = 0;
  3947   3938     }
  3948   3939     return SQLITE_OK;
  3949   3940   }
................................................................................
  4681   4672     Bitmask mPrior = 0;
  4682   4673     int iTab;
  4683   4674     SrcList *pTabList = pWInfo->pTabList;
  4684   4675     struct SrcList_item *pItem;
  4685   4676     sqlite3 *db = pWInfo->pParse->db;
  4686   4677     int nTabList = pWInfo->nLevel;
  4687   4678     int rc = SQLITE_OK;
  4688         -  WhereLoop *pNew;
         4679  +  WhereLoop *pNew, sNew;
  4689   4680   
  4690   4681     /* Loop over the tables in the join, from left to right */
  4691         -  pBuilder->pNew = pNew = sqlite3DbMallocZero(db, sizeof(WhereLoop));
  4692         -  if( pNew==0 ) return SQLITE_NOMEM;
  4693         -  pNew->aLTerm = pNew->aLTermSpace;
  4694         -  pNew->nLSlot = ArraySize(pNew->aLTermSpace);
         4682  +  pBuilder->pNew = pNew = &sNew;
         4683  +  whereLoopInit(pNew);
  4695   4684     for(iTab=0, pItem=pTabList->a; iTab<nTabList; iTab++, pItem++){
  4696   4685       pNew->iTab = iTab;
  4697   4686       pNew->maskSelf = getMask(&pWInfo->sMaskSet, pItem->iCursor);
  4698   4687       if( (pItem->jointype & (JT_LEFT|JT_CROSS))!=0 ){
  4699   4688         mExtra = mPrior;
  4700   4689       }
  4701   4690       if( IsVirtual(pItem->pTab) ){
................................................................................
  4705   4694       }
  4706   4695       if( rc==SQLITE_OK ){
  4707   4696         rc = whereLoopAddOr(pBuilder, mExtra);
  4708   4697       }
  4709   4698       mPrior |= pNew->maskSelf;
  4710   4699       if( rc || db->mallocFailed ) break;
  4711   4700     }
  4712         -  whereLoopDelete(db, pBuilder->pNew);
         4701  +  whereLoopClear(db, pNew);
  4713   4702     pBuilder->pNew = 0;
  4714   4703     return rc;
  4715   4704   }
  4716   4705   
  4717   4706   /*
  4718   4707   ** Examine a WherePath (with the addition of the extra WhereLoop of the 5th
  4719   4708   ** parameters) to see if it outputs rows in the requested ORDER BY