/ Check-in [bcc8b38a]
Login

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

Overview
Comment:Minor performance improvement in sqlite3ExprDeleteNN().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | filter-clause
Files: files | file ages | folders
SHA3-256: bcc8b38ac75b731a4cd2873ab83f423be036467a511b617c779869de9bbb5383
User & Date: dan 2019-07-10 20:16:53
Context
2019-07-11
18:43
Change the parser on this branch to more closely match trunk. This saves a few more cycles. check-in: be01b801 user: dan tags: filter-clause
2019-07-10
20:16
Minor performance improvement in sqlite3ExprDeleteNN(). check-in: bcc8b38a user: dan tags: filter-clause
2019-07-05
19:10
Another very small performance improvement. check-in: 7a1e30a1 user: dan tags: filter-clause
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

  1036   1036     }
  1037   1037   #endif
  1038   1038     if( !ExprHasProperty(p, (EP_TokenOnly|EP_Leaf)) ){
  1039   1039       /* The Expr.x union is never used at the same time as Expr.pRight */
  1040   1040       assert( p->x.pList==0 || p->pRight==0 );
  1041   1041       if( p->pLeft && p->op!=TK_SELECT_COLUMN ) sqlite3ExprDeleteNN(db, p->pLeft);
  1042   1042       if( p->pRight ){
         1043  +      assert( !ExprHasProperty(p, (EP_WinFunc|EP_Filter)) );
  1043   1044         sqlite3ExprDeleteNN(db, p->pRight);
  1044   1045       }else if( ExprHasProperty(p, EP_xIsSelect) ){
         1046  +      assert( !ExprHasProperty(p, (EP_WinFunc|EP_Filter)) );
  1045   1047         sqlite3SelectDelete(db, p->x.pSelect);
  1046   1048       }else{
  1047   1049         sqlite3ExprListDelete(db, p->x.pList);
  1048         -    }
  1049   1050   #ifndef SQLITE_OMIT_WINDOWFUNC
  1050         -    if( ExprHasProperty(p, EP_WinFunc) ){
  1051         -      assert( p->op==TK_FUNCTION && !ExprHasProperty(p, EP_Filter) );
  1052         -      sqlite3WindowDelete(db, p->y.pWin);
  1053         -    }else if( ExprHasProperty(p, EP_Filter) ){
  1054         -      assert( p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION );
  1055         -      sqlite3ExprDelete(db, p->y.pFilter);
         1051  +      if( ExprHasProperty(p, (EP_WinFunc|EP_Filter)) ){
         1052  +        if( ExprHasProperty(p, EP_WinFunc) ){
         1053  +          assert( p->op==TK_FUNCTION && !ExprHasProperty(p, EP_Filter) );
         1054  +          sqlite3WindowDelete(db, p->y.pWin);
         1055  +        }else{
         1056  +          assert( p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION );
         1057  +          sqlite3ExprDeleteNN(db, p->y.pFilter);
         1058  +        }
         1059  +      }
         1060  +#endif
  1056   1061       }
  1057         -#endif
  1058   1062     }
  1059   1063     if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
  1060   1064     if( !ExprHasProperty(p, EP_Static) ){
  1061   1065       sqlite3DbFreeNN(db, p);
  1062   1066     }
  1063   1067   }
  1064   1068   void sqlite3ExprDelete(sqlite3 *db, Expr *p){

Changes to src/resolve.c.

   822    822             no_such_func = 1;
   823    823             pDef = 0;
   824    824           }
   825    825         }
   826    826   
   827    827         if( 0==IN_RENAME_OBJECT ){
   828    828   #ifndef SQLITE_OMIT_WINDOWFUNC
   829         -        int is_win = ExprHasProperty(pExpr, EP_WinFunc);
          829  +        Window *pWin = (ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0);
   830    830           assert( is_agg==0 || (pDef->funcFlags & SQLITE_FUNC_MINMAX)
   831    831             || (pDef->xValue==0 && pDef->xInverse==0)
   832    832             || (pDef->xValue && pDef->xInverse && pDef->xSFunc && pDef->xFinalize)
   833    833           );
   834         -        if( pDef && pDef->xValue==0 && is_win ){
          834  +        if( pDef && pDef->xValue==0 && pWin ){
   835    835             sqlite3ErrorMsg(pParse, 
   836    836                 "%.*s() may not be used as a window function", nId, zId
   837    837             );
   838    838             pNC->nErr++;
   839    839           }else if( 
   840    840                 (is_agg && (pNC->ncFlags & NC_AllowAgg)==0)
   841         -           || (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !is_win)
   842         -           || (is_agg && is_win && (pNC->ncFlags & NC_AllowWin)==0)
          841  +           || (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !pWin)
          842  +           || (is_agg && pWin && (pNC->ncFlags & NC_AllowWin)==0)
   843    843           ){
   844    844             const char *zType;
   845         -          if( (pDef->funcFlags & SQLITE_FUNC_WINDOW) || is_win ){
          845  +          if( (pDef->funcFlags & SQLITE_FUNC_WINDOW) || pWin ){
   846    846               zType = "window";
   847    847             }else{
   848    848               zType = "aggregate";
   849    849             }
   850    850             sqlite3ErrorMsg(pParse, "misuse of %s function %.*s()",zType,nId,zId);
   851    851             pNC->nErr++;
   852    852             is_agg = 0;
................................................................................
   877    877             pNC->nErr++;
   878    878           }
   879    879           if( is_agg ){
   880    880             /* Window functions may not be arguments of aggregate functions.
   881    881             ** Or arguments of other window functions. But aggregate functions
   882    882             ** may be arguments for window functions.  */
   883    883   #ifndef SQLITE_OMIT_WINDOWFUNC
   884         -          pNC->ncFlags &= ~(NC_AllowWin | (!is_win ? NC_AllowAgg : 0));
          884  +          pNC->ncFlags &= ~(NC_AllowWin | (!pWin ? NC_AllowAgg : 0));
   885    885   #else
   886    886             pNC->ncFlags &= ~NC_AllowAgg;
   887    887   #endif
   888    888           }
   889    889         }
   890    890         sqlite3WalkExprList(pWalker, pList);
   891    891         if( is_agg ){

Changes to src/walker.c.

    59     59     while(1){
    60     60       rc = pWalker->xExprCallback(pWalker, pExpr);
    61     61       if( rc ) return rc & WRC_Abort;
    62     62       if( !ExprHasProperty(pExpr,(EP_TokenOnly|EP_Leaf)) ){
    63     63         if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
    64     64          assert( pExpr->x.pList==0 || pExpr->pRight==0 );
    65     65         if( pExpr->pRight ){
           66  +        assert( !ExprHasProperty(pExpr, EP_WinFunc|EP_Filter) );
    66     67           pExpr = pExpr->pRight;
    67     68           continue;
    68     69         }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
           70  +        assert( !ExprHasProperty(pExpr, EP_WinFunc|EP_Filter) );
    69     71           if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
    70         -      }else if( pExpr->x.pList ){
    71         -        if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
    72         -      }
           72  +      }else{
           73  +        if( pExpr->x.pList ){
           74  +          if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
           75  +        }
    73     76   #ifndef SQLITE_OMIT_WINDOWFUNC
    74         -      if( ExprHasProperty(pExpr, EP_WinFunc) ){
    75         -        if( walkWindowList(pWalker, pExpr->y.pWin) ) return WRC_Abort;
    76         -      }
    77         -      if( ExprHasProperty(pExpr, EP_Filter) ){
    78         -        if( walkExpr(pWalker, pExpr->y.pFilter) ) return WRC_Abort;
    79         -      }
           77  +        if( ExprHasProperty(pExpr, EP_WinFunc|EP_Filter) ){
           78  +          if( ExprHasProperty(pExpr, EP_WinFunc) ){
           79  +            if( walkWindowList(pWalker, pExpr->y.pWin) ) return WRC_Abort;
           80  +          }else if( ExprHasProperty(pExpr, EP_Filter) ){
           81  +            if( walkExpr(pWalker, pExpr->y.pFilter) ) return WRC_Abort;
           82  +          }
           83  +        }
    80     84   #endif
           85  +      }
    81     86       }
    82     87       break;
    83     88     }
    84     89     return WRC_Continue;
    85     90   }
    86     91   int sqlite3WalkExpr(Walker *pWalker, Expr *pExpr){
    87     92     return pExpr ? walkExpr(pWalker,pExpr) : WRC_Continue;