MySQL  8.0.18
Source Code Documentation
Item_sum Class Referenceabstract


Class Item_sum is the base class used for special expressions that SQL calls 'set functions'. More...

#include <item_sum.h>

Inheritance diagram for Item_sum:
Item_result_field Item Parse_tree_node_tmpl< Context > Item_first_last_value Item_func_group_concat Item_non_framing_wf Item_nth_value Item_sum_bit Item_sum_hybrid Item_sum_json Item_sum_num Item_udf_sum

Public Types

enum  Sumfunctype {
  COUNT_FUNC, COUNT_DISTINCT_FUNC, SUM_FUNC, SUM_DISTINCT_FUNC,
  AVG_FUNC, AVG_DISTINCT_FUNC, MIN_FUNC, MAX_FUNC,
  STD_FUNC, VARIANCE_FUNC, SUM_BIT_FUNC, UDF_SUM_FUNC,
  GROUP_CONCAT_FUNC, JSON_AGG_FUNC, ROW_NUMBER_FUNC, RANK_FUNC,
  DENSE_RANK_FUNC, CUME_DIST_FUNC, PERCENT_RANK_FUNC, NTILE_FUNC,
  LEAD_LAG_FUNC, FIRST_LAST_VALUE_FUNC, NTH_VALUE_FUNC
}
 
- Public Types inherited from Item
enum  Type {
  INVALID_ITEM = 0, FIELD_ITEM, FUNC_ITEM, SUM_FUNC_ITEM,
  STRING_ITEM, INT_ITEM, REAL_ITEM, NULL_ITEM,
  VARBIN_ITEM, COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM,
  PROC_ITEM, COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
  FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM, SUBSELECT_ITEM, ROW_ITEM,
  CACHE_ITEM, TYPE_HOLDER, PARAM_ITEM, TRIGGER_FIELD_ITEM,
  DECIMAL_ITEM, XPATH_NODESET, XPATH_NODESET_CMP, VIEW_FIXER_ITEM,
  FIELD_BIT_ITEM, NULL_RESULT_ITEM
}
 
enum  cond_result { COND_UNDEF, COND_OK, COND_TRUE, COND_FALSE }
 
enum  traverse_order { POSTFIX, PREFIX }
 
enum  enum_const_item_cache { CACHE_NONE = 0, CACHE_JSON_VALUE, CACHE_JSON_ATOM }
 How to cache constant JSON data. More...
 
enum  Bool_test {
  BOOL_IS_TRUE = 0x00, BOOL_IS_FALSE = 0x01, BOOL_IS_UNKNOWN = 0x02, BOOL_NOT_TRUE = 0x03,
  BOOL_NOT_FALSE = 0x04, BOOL_NOT_UNKNOWN = 0x05, BOOL_IDENTITY = 0x06, BOOL_NEGATED = 0x07,
  BOOL_ALWAYS_TRUE = 0x08, BOOL_ALWAYS_FALSE = 0x09
}
 < Modifier for result transformation More...
 
enum  item_marker {
  MARKER_NONE = 0, MARKER_CONST_PROPAG = 1, MARKER_BIT = 4, MARKER_FUNC_DEP_NOT_NULL = 5,
  MARKER_DISTINCT_GROUP = 6, MARKER_ICP_COND_USES_INDEX_ONLY = 10
}
 < Values for member 'marker' More...
 
- Public Types inherited from Parse_tree_node_tmpl< Context >
typedef Context context_t
 

Public Member Functions

bool has_force_copy_fields () const
 
bool has_with_distinct () const
 
void mark_as_sum_func ()
 
void mark_as_sum_func (SELECT_LEX *)
 
 Item_sum (const POS &pos, PT_window *w)
 
 Item_sum (Item *a)
 
 Item_sum (const POS &pos, Item *a, PT_window *w)
 
 Item_sum (const POS &pos, Item *a, Item *b, PT_window *w)
 
 Item_sum (const POS &pos, PT_item_list *opt_list, PT_window *w)
 
 Item_sum (THD *thd, const Item_sum *item)
 Copy constructor, need to perform subqueries with temporary tables. More...
 
bool itemize (Parse_context *pc, Item **res) override
 The same as contextualize()/contextualize_() but with additional parameter. More...
 
Type type () const override
 
virtual enum Sumfunctype sum_func () const =0
 
virtual void fix_after_pullout (SELECT_LEX *parent_select, SELECT_LEX *removed_select) override
 Fix after tables have been moved from one select_lex level to the parent level, e.g by semijoin conversion. More...
 
bool reset_and_add ()
 Resets the aggregate value to its default and aggregates the current value of its attribute(s). More...
 
virtual void reset_field ()=0
 
virtual void update_field ()=0
 
virtual bool keep_field_type () const
 
bool resolve_type (THD *) override
 Resolve type-related information for this item, such as result field type, maximum size, precision, signedness, character set and collation. More...
 
virtual Itemresult_item (Field *field)
 
table_map used_tables () const override
 
void update_used_tables () override
 
bool is_null () override
 
void make_const ()
 
void print (const THD *thd, String *str, enum_query_type query_type) const override
 This method is used for to: More...
 
void fix_num_length_and_dec ()
 
bool eq (const Item *item, bool binary_cmp) const override
 
void no_rows_in_result () override
 Mark an aggregate as having no rows. More...
 
virtual void make_unique ()
 
virtual Fieldcreate_tmp_field (bool group, TABLE *table)
 
bool walk (Item_processor processor, enum_walk walk, uchar *arg) override
 Traverses a tree of Items in prefix and/or postfix order. More...
 
bool clean_up_after_removal (uchar *arg) override
 Remove the item from the list of inner aggregation functions in the SELECT_LEX it was moved to by Item_sum::check_sum_func(). More...
 
bool aggregate_check_group (uchar *arg) override
 
bool aggregate_check_distinct (uchar *arg) override
 
bool has_aggregate_ref_in_group_by (uchar *arg) override
 Check if an aggregate is referenced from within the GROUP BY clause of the query block in which it is aggregated. More...
 
bool init_sum_func_check (THD *thd)
 Prepare an aggregate function for checking of context. More...
 
bool check_sum_func (THD *thd, Item **ref)
 Validate the semantic requirements of a set function. More...
 
Itemget_arg (uint i)
 
Itemset_arg (uint i, THD *thd, Item *new_val)
 
uint get_arg_count () const
 
Item ** get_arg_ptr (uint i)
 
bool fix_fields (THD *thd, Item **ref) override
 
void init_aggregator ()
 
bool aggregator_setup (THD *thd)
 Called to initialize the aggregator. More...
 
void aggregator_clear ()
 Called to cleanup the aggregator. More...
 
bool aggregator_add ()
 Called to add value to the aggregator. More...
 
void set_distinct (bool distinct)
 
int set_aggregator (Aggregator::Aggregator_type aggregator)
 
virtual void clear ()=0
 
virtual bool add ()=0
 
virtual bool setup (THD *)
 
virtual bool check_wf_semantics (THD *thd, SELECT_LEX *select, Window::Evaluation_requirements *reqs)
 Only relevant for aggregates qua window functions. More...
 
void split_sum_func (THD *thd, Ref_item_array ref_item_array, List< Item > &fields) override
 
void cleanup () override
 
const Windowwindow () const
 
bool reset_wf_state (uchar *arg) override
 Reset execution state for such window function types as determined by arg. More...
 
virtual bool framing () const
 All aggregates are framing, i.e. More...
 
virtual bool uses_only_one_row () const
 Only for framing window functions. More...
 
