MySQL 8.4.2
Source Code Documentation
Window Class Reference

Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined) window of a window function call, or a reference to a named window in a window function call (instead of the inlined definition) before resolution. More...

#include <window.h>

Inheritance diagram for Window:
[legend]

Classes

struct  Frame_buffer_position
 Holds information about a position in the buffer frame as stored in a temporary file (cf. More...
 
struct  st_lead_lag
 
struct  st_ll_offset
 
struct  st_nth
 
struct  st_offset
 

Public Types

enum  Special_keys { FBC_FIRST_IN_NEXT_PARTITION = -1 , FBC_FIRST_KEY = FBC_FIRST_IN_NEXT_PARTITION , FBC_LAST_KEY = FBC_FIRST_IN_NEXT_PARTITION }
 Keys for m_special_rows_cache, for special rows (see the comment on m_special_row_cache). More...
 

Public Member Functions

void save_pos (Window_retrieve_cached_row_reason reason)
 See m_tmp_pos. More...
 
void restore_pos (Window_retrieve_cached_row_reason reason)
 See m_tmp_pos. More...
 
void copy_pos (Window_retrieve_cached_row_reason from_reason, Window_retrieve_cached_row_reason to_reason)
 Copy frame buffer position hint from one to another. More...
 
 Window (Item_string *name)
 Reference to a named window. More...
 
 Window (PT_order_list *partition_by, PT_order_list *order_by, PT_frame *frame)
 Unnamed window. More...
 
 Window (PT_order_list *partition_by, PT_order_list *order_by, PT_frame *frame, Item_string *inherit)
 Unnamed window based on a named window. More...
 
void set_name (Item_string *name)
 We have a named window. More...
 
void set_ancestor (Window *a)
 After resolving an existing window name reference in a window definition, we set the ancestor pointer to easy access later. More...
 
Item_stringname () const
 Get the name of a window. More...
 
uint def_pos () const
 
void set_def_pos (uint pos)
 
const PT_frameframe () const
 Get the frame, if any. More...
 
const PT_order_listeffective_order_by () const
 Get the ORDER BY, if any. More...
 
ORDERfirst_order_by () const
 Get the first argument of the ORDER BY clause for this window if any. More...
 
const PT_order_listeffective_partition_by () const
 Get partition, if any. More...
 
ORDERfirst_partition_by () const
 Get the first argument of the PARTITION clause for this window if any. More...
 
List< Item_sum > & functions ()
 Get the list of functions invoked on this window. More...
 
ORDERsorting_order (THD *thd=nullptr, bool implicit_grouping=false)
 Concatenation of columns in PARTITION BY and ORDER BY. More...
 
bool check_window_functions1 (THD *thd, Query_block *select)
 Check that the semantic requirements for window functions over this window are fulfilled, and accumulate evaluation requirements. More...
 
bool check_window_functions2 (THD *thd)
 Like check_window_functions1() but contains checks which must wait until the start of the execution phase. More...
 
bool setup_range_expressions (THD *thd)
 For RANGE frames we need to do computations involving add/subtract and less than, smaller than. More...
 
bool is_reference () const
 Return if this window represents an unresolved window reference seen in a window function OVER clause. More...
 
void check_partition_boundary ()
 Check if the just read input row marks the start of a new partition. More...
 
void reset_order_by_peer_set ()
 Reset the current row's ORDER BY expressions when starting a new peer set. More...
 
bool in_new_order_by_peer_set (bool compare_all_order_by_items=true)
 Determine if the current row is not in the same peer set as the previous row. More...
 
bool before_frame ()
 While processing buffered rows in RANGE frame mode we, determine if the present row revisited from the buffer is before the row being processed; i.e. More...
 
bool after_frame ()
 
bool at_partition_border () const
 Check if we have read all the rows in a partition, possibly having buffered them for further processing. More...
 
void save_special_row (uint64 special_rowno, TABLE *t)
 Save row special_rowno in table t->record[0] to an in-memory copy for later restoration. More...
 
void restore_special_row (uint64 special_rowno, uchar *record)
 Restore row special_rowno into record from in-memory copy. More...
 
bool resolve_window_ordering (THD *thd, Ref_item_array ref_item_array, Table_ref *tables, mem_root_deque< Item * > *fields, ORDER *o, bool partition_order)
 Resolve and set up the PARTITION BY or an ORDER BY list of a window. More...
 
bool check_unique_name (const List< Window > &windows)
 Return true if this window's name is not unique in windows. More...
 
void apply_temp_table (THD *thd, const Func_ptr_array &items_to_copy, bool first)
 Specify that this window is to be evaluated after a given temporary table. More...
 
bool setup_ordering_cached_items (THD *thd, Query_block *select, const PT_order_list *o, bool partition_order)
 Set up cached items for an partition or an order by list updating m_partition_items or m_order_by_items respectively. More...
 
bool needs_sorting () const
 Determine if the window had either a partition clause (inclusive) or a ORDER BY clause, either defined by itself or inherited from another window. More...
 
bool needs_buffering () const
 If we cannot compute one of window functions without looking at succeeding rows, return true, else false. More...
 
bool needs_peerset () const
 If we cannot compute one of window functions without looking at all rows in the peerset of the current row, return true, else false. More...
 
bool needs_last_peer_in_frame () const
 If we cannot compute one of window functions without looking at all rows in the peerset of the current row in this frame, return true, else false. More...
 
bool needs_partition_cardinality () const
 If we need to read the entire partition before we can evaluate some window function(s) on this window,. More...
 
bool optimizable_row_aggregates () const
 Return true if the set of window functions are all ROW unit optimizable. More...
 
bool optimizable_range_aggregates () const
 Return true if the set of window functions are all RANGE unit optimizable. More...
 
bool static_aggregates () const
 Return true if the aggregates are static, i.e. More...
 
bool opt_first_row () const
 See m_opt_first_row. More...
 
bool opt_last_row () const
 See m_opt_last_row. More...
 
bool is_last () const
 See m_last. More...
 
void set_is_last (bool last)
 An override used by the hypergraph join optimizer only. More...
 
const st_nthopt_nth_row () const
 See m_opt_nth_row. More...
 
const st_lead_lagopt_lead_lag () const
 See m_opt_lead_lag. More...
 
Temp_table_paramframe_buffer_param () const
 Getter for m_frame_buffer_param, q.v. More...
 
void set_frame_buffer_param (Temp_table_param *p)
 Setter for m_frame_buffer_param, q.v. More...
 
TABLEframe_buffer () const
 Getter for m_frame_buffer, q.v. More...
 
void set_frame_buffer (TABLE *tab)
 Setter for m_frame_buffer, q.v. More...
 
bool short_circuit () const
 
void set_short_circuit (bool short_circuit)
 
int64 partition_rowno () const
 Getter for m_part_row_number, q.v., the current row number within the partition. More...
 
bool make_special_rows_cache (THD *thd, TABLE *out_tbl)
 Allocate the cache for special rows. More...
 
int64 last_row_output () const
 See m_last_row_output. More...
 
void set_last_row_output (int64 rno)
 See m_last_row_output. More...
 
int64 rowno_being_visited () const
 See m_rowno_being_visited. More...
 
void set_rowno_being_visited (int64 rno)
 See m_rowno_being_visited. More...
 
int64 last_rowno_in_cache () const
 See m_last_rowno_in_cache. More...
 
void set_last_rowno_in_cache (uint64 rno)
 See m_last_rowno_in_cache. More...
 
int64 last_rowno_in_range_frame () const
 See m_last_rowno_in_range_frame. More...
 
void set_last_rowno_in_range_frame (uint64 rno)
 See m_last_rowno_in_range_frame. More...
 
int64 last_rowno_in_peerset () const
 See m_last_rowno_in_peerset. More...
 
void set_last_rowno_in_peerset (uint64 rno)
 See m_last_rowno_in_peerset. More...
 
int64 is_last_row_in_peerset_within_frame () const
 See m_is_last_row_in_peerset_within_frame. More...
 
void set_is_last_row_in_peerset_within_frame (bool value)
 See m_is_last_row_in_peerset_within_frame. More...
 
bool do_copy_null () const
 See m_do_copy_null. More...
 
void set_do_copy_null (bool b)
 See m_do_copy_null. More...
 
bool do_inverse () const
 See m_inverse_aggregation. More...
 
Windowset_inverse (bool b)
 See m_inverse_aggregation. More...
 
bool aggregates_primed () const
 See m_aggregates_primed. More...
 
void set_aggregates_primed (bool b)
 See m_aggregates_primed. More...
 
bool is_last_row_in_frame () const
 See m_is_last_row_in_frame. More...
 
void set_is_last_row_in_frame (bool b)
 See m_is_last_row_in_frame. More...
 
int64 rowno_in_frame () const
 Return the size of the frame in number of rows. More...
 
Windowset_rowno_in_frame (int64 rowno)
 See m_rowno_in_frame. More...
 
int64 rowno_in_partition () const
 See m_rowno_in_partition. More...
 
void set_rowno_in_partition (int64 rowno)
 See m_rowno_in_partition. More...
 
void set_first_rowno_in_rows_frame (int64 rowno)
 See m_first_rowno_in_rows_frame. More...
 
int64 first_rowno_in_rows_frame () const
 
void set_first_rowno_in_range_frame (int64 rowno)
 See m_first_rowno_in_range_frame. More...
 
int64 first_rowno_in_range_frame () const
 See m_first_rowno_in_range_frame. More...
 
void set_frame_buffer_total_rows (int64 rows)
 See m_frame_buffer_total_rows. More...
 
int64 frame_buffer_total_rows () const
 See m_frame_buffer_total_rows. More...
 
void set_frame_buffer_partition_offset (int64 offset)
 See m_frame_buffer_partition_offset. More...
 
int64 frame_buffer_partition_offset () const
 See m_frame_buffer_partition_offset. More...
 
int64 row_has_fields_in_out_table () const
 See m_row_has_fields_in_out_table. More...
 
void set_row_has_fields_in_out_table (int64 rowno)
 See m_row_has_fields_in_out_table. More...
 
void cleanup ()
 Free up any resource used to process the window functions of this window, e.g. More...
 
void destroy ()
 Free structures that were set up during preparation of window functions. More...
 
void reset_partition_state ()
 Reset window state for a new partition. More...
 
void reset_round ()
 Reset execution state for next call to JOIN::exec, cf. More...
 
void reset_lead_lag ()
 Reset execution state for LEAD/LAG for the current row in partition. More...
 
void reset_all_wf_state ()
 Reset the execution state for all window functions defined on this window. More...
 
const char * printable_name () const
 
void print (const THD *thd, String *str, enum_query_type qt, bool expand_definition) const
 
bool has_windowing_steps () const
 

Static Public Member Functions

static bool resolve_reference (THD *thd, Item_sum *wf, PT_window **m_window)
 Resolve any named window to its definition and update m_window to point to the definition instead. More...
 
static bool setup_windows1 (THD *thd, Query_block *select, Ref_item_array ref_item_array, Table_ref *tables, mem_root_deque< Item * > *fields, List< Window > *windows)
 Semantic checking of windows. More...
 
static bool setup_windows2 (THD *thd, List< Window > *windows)
 Like setup_windows1() but contains operations which must wait until the start of the execution phase. More...
 
static void eliminate_unused_objects (List< Window > *windows)
 Check window definitions to remove unused windows. More...
 
static double compute_cost (double cost, const List< Window > &windows)
 Compute sorting costs for windowing. More...
 

Public Attributes

Mem_root_array_YY< Frame_buffer_positionm_frame_buffer_positions
 Execution state: used iff m_needs_frame_buffering. More...
 
Frame_buffer_position m_tmp_pos
 Sometimes we read one row too many, so that the saved position will be too far out because we subsequently need to read an earlier (previous) row of the same kind (reason). More...
 
Bounds_checked_array< Arg_comparatorm_comparators [2]
 
int m_ordering_idx
 The logical ordering index (into LogicalOrderings) needed by this window's PARTITION BY and ORDER BY clauses together (if any; else, 0). More...
 
bool m_mark
 Used temporarily by the hypergraph join optimizer to mark which windows are referred to by a given ordering (so that one doesn't try to satisfy a window's ordering by an ordering referring to that window). More...
 

Static Public Attributes

static constexpr int FRAME_BUFFER_POSITIONS_CARD
 Cardinality of m_frame_buffer_positions if no NTH_VALUE, LEAD/LAG. More...
 

Protected Attributes

Query_blockm_query_block
 The SELECT the window is on. More...
 
PT_order_list *const m_partition_by
 <window partition clause> More...
 
PT_order_list *const m_order_by
 <window order clause> More...
 
ORDERm_sorting_order
 merged partition/order by More...
 
PT_frame *const m_frame
 <window frame clause> More...
 
Item_stringm_name
 <window name> More...
 
uint m_def_pos
 Position of definition in query's text, 1 for leftmost. More...
 
Item_string *const m_inherit_from
 <existing window name> More...
 
const bool m_is_reference
 If true, m_name is an unbound window reference, other fields are unused. More...
 
bool m_needs_frame_buffering
 (At least) one window function needs to buffer frame rows for evaluation i.e. More...
 
bool m_needs_peerset
 (At least) one window function needs the peer set of the current row to evaluate the wf for the current row More...
 
bool m_needs_last_peer_in_frame
 (At least) one window function (currently JSON_OBJECTAGG) needs the last peer for the current row to evaluate the wf for the current row. More...
 
bool m_needs_partition_cardinality
 (At least) one window function needs the cardinality of the partition of the current row to evaluate the wf for the current row More...
 
bool m_row_optimizable
 The functions are optimizable with ROW unit. More...
 
bool m_range_optimizable
 The functions are optimizable with RANGE unit. More...
 
bool m_static_aggregates
 The aggregates (SUM, etc) can be evaluated once for a partition, since it is static, i.e. More...
 
bool m_opt_first_row
 Window equires re-evaluation of the first row in optimized moving frame mode e.g. More...
 
bool m_opt_last_row
 Window requires re-evaluation of the last row in optimized moving frame mode e.g. More...
 
bool m_last
 The last window to be evaluated at execution time. More...
 
st_nth m_opt_nth_row
 Window requires re-evaluation of the Nth row in optimized moving frame mode e.g. More...
 
st_lead_lag m_opt_lead_lag
 
const Windowm_ancestor
 resolved from existing window name More...
 
List< Item_summ_functions
 window functions based on 'this' More...
 
Mem_root_array< Cached_item * > m_partition_items
 items for the PARTITION BY columns More...
 
Mem_root_array< Cached_item * > m_order_by_items
 items for the ORDER BY exprs. More...
 
Temp_table_paramm_frame_buffer_param
 Execution state: used iff m_needs_frame_buffering. More...
 
bool m_short_circuit = false
 Holds whether this window should be “short-circuit”, ie., goes directly to the query output instead of to a temporary table. More...
 
TABLEm_frame_buffer
 Execution state: used iff m_needs_frame_buffering. More...
 
int64 m_frame_buffer_total_rows
 Execution state: The frame buffer tmp file is not truncated for each new partition. More...
 
int64 m_frame_buffer_partition_offset
 Execution state: Snapshot of m_frame_buffer_total_rows when we start a new partition, i.e. More...
 
int64 m_row_has_fields_in_out_table
 If >=1: the row with this number (1-based, relative to start of partition) currently has its fields in the record buffer of the IN table and of the OUT table. More...
 
ucharm_special_rows_cache
 Holds a fixed number of copies of special rows; each copy can use up to m_special_rows_cache_max_length bytes. More...
 
size_t m_special_rows_cache_length [FBC_FIRST_KEY - FBC_LAST_KEY+1]
 Length of each copy in m_special_rows_cache, in bytes. More...
 
size_t m_special_rows_cache_max_length
 Maximum allocated size in m_special_rows_cache. More...
 
int64 m_last_rowno_in_cache
 Execution state: used iff m_needs_frame_buffering. More...
 
int64 m_last_rowno_in_peerset
 Execution state: used iff m_needs_peerset. More...
 
int64 m_is_last_row_in_peerset_within_frame
 Execution state: used iff m_needs_last_peer_in_frame. More...
 
int64 m_part_row_number
 Execution state: the current row number in the current partition. More...
 
bool m_partition_border
 Execution state: the current row starts a new partition. More...
 
int64 m_last_row_output
 Execution state: The number, in the current partition, of the last output row, i.e. More...
 
int64 m_rowno_being_visited
 Execution state: The number of the row being visited for its contribution to a window function, relative to the start of the partition. More...
 
int64 m_rowno_in_frame
 Execution state: the row number of the row we are looking at for evaluating its contribution to some window function(s). More...
 
int64 m_rowno_in_partition
 Execution state: The row number of the current row being readied for output within the partition. More...
 
bool m_aggregates_primed
 Execution state: for optimizable aggregates, cf. More...
 
int64 m_first_rowno_in_range_frame
 Execution state: the row number of the first row in a frame when evaluating RANGE based frame bounds. More...
 
int64 m_last_rowno_in_range_frame
 Execution state: used for RANGE bounds frame evaluation for the continued evaluation for current row > 2 in a partition. More...
 
int64 m_first_rowno_in_rows_frame
 Execution state. More...
 
bool m_is_last_row_in_frame
 Execution state: the current row is the last row in a window frame For some aggregate functions, e.g AVG, we can save computation by not evaluating the entire function value before the last row has been read. More...
 
bool m_do_copy_null
 Execution state: make frame wf produce a NULL (or 0 depending, e.g. More...
 
bool m_inverse_aggregation
 Execution state: do inverse, e.g. More...
 

Private Types

enum  Reset_level { RL_ROUND , RL_PARTITION }
 

Private Member Functions

 Window (Item_string *name, PT_order_list *part, PT_order_list *ord, PT_frame *frame, bool is_reference, Item_string *inherit)
 Generic window constructor, shared. More...
 
void reset_execution_state (Reset_level level)
 Common function for all types of resetting. More...
 
bool before_or_after_frame (bool before)
 Common implementation of before_frame() and after_frame(). More...
 
void print_frame (const THD *thd, String *str, enum_query_type qt) const
 
void print_border (const THD *thd, String *str, PT_border *b, enum_query_type qt) const
 
bool check_constant_bound (THD *thd, PT_border *border)
 Check that a frame border is constant during execution and that it does not contain subqueries (relevant for INTERVAL only): implementation limitation. More...
 
bool check_border_sanity1 (THD *thd)
 Check that frame borders are sane; resolution phase. More...
 
bool check_border_sanity2 (THD *thd)
 Like check_border_sanity1() but contains checks which must wait until the start of the execution phase. More...
 

Static Private Member Functions

static void reorder_and_eliminate_sorts (List< Window > *windows)
 Reorder windows and eliminate redundant ordering. More...
 
static bool equal_sort (Window *w1, Window *w2)
 Return true of the physical[1] sort orderings for the two windows are the same, cf. More...
 

Detailed Description

Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined) window of a window function call, or a reference to a named window in a window function call (instead of the inlined definition) before resolution.

After resolving referencing instances become unused, having been replaced with the window resolved to in the w.f. call.

Cf. 7.11 <window definition> and <existing window name>
    6.10 <window name or specification> and
         <in-line window specification>
    5.4 <window name>

See also PT_window (which wraps Window as a parse_tree_node), and the related classes PT_frame, PT_border and PT_exclusion in parse_tree_nodes.

Currently includes both prepared query and execution state information. The latter is marked as such for ease of separation later.

Member Enumeration Documentation

◆ Reset_level

enum Window::Reset_level
private
Enumerator
RL_ROUND 
RL_PARTITION 

◆ Special_keys

Keys for m_special_rows_cache, for special rows (see the comment on m_special_row_cache).

Note that they are negative, so that they will never collide with actual row numbers in the frame. This allows us to treat them interchangeably with real row numbers as function arguments; e.g., bring_back_frame_row() can restore either a “normal” row from the frame, or one of the special rows, and does not need to take in separate flags for the two. TODO(Chaithra): We have only one special key. Do we need the enum? Also m_special_rows_cache/cache_length/max_cache_length should be looked into.

Enumerator
FBC_FIRST_IN_NEXT_PARTITION 

We read an incoming row.

We notice it is the start of a new partition. We must thus process the just-finished partition, but that processing uses this row's buffer; so, we save this row first, process the partition, and restore it later.

FBC_FIRST_KEY 
FBC_LAST_KEY 

Constructor & Destructor Documentation

◆ Window() [1/4]

Window::Window ( Item_string name,
PT_order_list part,
PT_order_list ord,
PT_frame frame,
bool  is_reference,
Item_string inherit 
)
inlineprivate

Generic window constructor, shared.

◆ Window() [2/4]

Window::Window ( Item_string name)
inline

Reference to a named window.

This kind is only used before resolution, references to it being replaced by the referenced window object thereafter.

◆ Window() [3/4]

Window::Window ( PT_order_list partition_by,
PT_order_list order_by,
PT_frame frame 
)
inline

Unnamed window.

If the window turns out to be named, the name will be set later, cf. set_name().

◆ Window() [4/4]

Window::Window ( PT_order_list partition_by,
PT_order_list order_by,
PT_frame frame,
Item_string inherit 
)
inline

Unnamed window based on a named window.

If the window turns out to be named, the name will be set later, cf. set_name().

Member Function Documentation

◆ after_frame()

bool Window::after_frame ( )
inline

◆ aggregates_primed()

bool Window::aggregates_primed ( ) const
inline

See m_aggregates_primed.

◆ apply_temp_table()

void Window::apply_temp_table ( THD thd,
const Func_ptr_array items_to_copy,
bool  first 
)

Specify that this window is to be evaluated after a given temporary table.

This means that all expressions that have been materialized (as given by items_to_copy) will be replaced with the given temporary table fields. (If there are multiple materializations, this function must be called for each of them in order.)

Only the hypergraph join optimizer uses this currently; the old join optimizer instead uses Item_ref objects that point to the base slice, which is then replaced at runtime depending on which temporary table we are to evaluate from.

Parameters
thdThe session's execution thread.
items_to_copyThe expressions materialized in the temporary table.
firstTrue if this is the first temporary table applied to this window.

◆ at_partition_border()

bool Window::at_partition_border ( ) const
inline

Check if we have read all the rows in a partition, possibly having buffered them for further processing.

Returns
true if this is the case

◆ before_frame()

bool Window::before_frame ( )
inline

While processing buffered rows in RANGE frame mode we, determine if the present row revisited from the buffer is before the row being processed; i.e.

the current row.

Returns
true if the present row is before the RANGE, i.e. not to be included See before_frame()

◆ before_or_after_frame()

bool Window::before_or_after_frame ( bool  before)
private

Common implementation of before_frame() and after_frame().

Parameters
beforeTrue if 'before' is wanted; false if 'after' is.

◆ check_border_sanity1()

bool Window::check_border_sanity1 ( THD thd)
private

Check that frame borders are sane; resolution phase.

Parameters
thdSession thread
Returns
true if error

◆ check_border_sanity2()

bool Window::check_border_sanity2 ( THD thd)
private

Like check_border_sanity1() but contains checks which must wait until the start of the execution phase.

Parameters
thdSession thread
Returns
true if error

◆ check_constant_bound()

bool Window::check_constant_bound ( THD thd,
PT_border border 
)
private

Check that a frame border is constant during execution and that it does not contain subqueries (relevant for INTERVAL only): implementation limitation.

Parameters
thdSession thread
borderThe border to check
Returns
false if OK, true if error

◆ check_partition_boundary()

void Window::check_partition_boundary ( )

Check if the just read input row marks the start of a new partition.

Sets the member variables:

m_partition_border and m_part_row_number

If we have partitioning and any one of the partitioning columns have changed since last row, we have a new partition.

◆ check_unique_name()

bool Window::check_unique_name ( const List< Window > &  windows)

Return true if this window's name is not unique in windows.

◆ check_window_functions1()

bool Window::check_window_functions1 ( THD thd,
Query_block select 
)

Check that the semantic requirements for window functions over this window are fulfilled, and accumulate evaluation requirements.

This is run at resolution.

◆ check_window_functions2()

bool Window::check_window_functions2 ( THD thd)

Like check_window_functions1() but contains checks which must wait until the start of the execution phase.

◆ cleanup()

void Window::cleanup ( void  )

Free up any resource used to process the window functions of this window, e.g.

temporary files and in-memory data structures. Called when done with all window processing steps from Query_block::cleanup.

◆ compute_cost()

double Window::compute_cost ( double  cost,
const List< Window > &  windows 
)
static

Compute sorting costs for windowing.

Parameters
costCost of sorting result set once
windowsThe set of windows
Returns
the aggregated sorting costs of the windowing

◆ copy_pos()

void Window::copy_pos ( Window_retrieve_cached_row_reason  from_reason,
Window_retrieve_cached_row_reason  to_reason 
)
inline

Copy frame buffer position hint from one to another.

◆ def_pos()

uint Window::def_pos ( ) const
inline
See also
m_def_pos

◆ destroy()

void Window::destroy ( )

Free structures that were set up during preparation of window functions.

◆ do_copy_null()

bool Window::do_copy_null ( ) const
inline

See m_do_copy_null.

◆ do_inverse()

bool Window::do_inverse ( ) const
inline

See m_inverse_aggregation.

◆ effective_order_by()

const PT_order_list * Window::effective_order_by ( ) const
inline

Get the ORDER BY, if any.

That is, the first we find along the ancestor chain. Uniqueness checked in setup_windows1 SQL 2011 7.11 GR 1.b.i.5.A-C

◆ effective_partition_by()

const PT_order_list * Window::effective_partition_by ( ) const
inline

Get partition, if any.

That is, the partition if any, of the root window. SQL 2011 7.11 GR 1.b.i.4.A-C

◆ eliminate_unused_objects()

void Window::eliminate_unused_objects ( List< Window > *  windows)
static

Check window definitions to remove unused windows.

We do this only after syntactic and semantic checking for errors has been performed. Eliminate redundant sorts after unused windows are removed.

Parameters
windowsThe list of windows defined for this select

◆ equal_sort()

bool Window::equal_sort ( Window w1,
Window w2 
)
staticprivate

Return true of the physical[1] sort orderings for the two windows are the same, cf.

guarantee of SQL 2014 4.15.15 Windowed tables bullet two: The windowing functions are computed using the same row ordering if they specify the same ordering.

Collation and null handling is not supported, so moot.

The two other bullet points are also covered by this test.

[1] After concatenating effective PARTITION BY and ORDER BY (including inheritance) expressions.

◆ first_order_by()

ORDER * Window::first_order_by ( ) const

Get the first argument of the ORDER BY clause for this window if any.

"ORDER BY" is not checked in ancestor unlike effective_order_by(). Use when the goal is to operate on the set of item clauses for all windows of a query. When interrogating the effective order by for a window (specified for it or inherited from another window) use effective_order_by().

◆ first_partition_by()

ORDER * Window::first_partition_by ( ) const

Get the first argument of the PARTITION clause for this window if any.

"PARTITION BY" is not checked in ancestor unlike effective_partition_by(). Use when the goal is to operate on the set of item clauses for all windows of a query. When interrogating the effective partition by for a window (specified for it or inherited from another window) use effective_partition_by().

◆ first_rowno_in_range_frame()

int64 Window::first_rowno_in_range_frame ( ) const
inline

See m_first_rowno_in_range_frame.

◆ first_rowno_in_rows_frame()

int64 Window::first_rowno_in_rows_frame ( ) const
inline

◆ frame()

const PT_frame * Window::frame ( ) const
inline

Get the frame, if any.

SQL 2011 7.11 GR 1.b.i.6

◆ frame_buffer()

TABLE * Window::frame_buffer ( ) const
inline

Getter for m_frame_buffer, q.v.

◆ frame_buffer_param()

Temp_table_param * Window::frame_buffer_param ( ) const
inline

Getter for m_frame_buffer_param, q.v.

◆ frame_buffer_partition_offset()

int64 Window::frame_buffer_partition_offset ( ) const
inline

See m_frame_buffer_partition_offset.

◆ frame_buffer_total_rows()

int64 Window::frame_buffer_total_rows ( ) const
inline

See m_frame_buffer_total_rows.

◆ functions()

List< Item_sum > & Window::functions ( )
inline

Get the list of functions invoked on this window.

◆ has_windowing_steps()

bool Window::has_windowing_steps ( ) const

◆ in_new_order_by_peer_set()

bool Window::in_new_order_by_peer_set ( bool  compare_all_order_by_items = true)

Determine if the current row is not in the same peer set as the previous row.

Used for RANGE frame and implicit RANGE frame (the latter is used by aggregates in the presence of ORDER BY).

The current row is in the same peer set if all ORDER BY columns have the same value as in the previous row.

For JSON_OBJECTAGG only the first order by column needs to be compared to check if a row is in peer set.

Parameters
compare_all_order_by_itemsIf true, compare all the order by items to determine if a row is in peer set. Else, compare only the first order by item to determine peer set.
Returns
true if current row is in a new peer set

◆ is_last()

bool Window::is_last ( void  ) const
inline

See m_last.

◆ is_last_row_in_frame()

bool Window::is_last_row_in_frame ( ) const
inline

See m_is_last_row_in_frame.

◆ is_last_row_in_peerset_within_frame()

int64 Window::is_last_row_in_peerset_within_frame ( ) const
inline

See m_is_last_row_in_peerset_within_frame.

◆ is_reference()

bool Window::is_reference ( ) const
inline

Return if this window represents an unresolved window reference seen in a window function OVER clause.

◆ last_row_output()

int64 Window::last_row_output ( ) const
inline

See m_last_row_output.

◆ last_rowno_in_cache()

int64 Window::last_rowno_in_cache ( ) const
inline

See m_last_rowno_in_cache.

◆ last_rowno_in_peerset()

int64 Window::last_rowno_in_peerset ( ) const
inline

See m_last_rowno_in_peerset.

◆ last_rowno_in_range_frame()

int64 Window::last_rowno_in_range_frame ( ) const
inline

See m_last_rowno_in_range_frame.

◆ make_special_rows_cache()

bool Window::make_special_rows_cache ( THD thd,
TABLE out_tbl 
)

Allocate the cache for special rows.

Parameters
thdthread handle
out_tblThe table where this window function's value is written to
Returns
true if error.

◆ name()

Item_string * Window::name ( ) const
inline

Get the name of a window.

Can be empty, cf. printable_name which is not.

◆ needs_buffering()

bool Window::needs_buffering ( ) const
inline

If we cannot compute one of window functions without looking at succeeding rows, return true, else false.

◆ needs_last_peer_in_frame()

bool Window::needs_last_peer_in_frame ( ) const
inline

If we cannot compute one of window functions without looking at all rows in the peerset of the current row in this frame, return true, else false.

E.g. JSON_OBJECTAGG.

◆ needs_partition_cardinality()

bool Window::needs_partition_cardinality ( ) const
inline

If we need to read the entire partition before we can evaluate some window function(s) on this window,.

Returns
true if that is the case, else false

◆ needs_peerset()

bool Window::needs_peerset ( ) const
inline

If we cannot compute one of window functions without looking at all rows in the peerset of the current row, return true, else false.

E.g. CUME_DIST.

◆ needs_sorting()

bool Window::needs_sorting ( ) const
inline

Determine if the window had either a partition clause (inclusive) or a ORDER BY clause, either defined by itself or inherited from another window.

Returns
true if we have such a clause, which means we need to sort the input table before evaluating the window functions, unless it has been made redundant by a previous windowing step, cf. reorder_and_eliminate_sorts, or due to a single row result set, cf. Query_block::is_implicitly_grouped().

◆ opt_first_row()

bool Window::opt_first_row ( ) const
inline

See m_opt_first_row.

◆ opt_last_row()

bool Window::opt_last_row ( ) const
inline

See m_opt_last_row.

◆ opt_lead_lag()

const st_lead_lag & Window::opt_lead_lag ( ) const
inline

See m_opt_lead_lag.

◆ opt_nth_row()

const st_nth & Window::opt_nth_row ( ) const
inline

See m_opt_nth_row.

◆ optimizable_range_aggregates()

bool Window::optimizable_range_aggregates ( ) const
inline

Return true if the set of window functions are all RANGE unit optimizable.

Only relevant if m_needs_buffering and m_range_optimizable are true.

◆ optimizable_row_aggregates()

bool Window::optimizable_row_aggregates ( ) const
inline

Return true if the set of window functions are all ROW unit optimizable.

Only relevant if m_needs_buffering and m_row_optimizable are true.

◆ partition_rowno()

int64 Window::partition_rowno ( ) const
inline

Getter for m_part_row_number, q.v., the current row number within the partition.

◆ print()

void Window::print ( const THD thd,
String str,
enum_query_type  qt,
bool  expand_definition 
) const

◆ print_border()

void Window::print_border ( const THD thd,
String str,
PT_border b,
enum_query_type  qt 
) const
private

◆ print_frame()

void Window::print_frame ( const THD thd,
String str,
enum_query_type  qt 
) const
private

◆ printable_name()

const char * Window::printable_name ( ) const

◆ reorder_and_eliminate_sorts()

void Window::reorder_and_eliminate_sorts ( List< Window > *  windows)
staticprivate

Reorder windows and eliminate redundant ordering.

If a window has the same ordering requirements as another, we will move them next to each other in the evaluation sequence, so we can sort only once, i.e. before the first window step. This allows us to fulfill the guarantee given by SQL standard when it comes to repeatability of non-deterministic (partially ordered) result sets for windowing inside a query, cf. equal_sort. If more than two have the same ordering, the same applies, we only sort before the first (sort equivalent) window. The hypergraph optimizer uses the interesting order framework instead, eliding all sorts eliminated by this function and possibly more.

Note that we do not merge windows that have the same ordering requirements, so we may still get the extra materialization and multiple rounds of buffering. Yet, we should get correctness, as long as materialization preserves row ordering (which it does for all of our supported temporary table types).

If the result set is implicitly grouped, we also skip any sorting for windows.

Parameters
windowslist of windows

◆ reset_all_wf_state()

void Window::reset_all_wf_state ( )

Reset the execution state for all window functions defined on this window.

◆ reset_execution_state()

void Window::reset_execution_state ( Reset_level  level)
private

Common function for all types of resetting.

◆ reset_lead_lag()

void Window::reset_lead_lag ( )

Reset execution state for LEAD/LAG for the current row in partition.

◆ reset_order_by_peer_set()

void Window::reset_order_by_peer_set ( )

Reset the current row's ORDER BY expressions when starting a new peer set.

◆ reset_partition_state()

void Window::reset_partition_state ( )
inline

Reset window state for a new partition.

Reset the temporary storage used for window frames, typically when we find a new partition. The rows in the buffer are then no longer needed.

◆ reset_round()

void Window::reset_round ( )
inline

Reset execution state for next call to JOIN::exec, cf.

JOIN::reset, or using [Buffering]WindowingIterator::Init.

◆ resolve_reference()

bool Window::resolve_reference ( THD thd,
Item_sum wf,
PT_window **  m_window 
)
static

Resolve any named window to its definition and update m_window to point to the definition instead.

◆ resolve_window_ordering()

bool Window::resolve_window_ordering ( THD thd,
Ref_item_array  ref_item_array,
Table_ref tables,
mem_root_deque< Item * > *  fields,
ORDER o,
bool  partition_order 
)

Resolve and set up the PARTITION BY or an ORDER BY list of a window.

Parameters
thdThe session's execution thread
ref_item_arrayThe base ref items
tablesThe list of tables involved
fieldsThe list of all fields, including hidden ones
oA list of order by expressions
partition_orderIf true, o represent a windowing PARTITION BY, else it represents a windowing ORDER BY
Returns
false if success, true if error

◆ restore_pos()

void Window::restore_pos ( Window_retrieve_cached_row_reason  reason)
inline

See m_tmp_pos.

◆ restore_special_row()

void Window::restore_special_row ( uint64  special_rowno,
uchar record 
)

Restore row special_rowno into record from in-memory copy.

Any fields not the result of window functions are not used, but they do tag along here (unnecessary copying..). BLOBs: have storage in result_field of Item for the window function although the pointer is copied here. The result field storage is stable across reads from the frame buffer, so safe.

◆ row_has_fields_in_out_table()

int64 Window::row_has_fields_in_out_table ( ) const
inline

See m_row_has_fields_in_out_table.

◆ rowno_being_visited()

int64 Window::rowno_being_visited ( ) const
inline

See m_rowno_being_visited.

◆ rowno_in_frame()

int64 Window::rowno_in_frame ( ) const
inline

Return the size of the frame in number of rows.

Returns
frame size See m_rowno_in_frame

◆ rowno_in_partition()

int64 Window::rowno_in_partition ( ) const
inline

See m_rowno_in_partition.

◆ save_pos()

void Window::save_pos ( Window_retrieve_cached_row_reason  reason)
inline

See m_tmp_pos.

◆ save_special_row()

void Window::save_special_row ( uint64  special_rowno,
TABLE t 
)

Save row special_rowno in table t->record[0] to an in-memory copy for later restoration.

◆ set_aggregates_primed()

void Window::set_aggregates_primed ( bool  b)
inline

See m_aggregates_primed.

◆ set_ancestor()

void Window::set_ancestor ( Window a)
inline

After resolving an existing window name reference in a window definition, we set the ancestor pointer to easy access later.

◆ set_def_pos()

void Window::set_def_pos ( uint  pos)
inline
See also
m_def_pos

◆ set_do_copy_null()

void Window::set_do_copy_null ( bool  b)
inline

See m_do_copy_null.

◆ set_first_rowno_in_range_frame()

void Window::set_first_rowno_in_range_frame ( int64  rowno)
inline

See m_first_rowno_in_range_frame.

◆ set_first_rowno_in_rows_frame()

void Window::set_first_rowno_in_rows_frame ( int64  rowno)
inline

See m_first_rowno_in_rows_frame.

◆ set_frame_buffer()

void Window::set_frame_buffer ( TABLE tab)
inline

Setter for m_frame_buffer, q.v.

◆ set_frame_buffer_param()

void Window::set_frame_buffer_param ( Temp_table_param p)
inline

Setter for m_frame_buffer_param, q.v.

◆ set_frame_buffer_partition_offset()

void Window::set_frame_buffer_partition_offset ( int64  offset)
inline

See m_frame_buffer_partition_offset.

◆ set_frame_buffer_total_rows()

void Window::set_frame_buffer_total_rows ( int64  rows)
inline

See m_frame_buffer_total_rows.

◆ set_inverse()

Window & Window::set_inverse ( bool  b)
inline

See m_inverse_aggregation.

◆ set_is_last()

void Window::set_is_last ( bool  last)
inline

An override used by the hypergraph join optimizer only.

◆ set_is_last_row_in_frame()

void Window::set_is_last_row_in_frame ( bool  b)
inline

See m_is_last_row_in_frame.

◆ set_is_last_row_in_peerset_within_frame()

void Window::set_is_last_row_in_peerset_within_frame ( bool  value)
inline

See m_is_last_row_in_peerset_within_frame.

◆ set_last_row_output()

void Window::set_last_row_output ( int64  rno)
inline

See m_last_row_output.

◆ set_last_rowno_in_cache()

void Window::set_last_rowno_in_cache ( uint64  rno)
inline

See m_last_rowno_in_cache.

◆ set_last_rowno_in_peerset()

void Window::set_last_rowno_in_peerset ( uint64  rno)
inline

See m_last_rowno_in_peerset.

◆ set_last_rowno_in_range_frame()

void Window::set_last_rowno_in_range_frame ( uint64  rno)
inline

See m_last_rowno_in_range_frame.

◆ set_name()

void Window::set_name ( Item_string name)
inline

We have a named window.

Now set its name. Used once, if at all, for a window as part of parsing.

◆ set_row_has_fields_in_out_table()

void Window::set_row_has_fields_in_out_table ( int64  rowno)
inline

See m_row_has_fields_in_out_table.

◆ set_rowno_being_visited()

void Window::set_rowno_being_visited ( int64  rno)
inline

See m_rowno_being_visited.

◆ set_rowno_in_frame()

Window & Window::set_rowno_in_frame ( int64  rowno)
inline

See m_rowno_in_frame.

◆ set_rowno_in_partition()

void Window::set_rowno_in_partition ( int64  rowno)
inline

See m_rowno_in_partition.

◆ set_short_circuit()

void Window::set_short_circuit ( bool  short_circuit)
inline

◆ setup_ordering_cached_items()

bool Window::setup_ordering_cached_items ( THD thd,
Query_block select,
const PT_order_list o,
bool  partition_order 
)

Set up cached items for an partition or an order by list updating m_partition_items or m_order_by_items respectively.

Parameters
thdThe session's execution thread
selectThe select for which we are doing windowing
oThe list of ordering expressions
partition_orderIf true, o represents a partition order list, else an ORDER BY list.
Returns
false if success, true if error

◆ setup_range_expressions()

bool Window::setup_range_expressions ( THD thd)

For RANGE frames we need to do computations involving add/subtract and less than, smaller than.

To make this work across types, we construct item trees to do the computations, so we can reuse all the special case handling, e.g. for signed/unsigned int wrap-around, overflow etc.

◆ setup_windows1()

bool Window::setup_windows1 ( THD thd,
Query_block select,
Ref_item_array  ref_item_array,
Table_ref tables,
mem_root_deque< Item * > *  fields,
List< Window > *  windows 
)
static

Semantic checking of windows.

Run at resolution.

Process any window inheritance, that is a window, that in its specification refer to another named window.

Rules: 1) There should be no loops 2) The inheriting window can not specify partitioning 3) The inheriting window can not specify is already specify by an ancestor. 4) An ancestor can not specify window framing clause.

