/ Check-in [695aee46]
Login

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

Overview
Comment:Refactor the ExprSetIrreducible() macro into ExprSetVVAProperty(*,EP_NoReduce). This is a naming change only. The logic is the same.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | unlikely-func
Files: files | file ages | folders
SHA1:695aee46e9bdf15159ab52db7f522b30c91aed0f
User & Date: drh 2013-09-12 23:42:22
Context
2013-09-13
17:47
Adjust the query planner to take into account WHERE clause terms that do not drive indices. Add the unlikely() and likelihood() functions used to give hints to the query planner about the selectivity of WHERE clause terms. check-in: bc446449 user: drh tags: trunk
2013-09-12
23:42
Refactor the ExprSetIrreducible() macro into ExprSetVVAProperty(*,EP_NoReduce). This is a naming change only. The logic is the same. Closed-Leaf check-in: 695aee46 user: drh tags: unlikely-func
17:29
Merge in the Expr.flags expansion to 32-bits. Use an extra bit to help optimize the sqlite3ExprSkipCollate() routine. check-in: 4c84d1b4 user: drh tags: unlikely-func
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

   741    741     assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
   742    742     if( 0==(flags&EXPRDUP_REDUCE) ){
   743    743       nSize = EXPR_FULLSIZE;
   744    744     }else{
   745    745       assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
   746    746       assert( !ExprHasProperty(p, EP_FromJoin) ); 
   747    747       assert( !ExprHasProperty(p, EP_MemToken) );
   748         -    assert( !ExprHasProperty(p, EP_Irreduce) );
          748  +    assert( !ExprHasProperty(p, EP_NoReduce) );
   749    749       if( p->pLeft || p->pRight || p->x.pList ){
   750    750         nSize = EXPR_REDUCEDSIZE | EP_Reduced;
   751    751       }else{
   752    752         nSize = EXPR_TOKENONLYSIZE | EP_TokenOnly;
   753    753       }
   754    754     }
   755    755     return nSize;
................................................................................
  1847   1847         pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0,
  1848   1848                                     &sqlite3IntTokens[1]);
  1849   1849         pSel->iLimit = 0;
  1850   1850         if( sqlite3Select(pParse, pSel, &dest) ){
  1851   1851           return 0;
  1852   1852         }
  1853   1853         rReg = dest.iSDParm;
  1854         -      ExprSetIrreducible(pExpr);
         1854  +      ExprSetVVAProperty(pExpr, EP_NoReduce);
  1855   1855         break;
  1856   1856       }
  1857   1857     }
  1858   1858   
  1859   1859     if( testAddr>=0 ){
  1860   1860       sqlite3VdbeJumpHere(v, testAddr);
  1861   1861     }
................................................................................
  4098   4098                 }
  4099   4099               }
  4100   4100               /* There is now an entry for pExpr in pAggInfo->aCol[] (either
  4101   4101               ** because it was there before or because we just created it).
  4102   4102               ** Convert the pExpr to be a TK_AGG_COLUMN referring to that
  4103   4103               ** pAggInfo->aCol[] entry.
  4104   4104               */
  4105         -            ExprSetIrreducible(pExpr);
         4105  +            ExprSetVVAProperty(pExpr, EP_NoReduce);
  4106   4106               pExpr->pAggInfo = pAggInfo;
  4107   4107               pExpr->op = TK_AGG_COLUMN;
  4108   4108               pExpr->iAgg = (i16)k;
  4109   4109               break;
  4110   4110             } /* endif pExpr->iTable==pItem->iCursor */
  4111   4111           } /* end loop over pSrcList */
  4112   4112         }
................................................................................
  4145   4145                 pItem->iDistinct = -1;
  4146   4146               }
  4147   4147             }
  4148   4148           }
  4149   4149           /* Make pExpr point to the appropriate pAggInfo->aFunc[] entry
  4150   4150           */
  4151   4151           assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
  4152         -        ExprSetIrreducible(pExpr);
         4152  +        ExprSetVVAProperty(pExpr, EP_NoReduce);
  4153   4153           pExpr->iAgg = (i16)i;
  4154   4154           pExpr->pAggInfo = pAggInfo;
  4155   4155           return WRC_Prune;
  4156   4156         }else{
  4157   4157           return WRC_Continue;
  4158   4158         }
  4159   4159       }

