24 #include <drizzled/tree.h>
25 #include <drizzled/hybrid_type.h>
26 #include <drizzled/item.h>
27 #include <drizzled/item/field.h>
28 #include <drizzled/item/bin_string.h>
29 #include <drizzled/charset.h>
236 { COUNT_FUNC, COUNT_DISTINCT_FUNC, SUM_FUNC, SUM_DISTINCT_FUNC, AVG_FUNC,
237 AVG_DISTINCT_FUNC, MIN_FUNC, MAX_FUNC, STD_FUNC,
238 VARIANCE_FUNC, SUM_BIT_FUNC, GROUP_CONCAT_FUNC
241 Item **args, *tmp_args[2];
246 Select_Lex * aggr_sel;
249 int8_t max_arg_level;
250 int8_t max_sum_func_level;
261 table_map used_tables_cache;
266 void mark_as_sum_func();
267 Item_sum() :arg_count(0), quick_group(1), forced_const(
false)
271 Item_sum(
Item *a) :args(tmp_args), arg_count(1), quick_group(1),
280 args[0]=a; args[1]=b;
286 enum Type type()
const {
return SUM_FUNC_ITEM; }
287 virtual enum Sumfunctype sum_func ()
const=0;
294 inline bool reset() { clear();
return add(); };
302 virtual void clear()= 0;
310 virtual bool add()=0;
321 virtual void reset_field()=0;
327 virtual void update_field()=0;
328 virtual bool keep_field_type(
void)
const {
return 0; }
345 virtual const char *func_name()
const= 0;
349 void update_used_tables ();
358 used_tables_cache= 0;
365 void fix_num_length_and_dec();
377 virtual bool setup(
Session *) {
return 0;}
378 virtual void make_unique(
void) {}
379 Item *get_tmp_table_item(Session *session);
380 virtual Field *create_tmp_field(
bool group, Table *table,
381 uint32_t convert_blob_length);
382 bool walk(Item_processor processor,
bool walk_subquery,
unsigned char *argument);
386 Select_Lex *depended_from()
387 {
return (nest_level == aggr_level ? 0 : aggr_sel); }
404 :
Item_sum(item_par), is_evaluated(
false) {}
407 :
Item_sum(list), is_evaluated(
false) {}
409 :
Item_sum(session, item),is_evaluated(item->is_evaluated) {}
427 enum Item_result result_type ()
const {
return INT_RESULT; }
428 void fix_length_and_dec()
436 Item_result hybrid_type;
439 uint32_t curr_dec_buff;
440 void fix_length_and_dec();
445 enum Sumfunctype sum_func ()
const {
return SUM_FUNC;}
452 enum Item_result result_type ()
const {
return hybrid_type; }
456 const char *func_name()
const {
return "sum("; }
457 Item *copy_or_same(Session* session);
473 enum enum_field_types table_field_type;
474 uint32_t tree_key_length;
492 enum Sumfunctype sum_func ()
const {
return SUM_DISTINCT_FUNC; }
493 void reset_field() {}
494 void update_field() {}
496 void fix_length_and_dec();
497 enum Item_result result_type ()
const;
498 virtual void calculate_val_and_count();
499 virtual bool unique_walk_function(
void *elem);
517 enum Sumfunctype sum_func ()
const {
return SUM_DISTINCT_FUNC; }
518 const char *func_name()
const {
return "sum(distinct "; }
531 uint32_t prec_increment;
534 void fix_length_and_dec();
535 virtual void calculate_val_and_count();
536 enum Sumfunctype sum_func ()
const {
return AVG_DISTINCT_FUNC; }
537 const char *func_name()
const {
return "avg(distinct "; }
553 enum Sumfunctype sum_func ()
const {
return COUNT_FUNC; }
557 void make_const_count(int64_t count_arg)
560 Item_sum::make_const();
566 const char *func_name()
const {
return "count("; }
567 Item *copy_or_same(Session* session);
574 uint32_t *field_lengths;
576 bool force_copy_fields;
594 uint32_t tree_key_length;
600 friend int composite_key_cmp(
void* arg,
unsigned char* key1,
unsigned char* key2);
601 friend int simple_str_key_cmp(
void* arg,
unsigned char* key1,
unsigned char* key2);
605 :
Item_sum_int(list), table(0), field_lengths(0), tmp_table_param(0),
606 force_copy_fields(0), tree(0), count(0),
607 original(0), always_null(
false)
611 field_lengths(item->field_lengths),
612 tmp_table_param(item->tmp_table_param),
613 force_copy_fields(0), tree(item->tree), count(item->count),
614 original(item), tree_key_length(item->tree_key_length),
615 always_null(item->always_null)
621 enum Sumfunctype sum_func ()
const {
return COUNT_DISTINCT_FUNC; }
625 void reset_field() { return ;}
626 void update_field() { return ; }
627 const char *func_name()
const {
return "count(distinct "; }
641 Item_result hybrid_type;
642 uint32_t f_precision, f_scale, dec_bin_size;
643 uint32_t prec_increment;
645 enum Type type()
const {
return FIELD_AVG_ITEM; }
651 enum_field_types field_type()
const
653 return hybrid_type == DECIMAL_RESULT ?
654 DRIZZLE_TYPE_DECIMAL : DRIZZLE_TYPE_DOUBLE;
656 void fix_length_and_dec() {}
657 enum Item_result result_type ()
const {
return hybrid_type; }
665 uint32_t prec_increment;
666 uint32_t f_precision, f_scale, dec_bin_size;
671 prec_increment(item->prec_increment) {}
673 void fix_length_and_dec();
674 enum Sumfunctype sum_func ()
const {
return AVG_FUNC;}
687 const char *func_name()
const {
return "avg("; }
688 Item *copy_or_same(Session* session);
689 Field *create_tmp_field(
bool group, Table *table, uint32_t convert_blob_length);
693 Item_sum_sum::cleanup();
701 Item_result hybrid_type;
702 uint32_t f_precision0, f_scale0;
703 uint32_t f_precision1, f_scale1;
704 uint32_t dec_bin_size0, dec_bin_size1;
706 uint32_t prec_increment;
708 enum Type type()
const {
return FIELD_VARIANCE_ITEM; }
712 {
return val_string_from_real(str); }
714 {
return val_decimal_from_real(dec_buf); }
716 enum_field_types field_type()
const
718 return hybrid_type == DECIMAL_RESULT ?
719 DRIZZLE_TYPE_DECIMAL : DRIZZLE_TYPE_DOUBLE;
721 void fix_length_and_dec() {}
722 enum Item_result result_type ()
const {
return hybrid_type; }
748 void fix_length_and_dec();
751 Item_result hybrid_type;
753 double recurrence_m, recurrence_s;
755 uint32_t f_precision0, f_scale0;
756 uint32_t f_precision1, f_scale1;
757 uint32_t dec_bin_size0, dec_bin_size1;
759 uint32_t prec_increment;
762 hybrid_type(REAL_RESULT), count(0), sample(sample_arg)
765 enum Sumfunctype sum_func ()
const {
return VARIANCE_FUNC; }
776 const char *func_name()
const
777 {
return sample ?
"var_samp(" :
"variance("; }
778 Item *copy_or_same(Session* session);
779 Field *
create_tmp_field(
bool group, Table *table, uint32_t convert_blob_length);
780 enum Item_result result_type ()
const {
return REAL_RESULT; }
784 Item_sum_num::cleanup();
792 enum Type type()
const {
return FIELD_STD_ITEM; }
795 enum Item_result result_type ()
const {
return REAL_RESULT; }
796 enum_field_types field_type()
const {
return DRIZZLE_TYPE_DOUBLE;}
811 enum Sumfunctype sum_func ()
const {
return STD_FUNC; }
815 const char *func_name()
const {
return "std("; }
817 enum Item_result result_type ()
const {
return REAL_RESULT; }
818 enum_field_types field_type()
const {
return DRIZZLE_TYPE_DOUBLE;}
830 Item_result hybrid_type;
831 enum_field_types hybrid_field_type;
837 :
Item_sum(item_par), sum(0.0), sum_int(0),
838 hybrid_type(INT_RESULT), hybrid_field_type(DRIZZLE_TYPE_LONGLONG),
839 cmp_sign(sign), was_values(
true)
840 { collation.set(&my_charset_bin); }
849 bool keep_field_type(
void)
const {
return 1; }
850 enum Item_result result_type ()
const {
return hybrid_type; }
851 enum enum_field_types field_type()
const {
return hybrid_field_type; }
853 void min_max_update_str_field();
854 void min_max_update_real_field();
855 void min_max_update_int_field();
858 bool any_value() {
return was_values; }
860 Field *create_tmp_field(
bool group,
Table *table,
861 uint32_t convert_blob_length);
870 enum Sumfunctype sum_func ()
const {
return MIN_FUNC;}
873 const char *func_name()
const {
return "min("; }
883 enum Sumfunctype sum_func ()
const {
return MAX_FUNC;}
886 const char *func_name()
const {
return "max("; }
894 uint64_t reset_bits,bits;
898 :
Item_sum_int(item_par),reset_bits(reset_arg),bits(reset_arg) {}
900 Item_sum_int(session, item), reset_bits(item->reset_bits), bits(item->bits) {}
901 enum Sumfunctype sum_func ()
const {
return SUM_BIT_FUNC;}
906 void fix_length_and_dec()
911 Item_sum_int::cleanup();
922 const char *func_name()
const {
return "bit_or("; }
933 const char *func_name()
const {
return "bit_and("; }
943 const char *func_name()
const {
return "bit_xor("; }
971 uint32_t count_cut_values;
973 bool warning_for_row;
975 bool force_copy_fields;
999 enum Sumfunctype sum_func ()
const {
return GROUP_CONCAT_FUNC;}
1000 const char *func_name()
const {
return "group_concat"; }
1001 virtual Item_result result_type ()
const {
return STRING_RESULT; }
1002 enum_field_types field_type()
const
1004 if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB )
1005 return DRIZZLE_TYPE_BLOB;
1007 return DRIZZLE_TYPE_VARCHAR;
1011 void reset_field() { assert(0); }
1012 void update_field() { assert(0); }
1013 bool fix_fields(Session *,
Item **);
1014 bool setup(Session *session);
1020 return val_decimal_from_string(decimal_value);
1026 virtual bool change_context_processor(
unsigned char *cntx)
type::Decimal * val_decimal(type::Decimal *)
String * val_str(String *str)
bool check_sum_func(Session *session, Item **ref)
String * val_str(String *str)
virtual bool const_during_execution() const
String * val_str(String *)
virtual bool const_item() const
Item_func_group_concat(Name_resolution_context *context_arg, bool is_distinct, List< Item > *is_select, SQL_LIST *is_order, String *is_separator)
friend int group_concat_key_cmp_with_order(void *arg, const void *key1, const void *key2)
TODO: Rename this file - func.h is stupid.
type::Decimal * val_decimal(type::Decimal *)
type::Decimal * val_decimal(type::Decimal *)
String * val_str(String *str)
bool register_sum_func(Session *session, Item **ref)
friend int composite_key_cmp(void *arg, unsigned char *key1, unsigned char *key2)
type::Decimal * val_decimal(type::Decimal *)
type::Decimal * val_decimal(type::Decimal *)
friend int dump_leaf_key(unsigned char *key, uint32_t, Item_func_group_concat *group_concat_item)
type::Decimal * val_decimal(type::Decimal *)
String * val_str(String *str)
virtual void update_null_value()
type::Decimal * val_decimal(type::Decimal *dec_buf)
type::Decimal * val_decimal(type::Decimal *)
virtual void no_rows_in_result()
type::Decimal * val_decimal(type::Decimal *)
String * val_str(String *str)
virtual void print(String *str)
type::Decimal * val_decimal(type::Decimal *decimal_value)
table_map used_tables() const
Field * create_tmp_field(bool group, Table *table, uint32_t convert_blob_length)
String * val_str(String *)
friend int group_concat_key_cmp_with_distinct(void *arg, const void *key1, const void *key2)
type::Decimal * val_decimal(type::Decimal *)
bool setup(Session *session)
String * val_str(String *str)
int group_concat_key_cmp_with_order(void *arg, const void *key1, const void *key2)
virtual void print(String *str)
String * val_str(String *str)
void min_max_update_decimal_field()
int group_concat_key_cmp_with_distinct(void *arg, const void *key1, const void *key2)
bool init_sum_func_check(Session *session)