Cf. SQL 2011 7.11 window clause SR 10-11.

Check requirements to the window from its using window functions and make a note of those so we know at execution time, for example if we need to buffer rows to process the window functions, whether inversion optimzation will be used for moving frames etc.

Prepare the physical ordering lists used by sorting at execution time.

Set up cached items for partition determination and for range/peer determination based on order by columns.

Check any frame semantics and for RANGE frames, set up bounds computation item trees.

Parameters
thdThe session's execution thread
selectThe select for which we are doing windowing
ref_item_arrayThe base ref items
tablesThe list of tables involved
fieldsThe list of all fields, including hidden ones
windowsThe list of windows defined for this select
Returns
false if success, true if error

◆ setup_windows2()

bool Window::setup_windows2 ( THD thd,
List< Window > *  windows 
)
static

Like setup_windows1() but contains operations which must wait until the start of the execution phase.

Parameters
thdThe session's execution thread
windowsThe list of windows defined for this select
Returns
false if success, true if error

◆ short_circuit()

bool Window::short_circuit ( ) const
inline

◆ sorting_order()

ORDER * Window::sorting_order ( THD thd = nullptr,
bool  implicit_grouping = false 
)

Concatenation of columns in PARTITION BY and ORDER BY.

Columns present in both list (redundancies) are eliminated, while making sure the order of columns in the ORDER BY is maintained in the merged list.

