/ Check-in [4226e51f]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Augment the WhereBestIdx structure to pass down into the query planner information that might be used to better detect ORDER BY and DISTINCT optimizations spanning multiple tables of a join.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | qp-enhancements
Files: files | file ages | folders
SHA1: 4226e51ff837f0ffe16355491a655d919d13488e
User & Date: drh 2012-09-25 20:43:35
Context
2012-09-26
23:17
Further refactoring of the ORDER BY related query-planning logic in order to make it easier to extend to support optimizing out ORDER BY on joins. No actual behavior changes, yet. check-in: 96496dda user: drh tags: qp-enhancements
2012-09-25
20:43
Augment the WhereBestIdx structure to pass down into the query planner information that might be used to better detect ORDER BY and DISTINCT optimizations spanning multiple tables of a join. check-in: 4226e51f user: drh tags: qp-enhancements
14:29
Pass information around between the major routines of the query planner using a single pointer to a structure rather than a long list of parameters. check-in: 1104d42e user: drh tags: qp-enhancements
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

   280    280     WhereClause *pWC;               /* The WHERE clause */
   281    281     struct SrcList_item *pSrc;      /* The FROM clause term to search */
   282    282     Bitmask notReady;               /* Mask of cursors not available */
   283    283     Bitmask notValid;               /* Cursors not available for any purpose */
   284    284     ExprList *pOrderBy;             /* The ORDER BY clause */
   285    285     ExprList *pDistinct;            /* The select-list if query is DISTINCT */
   286    286     sqlite3_index_info **ppIdxInfo; /* Index information passed to xBestIndex */
          287  +  int i, n;                       /* Which loop is being coded; # of loops */
          288  +  WhereLevel *a;                  /* Info about outer loops */
   287    289     WhereCost cost;                 /* Lowest cost query plan */
   288    290   };
   289    291   
   290    292   /*
   291    293   ** Initialize a preallocated WhereClause structure.
   292    294   */
   293    295   static void whereClauseInit(
................................................................................
  3033   3035       **             SELECT a, b, c FROM tbl WHERE a = 1;
  3034   3036       */
  3035   3037       int nEq;                      /* Number of == or IN terms matching index */
  3036   3038       int bInEst = 0;               /* True if "x IN (SELECT...)" seen */
  3037   3039       int nInMul = 1;               /* Number of distinct equalities to lookup */
  3038   3040       double rangeDiv = (double)1;  /* Estimated reduction in search space */
  3039   3041       int nBound = 0;               /* Number of range constraints seen */
  3040         -    int bSort = !!p->pOrderBy;    /* True if external sort required */
  3041         -    int bDist = !!p->pDistinct;   /* True if index cannot help with DISTINCT */
         3042  +    int bSort;                    /* True if external sort required */
         3043  +    int bDist;                    /* True if index cannot help with DISTINCT */
  3042   3044       int bLookup = 0;              /* True if not a covering index */
  3043   3045       WhereTerm *pTerm;             /* A single term of the WHERE clause */
  3044   3046   #ifdef SQLITE_ENABLE_STAT3
  3045   3047       WhereTerm *pFirstTerm = 0;    /* First term matching the index */
  3046   3048   #endif
         3049  +
         3050  +    if( (p->i) > 0 ){
         3051  +      bSort = 0;
         3052  +      bDist = 0;
         3053  +    }else{
         3054  +      bSort = p->pOrderBy!=0;
         3055  +      bDist = p->pDistinct!=0;
         3056  +    }
  3047   3057   
  3048   3058       /* Determine the values of nEq and nInMul */
  3049   3059       for(nEq=0; nEq<pProbe->nColumn; nEq++){
  3050   3060         int j = pProbe->aiColumn[nEq];
  3051   3061         pTerm = findTerm(pWC, iCur, j, p->notReady, eqTermMask, pIdx);
  3052   3062         if( pTerm==0 ) break;
  3053   3063         wsFlags |= (WHERE_COLUMN_EQ|WHERE_ROWID_EQ);
................................................................................
  3110   3120         }
  3111   3121       }
  3112   3122   
  3113   3123       /* If there is an ORDER BY clause and the index being considered will
  3114   3124       ** naturally scan rows in the required order, set the appropriate flags
  3115   3125       ** in wsFlags. Otherwise, if there is an ORDER BY clause but the index
  3116   3126       ** will scan rows in a different order, set the bSort variable.  */
  3117         -    if( isSortingIndex(
         3127  +    if( bSort && isSortingIndex(
  3118   3128             pParse, pWC->pMaskSet, pProbe, iCur, p->pOrderBy, nEq, wsFlags, &rev)
  3119   3129       ){
  3120   3130         bSort = 0;
  3121   3131         wsFlags |= WHERE_ROWID_RANGE|WHERE_COLUMN_RANGE|WHERE_ORDERBY;
  3122   3132         wsFlags |= (rev ? WHERE_REVERSE : 0);
  3123   3133       }
  3124   3134   
  3125   3135       /* If there is a DISTINCT qualifier and this index will scan rows in
  3126   3136       ** order of the DISTINCT expressions, clear bDist and set the appropriate
  3127   3137       ** flags in wsFlags. */
  3128         -    if( isDistinctIndex(pParse, pWC, pProbe, iCur, p->pDistinct, nEq)
         3138  +    if( bDist
         3139  +     && isDistinctIndex(pParse, pWC, pProbe, iCur, p->pDistinct, nEq)
  3129   3140        && (wsFlags & WHERE_COLUMN_IN)==0
  3130   3141       ){
  3131   3142         bDist = 0;
  3132   3143         wsFlags |= WHERE_ROWID_RANGE|WHERE_COLUMN_RANGE|WHERE_DISTINCT;
  3133   3144       }
  3134   3145   
  3135   3146       /* If currently calculating the cost of using an index (not the IPK
................................................................................
  4686   4697     SrcList *pTabList,    /* A list of all tables to be scanned */
  4687   4698     Expr *pWhere,         /* The WHERE clause */
  4688   4699     ExprList *pOrderBy,   /* An ORDER BY clause, or NULL */
  4689   4700     ExprList *pDistinct,  /* The select-list for DISTINCT queries - or NULL */
  4690   4701     u16 wctrlFlags,       /* One of the WHERE_* flags defined in sqliteInt.h */
  4691   4702     int iIdxCur           /* If WHERE_ONETABLE_ONLY is set, index cursor number */
  4692   4703   ){
  4693         -  int i;                     /* Loop counter */
  4694   4704     int nByteWInfo;            /* Num. bytes allocated for WhereInfo struct */
  4695   4705     int nTabList;              /* Number of elements in pTabList */
  4696   4706     WhereInfo *pWInfo;         /* Will become the return value of this function */
  4697   4707     Vdbe *v = pParse->pVdbe;   /* The virtual database engine */
  4698   4708     Bitmask notReady;          /* Cursors that are not yet positioned */
  4699   4709     WhereBestIdx sWBI;         /* Best index search context */
  4700   4710     WhereMaskSet *pMaskSet;    /* The expression mask set */
  4701   4711     WhereLevel *pLevel;        /* A single level in pWInfo->a[] */
  4702   4712     int iFrom;                 /* First unused FROM clause element */
  4703   4713     int andFlags;              /* AND-ed combination of all pWC->a[].wtFlags */
         4714  +  int ii;                    /* Loop counter */
  4704   4715     sqlite3 *db;               /* Database connection */
  4705   4716   
  4706   4717   
  4707   4718     /* Variable initialization */
  4708   4719     memset(&sWBI, 0, sizeof(sWBI));
  4709   4720     sWBI.pParse = pParse;
  4710   4721   
................................................................................
  4747   4758     pWInfo->pParse = pParse;
  4748   4759     pWInfo->pTabList = pTabList;
  4749   4760     pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
  4750   4761     pWInfo->pWC = sWBI.pWC = (WhereClause *)&((u8 *)pWInfo)[nByteWInfo];
  4751   4762     pWInfo->wctrlFlags = wctrlFlags;
  4752   4763     pWInfo->savedNQueryLoop = pParse->nQueryLoop;
  4753   4764     pMaskSet = (WhereMaskSet*)&sWBI.pWC[1];
         4765  +  sWBI.a = pWInfo->a;
  4754   4766   
  4755   4767     /* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via
  4756   4768     ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */
  4757   4769     if( db->flags & SQLITE_DistinctOpt ) pDistinct = 0;
  4758   4770   
  4759   4771     /* Split the WHERE clause into separate subexpressions where each
  4760   4772     ** subexpression is separated by an AND operator.
................................................................................
  4790   4802     **
  4791   4803     ** Note that bitmasks are created for all pTabList->nSrc tables in
  4792   4804     ** pTabList, not just the first nTabList tables.  nTabList is normally
  4793   4805     ** equal to pTabList->nSrc but might be shortened to 1 if the
  4794   4806     ** WHERE_ONETABLE_ONLY flag is set.
  4795   4807     */
  4796   4808     assert( sWBI.pWC->vmask==0 && pMaskSet->n==0 );
  4797         -  for(i=0; i<pTabList->nSrc; i++){
  4798         -    createMask(pMaskSet, pTabList->a[i].iCursor);
         4809  +  for(ii=0; ii<pTabList->nSrc; ii++){
         4810  +    createMask(pMaskSet, pTabList->a[ii].iCursor);
  4799   4811   #ifndef SQLITE_OMIT_VIRTUALTABLE
  4800         -    if( ALWAYS(pTabList->a[i].pTab) && IsVirtual(pTabList->a[i].pTab) ){
  4801         -      sWBI.pWC->vmask |= ((Bitmask)1 << i);
         4812  +    if( ALWAYS(pTabList->a[ii].pTab) && IsVirtual(pTabList->a[ii].pTab) ){
         4813  +      sWBI.pWC->vmask |= ((Bitmask)1 << ii);
  4802   4814       }
  4803   4815   #endif
  4804   4816     }
  4805   4817   #ifndef NDEBUG
  4806   4818     {
  4807   4819       Bitmask toTheLeft = 0;
  4808         -    for(i=0; i<pTabList->nSrc; i++){
  4809         -      Bitmask m = getMask(pMaskSet, pTabList->a[i].iCursor);
         4820  +    for(ii=0; ii<pTabList->nSrc; ii++){
         4821  +      Bitmask m = getMask(pMaskSet, pTabList->a[ii].iCursor);
  4810   4822         assert( (m-1)==toTheLeft );
  4811   4823         toTheLeft |= m;
  4812   4824       }
  4813   4825     }
  4814   4826   #endif
  4815   4827   
  4816   4828     /* Analyze all of the subexpressions.  Note that exprAnalyze() might
................................................................................
  4843   4855     **   pWInfo->a[].iTabCur   The VDBE cursor for the database table
  4844   4856     **   pWInfo->a[].iIdxCur   The VDBE cursor for the index
  4845   4857     **   pWInfo->a[].pTerm     When wsFlags==WO_OR, the OR-clause term
  4846   4858     **
  4847   4859     ** This loop also figures out the nesting order of tables in the FROM
  4848   4860     ** clause.
  4849   4861     */
  4850         -  notReady = ~(Bitmask)0;
         4862  +  sWBI.notValid = ~(Bitmask)0;
         4863  +  sWBI.pOrderBy = pOrderBy;
         4864  +  sWBI.n = nTabList;
         4865  +  sWBI.pDistinct = pDistinct;
  4851   4866     andFlags = ~0;
  4852   4867     WHERETRACE(("*** Optimizer Start ***\n"));
  4853         -  for(i=iFrom=0, pLevel=pWInfo->a; i<nTabList; i++, pLevel++){
         4868  +  for(sWBI.i=iFrom=0, pLevel=pWInfo->a; sWBI.i<nTabList; sWBI.i++, pLevel++){
  4854   4869       WhereCost bestPlan;         /* Most efficient plan seen so far */
  4855   4870       Index *pIdx;                /* Index for FROM table at pTabItem */
  4856   4871       int j;                      /* For looping over FROM tables */
  4857   4872       int bestJ = -1;             /* The value of j */
  4858   4873       Bitmask m;                  /* Bitmask value for j or bestJ */
  4859   4874       int isOptimal;              /* Iterator for optimal/non-optimal search */
  4860   4875       int nUnconstrained;         /* Number tables without INDEXED BY */
  4861   4876       Bitmask notIndexed;         /* Mask of tables that cannot use an index */
  4862   4877   
  4863   4878       memset(&bestPlan, 0, sizeof(bestPlan));
  4864   4879       bestPlan.rCost = SQLITE_BIG_DBL;
  4865         -    WHERETRACE(("*** Begin search for loop %d ***\n", i));
         4880  +    WHERETRACE(("*** Begin search for loop %d ***\n", sWBI.i));
  4866   4881   
  4867   4882       /* Loop through the remaining entries in the FROM clause to find the
  4868   4883       ** next nested loop. The loop tests all FROM clause entries
  4869   4884       ** either once or twice. 
  4870   4885       **
  4871   4886       ** The first test is always performed if there are two or more entries
  4872   4887       ** remaining and never performed if there is only one FROM clause entry
................................................................................
  4874   4889       ** this context an optimal scan is one that uses the same strategy
  4875   4890       ** for the given FROM clause entry as would be selected if the entry
  4876   4891       ** were used as the innermost nested loop.  In other words, a table
  4877   4892       ** is chosen such that the cost of running that table cannot be reduced
  4878   4893       ** by waiting for other tables to run first.  This "optimal" test works
  4879   4894       ** by first assuming that the FROM clause is on the inner loop and finding
  4880   4895       ** its query plan, then checking to see if that query plan uses any
  4881         -    ** other FROM clause terms that are notReady.  If no notReady terms are
  4882         -    ** used then the "optimal" query plan works.
         4896  +    ** other FROM clause terms that are sWBI.notValid.  If no notValid terms
         4897  +    ** are used then the "optimal" query plan works.
  4883   4898       **
  4884   4899       ** Note that the WhereCost.nRow parameter for an optimal scan might
  4885   4900       ** not be as small as it would be if the table really were the innermost
  4886   4901       ** join.  The nRow value can be reduced by WHERE clause constraints
  4887   4902       ** that do not use indices.  But this nRow reduction only happens if the
  4888   4903       ** table really is the innermost join.  
  4889   4904       **
................................................................................
  4912   4927       for(isOptimal=(iFrom<nTabList-1); isOptimal>=0 && bestJ<0; isOptimal--){
  4913   4928         for(j=iFrom, sWBI.pSrc=&pTabList->a[j]; j<nTabList; j++, sWBI.pSrc++){
  4914   4929           int doNotReorder;    /* True if this table should not be reordered */
  4915   4930     
  4916   4931           doNotReorder =  (sWBI.pSrc->jointype & (JT_LEFT|JT_CROSS))!=0;
  4917   4932           if( j!=iFrom && doNotReorder ) break;
  4918   4933           m = getMask(pMaskSet, sWBI.pSrc->iCursor);
  4919         -        if( (m & notReady)==0 ){
         4934  +        if( (m & sWBI.notValid)==0 ){
  4920   4935             if( j==iFrom ) iFrom++;
  4921   4936             continue;
  4922   4937           }
  4923         -        sWBI.notValid = notReady;
  4924         -        sWBI.notReady = (isOptimal ? m : notReady);
  4925         -        sWBI.pOrderBy = (i==0) ? pOrderBy : 0;
  4926         -        sWBI.pDistinct = (i==0 ? pDistinct : 0);
         4938  +        sWBI.notReady = (isOptimal ? m : sWBI.notValid);
  4927   4939           if( sWBI.pSrc->pIndex==0 ) nUnconstrained++;
  4928   4940     
  4929   4941           WHERETRACE(("=== trying table %d with isOptimal=%d ===\n",
  4930   4942                       j, isOptimal));
  4931   4943           assert( sWBI.pSrc->pTab );
  4932   4944   #ifndef SQLITE_OMIT_VIRTUALTABLE
  4933   4945           if( IsVirtual(sWBI.pSrc->pTab) ){
................................................................................
  4934   4946             sWBI.ppIdxInfo = &pWInfo->a[j].pIdxInfo;
  4935   4947             bestVirtualIndex(&sWBI);
  4936   4948           }else 
  4937   4949   #endif
  4938   4950           {
  4939   4951             bestBtreeIndex(&sWBI);
  4940   4952           }
  4941         -        assert( isOptimal || (sWBI.cost.used&notReady)==0 );
         4953  +        assert( isOptimal || (sWBI.cost.used&sWBI.notValid)==0 );
  4942   4954   
  4943   4955           /* If an INDEXED BY clause is present, then the plan must use that
  4944   4956           ** index if it uses any index at all */
  4945   4957           assert( sWBI.pSrc->pIndex==0 
  4946   4958                     || (sWBI.cost.plan.wsFlags & WHERE_NOT_FULLSCAN)==0
  4947   4959                     || sWBI.cost.plan.u.pIdx==sWBI.pSrc->pIndex );
  4948   4960   
................................................................................
  4949   4961           if( isOptimal && (sWBI.cost.plan.wsFlags & WHERE_NOT_FULLSCAN)==0 ){
  4950   4962             notIndexed |= m;
  4951   4963           }
  4952   4964   
  4953   4965           /* Conditions under which this table becomes the best so far:
  4954   4966           **
  4955   4967           **   (1) The table must not depend on other tables that have not
  4956         -        **       yet run.
         4968  +        **       yet run.  (In other words, it must not depend on tables
         4969  +        **       in inner loops.)
  4957   4970           **
  4958   4971           **   (2) A full-table-scan plan cannot supercede indexed plan unless
  4959   4972           **       the full-table-scan is an "optimal" plan as defined above.
  4960   4973           **
  4961   4974           **   (3) All tables have an INDEXED BY clause or this table lacks an
  4962   4975           **       INDEXED BY clause or this table uses the specific
  4963   4976           **       index specified by its INDEXED BY clause.  This rule ensures
................................................................................
  4966   4979           **       will be detected and relayed back to the application later.
  4967   4980           **       The NEVER() comes about because rule (2) above prevents
  4968   4981           **       An indexable full-table-scan from reaching rule (3).
  4969   4982           **
  4970   4983           **   (4) The plan cost must be lower than prior plans or else the
  4971   4984           **       cost must be the same and the number of rows must be lower.
  4972   4985           */
  4973         -        if( (sWBI.cost.used&notReady)==0                         /* (1) */
         4986  +        if( (sWBI.cost.used&sWBI.notValid)==0                    /* (1) */
  4974   4987               && (bestJ<0 || (notIndexed&m)!=0                     /* (2) */
  4975   4988                   || (bestPlan.plan.wsFlags & WHERE_NOT_FULLSCAN)==0
  4976   4989                   || (sWBI.cost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0)
  4977   4990               && (nUnconstrained==0 || sWBI.pSrc->pIndex==0        /* (3) */
  4978   4991                   || NEVER((sWBI.cost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0))
  4979   4992               && (bestJ<0 || sWBI.cost.rCost<bestPlan.rCost        /* (4) */
  4980   4993                   || (sWBI.cost.rCost<=bestPlan.rCost 
................................................................................
  4986   4999             bestPlan = sWBI.cost;
  4987   5000             bestJ = j;
  4988   5001           }
  4989   5002           if( doNotReorder ) break;
  4990   5003         }
  4991   5004       }
  4992   5005       assert( bestJ>=0 );
  4993         -    assert( notReady & getMask(pMaskSet, pTabList->a[bestJ].iCursor) );
         5006  +    assert( sWBI.notValid & getMask(pMaskSet, pTabList->a[bestJ].iCursor) );
  4994   5007       WHERETRACE(("*** Optimizer selects table %d for loop %d"
  4995   5008                   " with cost=%g and nRow=%g\n",
  4996   5009                   bestJ, pLevel-pWInfo->a, bestPlan.rCost, bestPlan.plan.nRow));
  4997   5010       if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 ){
  4998   5011         pWInfo->nOBSat = pOrderBy->nExpr;
  4999   5012       }
  5000   5013       if( (bestPlan.plan.wsFlags & WHERE_DISTINCT)!=0 ){
................................................................................
  5012   5025           pLevel->iIdxCur = iIdxCur;
  5013   5026         }else{
  5014   5027           pLevel->iIdxCur = pParse->nTab++;
  5015   5028         }
  5016   5029       }else{
  5017   5030         pLevel->iIdxCur = -1;
  5018   5031       }
  5019         -    notReady &= ~getMask(pMaskSet, pTabList->a[bestJ].iCursor);
         5032  +    sWBI.notValid &= ~getMask(pMaskSet, pTabList->a[bestJ].iCursor);
  5020   5033       pLevel->iFrom = (u8)bestJ;
  5021   5034       if( bestPlan.plan.nRow>=(double)1 ){
  5022   5035         pParse->nQueryLoop *= bestPlan.plan.nRow;
  5023   5036       }
  5024   5037   
  5025   5038       /* Check that if the table scanned by this loop iteration had an
  5026   5039       ** INDEXED BY clause attached to it, that the named index is being
................................................................................
  5065   5078   
  5066   5079     /* Open all tables in the pTabList and any indices selected for
  5067   5080     ** searching those tables.
  5068   5081     */
  5069   5082     sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
  5070   5083     notReady = ~(Bitmask)0;
  5071   5084     pWInfo->nRowOut = (double)1;
  5072         -  for(i=0, pLevel=pWInfo->a; i<nTabList; i++, pLevel++){
         5085  +  for(ii=0, pLevel=pWInfo->a; ii<nTabList; ii++, pLevel++){
  5073   5086       Table *pTab;     /* Table to open */
  5074   5087       int iDb;         /* Index of database containing table/index */
  5075   5088       struct SrcList_item *pTabItem;
  5076   5089   
  5077   5090       pTabItem = &pTabList->a[pLevel->iFrom];
  5078   5091       pTab = pTabItem->pTab;
  5079   5092       pLevel->iTabCur = pTabItem->iCursor;
................................................................................
  5128   5141     if( db->mallocFailed ) goto whereBeginError;
  5129   5142   
  5130   5143     /* Generate the code to do the search.  Each iteration of the for
  5131   5144     ** loop below generates code for a single nested loop of the VM
  5132   5145     ** program.
  5133   5146     */
  5134   5147     notReady = ~(Bitmask)0;
  5135         -  for(i=0; i<nTabList; i++){
  5136         -    pLevel = &pWInfo->a[i];
  5137         -    explainOneScan(pParse, pTabList, pLevel, i, pLevel->iFrom, wctrlFlags);
  5138         -    notReady = codeOneLoopStart(pWInfo, i, wctrlFlags, notReady);
         5148  +  for(ii=0; ii<nTabList; ii++){
         5149  +    pLevel = &pWInfo->a[ii];
         5150  +    explainOneScan(pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags);
         5151  +    notReady = codeOneLoopStart(pWInfo, ii, wctrlFlags, notReady);
  5139   5152       pWInfo->iContinue = pLevel->addrCont;
  5140   5153     }
  5141   5154   
  5142   5155   #ifdef SQLITE_TEST  /* For testing and debugging use only */
  5143   5156     /* Record in the query plan information about the current table
  5144   5157     ** and the index used to access it (if any).  If the table itself
  5145   5158     ** is not used, its name is just '{}'.  If no index is used
  5146   5159     ** the index is listed as "{}".  If the primary key is used the
  5147   5160     ** index name is '*'.
  5148   5161     */
  5149         -  for(i=0; i<nTabList; i++){
         5162  +  for(ii=0; ii<nTabList; ii++){
  5150   5163       char *z;
  5151   5164       int n;
  5152   5165       int w;
  5153   5166       struct SrcList_item *pTabItem;
  5154   5167   
  5155         -    pLevel = &pWInfo->a[i];
         5168  +    pLevel = &pWInfo->a[ii];
  5156   5169       w = pLevel->plan.wsFlags;
  5157   5170       pTabItem = &pTabList->a[pLevel->iFrom];
  5158   5171       z = pTabItem->zAlias;
  5159   5172       if( z==0 ) z = pTabItem->pTab->zName;
  5160   5173       n = sqlite3Strlen30(z);
  5161   5174       if( n+nQPlan < sizeof(sqlite3_query_plan)-10 ){
  5162   5175         if( (w & WHERE_IDX_ONLY)!=0 && (w & WHERE_COVER_SCAN)==0 ){