/ Check-in [fd093413]
Login

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

Overview
Comment:Performance improvement to sqlite3WhereExprUsage().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: fd0934139076848f2f2edfd3d74d54608531031a05a60ca6ac1d7016dcd538df
User & Date: drh 2018-06-09 02:49:11
Context
2018-06-09
14:13
Improved comments an presentation for the recent IN operator decision improvement. check-in: 31e480f6 user: drh tags: trunk
02:49
Performance improvement to sqlite3WhereExprUsage(). check-in: fd093413 user: drh tags: trunk
01:12
Compute the bitmask of indexed columns for each index once when the Index objecct is constructed, instead of recomputing it every time it is needed. check-in: d735872e user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/whereInt.h.

   492    492   );
   493    493   
   494    494   /* whereexpr.c: */
   495    495   void sqlite3WhereClauseInit(WhereClause*,WhereInfo*);
   496    496   void sqlite3WhereClauseClear(WhereClause*);
   497    497   void sqlite3WhereSplit(WhereClause*,Expr*,u8);
   498    498   Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*);
          499  +Bitmask sqlite3WhereExprUsageNN(WhereMaskSet*, Expr*);
   499    500   Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*);
   500    501   void sqlite3WhereExprAnalyze(SrcList*, WhereClause*);
   501    502   void sqlite3WhereTabFuncArgs(Parse*, struct SrcList_item*, WhereClause*);
   502    503   
   503    504   
   504    505   
   505    506   

Changes to src/whereexpr.c.

  1012   1012       }
  1013   1013     }else if( op==TK_ISNULL ){
  1014   1014       pTerm->prereqRight = 0;
  1015   1015     }else{
  1016   1016       pTerm->prereqRight = sqlite3WhereExprUsage(pMaskSet, pExpr->pRight);
  1017   1017     }
  1018   1018     pMaskSet->bVarSelect = 0;
  1019         -  prereqAll = sqlite3WhereExprUsage(pMaskSet, pExpr);
         1019  +  prereqAll = sqlite3WhereExprUsageNN(pMaskSet, pExpr);
  1020   1020     if( pMaskSet->bVarSelect ) pTerm->wtFlags |= TERM_VARSELECT;
  1021   1021     if( ExprHasProperty(pExpr, EP_FromJoin) ){
  1022   1022       Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->iRightJoinTable);
  1023   1023       prereqAll |= x;
  1024   1024       extraRight = x-1;  /* ON clause terms may not be used with an index
  1025   1025                          ** on left table of a LEFT JOIN.  Ticket #3015 */
  1026   1026       if( (prereqAll>>1)>=x ){
................................................................................
  1441   1441   
  1442   1442   
  1443   1443   /*
  1444   1444   ** These routines walk (recursively) an expression tree and generate
  1445   1445   ** a bitmask indicating which tables are used in that expression
  1446   1446   ** tree.
  1447   1447   */
  1448         -Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
         1448  +Bitmask sqlite3WhereExprUsageNN(WhereMaskSet *pMaskSet, Expr *p){
  1449   1449     Bitmask mask;
  1450         -  if( p==0 ) return 0;
  1451   1450     if( p->op==TK_COLUMN ){
  1452   1451       return sqlite3WhereGetMask(pMaskSet, p->iTable);
         1452  +  }else if( ExprHasProperty(p, EP_TokenOnly|EP_Leaf) ){
         1453  +    assert( p->op!=TK_IF_NULL_ROW );
         1454  +    return 0;
  1453   1455     }
  1454   1456     mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0;
  1455         -  assert( !ExprHasProperty(p, EP_TokenOnly) );
  1456         -  if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
         1457  +  if( p->pLeft ) mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pLeft);
  1457   1458     if( p->pRight ){
  1458         -    mask |= sqlite3WhereExprUsage(pMaskSet, p->pRight);
         1459  +    mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pRight);
  1459   1460       assert( p->x.pList==0 );
  1460   1461     }else if( ExprHasProperty(p, EP_xIsSelect) ){
  1461   1462       if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
  1462   1463       mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
  1463   1464     }else if( p->x.pList ){
  1464   1465       mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
  1465   1466     }
  1466   1467     return mask;
         1468  +}
         1469  +Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
         1470  +  return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0;
  1467   1471   }
  1468   1472   Bitmask sqlite3WhereExprListUsage(WhereMaskSet *pMaskSet, ExprList *pList){
  1469   1473     int i;
  1470   1474     Bitmask mask = 0;
  1471   1475     if( pList ){
  1472   1476       for(i=0; i<pList->nExpr; i++){
  1473   1477         mask |= sqlite3WhereExprUsage(pMaskSet, pList->a[i].pExpr);