@@ -302,7 +302,13 @@ class st_select_lex;
302302 We assume that the nesting level of subquries does not exceed 127.
303303 TODO: to catch queries where the limit is exceeded to make the
304304 code clean here.
305-
305+
306+ @note
307+ The implementation takes into account the used strategy:
308+ - Items resolved at optimization phase return 0 from Item_sum::used_tables().
309+ - Items that depend on the number of join output records, but not columns of
310+ any particular table (like COUNT(*)), returm 0 from Item_sum::used_tables(),
311+ but still return false from Item_sum::const_item().
306312*/
307313
308314class Item_sum :public Item_func_or_sum
@@ -368,32 +374,25 @@ class Item_sum :public Item_func_or_sum
368374 the current argument list can be altered by usage of temporary tables.
369375 */
370376 Item **orig_args, *tmp_orig_args[2 ];
371- table_map used_tables_cache;
372377
373- /*
374- TRUE <=> We've managed to calculate the value of this Item in
375- opt_sum_query(), hence it can be considered constant at all subsequent
376- steps.
377- */
378- bool forced_const;
379378 static ulonglong ram_limitation (THD *thd);
380379
381380public:
382381
383382 void mark_as_sum_func ();
384- Item_sum (THD *thd): Item_func_or_sum(thd), quick_group(1 ), forced_const( FALSE )
383+ Item_sum (THD *thd): Item_func_or_sum(thd), quick_group(1 )
385384 {
386385 mark_as_sum_func ();
387386 init_aggregator ();
388387 }
389388 Item_sum (THD *thd, Item *a): Item_func_or_sum(thd, a), quick_group(1 ),
390- orig_args (tmp_orig_args), forced_const( FALSE )
389+ orig_args (tmp_orig_args)
391390 {
392391 mark_as_sum_func ();
393392 init_aggregator ();
394393 }
395394 Item_sum (THD *thd, Item *a, Item *b): Item_func_or_sum(thd, a, b),
396- quick_group(1 ), orig_args(tmp_orig_args), forced_const( FALSE )
395+ quick_group(1 ), orig_args(tmp_orig_args)
397396 {
398397 mark_as_sum_func ();
399398 init_aggregator ();
@@ -433,16 +432,6 @@ class Item_sum :public Item_func_or_sum
433432 virtual void fix_length_and_dec () { maybe_null=1 ; null_value=1 ; }
434433 virtual Item *result_item (THD *thd, Field *field);
435434
436- /*
437- Return bitmap of tables that are needed to evaluate the item.
438-
439- The implementation takes into account the used strategy: items resolved
440- at optimization phase will report 0.
441- Items that depend on the number of join output records, but not columns
442- of any particular table (like COUNT(*)) will report 0 from used_tables(),
443- but will still return false from const_item().
444- */
445- table_map used_tables () const { return used_tables_cache; }
446435 void update_used_tables ();
447436 COND *build_equal_items (THD *thd, COND_EQUAL *inherited,
448437 bool link_item_fields,
@@ -458,12 +447,17 @@ class Item_sum :public Item_func_or_sum
458447 cond_equal_ref);
459448 }
460449 bool is_null () { return null_value; }
450+ /* *
451+ make_const()
452+ Called if we've managed to calculate the value of this Item in
453+ opt_sum_query(), hence it can be considered constant at all subsequent
454+ steps.
455+ */
461456 void make_const ()
462457 {
463458 used_tables_cache= 0 ;
464- forced_const= TRUE ;
459+ const_item_cache= true ;
465460 }
466- virtual bool const_item () const { return forced_const; }
467461 virtual bool const_during_execution () const { return false ; }
468462 virtual void print (String *str, enum_query_type query_type);
469463 void fix_num_length_and_dec ();
0 commit comments