virtual bool needs_card () const
 Return true if we need to make two passes over the rows in the partition - either because we need the cardinality of it (and we need to read all rows to detect the next partition), or we need to have all partition rows available to evaluate the window function for some other reason, e.g. More...
 
bool wf_common_init ()
 Common initial actions for window functions. More...
 
- Public Member Functions inherited from Item_result_field
 Item_result_field ()
 
 Item_result_field (const POS &pos)
 
 Item_result_field (THD *thd, const Item_result_field *item)
 
 ~Item_result_field () override
 
Fieldget_tmp_table_field () override
 
Fieldtmp_table_field (TABLE *) override
 
void set_result_field (Field *field) override
 
bool is_result_field () const override
 
Fieldget_result_field () const override
 
void save_in_result_field (bool no_conversions) override
 
virtual const char * func_name () const =0
 
bool check_function_as_value_generator (uchar *) override
 Check if this item is allowed for a virtual column or inside a default expression. More...
 
bool mark_field_in_map (uchar *arg) override
 Mark underlying field in read or write map of a table. More...
 
longlong llrint_with_overflow_check (double realval)
 
void raise_numeric_overflow (const char *type_name)
 
double raise_float_overflow ()
 
longlong raise_integer_overflow ()
 
int raise_decimal_overflow ()
 
- Public Member Functions inherited from Item
 Item (const Item &)=delete
 
void operator= (Item &)=delete
 
 Item ()
 Item constructor for general use. More...
 
 Item (THD *thd, const Item *item)
 Constructor used by Item_field, Item_ref & aggregate functions. More...
 
 Item (const POS &)
 Parse-time context-independent constructor. More...
 
virtual ~Item () override
 
void rename (char *new_name)
 rename item (used for views, cleanup() return original name). More...
 
void init_make_field (Send_field *tmp_field, enum enum_field_types type)
 
virtual void make_field (Send_field *field)
 
virtual Fieldmake_string_field (TABLE *table)
 Create a field to hold a string value from an item. More...
 
void quick_fix_field ()
 
virtual void set_can_use_prefix_key ()
 
type_conversion_status save_in_field_no_warnings (Field *field, bool no_conversions)
 Save the item into a field but do not emit any warnings. More...
 
type_conversion_status save_in_field (Field *field, bool no_conversions)
 Save a temporal value in packed longlong format into a Field. More...
 
virtual void save_org_in_field (Field *field)
 
virtual bool send (Protocol *protocol, String *str)
 This is only called from items that is not of type item_field. More...
 
bool evaluate (THD *thd, String *str)
 Evaluate item, possibly using the supplied buffer. More...
 
virtual Item_result result_type () const
 
virtual enum Item_result numeric_context_result_type () const
 Result type when an item appear in a numeric context. More...
 
enum Item_result temporal_with_date_as_number_result_type () const
 Similar to result_type() but makes DATE, DATETIME, TIMESTAMP pretend to be numbers rather than strings. More...
 
enum_field_types data_type () const
 Retrieve the derived data type of the Item. More...
 
void set_data_type (enum_field_types data_type)
 Set the data type of the current Item. More...
 
void set_data_type_bool ()
 
void set_data_type_longlong ()
 Set the data type of the Item to be longlong. More...
 
void set_data_type_decimal (uint8 precision, uint8 dec)
 Set the data type of the Item to be decimal. More...
 
void set_data_type_double ()
 Set the data type of the Item to be double precision floating point. More...
 
void set_data_type_float ()
 Set the data type of the Item to be single precision floating point. More...
 
void set_data_type_string_init ()
 Initialize an Item to be of VARCHAR type, other properties undetermined. More...
 
void set_data_type_string (uint32 max_l)
 Set the Item to be variable length string. More...
 
void set_data_type_string (ulonglong max_char_length_arg)
 Set the Item to be variable length string. More...
 
void set_data_type_string (ulonglong max_l, const CHARSET_INFO *cs)
 Set the Item to be variable length string. More...
 
void set_data_type_string (uint32 max_l, const DTCollation &coll)
 Set the Item to be variable length string. More...
 
void set_data_type_char (uint32 max_l)
 Set the Item to be fixed length string. More...
 
void set_data_type_char (uint32 max_l, const CHARSET_INFO *cs)
 Set the Item to be fixed length string. More...
 
void set_data_type_blob (uint32 max_l)
 Set the Item to be of BLOB type. More...
 
void set_data_type_date ()
 Set all type properties for Item of DATE type. More...
 
void set_data_type_time (uint8 fsp)
 Set all type properties for Item of TIME type. More...
 
void set_data_type_datetime (uint8 fsp)
 Set all properties for Item of DATETIME type. More...
 
void set_data_type_timestamp (uint8 fsp)
 Set all properties for Item of TIMESTAMP type. More...
 
void set_data_type_json ()
 Set the data type of the Item to be JSON. More...
 
void set_data_type_year ()
 Set the data type of the Item to be YEAR. More...
 
void set_data_type_geometry ()
 Set the Item to be of GEOMETRY type. More...
 
void set_data_type_from_result (Item_result result, uint32 length)
 Set type information of Item from "result" information. More...
 
void set_data_type_from_item (Item *item)
 Set data type properties of the item from the properties of another item. More...
 
virtual Item_result cast_to_int_type () const
 
void aggregate_type (Bounds_checked_array< Item *> items)
 Aggregates data types from array of items into current item. More...
 
virtual enum_monotonicity_info get_monotonicity_info () const
 
bool is_null_value ()
 For template-compatibility with Field. More...
 
virtual longlong val_int_endpoint (bool left_endp, bool *incl_endp)
 
virtual double val_real ()=0
 
virtual longlong val_int ()=0
 
virtual longlong val_date_temporal ()
 Return date value of item in packed longlong format. More...
 
virtual longlong val_time_temporal ()
 Return time value of item in packed longlong format. More...
 
longlong val_temporal_by_field_type ()
 Return date or time value of item in packed longlong format, depending on item field type. More...
 
longlong val_temporal_with_round (enum_field_types type, uint8 dec)
 Get date or time value in packed longlong format. More...
 
ulonglong val_uint ()
 
virtual Stringval_str (String *str)=0
 
virtual Stringval_str_ascii (String *str)
 
virtual my_decimalval_decimal (my_decimal *decimal_buffer)=0
 
virtual bool val_bool ()
 
virtual bool val_json (Json_wrapper *result)
 Get a JSON value from an Item. More...
 
virtual float get_filtering_effect (THD *thd, table_map filter_for_table, table_map read_tables, const MY_BITMAP *fields_to_ignore, double rows_in_table)
 Calculate the filter contribution that is relevant for table 'filter_for_table' for this item. More...
 
bool error_json ()
 Get the value to return from val_json() in case of errors. More...
 
bool get_date_from_non_temporal (MYSQL_TIME *ltime, my_time_flags_t fuzzydate)
 Convert a non-temporal type to date. More...
 
bool get_time_from_non_temporal (MYSQL_TIME *ltime)
 Convert a non-temporal type to time. More...
 
type_conversion_status save_time_in_field (Field *field)
 
type_conversion_status save_date_in_field (Field *field)
 
type_conversion_status save_str_value_in_field (Field *field, String *result)
 
virtual const char * full_name () const
 
virtual table_map not_null_tables () const
 
virtual bool basic_const_item () const
 Returns true if this is a simple constant item like an integer, not a constant expression. More...
 
virtual Itemclone_item () const
 
virtual cond_result eq_cmp_result () const
 
uint float_length (uint decimals_par) const
 
virtual uint decimal_precision () const
 
int decimal_int_part () const
 
virtual uint time_precision ()
 TIME precision of the item: 0..6. More...
 
