Commit 53b43f30 authored by Monty's avatar Monty Committed by Sergei Golubchik

Added full_name_cstring()

This returns a LEX_CSTRING and allows one to avoid strlen() calls.
parent b6ff139a
...@@ -501,8 +501,7 @@ void Item::print_parenthesised(String *str, enum_query_type query_type, ...@@ -501,8 +501,7 @@ void Item::print_parenthesised(String *str, enum_query_type query_type,
void Item::print(String *str, enum_query_type query_type) void Item::print(String *str, enum_query_type query_type)
{ {
const char *name= full_name(); str->append(full_name_cstring());
str->append(name, strlen(name));
} }
...@@ -3146,32 +3145,37 @@ bool Item_field::switch_to_nullable_fields_processor(void *arg) ...@@ -3146,32 +3145,37 @@ bool Item_field::switch_to_nullable_fields_processor(void *arg)
return 0; return 0;
} }
const char *Item_ident::full_name() const LEX_CSTRING Item_ident::full_name_cstring() const
{ {
char *tmp; char *tmp;
size_t length;
if (!table_name.str || !field_name.str) if (!table_name.str || !field_name.str)
return field_name.str ? field_name.str : name.str ? name.str : "tmp_field"; {
if (field_name.str)
return field_name;
if (name.str)
return name;
return { STRING_WITH_LEN("tmp_field") };
}
if (db_name.str && db_name.str[0]) if (db_name.str && db_name.str[0])
{ {
THD *thd= current_thd; THD *thd= current_thd;
tmp=(char*) thd->alloc((uint) db_name.length+ (uint) table_name.length + tmp=(char*) thd->alloc((uint) db_name.length+ (uint) table_name.length +
(uint) field_name.length+3); (uint) field_name.length+3);
strxmov(tmp,db_name.str,".",table_name.str,".",field_name.str,NullS); length= (strxmov(tmp,db_name.str,".",table_name.str,".",field_name.str,
NullS) - tmp);
} }
else else
{ {
if (table_name.str[0]) if (!table_name.str[0])
{ return field_name;
THD *thd= current_thd;
tmp= (char*) thd->alloc((uint) table_name.length + THD *thd= current_thd;
field_name.length + 2); tmp= (char*) thd->alloc((uint) table_name.length +
strxmov(tmp, table_name.str, ".", field_name.str, NullS); field_name.length + 2);
} length= (strxmov(tmp, table_name.str, ".", field_name.str, NullS) - tmp);
else
return field_name.str;
} }
return tmp; return {tmp, length};
} }
void Item_ident::print(String *str, enum_query_type query_type) void Item_ident::print(String *str, enum_query_type query_type)
......
...@@ -1697,7 +1697,13 @@ class Item :public Value_source, ...@@ -1697,7 +1697,13 @@ class Item :public Value_source,
virtual Field *get_tmp_table_field() { return 0; } virtual Field *get_tmp_table_field() { return 0; }
virtual Field *create_field_for_create_select(MEM_ROOT *root, TABLE *table); virtual Field *create_field_for_create_select(MEM_ROOT *root, TABLE *table);
virtual const char *full_name() const { return name.str ? name.str : "???"; } inline const char *full_name() const { return full_name_cstring().str; }
virtual LEX_CSTRING full_name_cstring() const
{
if (name.str)
return name;
return { STRING_WITH_LEN("???") };
}
const char *field_name_or_null() const char *field_name_or_null()
{ return real_item()->type() == Item::FIELD_ITEM ? name.str : NULL; } { return real_item()->type() == Item::FIELD_ITEM ? name.str : NULL; }
const TABLE_SHARE *field_table_or_null(); const TABLE_SHARE *field_table_or_null();
...@@ -3439,7 +3445,7 @@ class Item_ident :public Item_result_field ...@@ -3439,7 +3445,7 @@ class Item_ident :public Item_result_field
const LEX_CSTRING &field_name_arg); const LEX_CSTRING &field_name_arg);
Item_ident(THD *thd, Item_ident *item); Item_ident(THD *thd, Item_ident *item);
Item_ident(THD *thd, TABLE_LIST *view_arg, const LEX_CSTRING &field_name_arg); Item_ident(THD *thd, TABLE_LIST *view_arg, const LEX_CSTRING &field_name_arg);
const char *full_name() const override; LEX_CSTRING full_name_cstring() const override;
void cleanup() override; void cleanup() override;
st_select_lex *get_depended_from() const; st_select_lex *get_depended_from() const;
bool remove_dependence_processor(void * arg) override; bool remove_dependence_processor(void * arg) override;
...@@ -5845,7 +5851,8 @@ class Item_cache_wrapper :public Item_result_field ...@@ -5845,7 +5851,8 @@ class Item_cache_wrapper :public Item_result_field
/* Following methods make this item transparent as much as possible */ /* Following methods make this item transparent as much as possible */
void print(String *str, enum_query_type query_type) override; void print(String *str, enum_query_type query_type) override;
const char *full_name() const override { return orig_item->full_name(); } LEX_CSTRING full_name_cstring() const override
{ return orig_item->full_name_cstring(); }
void make_send_field(THD *thd, Send_field *field) override void make_send_field(THD *thd, Send_field *field) override
{ orig_item->make_send_field(thd, field); } { orig_item->make_send_field(thd, field); }
bool eq(const Item *item, bool binary_cmp) const override bool eq(const Item *item, bool binary_cmp) const override
......
...@@ -2307,8 +2307,7 @@ Item_in_subselect::create_single_in_to_exists_cond(JOIN *join, ...@@ -2307,8 +2307,7 @@ Item_in_subselect::create_single_in_to_exists_cond(JOIN *join,
if (join_having || select_lex->with_sum_func || if (join_having || select_lex->with_sum_func ||
select_lex->group_list.elements) select_lex->group_list.elements)
{ {
const char *tmp= this->full_name(); LEX_CSTRING field_name= this->full_name_cstring();
LEX_CSTRING field_name= {tmp, safe_strlen(tmp)};
Item *item= func->create(thd, expr, Item *item= func->create(thd, expr,
new (thd->mem_root) Item_ref_null_helper( new (thd->mem_root) Item_ref_null_helper(
thd, thd,
......
...@@ -189,8 +189,7 @@ TEST_join(JOIN *join) ...@@ -189,8 +189,7 @@ TEST_join(JOIN *join)
JOIN_TAB *tab= jt_range->start + i; JOIN_TAB *tab= jt_range->start + i;
for (ref= 0; ref < tab->ref.key_parts; ref++) for (ref= 0; ref < tab->ref.key_parts; ref++)
{ {
const char *full_name=(tab->ref.items[ref]->full_name()); ref_key_parts[i].append(tab->ref.items[ref]->full_name_cstring());
ref_key_parts[i].append(full_name, strlen(full_name));
ref_key_parts[i].append(STRING_WITH_LEN(" ")); ref_key_parts[i].append(STRING_WITH_LEN(" "));
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment