#include <item_sum.h>
Inheritance diagram for Item_sum_distinct:


Public Member Functions | |
| Item_sum_distinct (Item *item_par) | |
| ~Item_sum_distinct () | |
| bool | setup (THD *thd) |
| void | clear () |
| void | cleanup () |
| bool | add () |
| double | val_real () |
| my_decimal * | val_decimal (my_decimal *) |
| longlong | val_int () |
| String * | val_str (String *str) |
| enum Sumfunctype | sum_func () const |
| void | reset_field () |
| void | update_field () |
| virtual void | no_rows_in_result () |
| void | fix_length_and_dec () |
| enum Item_result | result_type () const |
| virtual void | calculate_val_and_count () |
| virtual bool | unique_walk_function (void *elem) |
Protected Member Functions | |
| Item_sum_distinct (THD *thd, Item_sum_distinct *item) | |
Protected Attributes | |
| ulonglong | count |
| Hybrid_type | val |
| Unique * | tree |
| TABLE * | table |
| enum enum_field_types | table_field_type |
| uint | tree_key_length |
Definition at line 390 of file item_sum.h.
| Item_sum_distinct::Item_sum_distinct | ( | THD * | thd, | |
| Item_sum_distinct * | item | |||
| ) | [protected] |
Definition at line 760 of file item_sum.cc.
References Item_sum::quick_group.
00761 :Item_sum_num(thd, original), val(original->val), tree(0), 00762 table_field_type(original->table_field_type) 00763 { 00764 quick_group= 0; 00765 }
| C_MODE_END Item_sum_distinct::Item_sum_distinct | ( | Item * | item_par | ) |
Definition at line 747 of file item_sum.cc.
References Item_sum::quick_group.
00748 :Item_sum_num(item_arg), tree(0) 00749 { 00750 /* 00751 quick_group is an optimizer hint, which means that GROUP BY can be 00752 handled with help of index on grouped columns. 00753 By setting quick_group to zero we force creation of temporary table 00754 to perform GROUP BY. 00755 */ 00756 quick_group= 0; 00757 }
| Item_sum_distinct::~Item_sum_distinct | ( | ) |
Definition at line 931 of file item_sum.cc.
References tree.
00932 { 00933 delete tree; 00934 /* no need to free the table */ 00935 }
| bool Item_sum_distinct::add | ( | ) | [virtual] |
Implements Item_sum.
Definition at line 888 of file item_sum.cc.
References Item_sum::args, DBUG_ASSERT, FALSE, st_table::field, Field::is_null(), Item::null_value, Field::ptr, Item::save_in_field(), table, and tree.
00889 { 00890 args[0]->save_in_field(table->field[0], FALSE); 00891 if (!table->field[0]->is_null()) 00892 { 00893 DBUG_ASSERT(tree); 00894 null_value= 0; 00895 /* 00896 '0' values are also stored in the tree. This doesn't matter 00897 for SUM(DISTINCT), but is important for AVG(DISTINCT) 00898 */ 00899 return tree->unique_add(table->field[0]->ptr); 00900 } 00901 return 0; 00902 }
Here is the call graph for this function:

