drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
drizzled::Item_sum Class Referenceabstract
Inheritance diagram for drizzled::Item_sum:
[legend]
Collaboration diagram for drizzled::Item_sum:
[legend]

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 , GROUP_CONCAT_FUNC
}
Public Types inherited from drizzled::Item
enum  Type {
  FIELD_ITEM = 0 , 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 , BOOLEAN_ITEM , DECIMAL_ITEM
}
enum  traverse_order { T_POSTFIX , T_PREFIX }
enum  cond_result { COND_UNDEF , COND_OK , COND_TRUE , COND_FALSE }

Public Member Functions

void mark_as_sum_func ()
 Item_sum (Item *a)
 Item_sum (Item *a, Item *b)
 Item_sum (List< Item > &list)
 Item_sum (Session *session, Item_sum *item)
enum Type type () const
virtual enum Sumfunctype sum_func () const =0
bool reset ()
virtual void clear ()=0
virtual bool add ()=0
virtual void reset_field ()=0
virtual void update_field ()=0
virtual bool keep_field_type (void) const
virtual void fix_length_and_dec ()
virtual const char * func_name () const =0
virtual Item * result_item (Field *field)
table_map used_tables () const
void update_used_tables ()
void cleanup ()
bool is_null ()
void make_const ()
virtual bool const_item () const
virtual bool const_during_execution () const
void make_field (SendField *field)
virtual void print (String *str)
void fix_num_length_and_dec ()
void no_rows_in_result ()
virtual bool setup (Session *)
virtual void make_unique (void)
Item * get_tmp_table_item (Session *session)
virtual Field * create_tmp_field (bool group, Table *table, uint32_t convert_blob_length)
bool walk (Item_processor processor, bool walk_subquery, unsigned char *argument)
bool init_sum_func_check (Session *session)
bool check_sum_func (Session *session, Item **ref)
bool register_sum_func (Session *session, Item **ref)
Select_Lex * depended_from ()
Public Member Functions inherited from drizzled::Item_result_field
 Item_result_field (Session *session, Item_result_field *item)
Field * get_tmp_table_field ()
Field * tmp_table_field (Table *)
void set_result_field (Field *field)
bool is_result_field ()
void save_in_result_field (bool no_conversions)
Public Member Functions inherited from drizzled::Item
bool is_unsigned () const
virtual bool negative () const
 Item ()
 Item (Session *session, Item *item)
void set_name (str_ref arg)
void set_name (const char *arg)
void set_name (const char *str, uint32_t length, const charset_info_st *cs=system_charset_info)
void init_make_field (SendField *tmp_field, enum_field_types type)
Field * make_string_field (Table *table)
virtual bool fix_fields (Session *, Item **)
virtual void fix_after_pullout (Select_Lex *new_parent, Item **ref)
void quick_fix_field ()
virtual int save_in_field (Field *field, bool no_conversions)
virtual void save_org_in_field (Field *field)
virtual int save_safe_in_field (Field *field)
virtual void send (plugin::Client *client, String *str)
virtual bool eq (const Item *, bool binary_cmp) const
virtual Item_result result_type () const
virtual Item_result cast_to_int_type () const
virtual enum_field_types string_field_type () const
virtual enum_field_types field_type () const
virtual int64_t val_int_endpoint (bool left_endp, bool *incl_endp)
virtual double val_real ()=0
virtual int64_t val_int ()=0
uint64_t val_uint ()
virtual String * val_str (String *str)=0
virtual type::Decimal * val_decimal (type::Decimal *decimal_buffer)=0
virtual bool val_bool ()
String * val_string_from_real (String *str)
String * val_string_from_int (String *str)
String * val_string_from_decimal (String *str)
type::Decimal * val_decimal_from_real (type::Decimal *decimal_value)
type::Decimal * val_decimal_from_int (type::Decimal *decimal_value)
type::Decimal * val_decimal_from_string (type::Decimal *decimal_value)
type::Decimal * val_decimal_from_date (type::Decimal *decimal_value)
type::Decimal * val_decimal_from_time (type::Decimal *decimal_value)
int64_t val_int_from_decimal ()
double val_real_from_decimal ()
bool save_time_in_field (Field *field)
bool save_date_in_field (Field *field)
int save_str_value_in_field (Field *field, String *result)
virtual const char * full_name (void) const
virtual double val_result ()
virtual int64_t val_int_result ()
virtual String * str_result (String *tmp)
virtual type::Decimal * val_decimal_result (type::Decimal *val)
virtual bool val_bool_result ()
virtual table_map not_null_tables () const
virtual bool basic_const_item () const
virtual Item * clone_item ()
virtual cond_result eq_cmp_result () const
uint32_t float_length (uint32_t decimals_par) const
virtual uint32_t decimal_precision () const
int decimal_int_part () const
void print_item_w_name (String *)
virtual void split_sum_func (Session *session, Item **ref_pointer_array, List< Item > &fields)
void split_sum_func (Session *session, Item **ref_pointer_array, List< Item > &fields, Item **ref, bool skip_registered)
virtual bool get_date (type::Time &ltime, uint32_t fuzzydate)
virtual bool get_time (type::Time &ltime)
virtual bool get_date_result (type::Time &ltime, uint32_t fuzzydate)
virtual void update_null_value ()
virtual void top_level_item (void)
virtual bool is_bool_func (void)
virtual Item * copy_or_same (Session *session)
virtual Item * copy_andor_structure (Session *session)
virtual Item * real_item (void)
virtual const Item * real_item (void) const
virtual const charset_info_st * compare_collation ()
virtual Item * transform (Item_transformer transformer, unsigned char *arg)
virtual Item * compile (Item_analyzer analyzer, unsigned char **arg_p, Item_transformer transformer, unsigned char *arg_t)
virtual void traverse_cond (Cond_traverser traverser, void *arg, traverse_order order)
virtual bool remove_dependence_processor (unsigned char *arg)
virtual bool collect_item_field_processor (unsigned char *arg)
virtual bool find_item_in_field_list_processor (unsigned char *arg)
virtual bool change_context_processor (unsigned char *context)
virtual bool register_field_in_read_map (unsigned char *arg)
virtual bool subst_argument_checker (unsigned char **arg)
virtual bool cache_const_expr_analyzer (unsigned char **arg)
virtual Item * cache_const_expr_transformer (unsigned char *arg)
virtual Item * equal_fields_propagator (unsigned char *arg)
virtual bool set_no_const_sub (unsigned char *arg)
virtual Item * replace_equal_field (unsigned char *arg)
virtual uint32_t cols ()
virtual Item * element_index (uint32_t i)
virtual Item ** addr (uint32_t i)
virtual bool check_cols (uint32_t c)
virtual bool null_inside ()
virtual void bring_value ()
Field * tmp_table_field_from_field_type (Table *table, bool fixed_length)
virtual Item * neg_transformer (Session *session)
virtual Item * update_value_transformer (unsigned char *select_arg)
virtual Item * safe_charset_converter (const charset_info_st *const tocs)
void delete_self ()
virtual bool result_as_int64_t ()
bool is_datetime ()
virtual bool is_expensive ()
String * check_well_formed_result (String *str, bool send_error=0)
bool eq_by_collation (Item *item, bool binary_cmp, const charset_info_st *const cs)
uint32_t char_to_byte_length_safe (uint32_t char_length_arg, uint32_t mbmaxlen_arg)
uint32_t max_char_length () const
void fix_char_length (uint32_t max_char_length_arg)

Public Attributes

Item ** args
Item * tmp_args [2]
Item ** ref_by
Item_sum * next
uint32_t arg_count
Item_sum * in_sum_func
Select_Lex * aggr_sel
int8_t nest_level
int8_t aggr_level
int8_t max_arg_level
int8_t max_sum_func_level
bool quick_group
List< Item_field > outer_fields
Public Attributes inherited from drizzled::Item_result_field
Field * result_field
Public Attributes inherited from drizzled::Item
String str_value
const char * name
uint32_t name_length
Item * next
uint32_t max_length
int8_t marker
uint8_t decimals
bool fixed
bool maybe_null
bool null_value
bool unsigned_flag
bool with_sum_func
bool is_autogenerated_name
bool with_subselect
DTCollation collation
Item_result cmp_context

Protected Attributes

table_map used_tables_cache
bool forced_const

Additional Inherited Members

Static Public Member Functions inherited from drizzled::Item
static const charset_info_st * default_charset ()
Static Public Member Functions inherited from drizzled::memory::SqlAlloc
static void * operator new (size_t size)
static void * operator new[] (size_t size)
static void * operator new (size_t size, Root &root)
static void * operator new[] (size_t size, Root &root)
static void * operator new (size_t size, Root *root)
static void * operator new[] (size_t size, Root *root)
static void operator delete (void *)
static void operator delete[] (void *)
static void operator delete (void *, Root &)
static void operator delete[] (void *, Root &)
static void operator delete (void *, Root *)
static void operator delete[] (void *, Root *)
Protected Member Functions inherited from drizzled::Item
Session & getSession ()

Detailed Description

Definition at line 232 of file item/sum.h.

Member Enumeration Documentation

◆ Sumfunctype

enum drizzled::Item_sum::Sumfunctype

Definition at line 235 of file item/sum.h.

Constructor & Destructor Documentation

◆ Item_sum() [1/5]

drizzled::Item_sum::Item_sum ( )
inline

Definition at line 267 of file item/sum.h.

◆ Item_sum() [2/5]

drizzled::Item_sum::Item_sum ( Item * a)
inline

Definition at line 271 of file item/sum.h.

◆ Item_sum() [3/5]

drizzled::Item_sum::Item_sum ( Item * a,
Item * b )
inline

Definition at line 277 of file item/sum.h.

◆ Item_sum() [4/5]

drizzled::Item_sum::Item_sum ( List< Item > & list)

Definition at line 384 of file item/sum.cc.

◆ Item_sum() [5/5]

drizzled::Item_sum::Item_sum ( Session * session,
Item_sum * item )

Constructor used in processing select with temporary tebles.

Definition at line 407 of file item/sum.cc.

Member Function Documentation

◆ check_sum_func()

bool drizzled::Item_sum::check_sum_func ( Session * session,
Item ** ref )

Check constraints imposed on a usage of a set function.

The method verifies whether context conditions imposed on a usage of any set function are met for this occurrence. It checks whether the set function occurs in the position where it can be aggregated and, when it happens to occur in argument of another set function, the method checks that these two functions are aggregated in different subqueries. If the context conditions are not met the method reports an error. If the set function is aggregated in some outer subquery the method adds it to the chain of items for such set functions that is attached to the the Select_Lex structure for this subquery.

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 session->lex structure. The bitmap contains 1 at n-th position if the set function happens to occur under a construct of the n-th level subquery where usage of set functions are allowed (i.e either in the SELECT list or in the HAVING clause of the corresponding subquery) 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);

allow_sum_func will contain:

  • for SUM(t1.b) - 1 at the first position
  • for AVG(t1.b) - 1 at the first position, 0 at the second position
  • for MIN(t2.d) - 1 at the first position, 1 at the second position.
Parameters
sessionreference to the thread context info
reflocation of the pointer to this item in the embedding expression
Note
This function is to be called for any item created for a set function object when the traversal of trees built for expressions used in the query is performed at the phase of context analysis. This function is to be invoked at the ascent of this traversal.
Return values
TRUEif an error is reported
FALSEotherwise

Definition at line 148 of file item/sum.cc.

◆ cleanup()

void drizzled::Item_sum::cleanup ( )
inlinevirtual

Reimplemented from drizzled::Item_result_field.

Definition at line 350 of file item/sum.h.

◆ const_during_execution()

virtual bool drizzled::Item_sum::const_during_execution ( ) const
inlinevirtual

Returns true if this is constant but its value may be not known yet. (Can be used for parameters of prep. stmts or of stored procedures.)

Reimplemented from drizzled::Item.

Definition at line 362 of file item/sum.h.

◆ const_item()

virtual bool drizzled::Item_sum::const_item ( ) const
inlinevirtual

Returns true if this is constant (during query execution, i.e. its value will not change until next fix_fields) and its value is known.

Reimplemented from drizzled::Item.

Definition at line 361 of file item/sum.h.

◆ create_tmp_field()

Field * drizzled::Item_sum::create_tmp_field ( bool group,
Table * table,
uint32_t convert_blob_length )
virtual

Reimplemented in drizzled::Item_sum_variance.

Definition at line 512 of file item/sum.cc.

◆ depended_from()

Select_Lex * drizzled::Item_sum::depended_from ( )
inline

Definition at line 386 of file item/sum.h.

◆ fix_length_and_dec()

virtual void drizzled::Item_sum::fix_length_and_dec ( )
inlinevirtual

Implements drizzled::Item_result_field.

Definition at line 329 of file item/sum.h.

◆ fix_num_length_and_dec()

void drizzled::Item_sum::fix_num_length_and_dec ( )

Definition at line 464 of file item/sum.cc.

◆ get_tmp_table_item()

Item * drizzled::Item_sum::get_tmp_table_item ( Session * session)
virtual

Reimplemented from drizzled::Item.

Definition at line 474 of file item/sum.cc.

◆ init_sum_func_check()

bool drizzled::Item_sum::init_sum_func_check ( Session * session)

Prepare an aggregate function item for checking context conditions.

The function initializes the members of the Item_sum object created for a set function that are used to check validity of the set function occurrence. If the set function is not allowed in any subquery where it occurs an error is reported immediately.

Parameters
sessionreference to the thread context info
Note
This function is to be called for any item created for a set function object when the traversal of trees built for expressions used in the query is performed at the phase of context analysis. This function is to be invoked at the descent of this traversal.
Return values
TRUEif an error is reported
FALSEotherwise

Definition at line 77 of file item/sum.cc.

◆ is_null()

bool drizzled::Item_sum::is_null ( )
inlinevirtual

The method allows to determine nullness of a complex expression without fully evaluating it, instead of calling val/result*() then checking null_value. Used in Item_func_isnull/Item_func_isnotnull and Item_sum_count/Item_sum_count_distinct. Any new item which can be NULL must implement this method.

Reimplemented from drizzled::Item.

Definition at line 355 of file item/sum.h.

◆ keep_field_type()

virtual bool drizzled::Item_sum::keep_field_type ( void ) const
inlinevirtual

Definition at line 328 of file item/sum.h.

◆ make_const()

void drizzled::Item_sum::make_const ( )
inline

Definition at line 356 of file item/sum.h.

◆ make_field()

void drizzled::Item_sum::make_field ( SendField * field)
virtual

Reimplemented from drizzled::Item.

Definition at line 431 of file item/sum.cc.

◆ make_unique()

virtual void drizzled::Item_sum::make_unique ( void )
inlinevirtual

Reimplemented in drizzled::Item_sum_count_distinct.

Definition at line 378 of file item/sum.h.

◆ mark_as_sum_func()

void drizzled::Item_sum::mark_as_sum_func ( )

Definition at line 422 of file item/sum.cc.

◆ no_rows_in_result()

void drizzled::Item_sum::no_rows_in_result ( void )
inlinevirtual

Sets value of aggregate function in case of no rows for grouping were found

Reimplemented from drizzled::Item.

Reimplemented in drizzled::Item_sum_avg, drizzled::Item_sum_count, drizzled::Item_sum_count_distinct, drizzled::Item_sum_distinct, drizzled::Item_sum_hybrid, drizzled::Item_sum_sum, and drizzled::Item_sum_variance.

Definition at line 375 of file item/sum.h.

◆ print()

void drizzled::Item_sum::print ( String * str)
virtual

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;
  • debug.

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

See also
register_view().

Reimplemented from drizzled::Item.

Reimplemented in drizzled::Item_func_group_concat.

Definition at line 450 of file item/sum.cc.

