1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-11 01:42:22 +03:00

Rework the FILTER clause implementation to share more code with window functions.

FossilOrigin-Name: 5dac8c38dfc3f41c5c8fb49ca35de7fd1b21f269d72e8ba6ba59ed0a4030a54d
This commit is contained in:
dan
2019-07-13 16:22:50 +00:00
parent 648d629953
commit 4f9adee289
10 changed files with 116 additions and 119 deletions

View File

@@ -2491,8 +2491,7 @@ struct Expr {
union {
Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL
** for a column of an index on an expression */
Window *pWin; /* EP_WinFunc: Window definition for the func */
Expr *pFilter; /* EP_Filter: Filter definition for the func */
Window *pWin; /* EP_WinFunc: Window/Filter defn for a function */
struct { /* TK_IN, TK_SELECT, and TK_EXISTS */
int iAddr; /* Subroutine entry address */
int regReturn; /* Register used to hold return address */
@@ -2537,7 +2536,6 @@ struct Expr {
#define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
#define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
#define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
#define EP_Filter 0x40000000 /* TK_[AGG_]FUNCTION with Expr.y.pFilter set */
/*
** The EP_Propagate mask is a set of properties that automatically propagate
@@ -2581,6 +2579,14 @@ struct Expr {
*/
#define EXPRDUP_REDUCE 0x0001 /* Used reduced-size Expr nodes */
/*
** True if the expression passed as an argument was a function with
** an OVER() clause (a window function).
*/
#define IsWindowFunc(p) ( \
ExprHasProperty((p), EP_WinFunc) && p->y.pWin->eFrmType!=TK_FILTER \
)
/*
** A list of expressions. Each expression may optionally have a
** name. An expr/name combination can be used in several ways, such
@@ -3604,8 +3610,8 @@ struct Window {
void sqlite3WindowDelete(sqlite3*, Window*);
void sqlite3WindowListDelete(sqlite3 *db, Window *p);
Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*, u8);
void sqlite3WindowAttach(Parse*, Expr*, Expr*, Window*);
int sqlite3WindowCompare(Parse*, Window*, Window*);
void sqlite3WindowAttach(Parse*, Expr*, Window*);
int sqlite3WindowCompare(Parse*, Window*, Window*, int);
void sqlite3WindowCodeInit(Parse*, Window*);
void sqlite3WindowCodeStep(Parse*, Select*, WhereInfo*, int, int);
int sqlite3WindowRewrite(Parse*, Select*);
@@ -3619,7 +3625,7 @@ Window *sqlite3WindowAssemble(Parse*, Window*, ExprList*, ExprList*, Token*);
#else
# define sqlite3WindowDelete(a,b)
# define sqlite3WindowFunctions()
# define sqlite3WindowAttach(a,b,c,d)
# define sqlite3WindowAttach(a,b,c)
#endif
/*