Parameters
thdOptional. Session state. If not nullptr, initialize the cache.
implicit_groupingOptional. If true, we won't sort (single row result set). Presence implies thd != nullptr for the first call when we lazily set up this information. Succeeding calls return the cached value.
Returns
The start of the concatenated ordering expressions, or nullptr

◆ static_aggregates()

bool Window::static_aggregates ( ) const
inline

Return true if the aggregates are static, i.e.

the same aggregate values for all rows in partition. Only relevant if m_needs_buffering is true.

Member Data Documentation

◆ FRAME_BUFFER_POSITIONS_CARD

constexpr int Window::FRAME_BUFFER_POSITIONS_CARD
staticconstexpr
Initial value:

Cardinality of m_frame_buffer_positions if no NTH_VALUE, LEAD/LAG.

◆ m_aggregates_primed

bool Window::m_aggregates_primed
protected

Execution state: for optimizable aggregates, cf.

m_row_optimizable and m_range_optimizable, we need to keep track of when we have computed the first aggregate, since aggregates for rows 2..N are computed in an optimized way by inverse aggregation of the row moving out of the frame.

◆ m_ancestor

const Window* Window::m_ancestor
protected

resolved from existing window name

◆ m_comparators

Bounds_checked_array<Arg_comparator> Window::m_comparators[2]