virtual uint datetime_precision ()
 DATETIME precision of the item: 0..6. More...
 
bool const_item () const
 Returns true if item is constant, regardless of query evaluation state. More...
 
bool const_for_execution () const
 Returns true if item is constant during one query execution. More...
 
bool may_evaluate_const (const THD *thd) const
 Return true if this is a const item that may be evaluated in the current phase of statement processing. More...
 
void print_item_w_name (const THD *thd, String *, enum_query_type query_type) const
 
void print_for_order (const THD *thd, String *str, enum_query_type query_type, bool used_alias) const
 Prints the item when it's part of ORDER BY and GROUP BY. More...
 
void split_sum_func2 (THD *thd, Ref_item_array ref_item_array, List< Item > &fields, Item **ref, bool skip_registered)
 
virtual bool get_date (MYSQL_TIME *ltime, my_time_flags_t fuzzydate)=0
 
virtual bool get_time (MYSQL_TIME *ltime)=0
 
virtual bool get_timeval (struct timeval *tm, int *warnings)
 Get timestamp in "struct timeval" format. More...
 
bool update_null_value ()
 Make sure the null_value member has a correct value. More...
 
virtual void apply_is_true ()
 Apply the IS TRUE truth property, meaning that an UNKNOWN result and a FALSE result are treated the same. More...
 
virtual bool is_bool_func () const
 
virtual Itemcopy_or_same (THD *)
 
virtual Itemcopy_andor_structure (THD *)
 
virtual Itemreal_item ()
 
virtual Itemsubstitutional_item ()
 
virtual void set_runtime_created ()
 
virtual Itemget_tmp_table_item (THD *thd)
 
virtual const CHARSET_INFOcompare_collation () const
 
virtual const CHARSET_INFOcharset_for_protocol () const
 
template<class T >
bool walk_helper_thunk (uchar *arg)
 
virtual Itemtransform (Item_transformer transformer, uchar *arg)
 Perform a generic transformation of the Item tree, by adding zero or more additional Item objects to it. More...
 
virtual Itemcompile (Item_analyzer analyzer, uchar **arg_p, Item_transformer transformer, uchar *arg_t)
 Perform a generic "compilation" of the Item tree, ie transform the Item tree by adding zero or more Item objects to it. More...
 
virtual void traverse_cond (Cond_traverser traverser, void *arg, traverse_order)
 
virtual bool intro_version (uchar *)
 
bool cleanup_processor (uchar *)
 cleanup() item if it is resolved ('fixed'). More...
 
virtual bool collect_item_field_processor (uchar *)
 
virtual bool add_field_to_set_processor (uchar *)
 Item::walk function. More...
 
virtual bool visitor_processor (uchar *arg)
 A processor to handle the select lex visitor framework. More...
 
virtual bool add_field_to_cond_set_processor (uchar *)
 Item::walk function. More...
 
virtual bool remove_column_from_bitmap (uchar *arg)
 Visitor interface for removing all column expressions (Item_field) in this expression tree from a bitmap. More...
 
virtual bool find_item_in_field_list_processor (uchar *)
 
virtual bool change_context_processor (uchar *)
 
virtual bool find_item_processor (uchar *arg)
 
virtual bool is_non_const_over_literals (uchar *)
 
virtual bool find_field_processor (uchar *)
 Is this an Item_field which references the given Field argument? More...
 
virtual bool cast_incompatible_args (uchar *)
 Wrap incompatible arguments in CAST nodes to the expected data types. More...
 
virtual bool references_select_expr_of (uchar *arg)
 
virtual bool used_tables_for_level (uchar *arg)
 Return used table information for the specified query block (level). More...
 
virtual bool check_column_privileges (uchar *thd)
 Check privileges. More...
 
virtual bool inform_item_in_cond_of_tab (uchar *)
 
bool propagate_derived_used (uchar *)
 Propagate components that use referenced columns from derived tables. More...
 
bool propagate_set_derived_used (uchar *)
 Called by Item::walk() to set all the referenced items' derived_used flag. More...
 
virtual bool is_strong_side_column_not_in_fd (uchar *)
 
virtual bool is_column_not_in_fd (uchar *)
 
virtual Bool3 local_column (const SELECT_LEX *) const
 
virtual bool cache_const_expr_analyzer (uchar **cache_item)
 Check if an item is a constant one and can be cached. More...
 
Itemcache_const_expr_transformer (uchar *item)
 Cache item if needed. More...
 
virtual bool equality_substitution_analyzer (uchar **)
 
virtual Itemequality_substitution_transformer (uchar *)
 
virtual bool check_partition_func_processor (uchar *)
 Check if a partition function is allowed. More...
 
virtual bool subst_argument_checker (uchar **arg)
 
virtual bool explain_subquery_checker (uchar **)
 
virtual Itemexplain_subquery_propagator (uchar *)
 
virtual Itemequal_fields_propagator (uchar *)
 
virtual bool set_no_const_sub (uchar *)
 
virtual Itemreplace_equal_field (uchar *)
 
virtual bool check_valid_arguments_processor (uchar *)
 
virtual bool check_gcol_depend_default_processor (uchar *args)
 Check if a generated expression depends on DEFAULT function with specific column name as argument. More...
 
virtual Itemthis_item ()
 
virtual const Itemthis_item () const
 
virtual Item ** this_item_addr (THD *, Item **addr_arg)
 
virtual uint cols () const
 
virtual Itemelement_index (uint)
 
virtual Item ** addr (uint)
 
virtual bool check_cols (uint c)
 
virtual bool null_inside ()
 
virtual void bring_value ()
 
Fieldtmp_table_field_from_field_type (TABLE *table, bool fixed_length)
 Create a field based on field_type of argument. More...
 
virtual Item_fieldfield_for_view_update ()
 
virtual Itemtruth_transformer (THD *thd, Bool_test test)
 Informs an item that it is wrapped in a truth test, in case it wants to transforms itself to implement this test by itself. More...
 
virtual Itemupdate_value_transformer (uchar *)
 
virtual Itemsafe_charset_converter (THD *thd, const CHARSET_INFO *tocs)
 
void delete_self ()
 
virtual bool is_splocal () const
 
virtual Settable_routine_parameterget_settable_routine_parameter ()
 
bool is_temporal_with_date () const
 
bool is_temporal_with_date_and_time () const
 
bool is_temporal_with_time () const
 
bool is_temporal () const
 
bool has_compatible_context (Item *item) const
 Check whether this and the given item has compatible comparison context. More...
 
virtual Field::geometry_type get_geometry_type () const
 
Stringcheck_well_formed_result (String *str, bool send_error, bool truncate)
 Verifies that the input string is well-formed according to its character set. More...
 
bool eq_by_collation (Item *item, bool binary_cmp, const CHARSET_INFO *cs)
 
virtual bool is_expensive ()
 
uint32 max_char_length () const
 
void fix_char_length (uint32 max_char_length_arg)
 
virtual bool is_outer_field () const
 
bool is_blob_field () const
 Check if an item either is a blob field, or will be represented as a BLOB field if a field is created based on this item. More...
 
bool has_subquery () const
 
bool has_stored_program () const
 
bool has_aggregation () const
 
void set_aggregation ()
 Set the "has aggregation" property. More...
 
void reset_aggregation ()
 Reset the "has aggregation" property. More...
 
bool has_wf () const
 
void set_wf ()
 Set the "has window function" property. More...
 
bool has_rollup_expr () const
 
void set_rollup_expr ()
 Set the property: this item (tree) contains a reference to a ROLLUP expr. More...
 
bool has_grouping_func () const
 
void set_grouping_func ()
 Set the property: this item is a call to GROUPING. More...
 
virtual bool created_by_in2exists () const
 Whether this Item was created by the IN->EXISTS subquery transformation. More...
 
bool is_derived_used () const
 
void mark_subqueries_optimized_away ()
 
virtual bool gc_subst_analyzer (uchar **)
 Analyzer function for GC substitution. More...
 
virtual Itemgc_subst_transformer (uchar *)
 Transformer function for GC substitution. More...
 
virtual bool replace_field_processor (uchar *)
 A processor that replaces any Fields with a Create_field_wrapper. More...
 
bool can_be_substituted_for_gc () const
 Check if this item is of a type that is eligible for GC substitution. More...
 
void aggregate_decimal_properties (Item **item, uint nitems)
 Set precision and decimals of function when this depends on arguments' values for these quantities. More...
 
void aggregate_float_properties (Item **item, uint nitems)
 Set max_length and decimals of function if function is floating point and result length/precision depends on argument ones. More...
 
void aggregate_char_length (Item **args, uint nitems)
 Set the maximum number of characters required by any of the items in args. More...
 
void aggregate_temporal_properties (Item **item, uint nitems)
 Set fractional seconds precision for temporal functions. More...
 
bool aggregate_string_properties (const char *name, Item **item, uint nitems)
 Aggregate string properties (character set, collation and maximum length) for string function. More...
 
void aggregate_num_type (Item_result result_type, Item **item, uint nitems)
 This function is used to resolve type for numeric result type of CASE, COALESCE, IF and LEAD/LAG. More...
 
virtual bool repoint_const_outer_ref (uchar *arg)
 This function applies only to Item_field objects referred to by an Item_ref object that has been marked as a const_item. More...
 
virtual Fieldget_orig_field ()
 
virtual void set_orig_field (Field *)
 
virtual bool strip_db_table_name_processor (uchar *)
 
virtual bool set_table_name (uchar *)
 Noop in Item for items that are not subclasses of Item_ident. More...
 
virtual bool supports_partial_update (const Field_json *field) const
 Check if this expression can be used for partial update of a given JSON column. More...
 
virtual bool returns_array () const
 Whether the item returns array of its data type. More...
 
virtual void allow_array_cast ()
 
