MySQL  8.0.18
Source Code Documentation
PT_window Class Reference

Parse tree node for a window; just a shallow wrapper for class Window, q.v. More...

#include <parse_tree_nodes.h>

Inheritance diagram for PT_window:
Parse_tree_node_tmpl< Context > Window

Public Member Functions

 PT_window (PT_order_list *partition_by, PT_order_list *order_by, PT_frame *frame)
 
 PT_window (PT_order_list *partition_by, PT_order_list *order_by, PT_frame *frame, Item_string *inherit)
 
 PT_window (Item_string *name)
 
bool contextualize (Parse_context *pc) override
 
- Public Member Functions inherited from Parse_tree_node_tmpl< Context >
virtual ~Parse_tree_node_tmpl ()
 
bool is_contextualized () const
 
virtual bool contextualize (Context *pc)
 Do all context-sensitive things and mark the node as contextualized. More...
 
virtual bool contextualize_ (Context *)
 
Intermediate version of the contextualize() function More...
 
void error (Context *pc, const POS &pos) const
 syntax_error() function replacement for deferred reporting of syntax errors More...
 
void error (Context *pc, const POS &pos, const char *msg) const
 syntax_error() function replacement for deferred reporting of syntax errors More...
 
void errorf (Context *pc, const POS &pos, const char *format,...) const
 syntax_error() function replacement for deferred reporting of syntax errors More...
 
- Public Member Functions inherited from Window
void save_pos (retrieve_cached_row_reason reason)
 See m_tmp_pos. More...
 
void restore_pos (retrieve_cached_row_reason reason)
 See m_tmp_pos. More...
 
void copy_pos (retrieve_cached_row_reason from_reason, 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_functions (THD *thd, SELECT_LEX *select)
 Check that the semantic requirements for window functions over this window are fulfilled, and accumulate evaluation requirements. 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_record (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_record (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_LIST *tables, List< Item > &fields, List< Item > &all_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 (List< Window > &windows)
 Return true if this window's name is not unique in windows. More...
 
bool setup_ordering_cached_items (THD *thd, SELECT_LEX *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_card () 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_needs_restore_input_row (bool b)
 See m_needs_restore_input_row. More...
 
bool needs_restore_input_row () const
 See m_needs_restore_input_row. 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...
 
Temp_table_paramouttable_param () const
 
Getter for m_outtable_param, q.v. More...
 
void set_outtable_param (Temp_table_param *p)
 
Setter for m_outtable_param, q.v. More...
 
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_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 (THD *thd)
 Free up any resource used to process the window functions of this window, e.g. 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 reinit_before_use ()
 Reset resolution and execution state to prepare for next execution of a prepared statement. 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
 

Private Types

typedef Parse_tree_node super
 

Additional Inherited Members

- Public Types inherited from Parse_tree_node_tmpl< Context >
typedef Context context_t
 
- Public Types inherited from Window
enum  retrieve_cached_row_reason {
  REA_WONT_UPDATE_HINT, REA_FIRST_IN_PARTITION = 0, REA_CURRENT = 1, REA_FIRST_IN_FRAME = 2,
  REA_LAST_IN_FRAME = 3, REA_LAST_IN_PEERSET = 4, REA_MISC_POSITIONS = 5
}
 Position hints for the frame buffer are saved for these kind of row accesses, cf. More...
 
enum  Special_keys { FBC_FIRST_IN_NEXT_PARTITION = -1, FBC_LAST_BUFFERED_ROW = -2, FBC_FIRST_KEY = FBC_FIRST_IN_NEXT_PARTITION, FBC_LAST_KEY = FBC_LAST_BUFFERED_ROW }
 Keys for m_frame_buffer_cache and m_special_rows_cache, for special rows. More...
 
enum  Reset_level { RL_FULL, RL_ROUND, RL_PARTITION }
 
- Static Public Member Functions inherited from Parse_tree_node_tmpl< Context >
static void * operator new (size_t size, MEM_ROOT *mem_root, const std::nothrow_t &arg=std::nothrow) noexcept
 
static void operator delete (void *ptr, size_t size)
 
static void operator delete (void *, MEM_ROOT *, const std::nothrow_t &) noexcept
 
- Static Public Member Functions inherited from Window
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_windows (THD *thd, SELECT_LEX *select, Ref_item_array ref_item_array, TABLE_LIST *tables, List< Item > &fields, List< Item > &all_fields, List< Window > &windows)
 Semantic checking of windows. More...
 
static void remove_unused_windows (THD *thd, List< Window > &windows)
 Remove unused window definitions. More...
 
static double compute_cost (double cost, List< Window > &windows)
 Compute sorting costs for windowing. More...
 
- Public Attributes inherited from Window
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...
 
Item_funcm_comparators [WBT_VALUE_FOLLOWING+1][2]
 RANGE bound determination computation; first index is a value of the enum_window_border_type enum; second index 0 for the start bound, 1 for the end bound. More...
 
Item_funcm_inverse_comparators [WBT_VALUE_FOLLOWING+1][2]
 Each item has inverse operation of the corresponding comparator in m_comparators. More...
 
- Static Public Attributes inherited from Window
static constexpr int FRAME_BUFFER_POSITIONS_CARD = REA_MISC_POSITIONS
 Cardinality of m_frame_buffer_positions if no NTH_VALUE, LEAD/LAG. More...
 
- Protected Member Functions inherited from Parse_tree_node_tmpl< Context >
 Parse_tree_node_tmpl ()
 
- Protected Attributes inherited from Window
SELECT_LEXm_select
 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...
 
bool m_sort_redundant
 Can use sort from previous w. 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_card
 (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_needs_restore_input_row
 Can be true if first window after a join: we may need to restore the input record after buffered window processing if EQRefIterator's caching logic presumes the record hasn't been modified (when last qep_tab uses JT_EQ_REF). 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...
 
List< Cached_itemm_partition_items
 items for the PARTITION BY columns More...
 
List< Cached_itemm_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...
 
Temp_table_paramm_outtable_param
 Execution state: Holds the temporary output table (for next step) parameters. 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 current row within a frame, cf. 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...
 
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...
 

Detailed Description

Parse tree node for a window; just a shallow wrapper for class Window, q.v.

Member Typedef Documentation

◆ super

Constructor & Destructor Documentation

◆ PT_window() [1/3]

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

◆ PT_window() [2/3]

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

◆ PT_window() [3/3]

PT_window::PT_window ( Item_string name)
inline

Member Function Documentation

◆ contextualize()

bool PT_window::contextualize ( Parse_context pc)
override

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