| void Item_sum_distinct::calculate_val_and_count | ( | ) | [virtual] |
Reimplemented in Item_sum_avg_distinct.
Definition at line 938 of file item_sum.cc.
References count, st_table::field, item_sum_distinct_walk(), Field::set_notnull(), Hybrid_type_traits::set_zero(), table, Hybrid_type::traits, tree, and val.
Referenced by Item_sum_avg_distinct::calculate_val_and_count(), val_decimal(), val_int(), val_real(), and val_str().
00939 { 00940 count= 0; 00941 val.traits->set_zero(&val); 00942 /* 00943 We don't have a tree only if 'setup()' hasn't been called; 00944 this is the case of sql_select.cc:return_zero_rows. 00945 */ 00946 if (tree) 00947 { 00948 table->field[0]->set_notnull(); 00949 tree->walk(item_sum_distinct_walk, (void*) this); 00950 } 00951 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void Item_sum_distinct::cleanup | ( | ) | [virtual] |
Reimplemented from Item_result_field.
Definition at line 923 of file item_sum.cc.
References Item_result_field::cleanup(), table, and tree.
00924 { 00925 Item_sum_num::cleanup(); 00926 delete tree; 00927 tree= 0; 00928 table= 0; 00929 }
Here is the call graph for this function:

| void Item_sum_distinct::clear | ( | ) | [virtual] |
Implements Item_sum.
Definition at line 914 of file item_sum.cc.
References DBUG_ASSERT, DBUG_ENTER, DBUG_VOID_RETURN, Item::null_value, and tree.
00915 { 00916 DBUG_ENTER("Item_sum_distinct::clear"); 00917 DBUG_ASSERT(tree != 0); /* we always have a tree */ 00918 null_value= 1; 00919 tree->reset(); 00920 DBUG_VOID_RETURN; 00921 }
| void Item_sum_distinct::fix_length_and_dec | ( | ) | [virtual] |
Reimplemented from Item_sum.
Reimplemented in Item_sum_avg_distinct.
Definition at line 801 of file item_sum.cc.
References Item_sum::args, DBUG_ASSERT, DECIMAL_RESULT, Item::field_type(), Hybrid_type_traits::fix_length_and_dec(), Item::fixed, Hybrid_type_traits_decimal::instance(), Hybrid_type_traits_fast_decimal::instance(), Hybrid_type_traits::instance(), INT_RESULT, MYSQL_TYPE_DOUBLE, MYSQL_TYPE_FLOAT, MYSQL_TYPE_INT24, MYSQL_TYPE_LONG, MYSQL_TYPE_LONGLONG, MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_TINY, REAL_RESULT, result_type(), ROW_RESULT, STRING_RESULT, table_field_type, Hybrid_type::traits, and val.
Referenced by Item_sum_avg_distinct::fix_length_and_dec().
00802 { 00803 DBUG_ASSERT(args[0]->fixed); 00804 00805 table_field_type= args[0]->field_type(); 00806 00807 /* Adjust tmp table type according to the chosen aggregation type */ 00808 switch (args[0]->result_type()) { 00809 case STRING_RESULT: 00810 case REAL_RESULT: 00811 val.traits= Hybrid_type_traits::instance(); 00812 if (table_field_type != MYSQL_TYPE_FLOAT) 00813 table_field_type= MYSQL_TYPE_DOUBLE; 00814 break; 00815 case INT_RESULT: 00816 /* 00817 Preserving int8, int16, int32 field types gives ~10% performance boost 00818 as the size of result tree becomes significantly smaller. 00819 Another speed up we gain by using longlong for intermediate 00820 calculations. The range of int64 is enough to hold sum 2^32 distinct 00821 integers each <= 2^32. 00822 */ 00823 if (table_field_type == MYSQL_TYPE_INT24 || 00824 table_field_type >= MYSQL_TYPE_TINY && 00825 table_field_type <= MYSQL_TYPE_LONG) 00826 { 00827 val.traits= Hybrid_type_traits_fast_decimal::instance(); 00828 break; 00829 } 00830 table_field_type= MYSQL_TYPE_LONGLONG; 00831 /* fallthrough */ 00832 case DECIMAL_RESULT: 00833 val.traits= Hybrid_type_traits_decimal::instance(); 00834 if (table_field_type != MYSQL_TYPE_LONGLONG) 00835 table_field_type= MYSQL_TYPE_NEWDECIMAL; 00836 break; 00837 case ROW_RESULT: 00838 default: 00839 DBUG_ASSERT(0); 00840 } 00841 val.traits->fix_length_and_dec(this, args[0]); 00842 }
Here is the call graph for this function:

Here is the caller graph for this function:

| virtual void Item_sum_distinct::no_rows_in_result | ( | ) | [inline, virtual] |
| void Item_sum_distinct::reset_field | ( | ) | [inline, virtual] |
| enum Item_result Item_sum_distinct::result_type | ( | ) | const [inline, virtual] |
Reimplemented from Item.
Definition at line 423 of file item_sum.h.
References Hybrid_type::traits, Hybrid_type_traits::type(), and val.
Referenced by fix_length_and_dec().
Here is the call graph for this function:

Here is the caller graph for this function:

| bool Item_sum_distinct::setup | ( | THD * | thd | ) | [virtual] |
Reimplemented from Item_sum.
Definition at line 845 of file item_sum.cc.
References Item_sum::args, create_virtual_tmp_table(), DBUG_ASSERT, DBUG_ENTER, DBUG_RETURN, Item::decimals, Item::fixed, create_field::init_for_tmp_table(), Item::max_length, Item::maybe_null, st_table_share::null_bytes, Item::null_value, List< T >::push_back(), Item_sum::quick_group, st_table_share::reclength, st_table::s, simple_raw_key_cmp(), table, table_field_type, tree, tree_key_length, TRUE, and Item::unsigned_flag.
00846 { 00847 List<create_field> field_list; 00848 create_field field_def; /* field definition */ 00849 DBUG_ENTER("Item_sum_distinct::setup"); 00850 DBUG_ASSERT(tree == 0); 00851 00852 /* 00853 Virtual table and the tree are created anew on each re-execution of 00854 PS/SP. Hence all further allocations are performed in the runtime 00855 mem_root. 00856 */ 00857 if (field_list.push_back(&field_def)) 00858 return TRUE; 00859 00860 null_value= maybe_null= 1; 00861 quick_group= 0; 00862 00863 DBUG_ASSERT(args[0]->fixed); 00864 00865 field_def.init_for_tmp_table(table_field_type, args[0]->max_length, 00866 args[0]->decimals, args[0]->maybe_null, 00867 args[0]->unsigned_flag); 00868 00869 if (! (table= create_virtual_tmp_table(thd, field_list))) 00870 return TRUE; 00871 00872 /* XXX: check that the case of CHAR(0) works OK */ 00873 tree_key_length= table->s->reclength - table->s->null_bytes; 00874 00875 /* 00876 Unique handles all unique elements in a tree until they can't fit 00877 in. Then the tree is dumped to the temporary file. We can use 00878 simple_raw_key_cmp because the table contains numbers only; decimals 00879 are converted to binary representation as well. 00880 */ 00881 tree= new Unique(simple_raw_key_cmp, &tree_key_length, tree_key_length, 00882 thd->variables.max_heap_table_size); 00883 00884 DBUG_RETURN(tree == 0); 00885 }
Here is the call graph for this function:

| enum Sumfunctype Item_sum_distinct::sum_func | ( | ) | const [inline, virtual] |
Implements Item_sum.
Reimplemented in Item_sum_sum_distinct, and Item_sum_avg_distinct.
Definition at line 418 of file item_sum.h.
References Item_sum::SUM_DISTINCT_FUNC.
00418 { return SUM_DISTINCT_FUNC; }
| bool Item_sum_distinct::unique_walk_function | ( | void * | elem | ) | [virtual] |
Definition at line 905 of file item_sum.cc.
References Hybrid_type_traits::add(), count, st_table::field, memcpy, Field::ptr, table, Hybrid_type::traits, tree_key_length, and val.
00906 { 00907 memcpy(table->field[0]->ptr, element, tree_key_length); 00908 ++count; 00909 val.traits->add(&val, table->field[0]); 00910 return 0; 00911 }
Here is the call graph for this function:

| void Item_sum_distinct::update_field | ( | ) | [inline, virtual] |
| my_decimal * Item_sum_distinct::val_decimal | ( | my_decimal * | ) | [virtual] |
Reimplemented from Item_sum_num.
Definition at line 961 of file item_sum.cc.
References calculate_val_and_count(), Item::null_value, to, Hybrid_type::traits, val, and Hybrid_type_traits::val_decimal().
00962 { 00963 calculate_val_and_count(); 00964 if (null_value) 00965 return 0; 00966 return val.traits->val_decimal(&val, to); 00967 }
Here is the call graph for this function:

| longlong Item_sum_distinct::val_int | ( | ) | [virtual] |
Reimplemented from Item_sum_num.
Definition at line 970 of file item_sum.cc.
References calculate_val_and_count(), Hybrid_type::traits, Item::unsigned_flag, val, and Hybrid_type_traits::val_int().
00971 { 00972 calculate_val_and_count(); 00973 return val.traits->val_int(&val, unsigned_flag); 00974 }
Here is the call graph for this function:

| double Item_sum_distinct::val_real | ( | ) | [virtual] |
Implements Item.
Definition at line 954 of file item_sum.cc.
References calculate_val_and_count(), Hybrid_type::traits, val, and Hybrid_type_traits::val_real().
00955 { 00956 calculate_val_and_count(); 00957 return val.traits->val_real(&val); 00958 }
Here is the call graph for this function:

Reimplemented from Item_sum_num.
Definition at line 977 of file item_sum.cc.
References calculate_val_and_count(), Item::decimals, Item::null_value, Hybrid_type::traits, val, and Hybrid_type_traits::val_str().
00978 { 00979 calculate_val_and_count(); 00980 if (null_value) 00981 return 0; 00982 return val.traits->val_str(&val, str, decimals); 00983 }
Here is the call graph for this function:

ulonglong Item_sum_distinct::count [protected] |
Definition at line 394 of file item_sum.h.
Referenced by Item_sum_avg_distinct::calculate_val_and_count(), calculate_val_and_count(), and unique_walk_function().
TABLE* Item_sum_distinct::table [protected] |
Definition at line 398 of file item_sum.h.
Referenced by add(), calculate_val_and_count(), cleanup(), setup(), and unique_walk_function().
enum enum_field_types Item_sum_distinct::table_field_type [protected] |
Unique* Item_sum_distinct::tree [protected] |
Definition at line 397 of file item_sum.h.
Referenced by add(), calculate_val_and_count(), cleanup(), clear(), setup(), and ~Item_sum_distinct().
uint Item_sum_distinct::tree_key_length [protected] |
Hybrid_type Item_sum_distinct::val [protected] |
Definition at line 395 of file item_sum.h.
Referenced by Item_sum_avg_distinct::calculate_val_and_count(), calculate_val_and_count(), fix_length_and_dec(), result_type(), unique_walk_function(), val_decimal(), val_int(), val_real(), and val_str().
1.4.7