A helper funciton to ensure proper usage of CAST(. More...
 
- 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 Attributes

Item ** ref_by [2]
 For a group aggregate which is aggregated into an outer query block; none, or just the first or both cells may be non-zero. More...
 
Item_sumnext_sum
 next in the circular chain of registered objects More...
 
Item_sumin_sum_func
 the containing set function if any More...
 
SELECT_LEXbase_select
 query block where function is placed More...
 
SELECT_LEXaggr_select
 For a group aggregate, query block where function is aggregated. More...
 
int8 max_aggr_level
 max level of unbound column references More...
 
int8 max_sum_func_level
 max level of aggregation for contained functions More...
 
bool allow_group_via_temp_table
 If incremental update of fields is supported. More...
 
nesting_map save_deny_window_func
 WFs are forbidden when resolving Item_sum; this member is used to restore WF allowance status afterwards. More...
 
- Public Attributes inherited from Item_result_field
Fieldresult_field
 
- Public Attributes inherited from Item
Itemnext_free
 Intrusive list pointer for free list. More...
 
DTCollation collation
 Character set and collation properties assigned for this Item. More...
 
Item_name_string item_name
 Name from query. More...
 
Item_name_string orig_name
 Original item name (if it was renamed) More...
 
uint32 max_length
 Maximum length of result of evaluating this item, in number of bytes. More...
 
item_marker marker
 This member has several successive meanings, depending on the phase we're in: More...
 
Item_result cmp_context
 Comparison context. More...
 
bool fixed
 True if item has been resolved. More...
 
uint8 decimals
 Number of decimals in result when evaluating this item. More...
 
bool maybe_null
 True if this item may be null. More...
 
bool null_value
 True if item is null. More...
 
bool unsigned_flag
 
bool m_is_window_function
 True if item represents window func. More...
 

Protected Member Functions

void unsupported_as_wf ()
 
- Protected Member Functions inherited from Item
Stringmake_empty_result ()
 Sets the result value of the function an empty string, using the current character set. More...
 
bool skip_itemize (Item **res)
 Helper function to skip itemize() for grammar-allocated items. More...
 
virtual type_conversion_status save_in_field_inner (Field *field, bool no_conversions)
 Helper function which does all of the work for save_in_field(Field*, bool), except some error checking common to all subclasses, which is performed by save_in_field() itself. More...
 
Stringval_string_from_real (String *str)
 
Stringval_string_from_int (String *str)
 
Stringval_string_from_decimal (String *str)
 
Stringval_string_from_date (String *str)
 
Stringval_string_from_datetime (String *str)
 
Stringval_string_from_time (String *str)
 
my_decimalval_decimal_from_real (my_decimal *decimal_value)
 
my_decimalval_decimal_from_int (my_decimal *decimal_value)
 
my_decimalval_decimal_from_string (my_decimal *decimal_value)
 
my_decimalval_decimal_from_date (my_decimal *decimal_value)
 
my_decimalval_decimal_from_time (my_decimal *decimal_value)
 
longlong val_int_from_decimal ()
 
longlong val_int_from_date ()
 
longlong val_int_from_time ()
 
longlong val_int_from_datetime ()
 
double val_real_from_decimal ()
 
bool error_bool ()
 Get the value to return from val_bool() in case of errors. More...
 
int error_int ()
 Get the value to return from val_int() in case of errors. More...
 
double error_real ()
 Get the value to return from val_real() in case of errors. More...
 
Stringerror_str ()
 Get the value to return from val_str() in case of errors. More...
 
Stringnull_return_str ()
 Gets the value to return from val_str() when returning a NULL value. More...
 
bool get_date_from_string (MYSQL_TIME *ltime, my_time_flags_t flags)
 Convert val_str() to date in MYSQL_TIME. More...
 
bool get_date_from_real (MYSQL_TIME *ltime, my_time_flags_t flags)
 Convert val_real() to date in MYSQL_TIME. More...
 
bool get_date_from_decimal (MYSQL_TIME *ltime, my_time_flags_t flags)
 Convert val_decimal() to date in MYSQL_TIME. More...
 
bool get_date_from_int (MYSQL_TIME *ltime, my_time_flags_t flags)
 Convert val_int() to date in MYSQL_TIME. More...
 
bool get_date_from_time (MYSQL_TIME *ltime)
 Convert get_time() from time to date in MYSQL_TIME. More...
 
bool get_date_from_numeric (MYSQL_TIME *ltime, my_time_flags_t fuzzydate)
 Convert a numeric type to date. More...
 
bool get_time_from_string (MYSQL_TIME *ltime)
 Convert val_str() to time in MYSQL_TIME. More...
 
bool get_time_from_real (MYSQL_TIME *ltime)
 Convert val_real() to time in MYSQL_TIME. More...
 
bool get_time_from_decimal (MYSQL_TIME *ltime)
 Convert val_decimal() to time in MYSQL_TIME. More...
 
bool get_time_from_int (MYSQL_TIME *ltime)
 Convert val_int() to time in MYSQL_TIME. More...
 
bool get_time_from_date (MYSQL_TIME *ltime)
 Convert date to time. More...
 
bool get_time_from_datetime (MYSQL_TIME *ltime)
 Convert datetime to time. More...
 
bool get_time_from_numeric (MYSQL_TIME *ltime)
 Convert a numeric type to time. More...
 
void set_accum_properties (const Item *item)
 Set accumulated properties for an Item. More...
 
void add_accum_properties (const Item *item)
 Add more accumulated properties to an Item. More...
 
void set_subquery ()
 Set the "has subquery" property. More...
 
void set_stored_program ()
 Set the "has stored program" property. More...
 
- Protected Member Functions inherited from Parse_tree_node_tmpl< Context >
 Parse_tree_node_tmpl ()
 

Static Protected Member Functions

static ulonglong ram_limitation (THD *thd)
 Calculate the affordable RAM limit for structures like TREE or Unique used in Item_sum_*. More...
 
- Static Protected Member Functions inherited from Item
static bool bit_func_returns_binary (const Item *a, const Item *b)
 
static bool mark_field_in_map (Mark_field *mark_field, Field *field)
 Helper function for mark_field_in_map(uchar *arg). More...
 

Protected Attributes

Aggregatoraggr
 Aggregator class instance. More...
 
PT_windowm_window
 If sum is a window function, this field contains the window. More...
 
bool m_window_resolved
 True if we have already resolved this window functions window reference. More...
 
uint arg_count
 
Item ** args
 
Itemtmp_args [2]
 
table_map used_tables_cache
 
bool forced_const
 
- Protected Attributes inherited from Item
String str_value
 str_values's main purpose is to cache the value in save_in_field More...
 
uint8 m_accum_properties
 

Private Types

typedef Item_result_field super
 

Private Attributes

bool force_copy_fields
 Used in making ROLLUP. More...
 
bool with_distinct
 Indicates how the aggregate function was specified by the parser : true if it was written as AGGREGATE(DISTINCT), false if it was AGGREGATE() More...
 

Friends

class Aggregator_distinct
 
class Aggregator_simple
 

Additional Inherited Members

- Static Public Member Functions inherited from Item
static void * operator new (size_t size) noexcept
 
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 enum_field_types type_for_variable (enum_field_types src_type)
 Provide data type for a user or system variable, based on the type of the item that is assigned to the variable. More...
 
static enum_field_types string_field_type (uint32 max_bytes)
 Determine correct string field type, based on string length. More...
 
static const CHARSET_INFOdefault_charset ()
 
- 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 Protected Attributes inherited from Item
static constexpr uint8 PROP_SUBQUERY = 0x01
 Set of properties that are calculated by accumulation from underlying items. More...
 
static constexpr uint8 PROP_STORED_PROGRAM = 0x02
 
static constexpr uint8 PROP_AGGREGATION = 0x04
 
static constexpr uint8 PROP_WINDOW_FUNCTION = 0x08
 
static constexpr uint8 PROP_ROLLUP_EXPR = 0x10
 Set if the item or one or more of the underlying items contains a ROLLUP expression. More...
 
static constexpr uint8 PROP_GROUPING_FUNC = 0x20
 Set if the item or one or more of the underlying items is a GROUPING function. More...
 

Detailed Description


Class Item_sum is the base class used for special expressions that SQL calls 'set functions'.

These expressions are formed with the help of aggregate functions such as SUM, MAX, GROUP_CONCAT etc. Class Item_sum is also the base class for Window functions; the text below first documents set functions, then window functions.

GENERAL NOTES

A set function cannot be used in all positions where expressions are accepted. There are some quite explicable restrictions for the use of set functions.

In the query:

SELECT AVG(b) FROM t1 WHERE SUM(b) > 20 GROUP by a

the set function AVG(b) is valid, while the usage of SUM(b) is invalid. A WHERE condition must contain expressions that can be evaluated for each row of the table. Yet the expression SUM(b) can be evaluated only for each group of rows with the same value of column a. In the query:

SELECT AVG(b) FROM t1 WHERE c > 30 GROUP BY a HAVING SUM(b) > 20

both set function expressions AVG(b) and SUM(b) are valid.

We can say that in a query without nested selects an occurrence of a set function in an expression of the SELECT list or/and in the HAVING clause is valid, while in the WHERE clause, FROM clause or GROUP BY clause it is invalid.

The general rule to detect whether a set function is valid in a query with nested subqueries is much more complicated.

Consider the following query:

SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > ALL (SELECT t2.c FROM t2 WHERE SUM(t1.b) < t2.c).

The set function SUM(b) is used here in the WHERE clause of the subquery. Nevertheless it is valid since it is contained in the HAVING clause of the outer query. The expression SUM(t1.b) is evaluated for each group defined in the main query, not for groups of the subquery.

The problem of finding the query where to aggregate a particular set function is not so simple as it seems to be.

In the query: SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > ALL(SELECT t2.c FROM t2 GROUP BY t2.c HAVING SUM(t1.a) < t2.c)

the set function can be evaluated in both the outer and the inner query block. If we evaluate SUM(t1.a) for the outer query then we get the value of t1.a multiplied by the cardinality of a group in table t1. In this case, SUM(t1.a) is used as a constant value in each correlated subquery. But SUM(t1.a) can also be evaluated for the inner query. In this case t1.a will be a constant value for each correlated subquery and summation is performed for each group of table t2. (Here it makes sense to remind that the query

SELECT c FROM t GROUP BY a HAVING SUM(1) < a

is quite valid in our SQL).

So depending on what query block we assign the set function to we can get different results.

The general rule to detect the query block Q where a set function will be aggregated (evaluated) can be formulated as follows.

Reference: SQL2011 <set function specification> syntax rules 6 and 7.

Consider a set function S(E) where E is an expression which contains column references C1, ..., Cn. Resolve all column references Ci against the query block Qi containing the set function S(E). Let Q be the innermost query block of all query blocks Qi. (It should be noted here that S(E) in no way can be aggregated in the query block containing the subquery Q, otherwise S(E) would refer to at least one unbound column reference). If S(E) is used in a construct of Q where set functions are allowed then we aggregate S(E) in Q. Otherwise:

  • if ANSI SQL mode is enabled (MODE_ANSI), then report an error.
  • otherwise, look for the innermost query block containing S(E) of those where usage of S(E) is allowed. The place of aggregation depends on which clause the subquery is contained within; It will be different when contained in a WHERE clause versus in the select list or in HAVING clause.

Let's demonstrate how this rule is applied to the following queries.

  1. SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > ALL(SELECT t2.b FROM t2 GROUP BY t2.b HAVING t2.b > ALL(SELECT t3.c FROM t3 GROUP BY t3.c HAVING SUM(t1.a+t2.b) < t3.c)) For this query the set function SUM(t1.a+t2.b) contains t1.a and t2.b with t1.a defined in the outermost query, and t2.b defined for its subquery. The set function is contained in the HAVING clause of the subquery and can be evaluated in this subquery.
  2. SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > ALL(SELECT t2.b FROM t2 WHERE t2.b > ALL (SELECT t3.c FROM t3 GROUP BY t3.c HAVING SUM(t1.a+t2.b) < t3.c)) The set function SUM(t1.a+t2.b) is contained in the WHERE clause of the second query block - the outermost query block where t1.a and t2.b are defined. If we evaluate the function in this subquery we violate the context rules. So we evaluate the function in the third query block (over table t3) where it is used under the HAVING clause; if in ANSI SQL mode, an error is thrown.
  3. SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > ALL(SELECT t2.b FROM t2 WHERE t2.b > ALL (SELECT t3.c FROM t3 WHERE SUM(t1.a+t2.b) < t3.c)) In this query, evaluation of SUM(t1.a+t2.b) is not valid neither in the second nor in the third query block.

Set functions can generally not be nested. In the query

SELECT t1.a from t1 GROUP BY t1.a HAVING AVG(SUM(t1.b)) > 20

the expression SUM(b) is not valid, even though it is contained inside a HAVING clause. However, it is acceptable in the query:

SELECT t.1 FROM t1 GROUP BY t1.a HAVING SUM(t1.b) > 20.

An argument of a set function does not have to be a simple column reference as seen in examples above. This can be a more complex expression

SELECT t1.a FROM t1 GROUP BY t1.a HAVING SUM(t1.b+1) > 20.

The expression SUM(t1.b+1) has clear semantics in this context: we sum up the values of t1.b+1 where t1.b varies for all values within a group of rows that contain the same t1.a value.

A set function for an outer query yields a constant value within a subquery. So the semantics of the query

SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c HAVING AVG(t2.c+SUM(t1.b)) > 20)