◆ m_def_pos

uint Window::m_def_pos
protected

Position of definition in query's text, 1 for leftmost.

References don't count. Thus, anonymous windows in SELECT list, then windows of WINDOW clause, then anonymous windows in ORDER BY.

◆ m_do_copy_null

bool Window::m_do_copy_null
protected

Execution state: make frame wf produce a NULL (or 0 depending, e.g.

if COUNT) value because no rows are available for aggregation: e.g. for first row in partition if frame is ROWS BETWEEN 2 PRECEDING and 1 PRECEDING has no rows for which aggregation can happen

◆ m_first_rowno_in_range_frame

int64 Window::m_first_rowno_in_range_frame
protected

Execution state: the row number of the first row in a frame when evaluating RANGE based frame bounds.

When using RANGE bounds, we don't know a priori when moving the frame which row number will be the next lower bound, but we know it will have to be a row number higher than the lower bound of the previous frame, since the bounds increase monotonically as long as the frame bounds are static within the query (current limitation). So, it makes sense to remember the first row number in a frame until we have determined the start of the next frame.

If the frame for the previous current row in the partition was empty (cf. "current_row" in process_buffered_windowing_record), this should point to the next possible frame start. Relative to partition start, 1-based.

◆ m_first_rowno_in_rows_frame

