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


Definition at line 221 of file item_sum.h.
| COUNT_FUNC | |
| COUNT_DISTINCT_FUNC | |
| SUM_FUNC | |
| SUM_DISTINCT_FUNC | |
| AVG_FUNC | |
| AVG_DISTINCT_FUNC | |
| MIN_FUNC | |
| MAX_FUNC | |
| UNIQUE_USERS_FUNC | |
| STD_FUNC | |
| VARIANCE_FUNC | |
| SUM_BIT_FUNC | |
| UDF_SUM_FUNC | |
| GROUP_CONCAT_FUNC |
Definition at line 224 of file item_sum.h.
00225 { COUNT_FUNC, COUNT_DISTINCT_FUNC, SUM_FUNC, SUM_DISTINCT_FUNC, AVG_FUNC, 00226 AVG_DISTINCT_FUNC, MIN_FUNC, MAX_FUNC, UNIQUE_USERS_FUNC, STD_FUNC, 00227 VARIANCE_FUNC, SUM_BIT_FUNC, UDF_SUM_FUNC, GROUP_CONCAT_FUNC 00228 };
| Item_sum::Item_sum | ( | ) | [inline] |
Definition at line 242 of file item_sum.h.
References mark_as_sum_func().
00242 :arg_count(0), quick_group(1) 00243 { 00244 mark_as_sum_func(); 00245 }
Here is the call graph for this function:

| Item_sum::Item_sum | ( | Item * | a | ) | [inline] |
Definition at line 246 of file item_sum.h.
References args, and mark_as_sum_func().
00247 :args(tmp_args), arg_count(1), quick_group(1) 00248 { 00249 args[0]=a; 00250 mark_as_sum_func(); 00251 }
Here is the call graph for this function:

Definition at line 252 of file item_sum.h.
References args, and mark_as_sum_func().
00253 :args(tmp_args), arg_count(2), quick_group(1) 00254 { 00255 args[0]=a; args[1]=b; 00256 mark_as_sum_func(); 00257 }
Here is the call graph for this function:

Definition at line 255 of file item_sum.cc.
References arg_count, args, list(), mark_as_sum_func(), and sql_alloc().
00256 :arg_count(list.elements) 00257 { 00258 if ((args=(Item**) sql_alloc(sizeof(Item*)*arg_count))) 00259 { 00260 uint i=0; 00261 List_iterator_fast<Item> li(list); 00262 Item *item; 00263 00264 while ((item=li++)) 00265 { 00266 args[i++]= item; 00267 } 00268 } 00269 mark_as_sum_func(); 00270 list.empty(); // Fields are used 00271 }
Here is the call graph for this function:

| Item_sum::Item_sum | ( | THD * | thd, | |
| Item_sum * | item | |||
| ) |
Definition at line 278 of file item_sum.cc.
References arg_count, args, memcpy, and tmp_args.
00278 : 00279 Item_result_field(thd, item), arg_count(item->arg_count), 00280 quick_group(item->quick_group) 00281 { 00282 if (arg_count <= 2) 00283 args=tmp_args; 00284 else 00285 if (!(args= (Item**) thd->alloc(sizeof(Item*)*arg_count))) 00286 return; 00287 memcpy(args, item->args, sizeof(Item*)*arg_count); 00288 }
| virtual bool Item_sum::add | ( | ) | [pure virtual] |
Implemented in Item_sum_sum, Item_sum_distinct, Item_sum_count, Item_sum_count_distinct, Item_sum_avg, Item_sum_variance, Item_sum_min, Item_sum_max, Item_sum_or, Item_sum_and, Item_sum_xor, Item_sum_udf_float, Item_sum_udf_int, Item_sum_udf_decimal, Item_sum_udf_str, Item_func_group_concat, and Item_sum_unique_users.
Referenced by reset(), and Item_sum_bit::update_field().
Here is the caller graph for this function:

Definition at line 122 of file item_sum.cc.
References aggr_level, ER, ER_INVALID_GROUP_FUNC_USE, FALSE, in_sum_func, max_arg_level, max_sum_func_level, my_message(), MYF, nest_level, register_sum_func(), set_if_bigger, and TRUE.
Referenced by Item_func_group_concat::fix_fields(), Item_sum_hybrid::fix_fields(), and Item_sum_num::fix_fields().
00123 { 00124 bool invalid= FALSE; 00125 nesting_map allow_sum_func= thd->lex->allow_sum_func; 00126 /* 00127 The value of max_arg_level is updated if an argument of the set function 00128 contains a column reference resolved against a subquery whose level is 00129 greater than the current value of max_arg_level. 00130 max_arg_level cannot be greater than nest level. 00131 nest level is always >= 0 00132 */ 00133 if (nest_level == max_arg_level) 00134 { 00135 /* 00136 The function must be aggregated in the current subquery, 00137 If it is there under a construct where it is not allowed 00138 we report an error. 00139 */ 00140 invalid= !(allow_sum_func & (1 << max_arg_level)); 00141 } 00142 else if (max_arg_level >= 0 || !(allow_sum_func & (1 << nest_level))) 00143 { 00144 /* 00145 The set function can be aggregated only in outer subqueries. 00146 Try to find a subquery where it can be aggregated; 00147 If we fail to find such a subquery report an error. 00148 */ 00149 if (register_sum_func(thd, ref)) 00150 return TRUE; 00151 invalid= aggr_level < 0 && !(allow_sum_func & (1 << nest_level)); 00152 } 00153 if (!invalid && aggr_level < 0) 00154 aggr_level= nest_level; 00155 /* 00156 By this moment we either found a subquery where the set function is 00157 to be aggregated and assigned a value that is >= 0 to aggr_level, 00158 or set the value of 'invalid' to TRUE to report later an error. 00159 */ 00160 /* 00161 Additionally we have to check whether possible nested set functions 00162 are acceptable here: they are not, if the level of aggregation of 00163 some of them is less than aggr_level. 00164 */ 00165 invalid= aggr_level <= max_sum_func_level; 00166 if (invalid) 00167 { 00168 my_message(ER_INVALID_GROUP_FUNC_USE, ER(ER_INVALID_GROUP_FUNC_USE), 00169 MYF(0)); 00170 return TRUE; 00171 } 00172 if (in_sum_func && in_sum_func->nest_level == nest_level) 00173 { 00174 /* 00175 If the set function is nested adjust the value of 00176 max_sum_func_level for the nesting set function. 00177 */ 00178 set_if_bigger(in_sum_func->max_sum_func_level, aggr_level); 00179 } 00180 thd->lex->in_sum_func= in_sum_func; 00181 return FALSE; 00182 }
Here is the call graph for this function:

Here is the caller graph for this function:

| virtual void Item_sum::clear | ( | ) | [pure virtual] |
Implemented in Item_sum_sum, Item_sum_distinct, Item_sum_count, Item_sum_count_distinct, Item_sum_avg, Item_sum_variance, Item_sum_hybrid, Item_sum_bit, Item_sum_udf_float, Item_sum_udf_int, Item_sum_udf_decimal, Item_sum_udf_str, Item_func_group_concat, and Item_sum_unique_users.
Referenced by reset().
Here is the caller graph for this function:

| bool Item_sum::const_item | ( | ) | const [inline, virtual] |
Reimplemented from Item.
Reimplemented in Item_sum_count, and Item_sum_hybrid.
Definition at line 303 of file item_sum.h.
| Field * Item_sum::create_tmp_field | ( | bool | group, | |
| TABLE * | table, | |||
| uint | convert_blob_length | |||
| ) | [virtual] |
Reimplemented in Item_sum_avg, Item_sum_variance, Item_sum_hybrid, and Item_sum_unique_users.
Definition at line 372 of file item_sum.cc.
References DTCollation::collation, Item::collation, DBUG_ASSERT, DECIMAL_RESULT, Item::decimals, Field::init(), INT_RESULT, Item::make_string_field(), Item::max_length, Item::maybe_null, charset_info_st::mbmaxlen, Item::name, REAL_RESULT, Item::result_type(), ROW_RESULT, STRING_RESULT, UINT_MAX16, and Item::unsigned_flag.
Referenced by create_tmp_field(), and Item_sum_hybrid::create_tmp_field().
00374 { 00375 Field *field; 00376 switch (result_type()) { 00377 case REAL_RESULT: 00378 field= new Field_double(max_length, maybe_null, name, decimals); 00379 break; 00380 case INT_RESULT: 00381 field= new Field_longlong(max_length, maybe_null, name, unsigned_flag); 00382 break; 00383 case STRING_RESULT: 00384 if (max_length/collation.collation->mbmaxlen <= 255 || 00385 max_length/collation.collation->mbmaxlen >=UINT_MAX16 || 00386 !convert_blob_length) 00387 return make_string_field(table); 00388 field= new Field_varstring(convert_blob_length, maybe_null, 00389 name, table->s, collation.collation); 00390 break; 00391 case DECIMAL_RESULT: 00392 field= new Field_new_decimal(max_length, maybe_null, name, 00393 decimals, unsigned_flag); 00394 break; 00395 case ROW_RESULT: 00396 default: 00397 // This case should never be choosen 00398 DBUG_ASSERT(0); 00399 return 0; 00400 } 00401 if (field) 00402 field->init(table); 00403 return field; 00404 }
Here is the call graph for this function:

Here is the caller graph for this function:

| virtual void Item_sum::fix_length_and_dec | ( | ) | [inline, virtual] |
Implements Item_result_field.
Reimplemented in Item_sum_int, Item_sum_sum, Item_sum_distinct, Item_sum_avg_distinct, Item_sum_avg, Item_sum_variance, Item_sum_bit, and Item_sum_udf_str.
Definition at line 283 of file item_sum.h.
References Item::maybe_null, and Item::null_value.
Referenced by Item_sum_hybrid::fix_fields(), and Item_sum_num::fix_fields().
00283 { maybe_null=1; null_value=1; }
Here is the caller graph for this function:

| void Item_sum::fix_num_length_and_dec | ( | ) |
Definition at line 326 of file item_sum.cc.
References arg_count, args, Item::decimals, Item::float_length(), Item::max_length, and set_if_bigger.
00327 { 00328 decimals=0; 00329 for (uint i=0 ; i < arg_count ; i++) 00330 set_if_bigger(decimals,args[i]->decimals); 00331 max_length=float_length(decimals); 00332 }
Here is the call graph for this function:

| virtual const char* Item_sum::func_name | ( | ) | const [pure virtual] |
Implemented in Item_sum_sum, Item_sum_sum_distinct, Item_sum_avg_distinct, Item_sum_count, Item_sum_count_distinct, Item_sum_avg, Item_sum_variance, Item_sum_std, Item_sum_min, Item_sum_max, Item_sum_or, Item_sum_and, Item_sum_xor, Item_func_group_concat, and Item_sum_unique_users.
Referenced by print().
Here is the caller graph for this function:

| Item * Item_sum::get_tmp_table_item | ( | THD * | thd | ) | [virtual] |
Reimplemented from Item.
Definition at line 334 of file item_sum.cc.
References arg_count, args, Item::copy_or_same(), Item::FIELD_ITEM, and Item_result_field::result_field.
00335 { 00336 Item_sum* sum_item= (Item_sum *) copy_or_same(thd); 00337 if (sum_item && sum_item->result_field) // If not a const sum func 00338 { 00339 Field *result_field_tmp= sum_item->result_field; 00340 for (uint i=0 ; i < sum_item->arg_count ; i++) 00341 { 00342 Item *arg= sum_item->args[i]; 00343 if (!arg->const_item()) 00344 { 00345 if (arg->type() == Item::FIELD_ITEM) 00346 ((Item_field*) arg)->field= result_field_tmp++; 00347 else 00348 sum_item->args[i]= new Item_field(result_field_tmp++); 00349 } 00350 } 00351 } 00352 return sum_item; 00353 }
Here is the call graph for this function:

| bool Item_sum::init_sum_func_check | ( | THD * | thd | ) |
Definition at line 52 of file item_sum.cc.
References aggr_level, ER, ER_INVALID_GROUP_FUNC_USE, FALSE, in_sum_func, max_arg_level, max_sum_func_level, my_message(), MYF, nest_level, ref_by, and TRUE.
Referenced by Item_func_group_concat::fix_fields(), Item_sum_hybrid::fix_fields(), and Item_sum_num::fix_fields().
00053 { 00054 if (!thd->lex->allow_sum_func) 00055 { 00056 my_message(ER_INVALID_GROUP_FUNC_USE, ER(ER_INVALID_GROUP_FUNC_USE), 00057 MYF(0)); 00058 return TRUE; 00059 } 00060 /* Set a reference to the nesting set function if there is any */ 00061 in_sum_func= thd->lex->in_sum_func; 00062 /* Save a pointer to object to be used in items for nested set functions */ 00063 thd->lex->in_sum_func= this; 00064 nest_level= thd->lex->current_select->nest_level; 00065 ref_by= 0; 00066 aggr_level= -1; 00067 max_arg_level= -1; 00068 max_sum_func_level= -1; 00069 return FALSE; 00070 }
Here is the call graph for this function:

Here is the caller graph for this function:

| bool Item_sum::is_null | ( | ) | [inline, virtual] |
Reimplemented from Item.
Definition at line 304 of file item_sum.h.
References Item::null_value.
00304 { return null_value; }
| virtual bool Item_sum::keep_field_type | ( | void | ) | const [inline, virtual] |
Reimplemented in Item_sum_hybrid.
Definition at line 282 of file item_sum.h.
Referenced by Item_type_holder::get_real_type(), and make_field().
Here is the caller graph for this function:

| void Item_sum::make_field | ( | Send_field * | field | ) | [virtual] |
Reimplemented from Item.
Definition at line 298 of file item_sum.cc.
References args, Item::FIELD_ITEM, Item::field_type(), Item::init_make_field(), keep_field_type(), Item::maybe_null, Item::name, NOT_NULL_FLAG, and type().
00299 { 00300 if (args[0]->type() == Item::FIELD_ITEM && keep_field_type()) 00301 { 00302 ((Item_field*) args[0])->field->make_field(tmp_field); 00303 tmp_field->db_name=(char*)""; 00304 tmp_field->org_table_name=tmp_field->table_name=(char*)""; 00305 tmp_field->org_col_name=tmp_field->col_name=name; 00306 if (maybe_null) 00307 tmp_field->flags&= ~NOT_NULL_FLAG; 00308 } 00309 else 00310 init_make_field(tmp_field, field_type()); 00311 }
Here is the call graph for this function:

| virtual void Item_sum::make_unique | ( | ) | [inline, virtual] |
Reimplemented in Item_sum_count_distinct, and Item_func_group_concat.
Definition at line 311 of file item_sum.h.
| void Item_sum::mark_as_sum_func | ( | ) |
Definition at line 291 of file item_sum.cc.
References current_thd, and Item::with_sum_func.
Referenced by Item_sum().
00292 { 00293 current_thd->lex->current_select->with_sum_func= 1; 00294 with_sum_func= 1; 00295 }
Here is the caller graph for this function:

| void Item_sum::no_rows_in_result | ( | ) | [inline, virtual] |
Reimplemented from Item.
Reimplemented in Item_sum_sum, Item_sum_distinct, Item_sum_count, Item_sum_count_distinct, Item_sum_avg, Item_sum_variance, Item_sum_hybrid, and Item_func_group_concat.
Definition at line 309 of file item_sum.h.
References reset().
00309 { reset(); }
Here is the call graph for this function:

| void Item_sum::print | ( | String * | str | ) | [virtual] |
Reimplemented from Item.
Reimplemented in Item_func_group_concat, and Item_sum_unique_users.
Definition at line 314 of file item_sum.cc.
References String::append(), arg_count, args, func_name(), and Item::print().
Referenced by change_to_use_tmp_fields().
00315 { 00316 str->append(func_name()); 00317 for (uint i=0 ; i < arg_count ; i++) 00318 { 00319 if (i) 00320 str->append(','); 00321 args[i]->print(str); 00322 } 00323 str->append(')'); 00324 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 211 of file item_sum.cc.
References aggr_level, FALSE, max_arg_level, next, NULL, and ref_by.
Referenced by check_sum_func().
00212 { 00213 SELECT_LEX *sl; 00214 SELECT_LEX *aggr_sl= NULL; 00215 nesting_map allow_sum_func= thd->lex->allow_sum_func; 00216 for (sl= thd->lex->current_select->master_unit()->outer_select() ; 00217 sl && sl->nest_level > max_arg_level; 00218 sl= sl->master_unit()->outer_select() ) 00219 { 00220 if (aggr_level < 0 && (allow_sum_func & (1 << sl->nest_level))) 00221 { 00222 /* Found the most nested subquery where the function can be aggregated */ 00223 aggr_level= sl->nest_level; 00224 aggr_sl= sl; 00225 } 00226 } 00227 if (sl && (allow_sum_func & (1 << sl->nest_level))) 00228 { 00229 /* 00230 We reached the subquery of level max_arg_level and checked 00231 that the function can be aggregated here. 00232 The set function will be aggregated in this subquery. 00233 */ 00234 aggr_level= sl->nest_level; 00235 aggr_sl= sl; 00236 } 00237 if (aggr_level >= 0) 00238 { 00239 ref_by= ref; 00240 /* Add the object to the list of registered objects assigned to aggr_sl */ 00241 if (!aggr_sl->inner_sum_func_list) 00242 next= this; 00243 else 00244 { 00245 next= aggr_sl->inner_sum_func_list->next; 00246 aggr_sl->inner_sum_func_list->next= this; 00247 } 00248 aggr_sl->inner_sum_func_list= this; 00249 00250 } 00251 return FALSE; 00252 }
Here is the caller graph for this function:

| bool Item_sum::reset | ( | void | ) | [inline] |
Definition at line 263 of file item_sum.h.
References add(), and clear().
Referenced by no_rows_in_result(), Item_sum_bit::reset_field(), QUICK_GROUP_MIN_MAX_SELECT::update_max_result(), and QUICK_GROUP_MIN_MAX_SELECT::update_min_result().
Here is the call graph for this function:

Here is the caller graph for this function:

| virtual void Item_sum::reset_field | ( | ) | [pure virtual] |
Reimplemented in Item_sum_avg, Item_sum_variance, and Item_sum_std.
Definition at line 300 of file item_sum.h.
00301 { return new Item_field(field); }
| virtual bool Item_sum::setup | ( | THD * | thd | ) | [inline, virtual] |
Reimplemented in Item_sum_distinct, Item_sum_count_distinct, and Item_func_group_concat.
Definition at line 310 of file item_sum.h.
| virtual enum Sumfunctype Item_sum::sum_func | ( | ) | const [pure virtual] |
Implemented in Item_sum_sum, Item_sum_distinct, Item_sum_sum_distinct, Item_sum_avg_distinct, Item_sum_count, Item_sum_count_distinct, Item_sum_avg, Item_sum_variance, Item_sum_std, Item_sum_min, Item_sum_max, Item_sum_bit, Item_sum_udf_float, Item_sum_udf_int, Item_sum_udf_decimal, Item_sum_udf_str, Item_func_group_concat, and Item_sum_unique_users.
Referenced by get_best_group_min_max(), and QUICK_GROUP_MIN_MAX_SELECT::init().
Here is the caller graph for this function:

| enum Type Item_sum::type | ( | ) | const [inline, virtual] |
Implements Item.
Definition at line 261 of file item_sum.h.
References Item::SUM_FUNC_ITEM.
Referenced by Item_sum_hybrid::create_tmp_field(), make_field(), and Item_sum_count_distinct::setup().
00261 { return SUM_FUNC_ITEM; }
Here is the caller graph for this function:

| virtual void Item_sum::update_field | ( | ) | [pure virtual] |
| void Item_sum::update_used_tables | ( | ) | [inline, virtual] |
| table_map Item_sum::used_tables | ( | ) | const [inline, virtual] |
Reimplemented from Item_result_field.
Reimplemented in Item_sum_count, and Item_sum_hybrid.
Definition at line 302 of file item_sum.h.
00302 { return ~(table_map) 0; } /* Not used */
| bool Item_sum::walk | ( | Item_processor | processor, | |
| bool | walk_subquery, | |||
| byte * | argument | |||
| ) | [virtual] |
Reimplemented from Item.
Definition at line 356 of file item_sum.cc.
References arg_count, and args.
00358 { 00359 if (arg_count) 00360 { 00361 Item **arg,**arg_end; 00362 for (arg= args, arg_end= args+arg_count; arg != arg_end; arg++) 00363 { 00364 if ((*arg)->walk(processor, walk_subquery, argument)) 00365 return 1; 00366 } 00367 } 00368 return (this->*processor)(argument); 00369 }
Definition at line 236 of file item_sum.h.
Referenced by check_sum_func(), init_sum_func_check(), and register_sum_func().
Definition at line 233 of file item_sum.h.
Referenced by Item_sum_num::fix_fields(), fix_num_length_and_dec(), get_tmp_table_item(), Item_sum(), print(), Item_sum_count_distinct::setup(), and walk().
Definition at line 230 of file item_sum.h.
Referenced by Item_func_group_concat::add(), Item_sum_and::add(), Item_sum_xor::add(), Item_sum_or::add(), Item_sum_max::add(), Item_sum_min::add(), Item_sum_variance::add(), Item_sum_avg::add(), Item_sum_count::add(), Item_sum_distinct::add(), Item_sum_sum::add(), Item_sum_hybrid::create_tmp_field(), dump_leaf_key(), Item_func_group_concat::fix_fields(), Item_sum_hybrid::fix_fields(), Item_sum_num::fix_fields(), Item_sum_variance::fix_length_and_dec(), Item_sum_avg::fix_length_and_dec(), Item_sum_distinct::fix_length_and_dec(), Item_sum_sum::fix_length_and_dec(), fix_num_length_and_dec(), get_best_group_min_max(), Item_type_holder::get_real_type(), get_tmp_table_item(), group_concat_key_cmp_with_distinct(), Item_func_group_concat::Item_func_group_concat(), Item_sum(), make_field(), Item_sum_hybrid::min_max_update_decimal_field(), Item_sum_hybrid::min_max_update_int_field(), Item_sum_hybrid::min_max_update_real_field(), Item_sum_hybrid::min_max_update_str_field(), Item_func_group_concat::print(), print(), Item_sum_avg::reset_field(), Item_sum_count::reset_field(), Item_sum_sum::reset_field(), Item_sum_hybrid::reset_field(), Item_sum_num::reset_field(), Item_sum_variance::reset_field(), Item_func_group_concat::setup(), Item_sum_count_distinct::setup(), Item_sum_distinct::setup(), Item_sum_avg::update_field(), Item_sum_count::update_field(), Item_sum_sum::update_field(), Item_sum_variance::update_field(), and walk().
Definition at line 234 of file item_sum.h.
Referenced by check_sum_func(), and init_sum_func_check().
Definition at line 237 of file item_sum.h.
Referenced by check_sum_func(), init_sum_func_check(), and register_sum_func().
Definition at line 238 of file item_sum.h.
Referenced by check_sum_func(), and init_sum_func_check().
Definition at line 235 of file item_sum.h.
Referenced by check_sum_func(), and init_sum_func_check().
Reimplemented from Item.
Definition at line 232 of file item_sum.h.
Referenced by JOIN::prepare(), and register_sum_func().
Definition at line 239 of file item_sum.h.
Referenced by Item_func_group_concat::Item_func_group_concat(), Item_sum_count_distinct::Item_sum_count_distinct(), Item_sum_distinct::Item_sum_distinct(), and Item_sum_distinct::setup().
Definition at line 231 of file item_sum.h.
Referenced by init_sum_func_check(), JOIN::prepare(), and register_sum_func().
| Item * Item_sum::tmp_args[2] |
1.4.7

