Lines Matching defs:pTemplate
158892 ** Try to adjust the cost and number of output rows of WhereLoop pTemplate
158895 ** (1) pTemplate costs less than any other WhereLoops that are a proper
158896 ** subset of pTemplate
158898 ** (2) pTemplate costs more than any other WhereLoops for which pTemplate
158905 static void whereLoopAdjustCost(const WhereLoop *p, WhereLoop *pTemplate){
158906 if( (pTemplate->wsFlags & WHERE_INDEXED)==0 ) return;
158908 if( p->iTab!=pTemplate->iTab ) continue;
158910 if( whereLoopCheaperProperSubset(p, pTemplate) ){
158911 /* Adjust pTemplate cost downward so that it is cheaper than its
158914 pTemplate->rRun, pTemplate->nOut,
158915 MIN(p->rRun, pTemplate->rRun),
158916 MIN(p->nOut - 1, pTemplate->nOut)));
158917 pTemplate->rRun = MIN(p->rRun, pTemplate->rRun);
158918 pTemplate->nOut = MIN(p->nOut - 1, pTemplate->nOut);
158919 }else if( whereLoopCheaperProperSubset(pTemplate, p) ){
158920 /* Adjust pTemplate cost upward so that it is costlier than p since
158921 ** pTemplate is a proper subset of p */
158923 pTemplate->rRun, pTemplate->nOut,
158924 MAX(p->rRun, pTemplate->rRun),
158925 MAX(p->nOut + 1, pTemplate->nOut)));
158926 pTemplate->rRun = MAX(p->rRun, pTemplate->rRun);
158927 pTemplate->nOut = MAX(p->nOut + 1, pTemplate->nOut);
158934 ** replaced by pTemplate.
158936 ** Return NULL if pTemplate does not belong on the WhereLoop list.
158937 ** In other words if pTemplate ought to be dropped from further consideration.
158939 ** If pX is a WhereLoop that pTemplate can replace, then return the
158942 ** If pTemplate cannot replace any existing element of the list but needs
158948 const WhereLoop *pTemplate
158952 if( p->iTab!=pTemplate->iTab || p->iSortIdx!=pTemplate->iSortIdx ){
158961 assert( p->rSetup==0 || pTemplate->rSetup==0
158962 || p->rSetup==pTemplate->rSetup );
158967 assert( p->rSetup>=pTemplate->rSetup );
158973 && (pTemplate->nSkip)==0
158974 && (pTemplate->wsFlags & WHERE_INDEXED)!=0
158975 && (pTemplate->wsFlags & WHERE_COLUMN_EQ)!=0
158976 && (p->prereq & pTemplate->prereq)==pTemplate->prereq
158981 /* If existing WhereLoop p is better than pTemplate, pTemplate can be
158983 ** (1) p has no more dependencies than pTemplate, and
158984 ** (2) p has an equal or lower cost than pTemplate
158986 if( (p->prereq & pTemplate->prereq)==p->prereq /* (1) */
158987 && p->rSetup<=pTemplate->rSetup /* (2a) */
158988 && p->rRun<=pTemplate->rRun /* (2b) */
158989 && p->nOut<=pTemplate->nOut /* (2c) */
158991 return 0; /* Discard pTemplate */
158994 /* If pTemplate is always better than p, then cause p to be overwritten
158995 ** with pTemplate. pTemplate is better than p if:
158996 ** (1) pTemplate has no more dependences than p, and
158997 ** (2) pTemplate has an equal or lower cost than p.
158999 if( (p->prereq & pTemplate->prereq)==pTemplate->prereq /* (1) */
159000 && p->rRun>=pTemplate->rRun /* (2a) */
159001 && p->nOut>=pTemplate->nOut /* (2b) */
159003 assert( p->rSetup>=pTemplate->rSetup ); /* SETUP-INVARIANT above */
159004 break; /* Cause p to be overwritten by pTemplate */
159034 static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
159048 whereLoopAdjustCost(pWInfo->pLoops, pTemplate);
159054 if( pTemplate->nLTerm ){
159059 whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
159060 pTemplate->nOut);
159064 sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC);
159071 /* Look for an existing WhereLoop to replace with pTemplate
159073 ppPrev = whereLoopFindLesser(&pWInfo->pLoops, pTemplate);
159077 ** than pTemplate, so just ignore pTemplate */
159081 sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC);
159090 ** with pTemplate[] if p[] exists, or if p==NULL then allocate a new
159102 sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC);
159114 ** p[] that are also supplated by pTemplate */
159118 ppTail = whereLoopFindLesser(ppTail, pTemplate);
159132 rc = whereLoopXfer(db, p, pTemplate);