int64 Window::m_first_rowno_in_rows_frame
protected

Execution state.

Only used for ROWS frame optimized MIN/MAX. The (1-based) number in the partition of first row in the current frame.

◆ m_frame

PT_frame* const Window::m_frame
protected

<window frame clause>

◆ m_frame_buffer

TABLE* Window::m_frame_buffer
protected

Execution state: used iff m_needs_frame_buffering.

Holds the TABLE object for the the temporary file used for the frame buffering.

◆ m_frame_buffer_param

Temp_table_param* Window::m_frame_buffer_param
protected

Execution state: used iff m_needs_frame_buffering.

Holds the temporary file (used for the frame buffering) parameters

◆ m_frame_buffer_partition_offset

int64 Window::m_frame_buffer_partition_offset
protected

Execution state: Snapshot of m_frame_buffer_total_rows when we start a new partition, i.e.

for the first row in the first partition we will have a value of 1.

◆ m_frame_buffer_positions

Mem_root_array_YY<Frame_buffer_position> Window::m_frame_buffer_positions

Execution state: used iff m_needs_frame_buffering.

Holds pointers to positions in the file in m_frame_buffer. We use these saved positions to avoid having to position to the first row in the partition and then making many read calls to find the desired row. By repositioning to a suitably(*) saved position we normally (**) need to do only one positioned read and one ha_rdn_next call to get at a desired row.

   [0] the first row in the partition: at the
       beginning of a new partition that is the first row in the partition.
       Its rowno == 1 by definition.
   [1] position of the current row N  (for jump-back to current row or next
                                       current row in combo with ha_rnd_next)
   [2] position of the current first row M in frame (for aggregation looping
       jump-back)
   [3] position of the current last row in a frame
   [4] position and line number of the row last read
