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,
void Item::print(String *str, enum_query_type query_type)
{
const char *name= full_name();
str->append(name, strlen(name));
str->append(full_name_cstring());
}
......@@ -3146,32 +3145,37 @@ bool Item_field::switch_to_nullable_fields_processor(void *arg)
return 0;
}
const char *Item_ident::full_name() const
LEX_CSTRING Item_ident::full_name_cstring() const
{
char *tmp;
size_t length;
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])
{
THD *thd= current_thd;
tmp=(char*) thd->alloc((uint) db_name.length+ (uint) table_name.length +
(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
{
if (table_name.str[0])
{
THD *thd= current_thd;
tmp= (char*) thd->alloc((uint) table_name.length +
field_name.length + 2);
strxmov(tmp, table_name.str, ".", field_name.str, NullS);
}
else
return field_name.str;
if (!table_name.str[0])
return field_name;
THD *thd= current_thd;
tmp= (char*) thd->alloc((uint) table_name.length +
field_name.length + 2);
length= (strxmov(tmp, table_name.str, ".", field_name.str, NullS) - tmp);
}
return tmp;
return {tmp, length};
}
void Item_ident::print(String *str, enum_query_type query_type)
......
......@@ -1697,7 +1697,13 @@ class Item :public Value_source,
virtual Field *get_tmp_table_field() { return 0; }
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()
{ return real_item()->type() == Item::FIELD_ITEM ? name.str : NULL; }
const TABLE_SHARE *field_table_or_null();
......@@ -3439,7 +3445,7 @@ class Item_ident :public Item_result_field
const LEX_CSTRING &field_name_arg);
Item_ident(THD *thd, Item_ident *item);
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;
st_select_lex *get_depended_from() const;
bool remove_dependence_processor(void * arg) override;
......@@ -5845,7 +5851,8 @@ class Item_cache_wrapper :public Item_result_field
/* Following methods make this item transparent as much as possible */
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
{ orig_item->make_send_field(thd, field); }
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,
if (join_having || select_lex->with_sum_func ||
select_lex->group_list.elements)
{
const char *tmp= this->full_name();
LEX_CSTRING field_name= {tmp, safe_strlen(tmp)};
LEX_CSTRING field_name= this->full_name_cstring();
Item *item= func->create(thd, expr,
new (thd->mem_root) Item_ref_null_helper(
thd,
......
......@@ -189,8 +189,7 @@ TEST_join(JOIN *join)
JOIN_TAB *tab= jt_range->start + i;
for (ref= 0; ref < tab->ref.key_parts; ref++)
{
const char *full_name=(tab->ref.items[ref]->full_name());
ref_key_parts[i].append(full_name, strlen(full_name));
ref_key_parts[i].append(tab->ref.items[ref]->full_name_cstring());
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