is still clear. For a group of rows with the same value for t1.a, calculate the value of SUM(t1.b) as 's'. This value is substituted in the subquery:

SELECT t2.c FROM t2 GROUP BY t2.c HAVING AVG(t2.c+s)

By the same reason the following query with a subquery

SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c HAVING AVG(SUM(t1.b)) > 20) is also valid.

IMPLEMENTATION NOTES

The member base_select contains a reference to the query block that the set function is contained within.

The member aggr_select contains a reference to the query block where the set function is aggregated.

The field max_aggr_level holds the maximum of the nest levels of the unbound column references contained in the set function. A column reference is unbound within a set function if it is not bound by any subquery used as a subexpression in this function. A column reference is bound by a subquery if it is a reference to the column by which the aggregation of some set function that is used in the subquery is calculated. For the set function used in the query

SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > ALL(SELECT t2.b FROM t2 GROUP BY t2.b HAVING t2.b > ALL(SELECT t3.c FROM t3 GROUP BY t3.c HAVING SUM(t1.a+t2.b) < t3.c))

the value of max_aggr_level is equal to 1 since t1.a is bound in the main query, and t2.b is bound by the first subquery whose nest level is 1. Obviously a set function cannot be aggregated in a subquery whose nest level is less than max_aggr_level. (Yet it can be aggregated in the subqueries whose nest level is greater than max_aggr_level.) In the query SELECT t1.a FROM t1 HAVING AVG(t1.a+(SELECT MIN(t2.c) FROM t2))

the value of the max_aggr_level for the AVG set function is 0 since the reference t2.c is bound in the subquery.

If a set function contains no column references (like COUNT(*)), max_aggr_level is -1.

The field 'max_sum_func_level' is to contain the maximum of the nest levels of the set functions that are used as subexpressions of the arguments of the given set function, but not aggregated in any subquery within this set function. A nested set function s1 can be used within set function s0 only if s1.max_sum_func_level < s0.max_sum_func_level. Set function s1 is considered as nested for set function s0 if s1 is not calculated in any subquery within s0.

A set function that is used as a subexpression in an argument of another set function refers to the latter via the field 'in_sum_func'.

The condition imposed on the usage of set functions are checked when we traverse query subexpressions with the help of the recursive method fix_fields. When we apply this method to an object of the class Item_sum, first, on the descent, we call the method init_sum_func_check that initialize members used at checking. Then, on the ascent, we call the method check_sum_func that validates the set function usage and reports an error if it is invalid. The method check_sum_func serves to link the items for the set functions that are aggregated in the containing query blocks. Circular chains of such functions are attached to the corresponding SELECT_LEX structures through the field inner_sum_func_list.

Exploiting the fact that the members mentioned above are used in one recursive function we could have allocated them on the thread stack. Yet we don't do it now.

It is assumed that the nesting level of subqueries does not exceed 63 (valid nesting levels are stored in a 64-bit bitmap called nesting_map). The assumption is enforced in LEX::new_query().

WINDOW FUNCTIONS

Most set functions (e.g. SUM, COUNT, AVG) can also be used as window functions. In that case, notable differences compared to set functions are:

  • not using any Aggregator
  • not supporting DISTINCT
  • val_*() does more than returning the function's current value: it first accumulates the function's argument into the function's state. Execution (e.g. end_write_wf()) manipulates temporary tables which contain input for WFs; each input row is passed to copy_funcs() which calls the WF's val_*() to accumulate it.

Member Typedef Documentation

◆ super

Member Enumeration Documentation

◆ Sumfunctype

Enumerator
COUNT_FUNC 
COUNT_DISTINCT_FUNC 
SUM_FUNC 
SUM_DISTINCT_FUNC 
AVG_FUNC 
AVG_DISTINCT_FUNC 
MIN_FUNC 
MAX_FUNC 
STD_FUNC 
VARIANCE_FUNC 
SUM_BIT_FUNC 
UDF_SUM_FUNC 
GROUP_CONCAT_FUNC 
JSON_AGG_FUNC 
ROW_NUMBER_FUNC 
RANK_FUNC 
DENSE_RANK_FUNC 
CUME_DIST_FUNC 
PERCENT_RANK_FUNC 
NTILE_FUNC 
LEAD_LAG_FUNC 
FIRST_LAST_VALUE_FUNC 
NTH_VALUE_FUNC 

Constructor & Destructor Documentation

◆ Item_sum() [1/6]

Item_sum::Item_sum ( const POS pos,
PT_window w 
)
inline

◆ Item_sum() [2/6]

Item_sum::Item_sum ( Item a)
inline

◆ Item_sum() [3/6]

Item_sum::Item_sum ( const POS pos,
Item a,
PT_window w 
)
inline

◆ Item_sum() [4/6]

Item_sum::Item_sum ( const POS pos,
Item a,
Item b,
PT_window w 
)
inline

◆ Item_sum() [5/6]

Item_sum::Item_sum ( const POS pos,
PT_item_list opt_list,
PT_window w 
)

◆ Item_sum() [6/6]

Item_sum::Item_sum ( THD thd,
const Item_sum item 
)

Copy constructor, need to perform subqueries with temporary tables.

Constructor used in processing select with temporary tebles.

Member Function Documentation

◆ add()

◆ aggregate_check_distinct()

bool Item_sum::aggregate_check_distinct ( uchar )
overridevirtual
See also
Distinct_check::check_query()

Reimplemented from Item.

◆ aggregate_check_group()

bool Item_sum::aggregate_check_group ( uchar )
overridevirtual
See also
Group_check::check_query()

Reimplemented from Item.

◆ aggregator_add()

bool Item_sum::aggregator_add ( )
inline

Called to add value to the aggregator.

◆ aggregator_clear()

void Item_sum::aggregator_clear ( )
inline

Called to cleanup the aggregator.

◆ aggregator_setup()

bool Item_sum::aggregator_setup ( THD thd)
inline

Called to initialize the aggregator.

◆ check_sum_func()

bool Item_sum::check_sum_func ( THD thd,
Item **  ref 
)

Validate the semantic requirements of a set function.

Check whether the context of the set function allows it to be aggregated and, when it is an argument of another set function, directly or indirectly, the function makes sure that these two set functions are aggregated in different query blocks. If the context conditions are not met, an error is reported. If the set function is aggregated in some outer query block, it is added to the chain of items inner_sum_func_list attached to the aggregating query block.

A number of designated members of the object are used to check the conditions. They are specified in the comment before the Item_sum class declaration. Additionally a bitmap variable called allow_sum_func is employed. It is included into the LEX structure. The bitmap contains 1 at n-th position if the query block at level "n" allows a set function reference (i.e the current resolver context for the query block is either in the SELECT list or in the HAVING or ORDER BY clause).

Consider the query:

SELECT SUM(t1.b) FROM t1 GROUP BY t1.a
HAVING t1.a IN (SELECT t2.c FROM t2 WHERE AVG(t1.b) > 20) AND
t1.a > (SELECT MIN(t2.d) FROM t2);