and optionally:
   [5..X] positions of Nth row of X-5+1 NTH_VALUE functions invoked on window
   [X+1..Y] position of last row of lead/lag functions invoked on window

Pointers are lazily initialized if needed.

(*) We use the position closest below the desired position, cf logic in read_frame_buffer_row.

(**) Unless we have a frame beyond the current row, in which case we need to do some scanning for the first row in the partition. Also NTH_VALUE with RANGE might sometimes needs to read several rows, since the frame start can jump several rows ahead when the current row moves forward.

◆ m_frame_buffer_total_rows

int64 Window::m_frame_buffer_total_rows
protected

Execution state: The frame buffer tmp file is not truncated for each new partition.

We need to keep track of where a partition starts in case we need to switch from heap to innodb tmp file on overflow, in order to re-initialize m_frame_buffer_positions with the current partition's row 1 (which is the minimum hint required) as we cross over. This number is incremented for each write.

◆ m_functions

List<Item_sum> Window::m_functions
protected

window functions based on 'this'

◆ m_inherit_from

Item_string* const Window::m_inherit_from
protected

<existing window name>

◆ m_inverse_aggregation

bool Window::m_inverse_aggregation
protected

Execution state: do inverse, e.g.

subtract rather than add in aggregates. Used for optimizing computation of sliding frames for eligible aggregates, cf. Item_sum::check_wf_semantics.