◆ register_sum_func()

bool drizzled::Item_sum::register_sum_func ( Session * session,
Item ** ref )

Attach a set function to the subquery where it must be aggregated.

The function looks for an outer subquery where the set function must be aggregated. If it finds such a subquery then aggr_level is set to the nest level of this subquery and the item for the set function is added to the list of set functions used in nested subqueries inner_sum_func_list defined for each subquery. When the item is placed there the field 'ref_by' is set to ref.

Note
Now we 'register' only set functions that are aggregated in outer subqueries. Actually it makes sense to link all set function for a subquery in one chain. It would simplify the process of 'splitting' for set functions.
Parameters
sessionreference to the thread context info
reflocation of the pointer to this item in the embedding expression
Return values
FALSEif the executes without failures (currently always)
TRUEotherwise

Definition at line 319 of file item/sum.cc.

◆ reset()

bool drizzled::Item_sum::reset ( )
inline

Definition at line 294 of file item/sum.h.

◆ result_item()

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

Definition at line 346 of file item/sum.h.

◆ setup()

virtual bool drizzled::Item_sum::setup ( Session * )
inlinevirtual

Reimplemented in drizzled::Item_sum_distinct.

Definition at line 377 of file item/sum.h.

◆ type()

enum Type drizzled::Item_sum::type ( ) const
inlinevirtual

Implements drizzled::Item.

Definition at line 286 of file item/sum.h.

◆ update_field()

virtual void drizzled::Item_sum::update_field ( )
pure virtual

Implemented in drizzled::Item_sum_sum.

◆ update_used_tables()

void drizzled::Item_sum::update_used_tables ( )
virtual

Reimplemented from drizzled::Item.

Definition at line 558 of file item/sum.cc.

◆ used_tables()

table_map drizzled::Item_sum::used_tables ( ) const
inlinevirtual

Returns bit map of tables used by item

Reimplemented from drizzled::Item_result_field.

Definition at line 348 of file item/sum.h.

◆ walk()

bool drizzled::Item_sum::walk ( Item_processor processor,
bool walk_subquery,
unsigned char * argument )
virtual

Reimplemented from drizzled::Item.

Definition at line 496 of file item/sum.cc.

Member Data Documentation

◆ aggr_level

int8_t drizzled::Item_sum::aggr_level

Definition at line 248 of file item/sum.h.

◆ aggr_sel

Select_Lex* drizzled::Item_sum::aggr_sel

Definition at line 246 of file item/sum.h.

◆ arg_count

uint32_t drizzled::Item_sum::arg_count

Definition at line 244 of file item/sum.h.

◆ args

Item** drizzled::Item_sum::args

Definition at line 241 of file item/sum.h.

◆ forced_const

bool drizzled::Item_sum::forced_const
protected

Definition at line 262 of file item/sum.h.

◆ in_sum_func

Item_sum* drizzled::Item_sum::in_sum_func

Definition at line 245 of file item/sum.h.

◆ max_arg_level

int8_t drizzled::Item_sum::max_arg_level

Definition at line 249 of file item/sum.h.

◆ max_sum_func_level

int8_t drizzled::Item_sum::max_sum_func_level

Definition at line 250 of file item/sum.h.

◆ nest_level

int8_t drizzled::Item_sum::nest_level

Definition at line 247 of file item/sum.h.

◆ next

Item_sum* drizzled::Item_sum::next

Definition at line 243 of file item/sum.h.

◆ outer_fields

List<Item_field> drizzled::Item_sum::outer_fields

Definition at line 258 of file item/sum.h.

◆ quick_group

bool drizzled::Item_sum::quick_group

Definition at line 251 of file item/sum.h.

◆ ref_by

Item** drizzled::Item_sum::ref_by

Definition at line 242 of file item/sum.h.

◆ tmp_args

Item * drizzled::Item_sum::tmp_args[2]

Definition at line 241 of file item/sum.h.

◆ used_tables_cache

table_map drizzled::Item_sum::used_tables_cache
protected

Definition at line 261 of file item/sum.h.


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