when the set functions are resolved, allow_sum_func will contain:

  • for SUM(t1.b) - 1 at position 0 (SUM is in SELECT list)
  • for AVG(t1.b) - 1 at position 0 (subquery is in HAVING clause) 0 at position 1 (AVG is in WHERE clause)
  • for MIN(t2.d) - 1 at position 0 (subquery is in HAVING clause) 1 at position 1 (MIN is in SELECT list)
Note
This function must be called for all set functions when expressions are resolved. It must be invoked in postfix order, ie at the ascent of this traversal.
Parameters
thdreference to the thread context info
reflocation of the pointer to this item in the containing expression
Returns
false if success, true if error

◆ check_wf_semantics()

bool Item_sum::check_wf_semantics ( THD thd,
SELECT_LEX select,
Window::Evaluation_requirements reqs 
)
virtual

Only relevant for aggregates qua window functions.

Checks semantics after windows have been set up and checked. Window functions have specific requirements on the window specifications.

Parameters
thdCurrent thread
selectThe current select
[out]reqsHolds collected requirements from this wf
Returns
true if error

Reimplemented in Item_nth_value, Item_first_last_value, Item_lead_lag, Item_ntile, Item_percent_rank, Item_cume_dist, Item_rank, Item_row_number, Item_func_group_concat, Item_sum_hybrid, Item_sum_variance, Item_sum_json_object, Item_sum_json, and Item_sum_sum.

◆ clean_up_after_removal()

bool Item_sum::clean_up_after_removal ( uchar arg)
overridevirtual

Remove the item from the list of inner aggregation functions in the SELECT_LEX it was moved to by Item_sum::check_sum_func().

This is done to undo some of the effects of Item_sum::check_sum_func() so that the item may be removed from the query.

Note
This doesn't completely undo Item_sum::check_sum_func(), as aggregation information is left untouched. This means that if this item is removed, aggr_select and all subquery items between aggr_select and this item may be left with has_aggregation() set to true, even if there are no aggregation functions. To our knowledge, this has no impact on the query result.
See also
Item_sum::check_sum_func()
remove_redundant_subquery_clauses()

If this is a window function, remove the reference from the window. This is needed when constant predicates are being removed.

See also
Item_cond::fix_fields()
Item_cond::remove_const_cond()

Reimplemented from Item.

◆ cleanup()

void Item_sum::cleanup ( )
overridevirtual

◆ clear()

◆ create_tmp_field()

Field * Item_sum::create_tmp_field ( bool  group,
TABLE table 
)
virtual

◆ eq()

bool Item_sum::eq ( const Item item,
bool  binary_cmp 
) const
overridevirtual
Note
Please keep in sync with Item_func::eq().

Reimplemented from Item.

◆ fix_after_pullout()

virtual void Item_sum::fix_after_pullout ( SELECT_LEX parent_select,
SELECT_LEX removed_select 
)
inlineoverridevirtual

Fix after tables have been moved from one select_lex level to the parent level, e.g by semijoin conversion.

Basically re-calculate all attributes dependent on the tables.

Parameters
parent_selectselect_lex that tables are moved to.
removed_selectselect_lex that tables are moved away from, child of parent_select.

Reimplemented from Item.

◆ fix_fields()

bool Item_sum::fix_fields ( THD thd,
Item **  ref 
)
overridevirtual

◆ fix_num_length_and_dec()

void Item_sum::fix_num_length_and_dec ( )

◆ framing()

virtual bool Item_sum::framing ( ) const
inlinevirtual

All aggregates are framing, i.e.

they work on the window's frame. If none is defined, the frame is by default the entire partition, unless ORDER BY is defined, in which case it is the set of rows from the start of the partition to and including the peer set of the current row.

Some window functions are not framing, i.e. they always work on the entire partition. For such window functions, the method is overridden to return false.

Reimplemented in Item_non_framing_wf.

◆ get_arg()

Item* Item_sum::get_arg ( uint  i)
inline

◆ get_arg_count()

uint Item_sum::get_arg_count ( ) const
inline

◆ get_arg_ptr()

Item** Item_sum::get_arg_ptr ( uint  i)
inline

◆ has_aggregate_ref_in_group_by()

bool Item_sum::has_aggregate_ref_in_group_by ( uchar )
overridevirtual

Check if an aggregate is referenced from within the GROUP BY clause of the query block in which it is aggregated.

Such references will be rejected.

See also
Item_ref::fix_fields()
Return values
trueif this is an aggregate which is referenced from the GROUP BY clause of the aggregating query block
falseotherwise

Reimplemented from Item.

◆ has_force_copy_fields()

bool Item_sum::has_force_copy_fields ( ) const
inline

◆ has_with_distinct()

bool Item_sum::has_with_distinct ( ) const
inline

◆ init_aggregator()

void Item_sum::init_aggregator ( )
inline

◆ init_sum_func_check()

bool Item_sum::init_sum_func_check ( THD thd)

Prepare an aggregate function for checking of context.

The function initializes the members of the Item_sum object. It also checks the general validity of the set function: If none of the currently active query blocks allow evaluation of set functions, an error is reported.

Note
This function must be called for all set functions when expressions are resolved. It must be invoked in prefix order, ie at the descent of this traversal.
See also
corresponding Item_sum::check_sum_func(), which should be called on ascent.
Parameters
thdreference to the thread context info
Returns
false if success, true if error

◆ is_null()

bool Item_sum::is_null ( )
inlineoverridevirtual

Reimplemented from Item.

◆ itemize()

bool Item_sum::itemize ( Parse_context pc,
Item **  res 
)
overridevirtual

The same as contextualize()/contextualize_() but with additional parameter.

This function finalize the construction of Item objects (see the Item(POS) constructor): we can access/change parser contexts from the itemize() function.

Parameters
pccurrent parse context
[out]respointer to "this" or to a newly allocated replacement object to use in the Item tree instead
Return values
falsesuccess
truesyntax/OOM/etc error

Reimplemented from Item.

Reimplemented in Item_func_group_concat, Item_udf_sum, and PTI_count_sym.

◆ keep_field_type()

virtual bool Item_sum::keep_field_type ( ) const
inlinevirtual

Reimplemented in Item_sum_hybrid.

◆ make_const()

void Item_sum::make_const ( )
inline

◆ make_unique()

virtual void Item_sum::make_unique ( )
inlinevirtual

Reimplemented in Item_func_group_concat.

◆ mark_as_sum_func() [1/2]

void Item_sum::mark_as_sum_func ( )

◆ mark_as_sum_func() [2/2]

void Item_sum::mark_as_sum_func ( SELECT_LEX cur_select)

◆ needs_card()

virtual bool Item_sum::needs_card ( ) const
inlinevirtual

Return true if we need to make two passes over the rows in the partition - either because we need the cardinality of it (and we need to read all rows to detect the next partition), or we need to have all partition rows available to evaluate the window function for some other reason, e.g.

we may need the last row in the partition in the frame buffer to be able to evaluate LEAD.

Reimplemented in Item_lead_lag, Item_ntile, Item_percent_rank, and Item_cume_dist.

◆ no_rows_in_result()

void Item_sum::no_rows_in_result ( )
inlineoverridevirtual

Mark an aggregate as having no rows.

This function is called by the execution engine to assign 'NO ROWS FOUND' value to an aggregate item, when the underlying result set has no rows. Such value, in a general case, may be different from the default value of the item after 'clear()': e.g. a numeric item may be initialized to 0 by clear() and to NULL by no_rows_in_result().

Reimplemented from Item.

Reimplemented in Item_func_group_concat, Item_sum_hybrid, Item_sum_variance, Item_sum_avg, Item_sum_count, and Item_sum_sum.

◆ print()

void Item_sum::print ( const THD ,
String str,
enum_query_type   
) const
overridevirtual

This method is used for to:

  • to generate a view definition query (SELECT-statement);
  • to generate a SQL-query for EXPLAIN EXTENDED;
  • to generate a SQL-query to be shown in INFORMATION_SCHEMA;
  • to generate a SQL-query that looks like a prepared statement for query_rewrite
  • debug.

For more information about view definition query, INFORMATION_SCHEMA query and why they should be generated from the Item-tree,

See also
mysql_register_view().

Reimplemented from Item.

Reimplemented in Item_func_group_concat, and Item_udf_sum.

◆ ram_limitation()

ulonglong Item_sum::ram_limitation ( THD thd)
staticprotected

Calculate the affordable RAM limit for structures like TREE or Unique used in Item_sum_*.

◆ reset_and_add()

bool Item_sum::reset_and_add ( )
inline

Resets the aggregate value to its default and aggregates the current value of its attribute(s).

◆ reset_field()

◆ reset_wf_state()

bool Item_sum::reset_wf_state ( uchar arg)
overridevirtual

Reset execution state for such window function types as determined by arg.

Parameters
argpointing to a bool which, if true, says to reset state for framing window function, else for non-framing

Reimplemented from Item.

◆ resolve_type()

bool Item_sum::resolve_type ( THD thd)
overridevirtual

Resolve type-related information for this item, such as result field type, maximum size, precision, signedness, character set and collation.

Also check compatibility of argument types and return error when applicable. Also adjust nullability when applicable.

Parameters
thdthread handler
Returns
false if success, true if error

Implements Item_result_field.

Reimplemented in Item_nth_value, Item_first_last_value, Item_lead_lag, Item_ntile, Item_percent_rank, Item_cume_dist, Item_rank, Item_row_number, Item_sum_udf_decimal, Item_sum_udf_str, Item_sum_udf_int, Item_sum_udf_float, Item_sum_bit, Item_sum_variance, Item_sum_avg, Item_sum_count, Item_sum_sum, and Item_sum_int.

◆ result_item()

virtual Item* Item_sum::result_item ( Field field)
inlinevirtual

◆ set_aggregator()

int Item_sum::set_aggregator ( Aggregator::Aggregator_type  aggregator)

◆ set_arg()

Item * Item_sum::set_arg ( uint  i,
THD thd,
Item new_val 
)

◆ set_distinct()

void Item_sum::set_distinct ( bool  distinct)
inline

◆ setup()

virtual bool Item_sum::setup ( THD )
inlinevirtual

Reimplemented in Item_func_group_concat.

◆ split_sum_func()

void Item_sum::split_sum_func ( THD thd,
Ref_item_array  ref_item_array,
List< Item > &  fields 
)
overridevirtual

Reimplemented from Item.

Reimplemented in Item_nth_value, Item_first_last_value, Item_lead_lag, and Item_sum_hybrid.

◆ sum_func()

◆ type()

Type Item_sum::type ( ) const
inlineoverridevirtual

Implements Item.

◆ unsupported_as_wf()

void Item_sum::unsupported_as_wf ( )
inlineprotected

◆ update_field()

◆ update_used_tables()

void Item_sum::update_used_tables ( )
overridevirtual

Reimplemented from Item.

◆ used_tables()

table_map Item_sum::used_tables ( ) const
inlineoverridevirtual

Reimplemented from Item_result_field.

◆ uses_only_one_row()

virtual bool Item_sum::uses_only_one_row ( ) const
inlinevirtual

Only for framing window functions.

True if this function only needs to read one row per frame.

Reimplemented in Item_nth_value, Item_first_last_value, and Item_sum_hybrid.

◆ walk()

bool Item_sum::walk ( Item_processor  processor,
enum_walk  walk,
uchar arg 
)
overridevirtual

Traverses a tree of Items in prefix and/or postfix order.

Optionally walks into subqueries.

Parameters
processorprocessor function to be invoked per item returns true to abort traversal, false to continue
walkcontrols how to traverse the item tree enum_walk::PREFIX: call processor before invoking children enum_walk::POSTFIX: call processor after invoking children enum_walk::SUBQUERY go down into subqueries walk values are bit-coded and may be combined. Omitting both enum_walk::PREFIX and enum_walk::POSTFIX is undefined behaviour.
argOptional pointer to a walk-specific object
Return values
falsewalk succeeded
truewalk aborted by agreement, an error may have been reported

Reimplemented from Item.

◆ wf_common_init()

bool Item_sum::wf_common_init ( )

Common initial actions for window functions.

For non-buffered processing ("on-the-fly"), check partition change and possible reset partition state. In this case return false. For buffered processing, if windowing state m_do_copy_null is true, set null_value to true and return true.

Returns
true if case two above holds, else false

◆ window()

const Window* Item_sum::window ( ) const
inline

Friends And Related Function Documentation

◆ Aggregator_distinct

friend class Aggregator_distinct
friend

◆ Aggregator_simple

friend class Aggregator_simple
friend

Member Data Documentation

◆ aggr

Aggregator* Item_sum::aggr
protected

Aggregator class instance.

Not set initially. Allocated only after it is determined if the incoming data are already distinct.

◆ aggr_select

SELECT_LEX* Item_sum::aggr_select

For a group aggregate, query block where function is aggregated.

For a window function, nullptr, as such function is always aggregated in base_select, as it mustn't contain any outer reference.

◆ allow_group_via_temp_table

bool Item_sum::allow_group_via_temp_table

If incremental update of fields is supported.

◆ arg_count

uint Item_sum::arg_count
protected

◆ args

Item** Item_sum::args
protected

◆ base_select

SELECT_LEX* Item_sum::base_select

query block where function is placed

◆ force_copy_fields

bool Item_sum::force_copy_fields
private

Used in making ROLLUP.

Set for the ROLLUP copies of the original Item_sum and passed to create_tmp_field() to cause it to work over the temp table buffer that is referenced by Item_result_field::result_field.

◆ forced_const

bool Item_sum::forced_const
protected

◆ in_sum_func

Item_sum* Item_sum::in_sum_func

the containing set function if any

◆ m_window

PT_window* Item_sum::m_window
protected

If sum is a window function, this field contains the window.

◆ m_window_resolved

bool Item_sum::m_window_resolved
protected

True if we have already resolved this window functions window reference.

Used in execution of prepared statement to avoid re-resolve.

◆ max_aggr_level

int8 Item_sum::max_aggr_level

max level of unbound column references

◆ max_sum_func_level

int8 Item_sum::max_sum_func_level

max level of aggregation for contained functions

◆ next_sum

Item_sum* Item_sum::next_sum

next in the circular chain of registered objects

◆ ref_by

Item** Item_sum::ref_by[2]

For a group aggregate which is aggregated into an outer query block; none, or just the first or both cells may be non-zero.

Note
most member variables below serve only for grouped aggregate functions. They are filled with references to the group aggregate (for example if it is the argument of a function; it is then a pointer to that function's args[i] pointer). "ref_by" stands for "referenced by".

◆ save_deny_window_func

nesting_map Item_sum::save_deny_window_func

WFs are forbidden when resolving Item_sum; this member is used to restore WF allowance status afterwards.

◆ tmp_args

Item * Item_sum::tmp_args[2]
protected

◆ used_tables_cache

table_map Item_sum::used_tables_cache
protected

◆ with_distinct

bool Item_sum::with_distinct
private

Indicates how the aggregate function was specified by the parser : true if it was written as AGGREGATE(DISTINCT), false if it was AGGREGATE()


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