◆ m_is_last_row_in_frame

bool Window::m_is_last_row_in_frame
protected

Execution state: the current row is the last row in a window frame For some aggregate functions, e.g AVG, we can save computation by not evaluating the entire function value before the last row has been read.

For AVG, do the summation for each row in the frame, but the division only for the last row, at which time the result is needed for the wf. Probably only useful for ROW based or static frames. For frame with peer set computation, determining the last row in the peer set ahead of processing is not possible, so we use a pessimistic assumption.

◆ m_is_last_row_in_peerset_within_frame

int64 Window::m_is_last_row_in_peerset_within_frame
protected

Execution state: used iff m_needs_last_peer_in_frame.

True if a row leaving the frame is the last row in the peer set within the frame.

◆ m_is_reference

const bool Window::m_is_reference
protected

If true, m_name is an unbound window reference, other fields are unused.

◆ m_last

bool Window::m_last
protected

The last window to be evaluated at execution time.

◆ m_last_row_output

int64 Window::m_last_row_output
protected

Execution state: The number, in the current partition, of the last output row, i.e.

the row number of the last row hitherto evaluated and output to the next phase.

◆ m_last_rowno_in_cache

int64 Window::m_last_rowno_in_cache
protected

Execution state: used iff m_needs_frame_buffering.

