Skip to content

Commit 00d1306

Browse files
montywivuvova
authored andcommitted
Removed Item::common_flags and replaced it with bit fields
This is to make the Item instances smaller
1 parent cd1782d commit 00d1306

File tree

8 files changed

+41
-45
lines changed

8 files changed

+41
-45
lines changed

sql/item.cc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,12 @@ Item::Item(THD *thd):
413413
name(null_clex_str), orig_name(0), is_expensive_cache(-1)
414414
{
415415
DBUG_ASSERT(thd);
416-
common_flags= IS_AUTO_GENERATED_NAME;
417-
marker= 0;
418416
maybe_null= with_window_func= with_field= in_rollup= with_param= 0;
417+
is_in_with_cycle= 0;
419418
fixed= 1; // Simple Item's doesn't have to be fixed
419+
is_autogenerated_name= 1;
420420
null_value= 0;
421+
marker= 0;
421422

422423
/* Initially this item is not attached to any JOIN_TAB. */
423424
join_tab_idx= MAX_TABLES;
@@ -447,10 +448,12 @@ Item::Item():
447448
name(null_clex_str), orig_name(0), is_expensive_cache(-1)
448449
{
449450
DBUG_ASSERT(my_progname == NULL); // before main()
450-
common_flags= IS_AUTO_GENERATED_NAME;
451-
marker= 0;
452451
maybe_null= with_window_func= with_field= in_rollup= with_param= 0;
453-
fixed= 1;
452+
is_in_with_cycle= 0;
453+
fixed= 1; // Simple Item's doesn't have to be fixed
454+
is_autogenerated_name= 1;
455+
null_value= 0;
456+
marker= 0;
454457
join_tab_idx= MAX_TABLES;
455458
}
456459

@@ -481,10 +484,11 @@ Item::Item(THD *thd, Item *item):
481484
with_param(item->with_param),
482485
with_window_func(item->with_window_func),
483486
with_field(item->with_field),
487+
is_autogenerated_name(item->is_autogenerated_name),
488+
is_in_with_cycle(item->is_in_with_cycle),
484489
marker(item->marker),
485490
null_value(item->null_value),
486491
is_expensive_cache(-1),
487-
common_flags(item->common_flags),
488492
join_tab_idx(item->join_tab_idx)
489493
{
490494
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)
11641168
str++;
11651169
}
11661170
}
1167-
if (str != str_start && !is_autogenerated_name())
1171+
if (str != str_start && !is_autogenerated_name)
11681172
{
11691173
char buff[SAFE_NAME_LEN];
11701174

@@ -5227,7 +5231,7 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
52275231

52285232
/* SELECT list element with explicit alias */
52295233
if ((*(cur_group->item))->name.str && !table_name.str &&
5230-
!(*(cur_group->item))->is_autogenerated_name() &&
5234+
!(*(cur_group->item))->is_autogenerated_name &&
52315235
!lex_string_cmp(system_charset_info,
52325236
&(*(cur_group->item))->name, &field_name))
52335237
{

sql/item.h

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -633,13 +633,6 @@ class st_select_lex_unit;
633633
class Item_func_not;
634634
class Item_splocal;
635635

636-
/* Item::common_flags */
637-
/* Indicates that name of this Item autogenerated or set by user */
638-
#define IS_AUTO_GENERATED_NAME 1
639-
/* Indicates that this item is in CYCLE clause of WITH */
640-
#define IS_IN_WITH_CYCLE 2
641-
642-
643636
/**
644637
String_copier that sends Item specific warnings.
645638
*/
@@ -931,7 +924,11 @@ class Item :public Value_source,
931924
with_window_func:1, /* True if item contains a window func */
932925
with_field:1, /* True if any item except Item_sum contains a field.
933926
Set during parsing. */
934-
fixed:1; /* If item was fixed with fix_fields */
927+
fixed:1, /* If item was fixed with fix_fields */
928+
/* Indicates that name of this Item autogenerated or set by user */
929+
is_autogenerated_name:1,
930+
/* Indicates that this item is in CYCLE clause of WITH */
931+
is_in_with_cycle:1;
935932

936933
int16 marker;
937934

@@ -943,7 +940,6 @@ class Item :public Value_source,
943940
bool null_value;
944941
/* Cache of the result of is_expensive(). */
945942
int8 is_expensive_cache;
946-
uint8 common_flags; /* To be integrated into above flags soon... */
947943
/**
948944
The index in the JOIN::join_tab array of the JOIN_TAB this Item is attached
949945
to. Items are attached (or 'pushed') to JOIN_TABs during optimization by the
@@ -955,8 +951,6 @@ class Item :public Value_source,
955951
*/
956952
uint8 join_tab_idx;
957953

958-
bool is_autogenerated_name()
959-
{ return (common_flags & IS_AUTO_GENERATED_NAME); }
960954
// alloc & destruct is done as start of select on THD::mem_root
961955
Item(THD *thd);
962956
/*
@@ -992,9 +986,7 @@ class Item :public Value_source,
992986
void share_name_with(const Item *item)
993987
{
994988
name= item->name;
995-
common_flags= static_cast<uint8>
996-
((common_flags & ~IS_AUTO_GENERATED_NAME) |
997-
(item->common_flags & IS_AUTO_GENERATED_NAME));
989+
is_autogenerated_name= item->is_autogenerated_name;
998990
}
999991
virtual void cleanup();
1000992
virtual void make_send_field(THD *thd, Send_field *field);
@@ -7432,7 +7424,8 @@ class Item_type_holder: public Item,
74327424
name= item->name;
74337425
Type_std_attributes::set(*attr);
74347426
maybe_null= maybe_null_arg;
7435-
common_flags= item->common_flags;
7427+
is_autogenerated_name= item->is_autogenerated_name;
7428+
is_in_with_cycle= item->is_in_with_cycle;
74367429
}
74377430

74387431
const Type_handler *type_handler() const override

sql/item_create.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ static bool has_named_parameters(List<Item> *params)
23872387
List_iterator<Item> it(*params);
23882388
while ((param= it++))
23892389
{
2390-
if (! param->is_autogenerated_name())
2390+
if (! param->is_autogenerated_name)
23912391
return true;
23922392
}
23932393
}
@@ -2633,7 +2633,7 @@ Create_func_arg1::create_func(THD *thd, LEX_CSTRING *name, List<Item> *item_list
26332633

26342634
Item *param_1= item_list->pop();
26352635

2636-
if (unlikely(! param_1->is_autogenerated_name()))
2636+
if (unlikely(! param_1->is_autogenerated_name))
26372637
{
26382638
my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name->str);
26392639
return NULL;
@@ -2660,8 +2660,8 @@ Create_func_arg2::create_func(THD *thd, LEX_CSTRING *name, List<Item> *item_list
26602660
Item *param_1= item_list->pop();
26612661
Item *param_2= item_list->pop();
26622662

2663-
if (unlikely(!param_1->is_autogenerated_name() ||
2664-
!param_2->is_autogenerated_name()))
2663+
if (unlikely(!param_1->is_autogenerated_name ||
2664+
!param_2->is_autogenerated_name))
26652665
{
26662666
my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name->str);
26672667
return NULL;
@@ -2689,9 +2689,9 @@ Create_func_arg3::create_func(THD *thd, LEX_CSTRING *name, List<Item> *item_list
26892689
Item *param_2= item_list->pop();
26902690
Item *param_3= item_list->pop();
26912691

2692-
if (unlikely(!param_1->is_autogenerated_name() ||
2693-
!param_2->is_autogenerated_name() ||
2694-
!param_3->is_autogenerated_name()))
2692+
if (unlikely(!param_1->is_autogenerated_name ||
2693+
!param_2->is_autogenerated_name ||
2694+
!param_3->is_autogenerated_name))
26952695
{
26962696
my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name->str);
26972697
return NULL;

sql/sql_base.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5849,7 +5849,7 @@ find_field_in_view(THD *thd, TABLE_LIST *table_list,
58495849
replace. If the item was aliased by the user, set the alias to
58505850
the replacing item.
58515851
*/
5852-
if (*ref && !(*ref)->is_autogenerated_name())
5852+
if (*ref && !(*ref)->is_autogenerated_name)
58535853
item->set_name(thd, (*ref)->name);
58545854
if (register_tree_change)
58555855
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
59405940
replace. If the item was aliased by the user, set the alias to
59415941
the replacing item.
59425942
*/
5943-
if (*ref && !(*ref)->is_autogenerated_name())
5943+
if (*ref && !(*ref)->is_autogenerated_name)
59445944
item->set_name(thd, (*ref)->name);
59455945
if (register_tree_change && arena)
59465946
thd->restore_active_arena(arena, &backup);

sql/sql_cte.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ With_element::process_columns_of_derived_unit(THD *thd,
993993
while ((item= it++, name= nm++))
994994
{
995995
item->set_name(thd, *name);
996-
item->common_flags&= ~IS_AUTO_GENERATED_NAME;
996+
item->is_autogenerated_name= 0;
997997
}
998998

999999
if (arena)
@@ -1036,7 +1036,7 @@ With_element::process_columns_of_derived_unit(THD *thd,
10361036
my_error(ER_BAD_FIELD_ERROR, MYF(0), name->str, "CYCLE clause");
10371037
return true;
10381038
}
1039-
item->common_flags|= IS_IN_WITH_CYCLE;
1039+
item->is_in_with_cycle= 1;
10401040
}
10411041
}
10421042
unit->columns_are_renamed= true;

sql/sql_select.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18644,7 +18644,7 @@ bool Create_tmp_table::add_fields(THD *thd,
1864418644
Item *item;
1864518645
Field **tmp_from_field= m_from_field;
1864618646
while (!m_with_cycle && (item= li++))
18647-
if (item->common_flags & IS_IN_WITH_CYCLE)
18647+
if (item->is_in_with_cycle)
1864818648
{
1864918649
m_with_cycle= true;
1865018650
/*
@@ -18662,8 +18662,7 @@ bool Create_tmp_table::add_fields(THD *thd,
1866218662
uint uneven_delta;
1866318663
current_counter= (((param->hidden_field_count < (fieldnr + 1)) &&
1866418664
distinct_record_structure &&
18665-
(!m_with_cycle ||
18666-
(item->common_flags & IS_IN_WITH_CYCLE)))?
18665+
(!m_with_cycle || item->is_in_with_cycle)) ?
1866718666
distinct :
1866818667
other);
1866918668
Item::Type type= item->type();
@@ -27993,7 +27992,7 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
2799327992
else
2799427993
str->append(',');
2799527994

27996-
if (is_subquery_function() && item->is_autogenerated_name())
27995+
if (is_subquery_function() && item->is_autogenerated_name)
2799727996
{
2799827997
/*
2799927998
Do not print auto-generated aliases in subqueries. It has no purpose

sql/sql_view.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,17 @@ bool check_duplicate_names(THD *thd, List<Item> &item_list, bool gen_unique_view
137137
Item *check;
138138
/* treat underlying fields like set by user names */
139139
if (item->real_item()->type() == Item::FIELD_ITEM)
140-
item->common_flags&= ~IS_AUTO_GENERATED_NAME;
140+
item->is_autogenerated_name= 0;
141141
itc.rewind();
142142
while ((check= itc++) && check != item)
143143
{
144144
if (lex_string_cmp(system_charset_info, &item->name, &check->name) == 0)
145145
{
146146
if (!gen_unique_view_name)
147147
goto err;
148-
if (item->is_autogenerated_name())
148+
if (item->is_autogenerated_name)
149149
make_unique_view_field_name(thd, item, item_list, item);
150-
else if (check->is_autogenerated_name())
150+
else if (check->is_autogenerated_name)
151151
make_unique_view_field_name(thd, check, item_list, item);
152152
else
153153
goto err;
@@ -179,7 +179,7 @@ void make_valid_column_names(THD *thd, List<Item> &item_list)
179179

180180
for (uint column_no= 1; (item= it++); column_no++)
181181
{
182-
if (!item->is_autogenerated_name() || !check_column_name(item->name.str))
182+
if (!item->is_autogenerated_name || !check_column_name(item->name.str))
183183
continue;
184184
name_len= my_snprintf(buff, NAME_LEN, "Name_exp_%u", column_no);
185185
item->orig_name= item->name.str;
@@ -566,7 +566,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
566566
while ((item= it++, name= nm++))
567567
{
568568
item->set_name(thd, *name);
569-
item->common_flags&= ~IS_AUTO_GENERATED_NAME;
569+
item->is_autogenerated_name= 0;
570570
}
571571
}
572572

sql/sql_yacc.yy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9223,7 +9223,7 @@ select_item:
92239223
if (unlikely(Lex->sql_command == SQLCOM_CREATE_VIEW &&
92249224
check_column_name($4.str)))
92259225
my_yyabort_error((ER_WRONG_COLUMN_NAME, MYF(0), $4.str));
9226-
$2->common_flags&= ~IS_AUTO_GENERATED_NAME;
9226+
$2->is_autogenerated_name= 0;
92279227
$2->set_name(thd, $4);
92289228
}
92299229
else if (!$2->name.str || $2->name.str == item_empty_name)
@@ -10801,7 +10801,7 @@ udf_expr:
1080110801
*/
1080210802
if ($4.str)
1080310803
{
10804-
$2->common_flags&= ~IS_AUTO_GENERATED_NAME;
10804+
$2->is_autogenerated_name= 0;
1080510805
$2->set_name(thd, $4);
1080610806
}
1080710807
/*

0 commit comments

Comments
 (0)