Changes to src/resolve.c.

   231    231     assert( pNC );     /* the name context cannot be NULL. */
   232    232     assert( zCol );    /* The Z in X.Y.Z cannot be NULL */
   233    233     assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
   234    234   
   235    235     /* Initialize the node to no-match */
   236    236     pExpr->iTable = -1;
   237    237     pExpr->pTab = 0;
   238         -  ExprSetIrreducible(pExpr);
          238  +  ExprSetVVAProperty(pExpr, EP_NoReduce);
   239    239   
   240    240     /* Translate the schema name in zDb into a pointer to the corresponding
   241    241     ** schema.  If not found, pSchema will remain NULL and nothing will match
   242    242     ** resulting in an appropriate error message toward the end of this routine
   243    243     */
   244    244     if( zDb ){
   245    245       testcase( pNC->ncFlags & NC_PartIdx );

Changes to src/select.c.

   261    261     pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
   262    262     pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
   263    263   
   264    264     pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2, 0);
   265    265     if( pEq && isOuterJoin ){
   266    266       ExprSetProperty(pEq, EP_FromJoin);
   267    267       assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
   268         -    ExprSetIrreducible(pEq);
          268  +    ExprSetVVAProperty(pEq, EP_NoReduce);
   269    269       pEq->iRightJoinTable = (i16)pE2->iTable;
   270    270     }
   271    271     *ppWhere = sqlite3ExprAnd(db, *ppWhere, pEq);
   272    272   }
   273    273   
   274    274   /*
   275    275   ** Set the EP_FromJoin property on all terms of the given expression.
................................................................................
   297    297   ** after the t1 loop and rows with t1.x!=5 will never appear in
   298    298   ** the output, which is incorrect.
   299    299   */
   300    300   static void setJoinExpr(Expr *p, int iTable){
   301    301     while( p ){
   302    302       ExprSetProperty(p, EP_FromJoin);
   303    303       assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
   304         -    ExprSetIrreducible(p);
          304  +    ExprSetVVAProperty(p, EP_NoReduce);
   305    305       p->iRightJoinTable = (i16)iTable;
   306    306       setJoinExpr(p->pLeft, iTable);
   307    307       p = p->pRight;
   308    308     } 
   309    309   }
   310    310   
   311    311   /*

Changes to src/sqliteInt.h.

  1780   1780   #define EP_IntValue  0x000400 /* Integer value contained in u.iValue */
  1781   1781   #define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
  1782   1782   #define EP_Skip      0x001000 /* COLLATE, AS, or UNLIKELY */
  1783   1783   #define EP_Reduced   0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
  1784   1784   #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
  1785   1785   #define EP_Static    0x008000 /* Held in memory not obtained from malloc() */
  1786   1786   #define EP_MemToken  0x010000 /* Need to sqlite3DbFree() Expr.zToken */
  1787         -#define EP_Irreduce  0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
         1787  +#define EP_NoReduce  0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
  1788   1788   #define EP_Unlikely  0x040000 /* unlikely() or likelihood() function */
  1789   1789   
  1790         -/*
  1791         -** The pseudo-routine sqlite3ExprSetIrreducible sets the EP2_Irreducible
  1792         -** flag on an expression structure.  This flag is used for VV&A only.  The
  1793         -** routine is implemented as a macro that only works when in debugging mode,
  1794         -** so as not to burden production code.
  1795         -*/
  1796         -#ifdef SQLITE_DEBUG
  1797         -# define ExprSetIrreducible(X)  (X)->flags |= EP_Irreduce
  1798         -#else
  1799         -# define ExprSetIrreducible(X)
  1800         -#endif
  1801         -
  1802   1790   /*
  1803   1791   ** These macros can be used to test, set, or clear bits in the 
  1804   1792   ** Expr.flags field.
  1805   1793   */
  1806   1794   #define ExprHasProperty(E,P)     (((E)->flags&(P))!=0)
  1807   1795   #define ExprHasAllProperty(E,P)  (((E)->flags&(P))==(P))
  1808   1796   #define ExprSetProperty(E,P)     (E)->flags|=(P)
  1809   1797   #define ExprClearProperty(E,P)   (E)->flags&=~(P)
         1798  +
         1799  +/* The ExprSetVVAProperty() macro is used for Verification, Validation,
         1800  +** and Accreditation only.  It works like ExprSetProperty() during VVA
         1801  +** processes but is a no-op for delivery.
         1802  +*/
         1803  +#ifdef SQLITE_DEBUG
         1804  +# define ExprSetVVAProperty(E,P)  (E)->flags|=(P)
         1805  +#else
         1806  +# define ExprSetVVAProperty(E,P)
         1807  +#endif
  1810   1808   
  1811   1809   /*
  1812   1810   ** Macros to determine the number of bytes required by a normal Expr 
  1813   1811   ** struct, an Expr struct with the EP_Reduced flag set in Expr.flags 
  1814   1812   ** and an Expr struct with the EP_TokenOnly flag set.
  1815   1813   */
  1816   1814   #define EXPR_FULLSIZE           sizeof(Expr)           /* Full size */