/ Check-in [965cbcea]
Login

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

Overview
Comment:Recover a some of the performance lost by window function alias fix two check-ins back.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 965cbcea117835d2c6d2ec58c8025b227f491c35805e282cb31228436bc6bec1
User & Date: drh 2019-03-29 01:15:11
Context
2019-03-29
11:48
Fix typos in the comments of the sessions extension, one of which affects the generated documentation. No code changes. check-in: 040d5d51 user: drh tags: trunk
11:13
Initial implementation of the sqlite3_value_frombind() interface. check-in: 98da62df user: drh tags: value_frombind
01:15
Recover a some of the performance lost by window function alias fix two check-ins back. check-in: 965cbcea user: drh tags: trunk
2019-03-28
20:50
Add new test cases to test/fuzzdata8.db check-in: f908cd40 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/resolve.c.

  1669   1669       return SQLITE_ERROR;
  1670   1670     }
  1671   1671   #endif
  1672   1672     sqlite3WalkExpr(&w, pExpr);
  1673   1673   #if SQLITE_MAX_EXPR_DEPTH>0
  1674   1674     w.pParse->nHeight -= pExpr->nHeight;
  1675   1675   #endif
  1676         -  if( pNC->ncFlags & NC_HasAgg ){
  1677         -    ExprSetProperty(pExpr, EP_Agg);
  1678         -  }
  1679         -  if( pNC->ncFlags & NC_HasWin ){
  1680         -    ExprSetProperty(pExpr, EP_Win);
  1681         -  }
         1676  +  assert( EP_Agg==NC_HasAgg );
         1677  +  assert( EP_Win==NC_HasWin );
         1678  +  testcase( pNC->ncFlags & NC_HasAgg );
         1679  +  testcase( pNC->ncFlags & NC_HasWin );
         1680  +  ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) );
  1682   1681     pNC->ncFlags |= savedHasAgg;
  1683   1682     return pNC->nErr>0 || w.pParse->nErr>0;
  1684   1683   }
  1685   1684   
  1686   1685   /*
  1687   1686   ** Resolve all names for all expression in an expression list.  This is
  1688   1687   ** just like sqlite3ResolveExprNames() except that it works for an expression

Changes to src/sqliteInt.h.

  2492   2492         int regReturn;         /* Register used to hold return address */
  2493   2493       } sub;
  2494   2494     } y;
  2495   2495   };
  2496   2496   
  2497   2497   /*
  2498   2498   ** The following are the meanings of bits in the Expr.flags field.
         2499  +** Value restrictions:
         2500  +**
         2501  +**          EP_Agg == NC_HasAgg == SF_HasAgg
         2502  +**          EP_Win == NC_HasWin
  2499   2503   */
  2500   2504   #define EP_FromJoin  0x000001 /* Originates in ON/USING clause of outer join */
  2501         -#define EP_Agg       0x000002 /* Contains one or more aggregate functions */
         2505  +#define EP_Distinct  0x000002 /* Aggregate function with DISTINCT keyword */
  2502   2506   #define EP_HasFunc   0x000004 /* Contains one or more functions of any kind */
  2503   2507   #define EP_FixedCol  0x000008 /* TK_Column with a known fixed value */
  2504         -#define EP_Distinct  0x000010 /* Aggregate function with DISTINCT keyword */
         2508  +#define EP_Agg       0x000010 /* Contains one or more aggregate functions */
  2505   2509   #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
  2506   2510   #define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
  2507   2511   #define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
  2508   2512   #define EP_Collate   0x000100 /* Tree contains a TK_COLLATE operator */
  2509   2513   #define EP_Generic   0x000200 /* Ignore COLLATE or affinity on this tree */
  2510   2514   #define EP_IntValue  0x000400 /* Integer value contained in u.iValue */
  2511   2515   #define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
  2512   2516   #define EP_Skip      0x001000 /* COLLATE, AS, or UNLIKELY */
  2513   2517   #define EP_Reduced   0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
  2514   2518   #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
  2515         -#define EP_Static    0x008000 /* Held in memory not obtained from malloc() */
         2519  +#define EP_Win       0x008000 /* Contains window functions */
  2516   2520   #define EP_MemToken  0x010000 /* Need to sqlite3DbFree() Expr.zToken */
  2517   2521   #define EP_NoReduce  0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
  2518   2522   #define EP_Unlikely  0x040000 /* unlikely() or likelihood() function */
  2519   2523   #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
  2520   2524   #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
  2521   2525   #define EP_Subquery  0x200000 /* Tree contains a TK_SELECT operator */
  2522   2526   #define EP_Alias     0x400000 /* Is an alias for a result set column */
  2523   2527   #define EP_Leaf      0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
  2524   2528   #define EP_WinFunc  0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
  2525   2529   #define EP_Subrtn   0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
  2526   2530   #define EP_Quoted   0x4000000 /* TK_ID was originally quoted */
  2527         -#define EP_Win      0x8000000 /* Contains window functions */
         2531  +#define EP_Static   0x8000000 /* Held in memory not obtained from malloc() */
  2528   2532   
  2529   2533   /*
  2530   2534   ** The EP_Propagate mask is a set of properties that automatically propagate
  2531   2535   ** upwards into parent nodes.
  2532   2536   */
  2533   2537   #define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc)
  2534   2538   
................................................................................
  2760   2764     Select *pWinSelect;  /* SELECT statement for any window functions */
  2761   2765   };
  2762   2766   
  2763   2767   /*
  2764   2768   ** Allowed values for the NameContext, ncFlags field.
  2765   2769   **
  2766   2770   ** Value constraints (all checked via assert()):
  2767         -**    NC_HasAgg    == SF_HasAgg
         2771  +**    NC_HasAgg    == SF_HasAgg    == EP_Agg
  2768   2772   **    NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX
         2773  +**    NC_HasWin    == EP_Win
  2769   2774   **
  2770   2775   */
  2771   2776   #define NC_AllowAgg  0x0001  /* Aggregate functions are allowed here */
  2772   2777   #define NC_PartIdx   0x0002  /* True if resolving a partial index WHERE */
  2773   2778   #define NC_IsCheck   0x0004  /* True if resolving names in a CHECK constraint */
  2774   2779   #define NC_InAggFunc 0x0008  /* True if analyzing arguments to an agg func */
  2775   2780   #define NC_HasAgg    0x0010  /* One or more aggregate functions seen */