From 00d13069ddebdfd95b79173abdcc8feacfb96f0e Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Tue, 28 Jul 2020 18:18:43 +0300 Subject: [PATCH] Removed Item::common_flags and replaced it with bit fields This is to make the Item instances smaller --- sql/item.cc | 20 ++++++++++++-------- sql/item.h | 23 ++++++++--------------- sql/item_create.cc | 14 +++++++------- sql/sql_base.cc | 4 ++-- sql/sql_cte.cc | 4 ++-- sql/sql_select.cc | 7 +++---- sql/sql_view.cc | 10 +++++----- sql/sql_yacc.yy | 4 ++-- 8 files changed, 41 insertions(+), 45 deletions(-) diff --git a/sql/item.cc b/sql/item.cc index 5e0f2f72440..e7ca2cc1d8b 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -413,11 +413,12 @@ Item::Item(THD *thd): name(null_clex_str), orig_name(0), is_expensive_cache(-1) { DBUG_ASSERT(thd); - common_flags= IS_AUTO_GENERATED_NAME; - marker= 0; maybe_null= with_window_func= with_field= in_rollup= with_param= 0; + is_in_with_cycle= 0; fixed= 1; // Simple Item's doesn't have to be fixed + is_autogenerated_name= 1; null_value= 0; + marker= 0; /* Initially this item is not attached to any JOIN_TAB. */ join_tab_idx= MAX_TABLES; @@ -447,10 +448,12 @@ Item::Item(): name(null_clex_str), orig_name(0), is_expensive_cache(-1) { DBUG_ASSERT(my_progname == NULL); // before main() - common_flags= IS_AUTO_GENERATED_NAME; - marker= 0; maybe_null= with_window_func= with_field= in_rollup= with_param= 0; - fixed= 1; + is_in_with_cycle= 0; + fixed= 1; // Simple Item's doesn't have to be fixed + is_autogenerated_name= 1; + null_value= 0; + marker= 0; join_tab_idx= MAX_TABLES; } @@ -481,10 +484,11 @@ Item::Item(THD *thd, Item *item): with_param(item->with_param), with_window_func(item->with_window_func), with_field(item->with_field), + is_autogenerated_name(item->is_autogenerated_name), + is_in_with_cycle(item->is_in_with_cycle), marker(item->marker), null_value(item->null_value), is_expensive_cache(-1), - common_flags(item->common_flags), join_tab_idx(item->join_tab_idx) { next= thd->free_list; // Put in free list @@ -1164,7 +1168,7 @@ void Item::set_name(THD *thd, const char *str, size_t length, CHARSET_INFO *cs) str++; } } - if (str != str_start && !is_autogenerated_name()) + if (str != str_start && !is_autogenerated_name) { char buff[SAFE_NAME_LEN]; @@ -5227,7 +5231,7 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list) /* SELECT list element with explicit alias */ if ((*(cur_group->item))->name.str && !table_name.str && - !(*(cur_group->item))->is_autogenerated_name() && + !(*(cur_group->item))->is_autogenerated_name && !lex_string_cmp(system_charset_info, &(*(cur_group->item))->name, &field_name)) { diff --git a/sql/item.h b/sql/item.h index 1161cb67f2a..bb34ea316ea 100644 --- a/sql/item.h +++ b/sql/item.h @@ -633,13 +633,6 @@ class st_select_lex_unit; class Item_func_not; class Item_splocal; -/* Item::common_flags */ -/* Indicates that name of this Item autogenerated or set by user */ -#define IS_AUTO_GENERATED_NAME 1 -/* Indicates that this item is in CYCLE clause of WITH */ -#define IS_IN_WITH_CYCLE 2 - - /** String_copier that sends Item specific warnings. */ @@ -931,7 +924,11 @@ public: with_window_func:1, /* True if item contains a window func */ with_field:1, /* True if any item except Item_sum contains a field. Set during parsing. */ - fixed:1; /* If item was fixed with fix_fields */ + fixed:1, /* If item was fixed with fix_fields */ + /* Indicates that name of this Item autogenerated or set by user */ + is_autogenerated_name:1, + /* Indicates that this item is in CYCLE clause of WITH */ + is_in_with_cycle:1; int16 marker; @@ -943,7 +940,6 @@ public: bool null_value; /* Cache of the result of is_expensive(). */ int8 is_expensive_cache; - uint8 common_flags; /* To be integrated into above flags soon... */ /** The index in the JOIN::join_tab array of the JOIN_TAB this Item is attached to. Items are attached (or 'pushed') to JOIN_TABs during optimization by the @@ -955,8 +951,6 @@ public: */ uint8 join_tab_idx; - bool is_autogenerated_name() - { return (common_flags & IS_AUTO_GENERATED_NAME); } // alloc & destruct is done as start of select on THD::mem_root Item(THD *thd); /* @@ -992,9 +986,7 @@ public: void share_name_with(const Item *item) { name= item->name; - common_flags= static_cast - ((common_flags & ~IS_AUTO_GENERATED_NAME) | - (item->common_flags & IS_AUTO_GENERATED_NAME)); + is_autogenerated_name= item->is_autogenerated_name; } virtual void cleanup(); virtual void make_send_field(THD *thd, Send_field *field); @@ -7432,7 +7424,8 @@ public: name= item->name; Type_std_attributes::set(*attr); maybe_null= maybe_null_arg; - common_flags= item->common_flags; + is_autogenerated_name= item->is_autogenerated_name; + is_in_with_cycle= item->is_in_with_cycle; } const Type_handler *type_handler() const override diff --git a/sql/item_create.cc b/sql/item_create.cc index 3a08add73b7..264d11332d3 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -2387,7 +2387,7 @@ static bool has_named_parameters(List *params) List_iterator it(*params); while ((param= it++)) { - if (! param->is_autogenerated_name()) + if (! param->is_autogenerated_name) return true; } } @@ -2633,7 +2633,7 @@ Create_func_arg1::create_func(THD *thd, LEX_CSTRING *name, List *item_list Item *param_1= item_list->pop(); - if (unlikely(! param_1->is_autogenerated_name())) + if (unlikely(! param_1->is_autogenerated_name)) { my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name->str); return NULL; @@ -2660,8 +2660,8 @@ Create_func_arg2::create_func(THD *thd, LEX_CSTRING *name, List *item_list Item *param_1= item_list->pop(); Item *param_2= item_list->pop(); - if (unlikely(!param_1->is_autogenerated_name() || - !param_2->is_autogenerated_name())) + if (unlikely(!param_1->is_autogenerated_name || + !param_2->is_autogenerated_name)) { my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name->str); return NULL; @@ -2689,9 +2689,9 @@ Create_func_arg3::create_func(THD *thd, LEX_CSTRING *name, List *item_list Item *param_2= item_list->pop(); Item *param_3= item_list->pop(); - if (unlikely(!param_1->is_autogenerated_name() || - !param_2->is_autogenerated_name() || - !param_3->is_autogenerated_name())) + if (unlikely(!param_1->is_autogenerated_name || + !param_2->is_autogenerated_name || + !param_3->is_autogenerated_name)) { my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name->str); return NULL; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 583903509a6..0417244a01c 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -5849,7 +5849,7 @@ find_field_in_view(THD *thd, TABLE_LIST *table_list, replace. If the item was aliased by the user, set the alias to the replacing item. */ - if (*ref && !(*ref)->is_autogenerated_name()) + if (*ref && !(*ref)->is_autogenerated_name) item->set_name(thd, (*ref)->name); if (register_tree_change) thd->change_item_tree(ref, item); @@ -5940,7 +5940,7 @@ find_field_in_natural_join(THD *thd, TABLE_LIST *table_ref, const char *name, si replace. If the item was aliased by the user, set the alias to the replacing item. */ - if (*ref && !(*ref)->is_autogenerated_name()) + if (*ref && !(*ref)->is_autogenerated_name) item->set_name(thd, (*ref)->name); if (register_tree_change && arena) thd->restore_active_arena(arena, &backup); diff --git a/sql/sql_cte.cc b/sql/sql_cte.cc index 815a0f43c17..f53590d6625 100644 --- a/sql/sql_cte.cc +++ b/sql/sql_cte.cc @@ -993,7 +993,7 @@ With_element::process_columns_of_derived_unit(THD *thd, while ((item= it++, name= nm++)) { item->set_name(thd, *name); - item->common_flags&= ~IS_AUTO_GENERATED_NAME; + item->is_autogenerated_name= 0; } if (arena) @@ -1036,7 +1036,7 @@ With_element::process_columns_of_derived_unit(THD *thd, my_error(ER_BAD_FIELD_ERROR, MYF(0), name->str, "CYCLE clause"); return true; } - item->common_flags|= IS_IN_WITH_CYCLE; + item->is_in_with_cycle= 1; } } unit->columns_are_renamed= true; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 14351268af6..0c30bdaa3bd 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -18644,7 +18644,7 @@ bool Create_tmp_table::add_fields(THD *thd, Item *item; Field **tmp_from_field= m_from_field; while (!m_with_cycle && (item= li++)) - if (item->common_flags & IS_IN_WITH_CYCLE) + if (item->is_in_with_cycle) { m_with_cycle= true; /* @@ -18662,8 +18662,7 @@ bool Create_tmp_table::add_fields(THD *thd, uint uneven_delta; current_counter= (((param->hidden_field_count < (fieldnr + 1)) && distinct_record_structure && - (!m_with_cycle || - (item->common_flags & IS_IN_WITH_CYCLE)))? + (!m_with_cycle || item->is_in_with_cycle)) ? distinct : other); Item::Type type= item->type(); @@ -27993,7 +27992,7 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type) else str->append(','); - if (is_subquery_function() && item->is_autogenerated_name()) + if (is_subquery_function() && item->is_autogenerated_name) { /* Do not print auto-generated aliases in subqueries. It has no purpose diff --git a/sql/sql_view.cc b/sql/sql_view.cc index c8f865fe475..71e2f0351d2 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -137,7 +137,7 @@ bool check_duplicate_names(THD *thd, List &item_list, bool gen_unique_view Item *check; /* treat underlying fields like set by user names */ if (item->real_item()->type() == Item::FIELD_ITEM) - item->common_flags&= ~IS_AUTO_GENERATED_NAME; + item->is_autogenerated_name= 0; itc.rewind(); while ((check= itc++) && check != item) { @@ -145,9 +145,9 @@ bool check_duplicate_names(THD *thd, List &item_list, bool gen_unique_view { if (!gen_unique_view_name) goto err; - if (item->is_autogenerated_name()) + if (item->is_autogenerated_name) make_unique_view_field_name(thd, item, item_list, item); - else if (check->is_autogenerated_name()) + else if (check->is_autogenerated_name) make_unique_view_field_name(thd, check, item_list, item); else goto err; @@ -179,7 +179,7 @@ void make_valid_column_names(THD *thd, List &item_list) for (uint column_no= 1; (item= it++); column_no++) { - if (!item->is_autogenerated_name() || !check_column_name(item->name.str)) + if (!item->is_autogenerated_name || !check_column_name(item->name.str)) continue; name_len= my_snprintf(buff, NAME_LEN, "Name_exp_%u", column_no); item->orig_name= item->name.str; @@ -566,7 +566,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, while ((item= it++, name= nm++)) { item->set_name(thd, *name); - item->common_flags&= ~IS_AUTO_GENERATED_NAME; + item->is_autogenerated_name= 0; } } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index d3d99ef9852..c0668959757 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -9223,7 +9223,7 @@ select_item: if (unlikely(Lex->sql_command == SQLCOM_CREATE_VIEW && check_column_name($4.str))) my_yyabort_error((ER_WRONG_COLUMN_NAME, MYF(0), $4.str)); - $2->common_flags&= ~IS_AUTO_GENERATED_NAME; + $2->is_autogenerated_name= 0; $2->set_name(thd, $4); } else if (!$2->name.str || $2->name.str == item_empty_name) @@ -10801,7 +10801,7 @@ udf_expr: */ if ($4.str) { - $2->common_flags&= ~IS_AUTO_GENERATED_NAME; + $2->is_autogenerated_name= 0; $2->set_name(thd, $4); } /*