/ Check-in [4fbb0c4d]
Login

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

Overview
Comment:Adjustments to testcase() macros for improved testability.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | nextgen-query-plan-exp
Files: files | file ages | folders
SHA1: 4fbb0c4d26c54aaefbe5397cde2a0b9d2ce3885f
User & Date: drh 2013-06-18 20:06:23
Context
2013-06-19
03:27
Fix compiler warnings. Fix a harmless off-by-one error in the solver. check-in: 10021941 user: drh tags: nextgen-query-plan-exp
2013-06-18
20:06
Adjustments to testcase() macros for improved testability. check-in: 4fbb0c4d user: drh tags: nextgen-query-plan-exp
01:52
Remove some redundant and unreachable code. check-in: 4c6d58d7 user: drh tags: nextgen-query-plan-exp
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

  1599   1599       u32 savedNQueryLoop = pParse->nQueryLoop;
  1600   1600       int rMayHaveNull = 0;
  1601   1601       eType = IN_INDEX_EPH;
  1602   1602       if( prNotFound ){
  1603   1603         *prNotFound = rMayHaveNull = ++pParse->nMem;
  1604   1604         sqlite3VdbeAddOp2(v, OP_Null, 0, *prNotFound);
  1605   1605       }else{
  1606         -      testcase( pParse->nQueryLoop>1 );
  1607         -      pParse->nQueryLoop = 1;
         1606  +      testcase( pParse->nQueryLoop>0 );
         1607  +      pParse->nQueryLoop = 0;
  1608   1608         if( pX->pLeft->iColumn<0 && !ExprHasAnyProperty(pX, EP_xIsSelect) ){
  1609   1609           eType = IN_INDEX_ROWID;
  1610   1610         }
  1611   1611       }
  1612   1612       sqlite3CodeSubselect(pParse, pX, rMayHaveNull, eType==IN_INDEX_ROWID);
  1613   1613       pParse->nQueryLoop = savedNQueryLoop;
  1614   1614     }else{

Changes to src/where.c.

  4093   4093       if( p->maskSelf!=0 ){
  4094   4094         WhereCost rCost = whereCostAdd(p->rRun,p->rSetup);
  4095   4095         WhereCost rTemplate = whereCostAdd(pTemplate->rRun,pTemplate->rSetup);
  4096   4096         if( rCost < rTemplate ){
  4097   4097           testcase( rCost==rTemplate-1 );
  4098   4098           goto whereLoopInsert_noop;
  4099   4099         }
  4100         -      if( rCost == rTemplate && p->prereq <= pTemplate->prereq ){
         4100  +      if( rCost==rTemplate && (p->prereq & pTemplate->prereq)==p->prereq ){
  4101   4101           goto whereLoopInsert_noop;
  4102   4102         }
  4103   4103       }
  4104   4104   #if WHERETRACE_ENABLED
  4105   4105       if( sqlite3WhereTrace & 0x8 ){
  4106   4106         sqlite3DebugPrintf(p->maskSelf==0 ? "ins-init: " : "ins-best: ");
  4107   4107         whereLoopPrint(pTemplate, pWInfo->pTabList);
................................................................................
  4116   4116     */
  4117   4117     for(ppPrev=&pWInfo->pLoops, p=*ppPrev; p; ppPrev=&p->pNextLoop, p=*ppPrev){
  4118   4118       if( p->iTab!=pTemplate->iTab || p->iSortIdx!=pTemplate->iSortIdx ) continue;
  4119   4119       if( (p->prereq & pTemplate->prereq)==p->prereq
  4120   4120        && p->rSetup<=pTemplate->rSetup
  4121   4121        && p->rRun<=pTemplate->rRun
  4122   4122       ){
  4123         -      testcase( p->rSetup==pTemplate->rSetup );
         4123  +      /* This branch taken when p is equal or better than pTemplate in 
         4124  +      ** all of (1) dependences (2) setup-cost, and (3) run-cost. */
  4124   4125         testcase( p->rRun==pTemplate->rRun );
  4125         -      /* p is equal or better than pTemplate */
  4126   4126         if( p->nLTerm<pTemplate->nLTerm
  4127   4127          && (p->wsFlags & WHERE_INDEXED)!=0
  4128   4128          && (pTemplate->wsFlags & WHERE_INDEXED)!=0
  4129   4129          && p->u.btree.pIndex==pTemplate->u.btree.pIndex
  4130   4130          && p->prereq==pTemplate->prereq
  4131   4131         ){
  4132   4132           /* Overwrite an existing WhereLoop with an similar one that uses
................................................................................
  4143   4143           break;
  4144   4144         }else{
  4145   4145           /* pTemplate is not helpful.
  4146   4146           ** Return without changing or adding anything */
  4147   4147           goto whereLoopInsert_noop;
  4148   4148         }
  4149   4149       }
  4150         -    testcase( (p->prereq & pTemplate->prereq)==p->prereq 
  4151         -              && p->rSetup==pTemplate->rSetup+1 );
  4152   4150       testcase( (p->prereq & pTemplate->prereq)==p->prereq
  4153   4151                 && p->rSetup<=pTemplate->rSetup
  4154   4152                 && p->rRun==pTemplate->rRun+1 );
  4155   4153       if( (p->prereq & pTemplate->prereq)==pTemplate->prereq
  4156   4154        && p->rSetup>=pTemplate->rSetup
  4157   4155        && p->rRun>=pTemplate->rRun
  4158   4156       ){
  4159         -      /* Overwrite an existing WhereLoop with a better one */
         4157  +      /* Overwrite an existing WhereLoop with a better one: one that is
         4158  +      ** better at one of (1) dependences, (2) setup-cost, or (3) run-cost
         4159  +      ** and is no worse in any of those categories. */
  4160   4160         testcase( p->rSetup==pTemplate->rSetup );
  4161   4161         testcase( p->rRun==pTemplate->rRun );
  4162   4162         pNext = p->pNextLoop;
  4163   4163         break;
  4164   4164       }
  4165   4165       testcase( (p->prereq & pTemplate->prereq)==pTemplate->prereq
  4166         -              && p->rSetup==pTemplate->rSetup-1 );
  4167         -    testcase( (p->prereq & pTemplate->prereq)==pTemplate->prereq
  4168         -              && p->rSetup>=pTemplate->rSetup-1
         4166  +              && p->rSetup>=pTemplate->rSetup
  4169   4167                 && p->rRun==pTemplate->rRun-1 );
  4170   4168     }
  4171   4169   
  4172   4170     /* If we reach this point it means that either p[] should be overwritten
  4173   4171     ** with pTemplate[] if p[] exists, or if p==NULL then allocate a new
  4174   4172     ** WhereLoop and insert it.
  4175   4173     */
................................................................................
  4299   4297         assert( (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN))!=0
  4300   4298                     || nInMul==0 );
  4301   4299         pNew->wsFlags |= WHERE_COLUMN_EQ;
  4302   4300         if( iCol<0  
  4303   4301          || (pProbe->onError!=OE_None && nInMul==0
  4304   4302              && pNew->u.btree.nEq==pProbe->nColumn-1)
  4305   4303         ){
  4306         -        testcase( pNew->wsFlags & WHERE_COLUMN_IN );
         4304  +        assert( (pNew->wsFlags & WHERE_COLUMN_IN)==0 || iCol<0 );
  4307   4305           pNew->wsFlags |= WHERE_ONEROW;
  4308   4306         }
  4309   4307         pNew->u.btree.nEq++;
  4310   4308         pNew->nOut = nRowEst + nInMul;
  4311   4309       }else if( pTerm->eOperator & (WO_ISNULL) ){
  4312   4310         pNew->wsFlags |= WHERE_COLUMN_NULL;
  4313   4311         pNew->u.btree.nEq++;