Holds the row number (in the partition) of the last row (hitherto) saved in the frame buffer

◆ m_last_rowno_in_peerset

int64 Window::m_last_rowno_in_peerset
protected

Execution state: used iff m_needs_peerset.

Holds the rowno for the last row in this peer set.

◆ m_last_rowno_in_range_frame

int64 Window::m_last_rowno_in_range_frame
protected

Execution state: used for RANGE bounds frame evaluation for the continued evaluation for current row > 2 in a partition.

If the frame for the current row visited (cf "current_row" in process_buffered_windowing_record) was empty, the invariant

 m_last_rowno_in_range_frame < m_first_rowno_in_range_frame

should hold after the visit. Relative to partition start. 1-based.

◆ m_mark

bool Window::m_mark

Used temporarily by the hypergraph join optimizer to mark which windows are referred to by a given ordering (so that one doesn't try to satisfy a window's ordering by an ordering referring to that window).

◆ m_name

Item_string* Window::m_name
protected

<window name>

◆ m_needs_frame_buffering

bool Window::m_needs_frame_buffering
protected

(At least) one window function needs to buffer frame rows for evaluation i.e.

it cannot be evaluated on the fly just from previous rows seen

◆ m_needs_last_peer_in_frame

bool Window::m_needs_last_peer_in_frame
protected

(At least) one window function (currently JSON_OBJECTAGG) needs the last peer for the current row to evaluate the wf for the current row.

(This is used only during inversion/optimization)

◆ m_needs_partition_cardinality

bool Window::m_needs_partition_cardinality
protected

(At least) one window function needs the cardinality of the partition of the current row to evaluate the wf for the current row

◆ m_needs_peerset

bool Window::m_needs_peerset
protected

(At least) one window function needs the peer set of the current row to evaluate the wf for the current row

◆ m_opt_first_row

bool Window::m_opt_first_row
protected

Window equires re-evaluation of the first row in optimized moving frame mode e.g.

FIRST_VALUE.

◆ m_opt_last_row

bool Window::m_opt_last_row
protected

Window requires re-evaluation of the last row in optimized moving frame mode e.g.

LAST_VALUE.

◆ m_opt_lead_lag

st_lead_lag Window::m_opt_lead_lag
protected

◆ m_opt_nth_row

st_nth Window::m_opt_nth_row
protected

Window requires re-evaluation of the Nth row in optimized moving frame mode e.g.

NTH_VALUE.

◆ m_order_by

PT_order_list* const Window::m_order_by
protected

<window order clause>

◆ m_order_by_items

Mem_root_array<Cached_item *> Window::m_order_by_items
protected

items for the ORDER BY exprs.

◆ m_ordering_idx

int Window::m_ordering_idx

The logical ordering index (into LogicalOrderings) needed by this window's PARTITION BY and ORDER BY clauses together (if any; else, 0).

Used only by the hypergraph join optimizer.

◆ m_part_row_number

int64 Window::m_part_row_number
protected

Execution state: the current row number in the current partition.

Set in check_partition_boundary. Used while reading input rows, in contrast to m_rowno_in_partition, which is used when processing buffered rows. Cf. check_partition_boundary.

◆ m_partition_border

bool Window::m_partition_border
protected

Execution state: the current row starts a new partition.

Set in check_partition_boundary.

◆ m_partition_by

PT_order_list* const Window::m_partition_by
protected

<window partition clause>

◆ m_partition_items

Mem_root_array<Cached_item *> Window::m_partition_items
protected

items for the PARTITION BY columns

◆ m_query_block

Query_block* Window::m_query_block
protected

The SELECT the window is on.

◆ m_range_optimizable

bool Window::m_range_optimizable
protected

The functions are optimizable with RANGE unit.

For example SUM is, MAX is not always optimizable. Optimized means we can use the optimized evaluation path in process_buffered_windowing_record which uses inversion to avoid revisiting all frame rows for every row being evaluated.

◆ m_row_has_fields_in_out_table

int64 Window::m_row_has_fields_in_out_table
protected

If >=1: the row with this number (1-based, relative to start of partition) currently has its fields in the record buffer of the IN table and of the OUT table.

0 means "unset". Usable only with buffering. Set and read by bring_back_frame_row(), so that multiple successive calls to it for same row do only one read from FB (optimization).

◆ m_row_optimizable

bool Window::m_row_optimizable
protected

The functions are optimizable with ROW unit.

For example SUM is, MAX is not always optimizable. Optimized means we can use the optimized evaluation path in process_buffered_windowing_record which uses inversion to avoid revisiting all frame rows for every row being evaluated.

◆ m_rowno_being_visited

int64 Window::m_rowno_being_visited
protected

Execution state: The number of the row being visited for its contribution to a window function, relative to the start of the partition.

Note that this will often be different from the current row for which we are processing the window function, readying it for output. That is given by m_rowno_in_partition, q.v. Contrast also with m_rowno_in_frame which is frame relative.

◆ m_rowno_in_frame

int64 Window::m_rowno_in_frame
protected

Execution state: the row number of the row we are looking at for evaluating its contribution to some window function(s).

It is relative to start of the frame and 1-based. It is typically set after fetching a row from the frame buffer using bring_back_frame_row and before calling copy_funcs. Cf. also m_is_last_row_in_frame.

◆ m_rowno_in_partition

int64 Window::m_rowno_in_partition
protected

Execution state: The row number of the current row being readied for output within the partition.

1-based. In process_buffered_windowing_record this is known as current_row.

◆ m_short_circuit

bool Window::m_short_circuit = false
protected

Holds whether this window should be “short-circuit”, ie., goes directly to the query output instead of to a temporary table.

◆ m_sorting_order

ORDER* Window::m_sorting_order
protected

merged partition/order by

◆ m_special_rows_cache

uchar* Window::m_special_rows_cache
protected

Holds a fixed number of copies of special rows; each copy can use up to m_special_rows_cache_max_length bytes.

Special rows are those that are not part of our frame, but that we need to store away nevertheless, because they might be in the table's buffers, which we need for our own purposes during window processing. cf. the Special_keys enumeration.

◆ m_special_rows_cache_length

size_t Window::m_special_rows_cache_length[FBC_FIRST_KEY - FBC_LAST_KEY+1]
protected

Length of each copy in m_special_rows_cache, in bytes.

◆ m_special_rows_cache_max_length

size_t Window::m_special_rows_cache_max_length
protected

Maximum allocated size in m_special_rows_cache.

◆ m_static_aggregates

bool Window::m_static_aggregates
protected

The aggregates (SUM, etc) can be evaluated once for a partition, since it is static, i.e.

all rows will have the same value for the aggregates, e.g. ROWS/RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING.

◆ m_tmp_pos

Frame_buffer_position Window::m_tmp_pos

Sometimes we read one row too many, so that the saved position will be too far out because we subsequently need to read an earlier (previous) row of the same kind (reason).

For such cases, we first save the current position, read, and if we see we read too far, restore the old position. See save_pos and restore_pos.


The documentation for this class was generated from the following files: