Lines Matching defs:Window
5991 ** needed by [aggregate window functions].
6068 ** or aggregate window function. More details regarding the implementation
6069 ** of aggregate window functions are
6070 ** [user-defined window functions|available here].
16191 ** 0x00000040 Window functions
16433 typedef struct Window Window;
18923 #define SQLITE_WindowFunc 0x00000002 /* Use xInverse for window functions */
19067 #define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */
20110 Window *pWin; /* EP_WinFunc: Window/Filter defn for a function */
20140 #define EP_Win 0x008000 /* Contains window functions */
20223 ** an OVER() clause (a window function).
20536 Select *pWinSelect; /* SELECT statement for any window functions */
20563 #define NC_AllowWin 0x004000 /* Window functions are allowed here */
20564 #define NC_HasWin 0x008000 /* One or more window functions seen */
20630 Window *pWin; /* List of window functions */
20631 Window *pWinDefn; /* List of named window definitions */
20665 #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */
21415 struct WindowRewrite *pRewrite; /* Window rewrite context */
21555 ** This object is used in various ways, most (but not all) related to window
21559 ** the Expr.y.pWin field for each window function in an expression tree.
21563 ** (2) All window functions in a single SELECT form a linked-list
21564 ** attached to Select.pWin. The Window.pFunc and Window.pExpr
21565 ** fields point back to the expression that is the window function.
21567 ** (3) The terms of the WINDOW clause of a SELECT are instances of this
21572 ** TK_FILTER. In this case the only field used is Window.pFilter.
21574 ** The uses (1) and (2) are really the same Window object that just happens
21577 struct Window {
21578 char *zName; /* Name of window (may be NULL) */
21579 char *zBase; /* Name of base window for chaining (may be NULL) */
21589 Window **ppThis; /* Pointer to this object in Select.pWin list */
21590 Window *pNextWin; /* Next window function belonging to this SELECT */
21599 Expr *pOwner; /* Expression object this window is attached to */
21605 u8 bExprArgs; /* Defer evaluation of window function arguments
21613 SQLITE_PRIVATE void sqlite3WindowDelete(sqlite3*, Window*);
21614 SQLITE_PRIVATE void sqlite3WindowUnlinkFromSelect(Window*);
21615 SQLITE_PRIVATE void sqlite3WindowListDelete(sqlite3 *db, Window *p);
21616 SQLITE_PRIVATE Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*, u8);
21617 SQLITE_PRIVATE void sqlite3WindowAttach(Parse*, Expr*, Window*);
21618 SQLITE_PRIVATE void sqlite3WindowLink(Select *pSel, Window *pWin);
21619 SQLITE_PRIVATE int sqlite3WindowCompare(const Parse*, const Window*, const Window*, int);
21623 SQLITE_PRIVATE void sqlite3WindowUpdate(Parse*, Window*, Window*, FuncDef*);
21624 SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p);
21625 SQLITE_PRIVATE Window *sqlite3WindowListDup(sqlite3 *db, Window *p);
21627 SQLITE_PRIVATE void sqlite3WindowChain(Parse*, Window*, Window*);
21628 SQLITE_PRIVATE Window *sqlite3WindowAssemble(Parse*, Window*, ExprList*, ExprList*, Token*);
21909 SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView*, const Window*, u8);
21910 SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView*, const Window*, u8);
21926 SQLITE_PRIVATE void sqlite3ShowWindow(const Window*);
21927 SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window*);
34308 Window *pX;
34310 sqlite3TreeViewLine(pView, "window-functions");
34338 Window *pX;
34339 sqlite3TreeViewItem(pView, "WINDOW", (n--)>0);
34412 ** Generate a human-readable explanation for a Window object
34414 SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
34435 sqlite3TreeViewLine(pView, "window: %s", pWin->zBase);
34479 ** Generate a human-readable explanation for a Window Function object
34481 SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){
34684 Window *pWin;
35317 SQLITE_PRIVATE void sqlite3ShowWindow(const Window *p){ sqlite3TreeViewWindow(0,p,0); }
35318 SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window *p){ sqlite3TreeViewWinFunc(0,p,0); }
104399 ** or window function. Execute the finalizer function
110081 ** Walk all expressions linked into the list of Window objects passed
110084 static int walkWindowList(Walker *pWalker, Window *pList, int bOneOnly){
110085 Window *pWin;
110209 ** symbols (e.g. a table that does not exist) in a window definition. */
110356 ** See also the sqlite3WindowExtraAggFuncDepth() routine in window.c
111004 sqlite3ErrorMsg(pParse, "misuse of aliased window function %s",zAs);
111446 Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0);
111565 "%#T() may not be used as a window function", pExpr
111575 zType = "window";
111616 /* Window functions may not be arguments of aggregate functions.
111617 ** Or arguments of other window functions. But aggregate functions
111618 ** may be arguments for window functions. */
112060 Window *pWin = pExpr->y.pWin;
112067 ** Remove any Window objects owned by the expression pExpr from the
112151 ** to an identical expression in the result set, remove all Window
112326 Window *pWin;
114426 ** an a newly duplicated SELECT statement and gather all of the Window
114432 Window *pWin = pExpr->y.pWin;
115116 ** (1) It is a scalar function (not an aggregate or window function)
136409 ** percentile_disc(Y,P) can be used as window functions.
136439 ** * For the window-function versions of these routines, the array of
136442 ** results in O(N*K) performance where K is the size of the window.
136446 ** algorithm for now, for simplicity, under the theory that window
136447 ** functions are seldom used and when they are, the window size K is
151442 sqlite3ErrorMsg(pParse, "cannot use window functions in recursive queries");
152645 Window *pWin = pExpr->y.pWin;
152963 ** (17e) the subquery may not contain window functions, and
153013 ** (25) If either the subquery or the parent query contains a window
153751 ** pSubq, which contains at least one window function. Return 1
153757 ** BY clause of all window function used by the sub-query. It is safe
153759 ** this may change the results of the window functions.
153763 ** * the sub-query uses only one distinct window frame, and
153764 ** * that the window frame has a PARTITION BY clause.
153835 ** (6) Window functions make things tricky as changes to the WHERE clause
153836 ** of the inner query could change the window over which window
153840 ** (6a) The inner query uses multiple incompatible window partitions.
153842 ** (6b) The inner query is a compound and uses window-functions.
153846 ** all window-functions used by the sub-query. It is safe to
153848 ** window over which any window-function is calculated.
154086 /* This optimization does not work for subqueries that use window
154290 ** SELECT is rewritten for window-functions processing and then passed
155906 if( ExprHasProperty(pExpr, EP_WinFunc) ) return 0;/* Not a window function */
156452 TREETRACE(0x40,pParse,p, ("after window rewrite:\n"));
156568 ** (2) The subquery was added to help with window-function
157029 Window *pWin = p->pWin; /* Main window object (or NULL) */
168121 ** not use window functions.
176473 /************** Begin file window.c ******************************************/
176493 ** Any SELECT statement that contains one or more window functions in
176494 ** either the select list or ORDER BY clause (the only two places window
176496 ** in order to support window function processing. For example, with the
176512 ** SELECT statement. This allows the implementation of the window function
176526 ** If there is more than one window function in the SELECT that uses
176527 ** the same window declaration (the OVER bit), then a single scan may
176528 ** be used to process more than one window function. For example:
176549 ** their respective window declarations.
176563 ** * The results of all window-functions for the row are stored
176564 ** in the associated Window.regResult registers.
176567 ** temp table Window.iEphCsr.
176569 ** In some cases, depending on the window frame and the specific window
176575 ** BUILT-IN WINDOW FUNCTIONS
176577 ** This implementation features the following built-in window functions:
176591 ** These are the same built-in window functions supported by Postgres.
176592 ** Although the behaviour of aggregate window functions (functions that
176593 ** can be used as either aggregates or window functions) allows them to
176594 ** be implemented using an API, built-in window functions are much more
176595 ** esoteric. Additionally, some window functions (e.g. nth_value())
176597 ** As such, some built-in window functions use the same API as aggregate
176598 ** window functions and some are implemented directly using VDBE
176600 ** window frame is sometimes modified before the SELECT statement is
176601 ** rewritten. For example, regardless of the specified window frame, the
176608 ** As well as some of the built-in window functions, aggregate window
176610 ** the start of the window frame is declared as anything other than
176615 ** Implementation of built-in window function row_number(). Assumes that the
176616 ** window frame has been coerced to:
176646 ** Implementation of built-in window function dense_rank(). Assumes that
176647 ** the window frame has been set to:
176675 ** Implementation of built-in window function nth_value(). This
176765 ** Implementation of built-in window function rank(). Assumes that
176766 ** the window frame has been set to:
176796 ** Implementation of built-in window function percent_rank(). Assumes that
176797 ** the window frame has been set to:
176841 ** Implementation of built-in window function cume_dist(). Assumes that
176842 ** the window frame has been set to:
176881 ** Context object for ntile() window function.
176890 ** Implementation of ntile(). This assumes that the window frame has
176951 ** Context object for last_value() window function.
177014 ** Static names for the built-in window function names. These static
177016 ** can be associated with a particular window function by direct
177035 ** for built-in window functions that never call those interfaces.
177054 /* Window functions that use all window interfaces: xStep, xFinal,
177062 /* Window functions that are implemented using bytecode and thus have
177070 /* Window functions that use all window interfaces: xStep, the
177081 ** Register those built-in window functions that are not also aggregates.
177104 static Window *windowFind(Parse *pParse, Window *pList, const char *zName){
177105 Window *p;
177110 sqlite3ErrorMsg(pParse, "no such window: %s", zName);
177117 ** for a window function within a SELECT statement. Argument pList is a
177118 ** linked list of WINDOW definitions for the current SELECT statement.
177120 ** is the Window object representing the associated OVER clause. This
177123 ** * If the OVER clause referred to a named window (as in "max(x) OVER win"),
177124 ** search list pList for a matching WINDOW definition, and update pWin
177125 ** accordingly. If no such WINDOW clause can be found, leave an error
177128 ** * If the function is a built-in window function that requires the
177129 ** window to be coerced (see "BUILT-IN WINDOW FUNCTIONS" at the top
177134 Window *pList, /* List of named windows for this SELECT */
177135 Window *pWin, /* Window frame to update */
177136 FuncDef *pFunc /* Window function definition */
177139 Window *p = windowFind(pParse, pList, pWin->zName);
177164 "FILTER clause may only be used with aggregate window functions"
177209 Window *pWin;
177230 ** not process aggregates or window functions at all, as they belong
177251 Window *pWin;
177323 ** * window function with a Window object that is not a member of the
177324 ** Window list passed as the second argument (pWin).
177333 Window *pWin,
177426 ** any SQL window functions, this function is a no-op. Otherwise, it
177427 ** rewrites the SELECT statement so that window function xStep functions
177448 Window *pMWin = p->pWin; /* Main window object */
177449 Window *pWin; /* Window object iterator */
177475 ** of the window PARTITION and ORDER BY clauses. Then, if this makes it
177505 /* Append the arguments passed to each window function to the
177507 ** window function - one for the accumulator, another for interim
177531 /* If there is no ORDER BY or PARTITION BY clause, and the window
177545 ("New window-function subquery in FROM clause of (%u/%p)\n",
177590 ** Unlink the Window object from the Select to which it is attached,
177593 SQLITE_PRIVATE void sqlite3WindowUnlinkFromSelect(Window *p){
177602 ** Free the Window object passed as the second argument.
177604 SQLITE_PRIVATE void sqlite3WindowDelete(sqlite3 *db, Window *p){
177619 ** Free the linked list of Window objects starting at the second argument.
177621 SQLITE_PRIVATE void sqlite3WindowListDelete(sqlite3 *db, Window *p){
177623 Window *pNext = p->pNextWin;
177646 ** Allocate and return a new Window object describing a Window Definition.
177648 SQLITE_PRIVATE Window *sqlite3WindowAlloc(
177652 Expr *pStart, /* Start window size if TK_PRECEDING or FOLLOWING */
177654 Expr *pEnd, /* End window size if TK_FOLLOWING or PRECEDING */
177657 Window *pWin = 0;
177695 pWin = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
177716 ** Attach PARTITION and ORDER BY clauses pPartition and pOrderBy to window
177720 SQLITE_PRIVATE Window *sqlite3WindowAssemble(
177722 Window *pWin,
177741 ** Window *pWin has just been created from a WINDOW clause. Token pBase
177742 ** is the base window. Earlier windows from the same WINDOW clause are
177747 SQLITE_PRIVATE void sqlite3WindowChain(Parse *pParse, Window *pWin, Window *pList){
177750 Window *pExist = windowFind(pParse, pList, pWin->zBase);
177763 "cannot override %s of window: %s", zErr, pWin->zBase
177779 ** Attach window object pWin to expression p.
177781 SQLITE_PRIVATE void sqlite3WindowAttach(Parse *pParse, Expr *p, Window *pWin){
177791 "DISTINCT is not supported for window functions"
177800 ** Possibly link window pWin into the list at pSel->pWin (window functions
177801 ** to be processed as part of SELECT statement pSel). The window is linked
177803 ** SELECT, or (b) the windows already linked use a compatible window frame.
177805 SQLITE_PRIVATE void sqlite3WindowLink(Select *pSel, Window *pWin){
177823 ** Return 0 if the two window objects are identical, 1 if they are
177825 ** or not. Identical window objects can be processed in a single scan.
177829 const Window *p1,
177830 const Window *p2,
177862 Window *pWin;
177864 Window *pMWin;
177997 ** Return the number of arguments passed to the window-function associated
178000 static int windowArgCount(Window *pWin){
178025 ** Each window function requires an accumulator register (just as an
178027 ** in an array of accumulator registers - one for each window function
178031 ** The window functions implementation sometimes caches the input rows
178041 ** An input row can be discarded after the window functions xInverse()
178045 ** An input row can be discarded after the window functions xStep()
178049 ** Consider a window-frame similar to the following:
178058 ** once its window function values have been calculated. Another (end)
178059 ** points to the next row to call the xStep() method of each window function
178061 ** points to the next row to call the xInverse() method of each window
178069 ** Depending on the window-frame in question, all three cursors may not
178075 Window *pMWin; /* First in list of functions being processed */
178089 ** Generate VM code to read the window frames peer values from cursor csr into
178097 Window *pMWin = p->pMWin;
178112 ** xInverse (if bInverse is non-zero) for each window function in the
178113 ** linked list starting at pMWin. Or, for built-in window functions
178131 Window *pMWin, /* Linked list of window functions */
178138 Window *pWin;
178148 /* All OVER clauses in the same window function aggregate step must
178244 ** (bFin==1) for each window function in the linked list starting at
178245 ** pMWin. Or, for built-in window-functions that do not use the standard
178250 Window *pMWin = p->pMWin;
178252 Window *pWin;
178282 ** Generate code to calculate the current values of all window functions in the
178283 ** p->pMWin list by doing a full scan of the current window frame. Store the
178284 ** results in the Window.regResult registers, ready to return the upper
178288 Window *pWin;
178290 Window *pMWin = p->pMWin;
178382 ** return the current row of Window.iEphCsr. If all window functions are
178383 ** aggregate window functions that use the standard API, a single
178385 ** for per-row processing is only generated for the following built-in window
178394 Window *pMWin = p->pMWin;
178401 Window *pWin;
178465 ** Generate code to set the accumulator register for each window function
178467 ** any equivalent initialization required by any built-in window functions
178470 static int windowInitAccum(Parse *pParse, Window *pMWin){
178474 Window *pWin;
178502 static int windowCacheFrame(Window *pMWin){
178503 Window *pWin;
178554 ** the ORDER BY term in the window, and that argument op is OP_Ge, it generates
178562 ** If the sort-order for the ORDER BY term in the window is DESC, then the
178584 ExprList *pOrderBy = p->pMWin->pOrderBy; /* ORDER BY clause for window */
178714 Window *pMWin = p->pMWin;
178851 ** Allocate and return a duplicate of the Window object indicated by the
178852 ** third argument. Set the Window.pOwner field of the new object to
178855 SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p){
178856 Window *pNew = 0;
178858 pNew = sqlite3DbMallocZero(db, sizeof(Window));
178885 ** Return a copy of the linked list of Window objects passed as the
178888 SQLITE_PRIVATE Window *sqlite3WindowListDup(sqlite3 *db, Window *p){
178889 Window *pWin;
178890 Window *pRet = 0;
178891 Window **pp = &pRet;
178925 ** code to populate the Window.regResult register for each window function
178929 ** This function handles several different types of window frames, which
178931 ** used to implement window frames of the form:
178935 ** Other window frame types use variants of the following:
178977 ** AGGSTEP: invoke the aggregate xStep() function for each window function
178985 ** AGGINVERSE: invoke the aggregate xInverse() function for each window
178989 ** There are two other ROWS window frames that are handled significantly
179149 ** RANGE window frames are a little different again. As for GROUPS, the
179264 Window *pMWin = p->pWin;
179312 ** be deleted as soon as they are no longer part of the window frame
179350 /* If the window frame contains an "<expr> PRECEDING" or "<expr> FOLLOWING"
179382 ** at regNew. If the window has a PARTITION clause, this block generates
179587 /************** End of window.c **********************************************/
180154 Window* yy211;
181145 0, /* WINDOW => nothing */
181415 /* 165 */ "WINDOW",
181561 /* 311 */ "window",
181898 /* 319 */ "windowdefn ::= nm AS LP window RP",
181899 /* 320 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt",
181900 /* 321 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt",
181901 /* 322 */ "window ::= ORDER BY sortlist frame_opt",
181902 /* 323 */ "window ::= nm ORDER BY sortlist frame_opt",
181903 /* 324 */ "window ::= nm frame_opt",
181919 /* 340 */ "window_clause ::= WINDOW windowdefn_list",
181923 /* 344 */ "over_clause ::= OVER LP window RP",
181990 /* 411 */ "window ::= frame_opt",
182192 case 311: /* window */
182837 310, /* (319) windowdefn ::= nm AS LP window RP */
182838 311, /* (320) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
182839 311, /* (321) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
182840 311, /* (322) window ::= ORDER BY sortlist frame_opt */
182841 311, /* (323) window ::= nm ORDER BY sortlist frame_opt */
182842 311, /* (324) window ::= nm frame_opt */
182858 253, /* (340) window_clause ::= WINDOW windowdefn_list */
182862 315, /* (344) over_clause ::= OVER LP window RP */
182929 311, /* (411) window ::= frame_opt */
183254 -5, /* (319) windowdefn ::= nm AS LP window RP */
183255 -5, /* (320) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
183256 -6, /* (321) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
183257 -4, /* (322) window ::= ORDER BY sortlist frame_opt */
183258 -5, /* (323) window ::= nm ORDER BY sortlist frame_opt */
183259 -2, /* (324) window ::= nm frame_opt */
183275 -2, /* (340) window_clause ::= WINDOW windowdefn_list */
183279 -4, /* (344) over_clause ::= OVER LP window RP */
183346 -1, /* (411) window ::= frame_opt */
184788 case 319: /* windowdefn ::= nm AS LP window RP */
184797 case 320: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
184802 case 321: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
184808 case 322: /* window ::= ORDER BY sortlist frame_opt */
184813 case 323: /* window ::= nm ORDER BY sortlist frame_opt */
184819 case 324: /* window ::= nm frame_opt */
184870 case 340: /* window_clause ::= WINDOW windowdefn_list */
184892 yylhsminor.yy211 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
184902 case 344: /* over_clause ::= OVER LP window RP */
184910 yymsp[-1].minor.yy211 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
184990 /* (411) window ::= frame_opt (OPTIMIZED OUT) */ assert(yyruleno!=411);
185702 ** 64: WINDOW ELSE
185931 testcase( i==142 ); /* WINDOW */
186031 ** reads the keywords WINDOW, OVER and FILTER, respectively, to determine
186041 ** impossible to call a window-function without a FILTER clause.
186043 ** WINDOW is treated as a keyword if: