MDEV-19599 Change db_name, table_name to LEX_CSTRING in Item_ident and Send_field

This commit is contained in:
Alexander Barkov 2019-05-26 06:17:35 +04:00
parent ac93d7d674
commit 9f23f8e598
31 changed files with 319 additions and 317 deletions

View File

@ -891,13 +891,6 @@ static char *dup_str_aux(MEM_ROOT *root, const char *from, uint length,
} }
static char *dup_str_aux(MEM_ROOT *root, const char *from,
CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
{
return dup_str_aux(root, from, (uint) strlen(from), fromcs, tocs);
}
static char *dup_str_aux(MEM_ROOT *root, const LEX_CSTRING &from, static char *dup_str_aux(MEM_ROOT *root, const LEX_CSTRING &from,
CHARSET_INFO *fromcs, CHARSET_INFO *tocs) CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
{ {

View File

@ -93,8 +93,9 @@ static COND* make_cond(THD *thd, TABLE_LIST *tables, LEX_STRING *filter)
{ {
Item_cond_or *res= NULL; Item_cond_or *res= NULL;
Name_resolution_context nrc; Name_resolution_context nrc;
const char *db= tables->db.str, *table= tables->alias.str; LEX_CSTRING &db= tables->db;
LEX_CSTRING *field= &tables->table->field[0]->field_name; LEX_CSTRING &table= tables->alias;
LEX_CSTRING &field= tables->table->field[0]->field_name;
CHARSET_INFO *cs= &my_charset_latin1; CHARSET_INFO *cs= &my_charset_latin1;
if (!filter->str) if (!filter->str)

View File

@ -1965,24 +1965,24 @@ void Field::make_send_field(Send_field *field)
{ {
if (orig_table && orig_table->s->db.str && *orig_table->s->db.str) if (orig_table && orig_table->s->db.str && *orig_table->s->db.str)
{ {
field->db_name= orig_table->s->db.str; field->db_name= orig_table->s->db;
if (orig_table->pos_in_table_list && if (orig_table->pos_in_table_list &&
orig_table->pos_in_table_list->schema_table) orig_table->pos_in_table_list->schema_table)
field->org_table_name= (orig_table->pos_in_table_list-> field->org_table_name= Lex_cstring_strlen(orig_table->pos_in_table_list->
schema_table->table_name); schema_table->table_name);
else else
field->org_table_name= orig_table->s->table_name.str; field->org_table_name= orig_table->s->table_name;
} }
else else
field->org_table_name= field->db_name= ""; field->org_table_name= field->db_name= empty_clex_str;
if (orig_table && orig_table->alias.ptr()) if (orig_table && orig_table->alias.ptr())
{ {
field->table_name= orig_table->alias.ptr(); field->table_name= orig_table->alias.lex_cstring();
field->org_col_name= field_name; field->org_col_name= field_name;
} }
else else
{ {
field->table_name= ""; field->table_name= empty_clex_str;
field->org_col_name= empty_clex_str; field->org_col_name= empty_clex_str;
} }
field->col_name= field_name; field->col_name= field_name;

View File

@ -5055,22 +5055,21 @@ class Send_field :public Sql_alloc,
public Type_handler_hybrid_field_type public Type_handler_hybrid_field_type
{ {
public: public:
const char *db_name; LEX_CSTRING db_name;
const char *table_name,*org_table_name; LEX_CSTRING table_name, org_table_name;
LEX_CSTRING col_name, org_col_name; LEX_CSTRING col_name, org_col_name;
ulong length; ulong length;
uint flags, decimals; uint flags, decimals;
Send_field() {}
Send_field(Field *field) Send_field(Field *field)
{ {
field->make_send_field(this); field->make_send_field(this);
DBUG_ASSERT(table_name != 0); DBUG_ASSERT(table_name.str != 0);
normalize(); normalize();
} }
Send_field(THD *thd, Item *item); Send_field(THD *thd, Item *item);
Send_field(Field *field, Send_field(Field *field,
const char *db_name_arg, const LEX_CSTRING &db_name_arg,
const char *table_name_arg) const LEX_CSTRING &table_name_arg)
:Type_handler_hybrid_field_type(field->type_handler()), :Type_handler_hybrid_field_type(field->type_handler()),
db_name(db_name_arg), db_name(db_name_arg),
table_name(table_name_arg), table_name(table_name_arg),

View File

@ -623,33 +623,34 @@ Item* Item::set_expr_cache(THD *thd)
Item_ident::Item_ident(THD *thd, Name_resolution_context *context_arg, Item_ident::Item_ident(THD *thd, Name_resolution_context *context_arg,
const char *db_name_arg,const char *table_name_arg, const LEX_CSTRING &db_name_arg,
const LEX_CSTRING *field_name_arg) const LEX_CSTRING &table_name_arg,
const LEX_CSTRING &field_name_arg)
:Item_result_field(thd), orig_db_name(db_name_arg), :Item_result_field(thd), orig_db_name(db_name_arg),
orig_table_name(table_name_arg), orig_table_name(table_name_arg),
orig_field_name(*field_name_arg), context(context_arg), orig_field_name(field_name_arg), context(context_arg),
db_name(db_name_arg), table_name(table_name_arg), db_name(db_name_arg), table_name(table_name_arg),
field_name(*field_name_arg), field_name(field_name_arg),
alias_name_used(FALSE), cached_field_index(NO_CACHED_FIELD_INDEX), alias_name_used(FALSE), cached_field_index(NO_CACHED_FIELD_INDEX),
cached_table(0), depended_from(0), can_be_depended(TRUE) cached_table(0), depended_from(0), can_be_depended(TRUE)
{ {
name= *field_name_arg; name= field_name_arg;
} }
Item_ident::Item_ident(THD *thd, TABLE_LIST *view_arg, Item_ident::Item_ident(THD *thd, TABLE_LIST *view_arg,
const LEX_CSTRING *field_name_arg) const LEX_CSTRING &field_name_arg)
:Item_result_field(thd), orig_db_name(NullS), :Item_result_field(thd), orig_db_name(null_clex_str),
orig_table_name(view_arg->table_name.str), orig_table_name(view_arg->table_name),
orig_field_name(*field_name_arg), orig_field_name(field_name_arg),
/* TODO: suspicious use of first_select_lex */ /* TODO: suspicious use of first_select_lex */
context(&view_arg->view->first_select_lex()->context), context(&view_arg->view->first_select_lex()->context),
db_name(NullS), table_name(view_arg->alias.str), db_name(null_clex_str), table_name(view_arg->alias),
field_name(*field_name_arg), field_name(field_name_arg),
alias_name_used(FALSE), cached_field_index(NO_CACHED_FIELD_INDEX), alias_name_used(FALSE), cached_field_index(NO_CACHED_FIELD_INDEX),
cached_table(NULL), depended_from(NULL), can_be_depended(TRUE) cached_table(NULL), depended_from(NULL), can_be_depended(TRUE)
{ {
name= *field_name_arg; name= field_name_arg;
} }
@ -780,10 +781,10 @@ bool Item_field::rename_fields_processor(void *arg)
while ((def=def_it++)) while ((def=def_it++))
{ {
if (def->change.str && if (def->change.str &&
(!db_name || !db_name[0] || (!db_name.str || !db_name.str[0] ||
!my_strcasecmp(table_alias_charset, db_name, rename->db_name.str)) && !my_strcasecmp(table_alias_charset, db_name.str, rename->db_name.str)) &&
(!table_name || !table_name[0] || (!table_name.str || !table_name.str[0] ||
!my_strcasecmp(table_alias_charset, table_name, rename->table_name.str)) && !my_strcasecmp(table_alias_charset, table_name.str, rename->table_name.str)) &&
!my_strcasecmp(system_charset_info, field_name.str, def->change.str)) !my_strcasecmp(system_charset_info, field_name.str, def->change.str))
{ {
field_name= def->field_name; field_name= def->field_name;
@ -1291,7 +1292,7 @@ Item *Item::const_charset_converter(THD *thd, CHARSET_INFO *tocs,
uint conv_errors; uint conv_errors;
Item_string *conv= (func_name ? Item_string *conv= (func_name ?
new (mem_root) new (mem_root)
Item_static_string_func(thd, Lex_cstring(func_name), Item_static_string_func(thd, Lex_cstring_strlen(func_name),
s, tocs, &conv_errors, s, tocs, &conv_errors,
collation.derivation, collation.derivation,
collation.repertoire) : collation.repertoire) :
@ -2089,8 +2090,8 @@ class Item_aggregate_ref : public Item_ref
{ {
public: public:
Item_aggregate_ref(THD *thd, Name_resolution_context *context_arg, Item_aggregate_ref(THD *thd, Name_resolution_context *context_arg,
Item **item, const char *table_name_arg, Item **item, const LEX_CSTRING &table_name_arg,
const LEX_CSTRING *field_name_arg): const LEX_CSTRING &field_name_arg):
Item_ref(thd, context_arg, item, table_name_arg, field_name_arg) {} Item_ref(thd, context_arg, item, table_name_arg, field_name_arg) {}
virtual inline void print (String *str, enum_query_type query_type) virtual inline void print (String *str, enum_query_type query_type)
@ -2212,8 +2213,8 @@ void Item::split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array,
if (!(item_ref= (new (thd->mem_root) if (!(item_ref= (new (thd->mem_root)
Item_direct_ref(thd, Item_direct_ref(thd,
&thd->lex->current_select->context, &thd->lex->current_select->context,
&ref_pointer_array[el], 0, &ref_pointer_array[el],
&name)))) null_clex_str, name))))
return; // fatal_error is set return; // fatal_error is set
} }
else else
@ -2221,8 +2222,8 @@ void Item::split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array,
if (!(item_ref= (new (thd->mem_root) if (!(item_ref= (new (thd->mem_root)
Item_aggregate_ref(thd, Item_aggregate_ref(thd,
&thd->lex->current_select->context, &thd->lex->current_select->context,
&ref_pointer_array[el], 0, &ref_pointer_array[el],
&name)))) null_clex_str, name))))
return; // fatal_error is set return; // fatal_error is set
} }
if (type() == SUM_FUNC_ITEM) if (type() == SUM_FUNC_ITEM)
@ -2888,7 +2889,8 @@ Item* Item_ref::build_clone(THD *thd)
/**********************************************/ /**********************************************/
Item_field::Item_field(THD *thd, Field *f) Item_field::Item_field(THD *thd, Field *f)
:Item_ident(thd, 0, NullS, *f->table_name, &f->field_name), :Item_ident(thd, 0, null_clex_str,
Lex_cstring_strlen(*f->table_name), f->field_name),
item_equal(0), item_equal(0),
have_privileges(0), any_privileges(0) have_privileges(0), any_privileges(0)
{ {
@ -2912,8 +2914,8 @@ Item_field::Item_field(THD *thd, Field *f)
Item_field::Item_field(THD *thd, Name_resolution_context *context_arg, Item_field::Item_field(THD *thd, Name_resolution_context *context_arg,
Field *f) Field *f)
:Item_ident(thd, context_arg, f->table->s->db.str, *f->table_name, :Item_ident(thd, context_arg, f->table->s->db,
&f->field_name), Lex_cstring_strlen(*f->table_name), f->field_name),
item_equal(0), item_equal(0),
have_privileges(0), any_privileges(0) have_privileges(0), any_privileges(0)
{ {
@ -2935,13 +2937,12 @@ Item_field::Item_field(THD *thd, Name_resolution_context *context_arg,
procedures). procedures).
*/ */
{ {
if (db_name) if (db_name.str)
orig_db_name= thd->strdup(db_name); orig_db_name= thd->strmake_lex_cstring(db_name);
if (table_name) if (table_name.str)
orig_table_name= thd->strdup(table_name); orig_table_name= thd->strmake_lex_cstring(table_name);
if (field_name.str) if (field_name.str)
thd->make_lex_string(&orig_field_name, field_name.str, orig_field_name= thd->strmake_lex_cstring(field_name);
field_name.length);
/* /*
We don't restore 'name' in cleanup because it's not changed We don't restore 'name' in cleanup because it's not changed
during execution. Still we need it to point to persistent during execution. Still we need it to point to persistent
@ -2955,8 +2956,9 @@ Item_field::Item_field(THD *thd, Name_resolution_context *context_arg,
Item_field::Item_field(THD *thd, Name_resolution_context *context_arg, Item_field::Item_field(THD *thd, Name_resolution_context *context_arg,
const char *db_arg,const char *table_name_arg, const LEX_CSTRING &db_arg,
const LEX_CSTRING *field_name_arg) const LEX_CSTRING &table_name_arg,
const LEX_CSTRING &field_name_arg)
:Item_ident(thd, context_arg, db_arg, table_name_arg, field_name_arg), :Item_ident(thd, context_arg, db_arg, table_name_arg, field_name_arg),
field(0), item_equal(0), field(0), item_equal(0),
have_privileges(0), any_privileges(0) have_privileges(0), any_privileges(0)
@ -2989,9 +2991,9 @@ void Item_field::set_field(Field *field_par)
field=result_field=field_par; // for easy coding with fields field=result_field=field_par; // for easy coding with fields
maybe_null=field->maybe_null(); maybe_null=field->maybe_null();
Type_std_attributes::set(field_par->type_std_attributes()); Type_std_attributes::set(field_par->type_std_attributes());
table_name= *field_par->table_name; table_name= Lex_cstring_strlen(*field_par->table_name);
field_name= field_par->field_name; field_name= field_par->field_name;
db_name= field_par->table->s->db.str; db_name= field_par->table->s->db;
alias_name_used= field_par->table->alias_name_used; alias_name_used= field_par->table->alias_name_used;
fixed= 1; fixed= 1;
@ -3074,24 +3076,24 @@ bool Item_field::switch_to_nullable_fields_processor(void *arg)
const char *Item_ident::full_name() const const char *Item_ident::full_name() const
{ {
char *tmp; char *tmp;
if (!table_name || !field_name.str) if (!table_name.str || !field_name.str)
return field_name.str ? field_name.str : name.str ? name.str : "tmp_field"; return field_name.str ? field_name.str : name.str ? name.str : "tmp_field";
if (db_name && db_name[0]) if (db_name.str && db_name.str[0])
{ {
THD *thd= current_thd; THD *thd= current_thd;
tmp=(char*) thd->alloc((uint) strlen(db_name)+(uint) strlen(table_name)+ 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,".",table_name,".",field_name.str,NullS); strxmov(tmp,db_name.str,".",table_name.str,".",field_name.str,NullS);
} }
else else
{ {
if (table_name[0]) if (table_name.str[0])
{ {
THD *thd= current_thd; THD *thd= current_thd;
tmp= (char*) thd->alloc((uint) strlen(table_name) + tmp= (char*) thd->alloc((uint) table_name.length +
field_name.length + 2); field_name.length + 2);
strxmov(tmp, table_name, ".", field_name.str, NullS); strxmov(tmp, table_name.str, ".", field_name.str, NullS);
} }
else else
return field_name.str; return field_name.str;
@ -3103,12 +3105,14 @@ void Item_ident::print(String *str, enum_query_type query_type)
{ {
THD *thd= current_thd; THD *thd= current_thd;
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME]; char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
const char *d_name= db_name, *t_name= table_name; LEX_CSTRING d_name= db_name;
bool use_table_name= table_name && table_name[0]; LEX_CSTRING t_name= table_name;
bool use_db_name= use_table_name && db_name && db_name[0] && !alias_name_used; bool use_table_name= table_name.str && table_name.str[0];
bool use_db_name= use_table_name && db_name.str && db_name.str[0] &&
!alias_name_used;
if (use_db_name && (query_type & QT_ITEM_IDENT_SKIP_DB_NAMES)) if (use_db_name && (query_type & QT_ITEM_IDENT_SKIP_DB_NAMES))
use_db_name= !thd->db.str || strcmp(thd->db.str, db_name); use_db_name= !thd->db.str || strcmp(thd->db.str, db_name.str);
if (use_db_name) if (use_db_name)
use_db_name= !(cached_table && cached_table->belong_to_view && use_db_name= !(cached_table && cached_table->belong_to_view &&
@ -3142,27 +3146,27 @@ void Item_ident::print(String *str, enum_query_type query_type)
{ {
if (use_table_name) if (use_table_name)
{ {
strmov(t_name_buff, table_name); strmov(t_name_buff, table_name.str);
my_casedn_str(files_charset_info, t_name_buff); my_casedn_str(files_charset_info, t_name_buff);
t_name= t_name_buff; t_name= Lex_cstring_strlen(t_name_buff);
} }
if (use_db_name) if (use_db_name)
{ {
strmov(d_name_buff, db_name); strmov(d_name_buff, db_name.str);
my_casedn_str(files_charset_info, d_name_buff); my_casedn_str(files_charset_info, d_name_buff);
d_name= d_name_buff; d_name= Lex_cstring_strlen(d_name_buff);
} }
} }
if (use_db_name) if (use_db_name)
{ {
append_identifier(thd, str, d_name, (uint)strlen(d_name)); append_identifier(thd, str, d_name.str, (uint) d_name.length);
str->append('.'); str->append('.');
DBUG_ASSERT(use_table_name); DBUG_ASSERT(use_table_name);
} }
if (use_table_name) if (use_table_name)
{ {
append_identifier(thd, str, t_name, (uint) strlen(t_name)); append_identifier(thd, str, t_name.str, (uint) t_name.length);
str->append('.'); str->append('.');
} }
append_identifier(thd, str, &field_name); append_identifier(thd, str, &field_name);
@ -3310,12 +3314,12 @@ bool Item_field::eq(const Item *item, bool binary_cmp) const
*/ */
return (!lex_string_cmp(system_charset_info, &item_field->name, return (!lex_string_cmp(system_charset_info, &item_field->name,
&field_name) && &field_name) &&
(!item_field->table_name || !table_name || (!item_field->table_name.str || !table_name.str ||
(!my_strcasecmp(table_alias_charset, item_field->table_name, (!my_strcasecmp(table_alias_charset, item_field->table_name.str,
table_name) && table_name.str) &&
(!item_field->db_name || !db_name || (!item_field->db_name.str || !db_name.str ||
(item_field->db_name && !strcmp(item_field->db_name, (item_field->db_name.str && !strcmp(item_field->db_name.str,
db_name)))))); db_name.str))))));
} }
@ -4943,10 +4947,10 @@ static bool mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current,
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
if (thd->lex->describe & DESCRIBE_EXTENDED) if (thd->lex->describe & DESCRIBE_EXTENDED)
{ {
const char *db_name= (resolved_item->db_name ? const char *db_name= (resolved_item->db_name.str ?
resolved_item->db_name : ""); resolved_item->db_name.str : "");
const char *table_name= (resolved_item->table_name ? const char *table_name= (resolved_item->table_name.str ?
resolved_item->table_name : ""); resolved_item->table_name.str : "");
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
ER_WARN_FIELD_RESOLVED, ER_WARN_FIELD_RESOLVED,
ER_THD(thd,ER_WARN_FIELD_RESOLVED), ER_THD(thd,ER_WARN_FIELD_RESOLVED),
@ -5040,9 +5044,9 @@ void mark_select_range_as_dependent(THD *thd,
static Item** find_field_in_group_list(Item *find_item, ORDER *group_list) static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
{ {
const char *db_name; LEX_CSTRING db_name;
const char *table_name; LEX_CSTRING table_name;
LEX_CSTRING *field_name; LEX_CSTRING field_name;
ORDER *found_group= NULL; ORDER *found_group= NULL;
int found_match_degree= 0; int found_match_degree= 0;
char name_buff[SAFE_NAME_LEN+1]; char name_buff[SAFE_NAME_LEN+1];
@ -5052,30 +5056,30 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
{ {
db_name= ((Item_ident*) find_item)->db_name; db_name= ((Item_ident*) find_item)->db_name;
table_name= ((Item_ident*) find_item)->table_name; table_name= ((Item_ident*) find_item)->table_name;
field_name= &((Item_ident*) find_item)->field_name; field_name= ((Item_ident*) find_item)->field_name;
} }
else else
return NULL; return NULL;
if (db_name && lower_case_table_names) if (db_name.str && lower_case_table_names)
{ {
/* Convert database to lower case for comparison */ /* Convert database to lower case for comparison */
strmake_buf(name_buff, db_name); strmake_buf(name_buff, db_name.str);
my_casedn_str(files_charset_info, name_buff); my_casedn_str(files_charset_info, name_buff);
db_name= name_buff; db_name= Lex_cstring_strlen(name_buff);
} }
DBUG_ASSERT(field_name->str != 0); DBUG_ASSERT(field_name.str != 0);
for (ORDER *cur_group= group_list ; cur_group ; cur_group= cur_group->next) for (ORDER *cur_group= group_list ; cur_group ; cur_group= cur_group->next)
{ {
int cur_match_degree= 0; int cur_match_degree= 0;
/* SELECT list element with explicit alias */ /* SELECT list element with explicit alias */
if ((*(cur_group->item))->name.str && !table_name && 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, !lex_string_cmp(system_charset_info,
&(*(cur_group->item))->name, field_name)) &(*(cur_group->item))->name, &field_name))
{ {
++cur_match_degree; ++cur_match_degree;
} }
@ -5084,30 +5088,30 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
(*(cur_group->item))->type() == Item::REF_ITEM ) (*(cur_group->item))->type() == Item::REF_ITEM )
{ {
Item_ident *cur_field= (Item_ident*) *cur_group->item; Item_ident *cur_field= (Item_ident*) *cur_group->item;
const char *l_db_name= cur_field->db_name; const char *l_db_name= cur_field->db_name.str;
const char *l_table_name= cur_field->table_name; const char *l_table_name= cur_field->table_name.str;
LEX_CSTRING *l_field_name= &cur_field->field_name; LEX_CSTRING *l_field_name= &cur_field->field_name;
DBUG_ASSERT(l_field_name->str != 0); DBUG_ASSERT(l_field_name->str != 0);
if (!lex_string_cmp(system_charset_info, if (!lex_string_cmp(system_charset_info,
l_field_name, field_name)) l_field_name, &field_name))
++cur_match_degree; ++cur_match_degree;
else else
continue; continue;
if (l_table_name && table_name) if (l_table_name && table_name.str)
{ {
/* If field_name is qualified by a table name. */ /* If field_name is qualified by a table name. */
if (my_strcasecmp(table_alias_charset, l_table_name, table_name)) if (my_strcasecmp(table_alias_charset, l_table_name, table_name.str))
/* Same field names, different tables. */ /* Same field names, different tables. */
return NULL; return NULL;
++cur_match_degree; ++cur_match_degree;
if (l_db_name && db_name) if (l_db_name && db_name.str)
{ {
/* If field_name is also qualified by a database name. */ /* If field_name is also qualified by a database name. */
if (strcmp(l_db_name, db_name)) if (strcmp(l_db_name, db_name.str))
/* Same field names, different databases. */ /* Same field names, different databases. */
return NULL; return NULL;
++cur_match_degree; ++cur_match_degree;
@ -5576,14 +5580,14 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
rf= (place == IN_HAVING ? rf= (place == IN_HAVING ?
new (thd->mem_root) new (thd->mem_root)
Item_ref(thd, context, ref, table_name, Item_ref(thd, context, ref, table_name,
&field_name, alias_name_used) : field_name, alias_name_used) :
(!select->group_list.elements ? (!select->group_list.elements ?
new (thd->mem_root) new (thd->mem_root)
Item_direct_ref(thd, context, ref, table_name, Item_direct_ref(thd, context, ref, table_name,
&field_name, alias_name_used) : field_name, alias_name_used) :
new (thd->mem_root) new (thd->mem_root)
Item_outer_ref(thd, context, ref, table_name, Item_outer_ref(thd, context, ref, table_name,
&field_name, alias_name_used))); field_name, alias_name_used)));
*ref= save; *ref= save;
if (!rf) if (!rf)
return -1; return -1;
@ -5628,9 +5632,9 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
{ {
Item_ref *rf; Item_ref *rf;
rf= new (thd->mem_root) Item_ref(thd, context, rf= new (thd->mem_root) Item_ref(thd, context,
(*from_field)->table->s->db.str, (*from_field)->table->s->db,
(*from_field)->table->alias.c_ptr(), Lex_cstring_strlen((*from_field)->table->alias.c_ptr()),
&field_name); field_name);
if (!rf) if (!rf)
return -1; return -1;
thd->change_item_tree(reference, rf); thd->change_item_tree(reference, rf);
@ -5778,7 +5782,7 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
Item_field created by the parser with the new Item_ref. Item_field created by the parser with the new Item_ref.
*/ */
Item_ref *rf= new (thd->mem_root) Item_ref *rf= new (thd->mem_root)
Item_ref(thd, context, db_name, table_name, &field_name); Item_ref(thd, context, db_name, table_name, field_name);
if (!rf) if (!rf)
return 1; return 1;
bool err= rf->fix_fields(thd, (Item **) &rf) || rf->check_cols(1); bool err= rf->fix_fields(thd, (Item **) &rf) || rf->check_cols(1);
@ -5961,7 +5965,7 @@ bool Item_field::post_fix_fields_part_expr_processor(void *int_arg)
/* /*
Update table_name to be real table name, not the alias. Because alias is Update table_name to be real table name, not the alias. Because alias is
reallocated for every statement, and this item has a long life time */ reallocated for every statement, and this item has a long life time */
table_name= field->table->s->table_name.str; table_name= field->table->s->table_name;
return FALSE; return FALSE;
} }
@ -6158,10 +6162,10 @@ Item *Item_field::replace_equal_field(THD *thd, uchar *arg)
void Item::init_make_send_field(Send_field *tmp_field, void Item::init_make_send_field(Send_field *tmp_field,
const Type_handler *h) const Type_handler *h)
{ {
tmp_field->db_name= ""; tmp_field->db_name= empty_clex_str;
tmp_field->org_table_name= ""; tmp_field->org_table_name= empty_clex_str;
tmp_field->org_col_name= empty_clex_str; tmp_field->org_col_name= empty_clex_str;
tmp_field->table_name= ""; tmp_field->table_name= empty_clex_str;
tmp_field->col_name= name; tmp_field->col_name= name;
tmp_field->flags= (maybe_null ? 0 : NOT_NULL_FLAG) | tmp_field->flags= (maybe_null ? 0 : NOT_NULL_FLAG) |
(my_binary_compare(charset_for_protocol()) ? (my_binary_compare(charset_for_protocol()) ?
@ -6320,15 +6324,15 @@ bool Item::eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs)
void Item_field::make_send_field(THD *thd, Send_field *tmp_field) void Item_field::make_send_field(THD *thd, Send_field *tmp_field)
{ {
field->make_send_field(tmp_field); field->make_send_field(tmp_field);
DBUG_ASSERT(tmp_field->table_name != 0); DBUG_ASSERT(tmp_field->table_name.str != 0);
if (name.str) if (name.str)
{ {
DBUG_ASSERT(name.length == strlen(name.str)); DBUG_ASSERT(name.length == strlen(name.str));
tmp_field->col_name= name; // Use user supplied name tmp_field->col_name= name; // Use user supplied name
} }
if (table_name) if (table_name.str)
tmp_field->table_name= table_name; tmp_field->table_name= table_name;
if (db_name) if (db_name.str)
tmp_field->db_name= db_name; tmp_field->db_name= db_name;
} }
@ -7163,7 +7167,7 @@ Item *Item_field::update_value_transformer(THD *thd, uchar *select_arg)
all_fields->push_front((Item*)this, thd->mem_root); all_fields->push_front((Item*)this, thd->mem_root);
ref= new (thd->mem_root) ref= new (thd->mem_root)
Item_ref(thd, &select->context, &ref_pointer_array[el], Item_ref(thd, &select->context, &ref_pointer_array[el],
table_name, &field_name); table_name, field_name);
return ref; return ref;
} }
return this; return this;
@ -7389,8 +7393,7 @@ Item *get_field_item_for_having(THD *thd, Item *item, st_select_lex *sel)
if (field_item) if (field_item)
{ {
Item_ref *ref= new (thd->mem_root) Item_ref(thd, &sel->context, Item_ref *ref= new (thd->mem_root) Item_ref(thd, &sel->context,
NullS, NullS, field_item->field_name);
&field_item->field_name);
return ref; return ref;
} }
DBUG_ASSERT(0); DBUG_ASSERT(0);
@ -7552,10 +7555,10 @@ void Item_temptable_field::print(String *str, enum_query_type query_type)
Item_ref::Item_ref(THD *thd, Name_resolution_context *context_arg, Item_ref::Item_ref(THD *thd, Name_resolution_context *context_arg,
Item **item, const char *table_name_arg, Item **item, const LEX_CSTRING &table_name_arg,
const LEX_CSTRING *field_name_arg, const LEX_CSTRING &field_name_arg,
bool alias_name_used_arg): bool alias_name_used_arg):
Item_ident(thd, context_arg, NullS, table_name_arg, field_name_arg), Item_ident(thd, context_arg, null_clex_str, table_name_arg, field_name_arg),
ref(item), reference_trough_name(0) ref(item), reference_trough_name(0)
{ {
alias_name_used= alias_name_used_arg; alias_name_used= alias_name_used_arg;
@ -7602,7 +7605,7 @@ public:
}; };
Item_ref::Item_ref(THD *thd, TABLE_LIST *view_arg, Item **item, Item_ref::Item_ref(THD *thd, TABLE_LIST *view_arg, Item **item,
const LEX_CSTRING *field_name_arg, const LEX_CSTRING &field_name_arg,
bool alias_name_used_arg): bool alias_name_used_arg):
Item_ident(thd, view_arg, field_name_arg), Item_ident(thd, view_arg, field_name_arg),
ref(item), reference_trough_name(0) ref(item), reference_trough_name(0)
@ -8036,7 +8039,7 @@ void Item_ref::print(String *str, enum_query_type query_type)
if ((*ref)->type() != Item::CACHE_ITEM && if ((*ref)->type() != Item::CACHE_ITEM &&
(*ref)->type() != Item::WINDOW_FUNC_ITEM && (*ref)->type() != Item::WINDOW_FUNC_ITEM &&
ref_type() != VIEW_REF && ref_type() != VIEW_REF &&
!table_name && name.str && alias_name_used) !table_name.str && name.str && alias_name_used)
{ {
THD *thd= current_thd; THD *thd= current_thd;
append_identifier(thd, str, &(*ref)->real_item()->name); append_identifier(thd, str, &(*ref)->real_item()->name);
@ -8252,13 +8255,13 @@ void Item_ref::make_send_field(THD *thd, Send_field *field)
/* Non-zero in case of a view */ /* Non-zero in case of a view */
if (name.str) if (name.str)
field->col_name= name; field->col_name= name;
if (table_name) if (table_name.str)
field->table_name= table_name; field->table_name= table_name;
if (db_name) if (db_name.str)
field->db_name= db_name; field->db_name= db_name;
if (orig_field_name.str) if (orig_field_name.str)
field->org_col_name= orig_field_name; field->org_col_name= orig_field_name;
if (orig_table_name) if (orig_table_name.str)
field->org_table_name= orig_table_name; field->org_table_name= orig_table_name;
} }

View File

@ -3187,14 +3187,14 @@ protected:
updated during fix_fields() to values from Field object and life-time updated during fix_fields() to values from Field object and life-time
of those is shorter than life-time of Item_field. of those is shorter than life-time of Item_field.
*/ */
const char *orig_db_name; LEX_CSTRING orig_db_name;
const char *orig_table_name; LEX_CSTRING orig_table_name;
LEX_CSTRING orig_field_name; LEX_CSTRING orig_field_name;
public: public:
Name_resolution_context *context; Name_resolution_context *context;
const char *db_name; LEX_CSTRING db_name;
const char *table_name; LEX_CSTRING table_name;
LEX_CSTRING field_name; LEX_CSTRING field_name;
bool alias_name_used; /* true if item was resolved against alias */ bool alias_name_used; /* true if item was resolved against alias */
/* /*
@ -3224,10 +3224,10 @@ public:
*/ */
bool can_be_depended; bool can_be_depended;
Item_ident(THD *thd, Name_resolution_context *context_arg, Item_ident(THD *thd, Name_resolution_context *context_arg,
const char *db_name_arg, const char *table_name_arg, const LEX_CSTRING &db_name_arg, const LEX_CSTRING &table_name_arg,
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; const char *full_name() const;
void cleanup(); void cleanup();
st_select_lex *get_depended_from() const; st_select_lex *get_depended_from() const;
@ -3262,8 +3262,15 @@ public:
/* field need any privileges (for VIEW creation) */ /* field need any privileges (for VIEW creation) */
bool any_privileges; bool any_privileges;
Item_field(THD *thd, Name_resolution_context *context_arg, Item_field(THD *thd, Name_resolution_context *context_arg,
const char *db_arg,const char *table_name_arg, const LEX_CSTRING &db_arg, const LEX_CSTRING &table_name_arg,
const LEX_CSTRING *field_name_arg); const LEX_CSTRING &field_name_arg);
Item_field(THD *thd, Name_resolution_context *context_arg,
const LEX_CSTRING &field_name_arg)
:Item_field(thd, context_arg, null_clex_str, null_clex_str, field_name_arg)
{ }
Item_field(THD *thd, Name_resolution_context *context_arg)
:Item_field(thd, context_arg, null_clex_str, null_clex_str, null_clex_str)
{ }
/* /*
Constructor needed to process subselect with temporary tables (see Item) Constructor needed to process subselect with temporary tables (see Item)
*/ */
@ -5098,10 +5105,14 @@ public:
Item **ref; Item **ref;
bool reference_trough_name; bool reference_trough_name;
Item_ref(THD *thd, Name_resolution_context *context_arg, Item_ref(THD *thd, Name_resolution_context *context_arg,
const char *db_arg, const char *table_name_arg, const LEX_CSTRING &db_arg, const LEX_CSTRING &table_name_arg,
const LEX_CSTRING *field_name_arg): const LEX_CSTRING &field_name_arg):
Item_ident(thd, context_arg, db_arg, table_name_arg, field_name_arg), Item_ident(thd, context_arg, db_arg, table_name_arg, field_name_arg),
set_properties_only(0), ref(0), reference_trough_name(1) {} set_properties_only(0), ref(0), reference_trough_name(1) {}
Item_ref(THD *thd, Name_resolution_context *context_arg,
const LEX_CSTRING &field_name_arg)
:Item_ref(thd, context_arg, null_clex_str, null_clex_str, field_name_arg)
{ }
/* /*
This constructor is used in two scenarios: This constructor is used in two scenarios:
A) *item = NULL A) *item = NULL
@ -5117,10 +5128,10 @@ public:
with Bar, and if we have a more broader set of problems like this. with Bar, and if we have a more broader set of problems like this.
*/ */
Item_ref(THD *thd, Name_resolution_context *context_arg, Item **item, Item_ref(THD *thd, Name_resolution_context *context_arg, Item **item,
const char *table_name_arg, const LEX_CSTRING *field_name_arg, const LEX_CSTRING &table_name_arg, const LEX_CSTRING &field_name_arg,
bool alias_name_used_arg= FALSE); bool alias_name_used_arg= FALSE);
Item_ref(THD *thd, TABLE_LIST *view_arg, Item **item, Item_ref(THD *thd, TABLE_LIST *view_arg, Item **item,
const LEX_CSTRING *field_name_arg, bool alias_name_used_arg= FALSE); const LEX_CSTRING &field_name_arg, bool alias_name_used_arg= FALSE);
/* Constructor need to process subselect with temporary tables (see Item) */ /* Constructor need to process subselect with temporary tables (see Item) */
Item_ref(THD *thd, Item_ref *item) Item_ref(THD *thd, Item_ref *item)
@ -5335,8 +5346,8 @@ class Item_direct_ref :public Item_ref
{ {
public: public:
Item_direct_ref(THD *thd, Name_resolution_context *context_arg, Item **item, Item_direct_ref(THD *thd, Name_resolution_context *context_arg, Item **item,
const char *table_name_arg, const LEX_CSTRING &table_name_arg,
const LEX_CSTRING *field_name_arg, const LEX_CSTRING &field_name_arg,
bool alias_name_used_arg= FALSE): bool alias_name_used_arg= FALSE):
Item_ref(thd, context_arg, item, table_name_arg, Item_ref(thd, context_arg, item, table_name_arg,
field_name_arg, alias_name_used_arg) field_name_arg, alias_name_used_arg)
@ -5344,7 +5355,7 @@ public:
/* Constructor need to process subselect with temporary tables (see Item) */ /* Constructor need to process subselect with temporary tables (see Item) */
Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {} Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {}
Item_direct_ref(THD *thd, TABLE_LIST *view_arg, Item **item, Item_direct_ref(THD *thd, TABLE_LIST *view_arg, Item **item,
const LEX_CSTRING *field_name_arg, const LEX_CSTRING &field_name_arg,
bool alias_name_used_arg= FALSE): bool alias_name_used_arg= FALSE):
Item_ref(thd, view_arg, item, field_name_arg, Item_ref(thd, view_arg, item, field_name_arg,
alias_name_used_arg) alias_name_used_arg)
@ -5384,7 +5395,7 @@ class Item_direct_ref_to_ident :public Item_direct_ref
public: public:
Item_direct_ref_to_ident(THD *thd, Item_ident *item): Item_direct_ref_to_ident(THD *thd, Item_ident *item):
Item_direct_ref(thd, item->context, (Item**)&item, item->table_name, Item_direct_ref(thd, item->context, (Item**)&item, item->table_name,
&item->field_name, FALSE) item->field_name, FALSE)
{ {
ident= item; ident= item;
ref= (Item**)&ident; ref= (Item**)&ident;
@ -5576,8 +5587,8 @@ class Item_direct_view_ref :public Item_direct_ref
public: public:
Item_direct_view_ref(THD *thd, Name_resolution_context *context_arg, Item_direct_view_ref(THD *thd, Name_resolution_context *context_arg,
Item **item, Item **item,
const char *table_name_arg, LEX_CSTRING &table_name_arg,
LEX_CSTRING *field_name_arg, LEX_CSTRING &field_name_arg,
TABLE_LIST *view_arg): TABLE_LIST *view_arg):
Item_direct_ref(thd, context_arg, item, table_name_arg, field_name_arg), Item_direct_ref(thd, context_arg, item, table_name_arg, field_name_arg),
item_equal(0), view(view_arg), item_equal(0), view(view_arg),
@ -5749,7 +5760,7 @@ public:
Item_outer_ref(THD *thd, Name_resolution_context *context_arg, Item_outer_ref(THD *thd, Name_resolution_context *context_arg,
Item_field *outer_field_arg): Item_field *outer_field_arg):
Item_direct_ref(thd, context_arg, 0, outer_field_arg->table_name, Item_direct_ref(thd, context_arg, 0, outer_field_arg->table_name,
&outer_field_arg->field_name), outer_field_arg->field_name),
outer_ref(outer_field_arg), in_sum_func(0), outer_ref(outer_field_arg), in_sum_func(0),
found_in_select_list(0), found_in_group_by(0) found_in_select_list(0), found_in_group_by(0)
{ {
@ -5758,7 +5769,7 @@ public:
fixed= 0; /* reset flag set in set_properties() */ fixed= 0; /* reset flag set in set_properties() */
} }
Item_outer_ref(THD *thd, Name_resolution_context *context_arg, Item **item, Item_outer_ref(THD *thd, Name_resolution_context *context_arg, Item **item,
const char *table_name_arg, LEX_CSTRING *field_name_arg, const LEX_CSTRING &table_name_arg, LEX_CSTRING &field_name_arg,
bool alias_name_used_arg): bool alias_name_used_arg):
Item_direct_ref(thd, context_arg, item, table_name_arg, field_name_arg, Item_direct_ref(thd, context_arg, item, table_name_arg, field_name_arg,
alias_name_used_arg), alias_name_used_arg),
@ -5799,8 +5810,8 @@ protected:
public: public:
Item_ref_null_helper(THD *thd, Name_resolution_context *context_arg, Item_ref_null_helper(THD *thd, Name_resolution_context *context_arg,
Item_in_subselect* master, Item **item, Item_in_subselect* master, Item **item,
const char *table_name_arg, const LEX_CSTRING &table_name_arg,
const LEX_CSTRING *field_name_arg): const LEX_CSTRING &field_name_arg):
Item_ref(thd, context_arg, item, table_name_arg, field_name_arg), Item_ref(thd, context_arg, item, table_name_arg, field_name_arg),
owner(master) {} owner(master) {}
void save_val(Field *to); void save_val(Field *to);
@ -6168,16 +6179,13 @@ class Item_default_value : public Item_field
public: public:
Item *arg; Item *arg;
Item_default_value(THD *thd, Name_resolution_context *context_arg) Item_default_value(THD *thd, Name_resolution_context *context_arg)
:Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL, :Item_field(thd, context_arg),
&null_clex_str),
arg(NULL) {} arg(NULL) {}
Item_default_value(THD *thd, Name_resolution_context *context_arg, Item *a) Item_default_value(THD *thd, Name_resolution_context *context_arg, Item *a)
:Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL, :Item_field(thd, context_arg),
&null_clex_str),
arg(a) {} arg(a) {}
Item_default_value(THD *thd, Name_resolution_context *context_arg, Field *a) Item_default_value(THD *thd, Name_resolution_context *context_arg, Field *a)
:Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL, :Item_field(thd, context_arg),
&null_clex_str),
arg(NULL) {} arg(NULL) {}
enum Type type() const { return DEFAULT_VALUE_ITEM; } enum Type type() const { return DEFAULT_VALUE_ITEM; }
bool eq(const Item *item, bool binary_cmp) const; bool eq(const Item *item, bool binary_cmp) const;
@ -6264,8 +6272,7 @@ class Item_insert_value : public Item_field
public: public:
Item *arg; Item *arg;
Item_insert_value(THD *thd, Name_resolution_context *context_arg, Item *a) Item_insert_value(THD *thd, Name_resolution_context *context_arg, Item *a)
:Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL, :Item_field(thd, context_arg),
&null_clex_str),
arg(a) {} arg(a) {}
bool eq(const Item *item, bool binary_cmp) const; bool eq(const Item *item, bool binary_cmp) const;
bool fix_fields(THD *, Item **); bool fix_fields(THD *, Item **);
@ -6326,10 +6333,9 @@ public:
Item_trigger_field(THD *thd, Name_resolution_context *context_arg, Item_trigger_field(THD *thd, Name_resolution_context *context_arg,
row_version_type row_ver_arg, row_version_type row_ver_arg,
const LEX_CSTRING *field_name_arg, const LEX_CSTRING &field_name_arg,
ulong priv, const bool ro) ulong priv, const bool ro)
:Item_field(thd, context_arg, :Item_field(thd, context_arg, field_name_arg),
(const char *)NULL, (const char *)NULL, field_name_arg),
row_version(row_ver_arg), field_idx((uint)-1), original_privilege(priv), row_version(row_ver_arg), field_idx((uint)-1), original_privilege(priv),
want_privilege(priv), table_grants(NULL), read_only (ro) want_privilege(priv), table_grants(NULL), read_only (ro)
{} {}

View File

@ -6933,9 +6933,9 @@ Item*
Create_func_version::create_builder(THD *thd) Create_func_version::create_builder(THD *thd)
{ {
thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION); thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
static Lex_cstring name("version()"); static Lex_cstring name(STRING_WITH_LEN("version()"));
return new (thd->mem_root) Item_static_string_func(thd, name, return new (thd->mem_root) Item_static_string_func(thd, name,
Lex_cstring(server_version), Lex_cstring_strlen(server_version),
system_charset_info, system_charset_info,
DERIVATION_SYSCONST); DERIVATION_SYSCONST);
} }

View File

@ -4992,7 +4992,7 @@ void Item_func_set_user_var::make_send_field(THD *thd, Send_field *tmp_field)
if (result_field) if (result_field)
{ {
result_field->make_send_field(tmp_field); result_field->make_send_field(tmp_field);
DBUG_ASSERT(tmp_field->table_name != 0); DBUG_ASSERT(tmp_field->table_name.str != 0);
if (Item::name.str) if (Item::name.str)
tmp_field->col_name= Item::name; // Use user supplied name tmp_field->col_name= Item::name; // Use user supplied name
} }

View File

@ -47,6 +47,8 @@ double get_post_group_estimate(JOIN* join, double join_op_rows);
LEX_CSTRING exists_outer_expr_name= { STRING_WITH_LEN("<exists outer expr>") }; LEX_CSTRING exists_outer_expr_name= { STRING_WITH_LEN("<exists outer expr>") };
LEX_CSTRING no_matter_name= {STRING_WITH_LEN("<no matter>") };
int check_and_do_in_subquery_rewrites(JOIN *join); int check_and_do_in_subquery_rewrites(JOIN *join);
Item_subselect::Item_subselect(THD *thd_arg): Item_subselect::Item_subselect(THD *thd_arg):
@ -1930,8 +1932,8 @@ Item_in_subselect::single_value_transformer(JOIN *join)
*/ */
expr= new (thd->mem_root) Item_direct_ref(thd, &select_lex->context, expr= new (thd->mem_root) Item_direct_ref(thd, &select_lex->context,
(Item**)optimizer->get_cache(), (Item**)optimizer->get_cache(),
"<no matter>", no_matter_name,
&in_left_expr_name); in_left_expr_name);
} }
DBUG_RETURN(false); DBUG_RETURN(false);
@ -2162,8 +2164,8 @@ Item_in_subselect::create_single_in_to_exists_cond(JOIN *join,
this, this,
&select_lex-> &select_lex->
ref_pointer_array[0], ref_pointer_array[0],
(char *)"<ref>", {STRING_WITH_LEN("<ref>")},
&field_name)); field_name));
if (!abort_on_null && left_expr->maybe_null) if (!abort_on_null && left_expr->maybe_null)
{ {
/* /*
@ -2244,8 +2246,8 @@ Item_in_subselect::create_single_in_to_exists_cond(JOIN *join,
&select_lex->context, &select_lex->context,
this, this,
&select_lex->ref_pointer_array[0], &select_lex->ref_pointer_array[0],
(char *)"<no matter>", no_matter_name,
&field_name)); field_name));
if (!abort_on_null && left_expr->maybe_null) if (!abort_on_null && left_expr->maybe_null)
{ {
disable_cond_guard_for_const_null_left_expr(0); disable_cond_guard_for_const_null_left_expr(0);
@ -2430,21 +2432,21 @@ Item_in_subselect::create_row_in_to_exists_cond(JOIN * join,
Item_direct_ref(thd, &select_lex->context, Item_direct_ref(thd, &select_lex->context,
(*optimizer->get_cache())-> (*optimizer->get_cache())->
addr(i), addr(i),
(char *)"<no matter>", no_matter_name,
&in_left_expr_name), in_left_expr_name),
new (thd->mem_root) new (thd->mem_root)
Item_ref(thd, &select_lex->context, Item_ref(thd, &select_lex->context,
&select_lex->ref_pointer_array[i], &select_lex->ref_pointer_array[i],
(char *)"<no matter>", no_matter_name,
&list_ref)); list_ref));
Item *item_isnull= Item *item_isnull=
new (thd->mem_root) new (thd->mem_root)
Item_func_isnull(thd, Item_func_isnull(thd,
new (thd->mem_root) new (thd->mem_root)
Item_ref(thd, &select_lex->context, Item_ref(thd, &select_lex->context,
&select_lex->ref_pointer_array[i], &select_lex->ref_pointer_array[i],
(char *)"<no matter>", no_matter_name,
&list_ref)); list_ref));
Item *col_item= new (thd->mem_root) Item *col_item= new (thd->mem_root)
Item_cond_or(thd, item_eq, item_isnull); Item_cond_or(thd, item_eq, item_isnull);
if (!abort_on_null && left_expr->element_index(i)->maybe_null && if (!abort_on_null && left_expr->element_index(i)->maybe_null &&
@ -2464,8 +2466,8 @@ Item_in_subselect::create_row_in_to_exists_cond(JOIN * join,
Item_ref(thd, &select_lex->context, Item_ref(thd, &select_lex->context,
&select_lex-> &select_lex->
ref_pointer_array[i], ref_pointer_array[i],
(char *)"<no matter>", no_matter_name,
&list_ref)); list_ref));
if (!abort_on_null && left_expr->element_index(i)->maybe_null && if (!abort_on_null && left_expr->element_index(i)->maybe_null &&
get_cond_guard(i) ) get_cond_guard(i) )
{ {
@ -2499,14 +2501,14 @@ Item_in_subselect::create_row_in_to_exists_cond(JOIN * join,
Item_direct_ref(thd, &select_lex->context, Item_direct_ref(thd, &select_lex->context,
(*optimizer->get_cache())-> (*optimizer->get_cache())->
addr(i), addr(i),
(char *)"<no matter>", no_matter_name,
&in_left_expr_name), in_left_expr_name),
new (thd->mem_root) new (thd->mem_root)
Item_direct_ref(thd, &select_lex->context, Item_direct_ref(thd, &select_lex->context,
&select_lex-> &select_lex->
ref_pointer_array[i], ref_pointer_array[i],
(char *)"<no matter>", no_matter_name,
&list_ref)); list_ref));
if (!abort_on_null && select_lex->ref_pointer_array[i]->maybe_null) if (!abort_on_null && select_lex->ref_pointer_array[i]->maybe_null)
{ {
Item *having_col_item= Item *having_col_item=
@ -2515,8 +2517,8 @@ Item_in_subselect::create_row_in_to_exists_cond(JOIN * join,
new (thd->mem_root) new (thd->mem_root)
Item_ref(thd, &select_lex->context, Item_ref(thd, &select_lex->context,
&select_lex->ref_pointer_array[i], &select_lex->ref_pointer_array[i],
(char *)"<no matter>", no_matter_name,
&list_ref)); list_ref));
item_isnull= new (thd->mem_root) item_isnull= new (thd->mem_root)
Item_func_isnull(thd, Item_func_isnull(thd,
@ -2524,8 +2526,8 @@ Item_in_subselect::create_row_in_to_exists_cond(JOIN * join,
Item_direct_ref(thd, &select_lex->context, Item_direct_ref(thd, &select_lex->context,
&select_lex-> &select_lex->
ref_pointer_array[i], ref_pointer_array[i],
(char *)"<no matter>", no_matter_name,
&list_ref)); list_ref));
item= new (thd->mem_root) Item_cond_or(thd, item, item_isnull); item= new (thd->mem_root) Item_cond_or(thd, item, item_isnull);
if (left_expr->element_index(i)->maybe_null && get_cond_guard(i)) if (left_expr->element_index(i)->maybe_null && get_cond_guard(i))
{ {
@ -3075,8 +3077,8 @@ bool Item_exists_subselect::exists2in_processor(void *opt_arg)
in_subs->expr= new (thd->mem_root) in_subs->expr= new (thd->mem_root)
Item_direct_ref(thd, &first_select->context, Item_direct_ref(thd, &first_select->context,
(Item**)optimizer->get_cache(), (Item**)optimizer->get_cache(),
(char *)"<no matter>", no_matter_name,
&in_left_expr_name); in_left_expr_name);
if (in_subs->fix_fields(thd, optimizer->arguments() + 1)) if (in_subs->fix_fields(thd, optimizer->arguments() + 1))
{ {
res= TRUE; res= TRUE;
@ -3146,8 +3148,8 @@ bool Item_exists_subselect::exists2in_processor(void *opt_arg)
Item_direct_ref(thd, Item_direct_ref(thd,
&unit->outer_select()->context, &unit->outer_select()->context,
optimizer->arguments(), optimizer->arguments(),
(char *)"<no matter>", no_matter_name,
&exists_outer_expr_name)), exists_outer_expr_name)),
optimizer) : optimizer) :
(Item *)optimizer); (Item *)optimizer);
} }
@ -3170,8 +3172,8 @@ bool Item_exists_subselect::exists2in_processor(void *opt_arg)
Item_direct_ref(thd, Item_direct_ref(thd,
&unit->outer_select()->context, &unit->outer_select()->context,
optimizer->arguments()[0]->addr((int)i), optimizer->arguments()[0]->addr((int)i),
(char *)"<no matter>", no_matter_name,
&exists_outer_expr_name)), exists_outer_expr_name)),
thd->mem_root); thd->mem_root);
} }
} }

View File

@ -2672,8 +2672,10 @@ void Load_log_event::set_fields(const char* affected_db,
{ {
LEX_CSTRING field_name= {field, field_lens[i] }; LEX_CSTRING field_name= {field, field_lens[i] };
field_list.push_back(new (thd->mem_root) field_list.push_back(new (thd->mem_root)
Item_field(thd, context, affected_db, table_name, Item_field(thd, context,
&field_name), Lex_cstring_strlen(affected_db),
Lex_cstring_strlen(table_name),
field_name),
thd->mem_root); thd->mem_root);
field+= field_lens[i] + 1; field+= field_lens[i] + 1;
} }

View File

@ -6759,8 +6759,7 @@ get_corresponding_item_for_in_subq_having(THD *thd, Item *in_item,
Item_ref *ref= Item_ref *ref=
new (thd->mem_root) Item_ref(thd, new (thd->mem_root) Item_ref(thd,
&subq_pred->unit->first_select()->context, &subq_pred->unit->first_select()->context,
NullS, NullS, new_item->name);
&new_item->name);
if (!ref) if (!ref)
DBUG_ASSERT(0); DBUG_ASSERT(0);
return ref; return ref;

View File

@ -990,7 +990,7 @@ bool Protocol_text::store_field_metadata_for_list_fields(const THD *thd,
uint pos) uint pos)
{ {
Send_field field= tl->view ? Send_field field= tl->view ?
Send_field(fld, tl->view_db.str, tl->view_name.str) : Send_field(fld, tl->view_db, tl->view_name) :
Send_field(fld); Send_field(fld);
return store_field_metadata(thd, field, fld->charset_for_protocol(), pos); return store_field_metadata(thd, field, fld->charset_for_protocol(), pos);
} }

View File

@ -122,11 +122,6 @@ public:
virtual bool store(const char *from, size_t length, CHARSET_INFO *cs)=0; virtual bool store(const char *from, size_t length, CHARSET_INFO *cs)=0;
virtual bool store(const char *from, size_t length, virtual bool store(const char *from, size_t length,
CHARSET_INFO *fromcs, CHARSET_INFO *tocs)=0; CHARSET_INFO *fromcs, CHARSET_INFO *tocs)=0;
bool store_str(const char *s, CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
{
DBUG_ASSERT(s);
return store(s, (uint) strlen(s), fromcs, tocs);
}
bool store_str(const LEX_CSTRING &s, CHARSET_INFO *fromcs, CHARSET_INFO *tocs) bool store_str(const LEX_CSTRING &s, CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
{ {
return store(s.str, (uint) s.length, fromcs, tocs); return store(s.str, (uint) s.length, fromcs, tocs);

View File

@ -2333,11 +2333,10 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
break; break;
} }
Send_field *out_param_info= new (thd->mem_root) Send_field(); Send_field *out_param_info= new (thd->mem_root) Send_field(thd, nctx->get_parameter(i));
nctx->get_parameter(i)->make_send_field(thd, out_param_info); out_param_info->db_name= m_db;
out_param_info->db_name= m_db.str; out_param_info->table_name= m_name;
out_param_info->table_name= m_name.str; out_param_info->org_table_name= m_name;
out_param_info->org_table_name= m_name.str;
out_param_info->col_name= spvar->name; out_param_info->col_name= spvar->name;
out_param_info->org_col_name= spvar->name; out_param_info->org_col_name= spvar->name;

View File

@ -6256,8 +6256,8 @@ find_field_in_tables(THD *thd, Item_ident *item,
bool check_privileges, bool register_tree_change) bool check_privileges, bool register_tree_change)
{ {
Field *found=0; Field *found=0;
const char *db= item->db_name; const char *db= item->db_name.str;
const char *table_name= item->table_name; const char *table_name= item->table_name.str;
const char *name= item->field_name.str; const char *name= item->field_name.str;
size_t length= item->field_name.length; size_t length= item->field_name.length;
char name_buff[SAFE_NAME_LEN+1]; char name_buff[SAFE_NAME_LEN+1];
@ -6533,8 +6533,8 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
if (is_ref_by_name) if (is_ref_by_name)
{ {
field_name= &((Item_ident*) find)->field_name; field_name= &((Item_ident*) find)->field_name;
table_name= ((Item_ident*) find)->table_name; table_name= ((Item_ident*) find)->table_name.str;
db_name= ((Item_ident*) find)->db_name; db_name= ((Item_ident*) find)->db_name.str;
} }
for (uint i= 0; i < n_items; i++) for (uint i= 0; i < n_items; i++)
@ -6574,13 +6574,13 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
item_field->field_name and item_field->table_name can be 0x0 if item_field->field_name and item_field->table_name can be 0x0 if
item is not fix_field()'ed yet. item is not fix_field()'ed yet.
*/ */
if (item_field->field_name.str && item_field->table_name && if (item_field->field_name.str && item_field->table_name.str &&
!lex_string_cmp(system_charset_info, &item_field->field_name, !lex_string_cmp(system_charset_info, &item_field->field_name,
field_name) && field_name) &&
!my_strcasecmp(table_alias_charset, item_field->table_name, !my_strcasecmp(table_alias_charset, item_field->table_name.str,
table_name) && table_name) &&
(!db_name || (item_field->db_name && (!db_name || (item_field->db_name.str &&
!strcmp(item_field->db_name, db_name)))) !strcmp(item_field->db_name.str, db_name))))
{ {
if (found_unaliased) if (found_unaliased)
{ {
@ -7477,8 +7477,8 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
MY_INT64_NUM_DECIMAL_DIGITS)); MY_INT64_NUM_DECIMAL_DIGITS));
} }
else if (insert_fields(thd, ((Item_field*) item)->context, else if (insert_fields(thd, ((Item_field*) item)->context,
((Item_field*) item)->db_name, ((Item_field*) item)->db_name.str,
((Item_field*) item)->table_name, &it, ((Item_field*) item)->table_name.str, &it,
any_privileges, hidden_bit_fields)) any_privileges, hidden_bit_fields))
{ {
if (arena) if (arena)

View File

@ -3626,6 +3626,18 @@ public:
return alloc_root(&transaction.mem_root,size); return alloc_root(&transaction.mem_root,size);
} }
LEX_CSTRING strmake_lex_cstring(const char *str, size_t length)
{
const char *tmp= strmake_root(mem_root, str, length);
if (!tmp)
return {0,0};
return {tmp, length};
}
LEX_CSTRING strmake_lex_cstring(const LEX_CSTRING &from)
{
return strmake_lex_cstring(from.str, from.length);
}
LEX_STRING *make_lex_string(LEX_STRING *lex_str, const char* str, size_t length) LEX_STRING *make_lex_string(LEX_STRING *lex_str, const char* str, size_t length)
{ {
if (!(lex_str->str= strmake_root(mem_root, str, length))) if (!(lex_str->str= strmake_root(mem_root, str, length)))

View File

@ -284,12 +284,11 @@ int Materialized_cursor::send_result_set_metadata(
*/ */
while ((item_dst= it_dst++, item_org= it_org++)) while ((item_dst= it_dst++, item_org= it_org++))
{ {
Send_field send_field;
Item_ident *ident= static_cast<Item_ident *>(item_dst); Item_ident *ident= static_cast<Item_ident *>(item_dst);
item_org->make_send_field(thd, &send_field); Send_field send_field(thd, item_org);
ident->db_name= thd->strdup(send_field.db_name); ident->db_name= thd->strmake_lex_cstring(send_field.db_name);
ident->table_name= thd->strdup(send_field.table_name); ident->table_name= thd->strmake_lex_cstring(send_field.table_name);
} }
/* /*

View File

@ -92,14 +92,12 @@ static bool init_fields(THD *thd, TABLE_LIST *tables,
context->resolve_in_table_list_only(tables); context->resolve_in_table_list_only(tables);
for (; count-- ; find_fields++) for (; count-- ; find_fields++)
{ {
LEX_CSTRING field_name= {find_fields->field_name,
strlen(find_fields->field_name) };
/* We have to use 'new' here as field will be re_linked on free */ /* We have to use 'new' here as field will be re_linked on free */
Item_field *field= (new (thd->mem_root) Item_field *field= (new (thd->mem_root)
Item_field(thd, context, Item_field(thd, context,
"mysql", {STRING_WITH_LEN("mysql")},
find_fields->table_name, Lex_cstring_strlen(find_fields->table_name),
&field_name)); Lex_cstring_strlen(find_fields->field_name)));
if (!(find_fields->field= find_field_in_tables(thd, field, tables, NULL, if (!(find_fields->field= find_field_in_tables(thd, field, tables, NULL,
0, REPORT_ALL_ERRORS, 1, 0, REPORT_ALL_ERRORS, 1,
TRUE))) TRUE)))

View File

@ -5397,8 +5397,7 @@ LEX::wrap_unit_into_derived(SELECT_LEX_UNIT *unit)
/* add SELECT list*/ /* add SELECT list*/
{ {
Item *item= new (thd->mem_root) Item *item= new (thd->mem_root) Item_field(thd, context, star_clex_str);
Item_field(thd, context, NULL, NULL, &star_clex_str);
if (item == NULL) if (item == NULL)
goto err; goto err;
if (add_item_to_list(thd, item)) if (add_item_to_list(thd, item))
@ -5460,8 +5459,7 @@ SELECT_LEX *LEX::wrap_select_chain_into_derived(SELECT_LEX *sel)
/* add SELECT list*/ /* add SELECT list*/
{ {
Item *item= new (thd->mem_root) Item *item= new (thd->mem_root) Item_field(thd, context, star_clex_str);
Item_field(thd, context, NULL, NULL, &star_clex_str);
if (item == NULL) if (item == NULL)
goto err; goto err;
if (add_item_to_list(thd, item)) if (add_item_to_list(thd, item))
@ -6005,7 +6003,7 @@ bool LEX::sp_for_loop_implicit_cursor_statement(THD *thd,
SELECT rec.a, rec.b; SELECT rec.a, rec.b;
END FOR; END FOR;
*/ */
if (!(item= new (thd->mem_root) Item_field(thd, NULL, NullS, NullS, &name))) if (!(item= new (thd->mem_root) Item_field(thd, NULL, name)))
return true; return true;
bounds->m_index->set_item_and_free_list(item, NULL); bounds->m_index->set_item_and_free_list(item, NULL);
if (thd->lex->sphead->restore_lex(thd)) if (thd->lex->sphead->restore_lex(thd))
@ -6158,7 +6156,7 @@ bool LEX::sp_for_loop_cursor_declarations(THD *thd,
name= item_splocal->m_name; name= item_splocal->m_name;
else if ((item_field= item->type() == Item::FIELD_ITEM ? else if ((item_field= item->type() == Item::FIELD_ITEM ?
static_cast<Item_field *>(item) : NULL) && static_cast<Item_field *>(item) : NULL) &&
item_field->table_name == NULL) item_field->table_name.str == NULL)
name= item_field->field_name; name= item_field->field_name;
else if (item->type() == Item::FUNC_ITEM && else if (item->type() == Item::FUNC_ITEM &&
static_cast<Item_func*>(item)->functype() == Item_func::FUNC_SP && static_cast<Item_func*>(item)->functype() == Item_func::FUNC_SP &&
@ -7014,7 +7012,7 @@ Item *LEX::create_and_link_Item_trigger_field(THD *thd,
new_row ? new_row ?
Item_trigger_field::NEW_ROW: Item_trigger_field::NEW_ROW:
Item_trigger_field::OLD_ROW, Item_trigger_field::OLD_ROW,
name, SELECT_ACL, tmp_read_only); *name, SELECT_ACL, tmp_read_only);
/* /*
Let us add this item to list of all Item_trigger_field objects Let us add this item to list of all Item_trigger_field objects
in trigger. in trigger.
@ -7163,7 +7161,7 @@ Item *LEX::create_item_for_loop_bound(THD *thd,
Pass NULL as the name resolution context. Pass NULL as the name resolution context.
This is OK, fix_fields() won't be called for this Item_field. This is OK, fix_fields() won't be called for this Item_field.
*/ */
return new (thd->mem_root) Item_field(thd, NULL, a->str, b->str, c); return new (thd->mem_root) Item_field(thd, NULL, *a, *b, *c);
} }
@ -7201,7 +7199,7 @@ Item *LEX::create_item_ident_nospvar(THD *thd,
if (current_select->parsing_place == FOR_LOOP_BOUND) if (current_select->parsing_place == FOR_LOOP_BOUND)
return create_item_for_loop_bound(thd, &null_clex_str, a, b); return create_item_for_loop_bound(thd, &null_clex_str, a, b);
return create_item_ident_field(thd, NullS, a->str, b); return create_item_ident_field(thd, Lex_ident_sys(), *a, *b);
} }
@ -7393,9 +7391,8 @@ Item *LEX::create_item_ident(THD *thd,
const Lex_ident_sys_st *b, const Lex_ident_sys_st *b,
const Lex_ident_sys_st *c) const Lex_ident_sys_st *c)
{ {
const char *schema= (thd->client_capabilities & CLIENT_NO_SCHEMA ? Lex_ident_sys_st schema= thd->client_capabilities & CLIENT_NO_SCHEMA ?
NullS : a->str); Lex_ident_sys() : *a;
if ((thd->variables.sql_mode & MODE_ORACLE) && c->length == 7) if ((thd->variables.sql_mode & MODE_ORACLE) && c->length == 7)
{ {
if (!my_strnncoll(system_charset_info, if (!my_strnncoll(system_charset_info,
@ -7417,7 +7414,7 @@ Item *LEX::create_item_ident(THD *thd,
if (current_select->parsing_place == FOR_LOOP_BOUND) if (current_select->parsing_place == FOR_LOOP_BOUND)
return create_item_for_loop_bound(thd, &null_clex_str, b, c); return create_item_for_loop_bound(thd, &null_clex_str, b, c);
return create_item_ident_field(thd, schema, b->str, c); return create_item_ident_field(thd, schema, *b, *c);
} }
@ -7503,11 +7500,12 @@ bool LEX::set_user_variable(THD *thd, const LEX_CSTRING *name, Item *val)
} }
Item *LEX::create_item_ident_field(THD *thd, const char *db, Item *LEX::create_item_ident_field(THD *thd,
const char *table, const Lex_ident_sys_st &db,
const Lex_ident_sys_st *name) const Lex_ident_sys_st &table,
const Lex_ident_sys_st &name)
{ {
if (check_expr_allows_fields_or_error(thd, name->str)) if (check_expr_allows_fields_or_error(thd, name.str))
return NULL; return NULL;
if (current_select->parsing_place != IN_HAVING || if (current_select->parsing_place != IN_HAVING ||
@ -8487,9 +8485,9 @@ bool SELECT_LEX::vers_push_field(THD *thd, TABLE_LIST *table,
{ {
DBUG_ASSERT(field_name.str); DBUG_ASSERT(field_name.str);
Item_field *fld= new (thd->mem_root) Item_field(thd, &context, Item_field *fld= new (thd->mem_root) Item_field(thd, &context,
table->db.str, table->db,
table->alias.str, table->alias,
&field_name); field_name);
if (unlikely(!fld) || unlikely(item_list.push_back(fld))) if (unlikely(!fld) || unlikely(item_list.push_back(fld)))
return true; return true;
@ -8607,8 +8605,8 @@ Item *LEX::create_item_qualified_asterisk(THD *thd,
{ {
Item *item; Item *item;
if (!(item= new (thd->mem_root) Item_field(thd, current_context(), if (!(item= new (thd->mem_root) Item_field(thd, current_context(),
NullS, name->str, null_clex_str, *name,
&star_clex_str))) star_clex_str)))
return NULL; return NULL;
current_select->with_wild++; current_select->with_wild++;
return item; return item;
@ -8620,11 +8618,10 @@ Item *LEX::create_item_qualified_asterisk(THD *thd,
const Lex_ident_sys_st *b) const Lex_ident_sys_st *b)
{ {
Item *item; Item *item;
const char* schema= thd->client_capabilities & CLIENT_NO_SCHEMA ? Lex_ident_sys_st schema= thd->client_capabilities & CLIENT_NO_SCHEMA ?
NullS : a->str; Lex_ident_sys() : *a;
if (!(item= new (thd->mem_root) Item_field(thd, current_context(), if (!(item= new (thd->mem_root) Item_field(thd, current_context(),
schema, b->str, schema, *b, star_clex_str)))
&star_clex_str)))
return NULL; return NULL;
current_select->with_wild++; current_select->with_wild++;
return item; return item;

View File

@ -3826,11 +3826,13 @@ public:
return create_item_qualified_asterisk(thd, &a, &b); return create_item_qualified_asterisk(thd, &a, &b);
} }
Item *create_item_ident_field(THD *thd, const char *db, const char *table, Item *create_item_ident_field(THD *thd,
const Lex_ident_sys_st *name); const Lex_ident_sys_st &db,
const Lex_ident_sys_st &table,
const Lex_ident_sys_st &name);
Item *create_item_ident_nosp(THD *thd, Lex_ident_sys_st *name) Item *create_item_ident_nosp(THD *thd, Lex_ident_sys_st *name)
{ {
return create_item_ident_field(thd, NullS, NullS, name); return create_item_ident_field(thd, Lex_ident_sys(), Lex_ident_sys(), *name);
} }
Item *create_item_ident_sp(THD *thd, Lex_ident_sys_st *name, Item *create_item_ident_sp(THD *thd, Lex_ident_sys_st *name,
const char *start, const char *end); const char *start, const char *end);

View File

@ -119,10 +119,8 @@ int make_profile_table_for_show(THD *thd, ST_SCHEMA_TABLE *schema_table)
continue; continue;
field_info= &schema_table->fields_info[i]; field_info= &schema_table->fields_info[i];
LEX_CSTRING field_name= {field_info->field_name,
strlen(field_info->field_name) };
Item_field *field= new (thd->mem_root) Item_field(thd, context, Item_field *field= new (thd->mem_root) Item_field(thd, context,
NullS, NullS, &field_name); Lex_cstring_strlen(field_info->field_name));
if (field) if (field)
{ {
field->set_name(thd, field_info->get_old_name()); field->set_name(thd, field_info->get_old_name());

View File

@ -565,9 +565,9 @@ fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
new_ref= direct_ref ? new_ref= direct_ref ?
new (thd->mem_root) Item_direct_ref(thd, ref->context, item_ref, ref->table_name, new (thd->mem_root) Item_direct_ref(thd, ref->context, item_ref, ref->table_name,
&ref->field_name, ref->alias_name_used) : ref->field_name, ref->alias_name_used) :
new (thd->mem_root) Item_ref(thd, ref->context, item_ref, ref->table_name, new (thd->mem_root) Item_ref(thd, ref->context, item_ref, ref->table_name,
&ref->field_name, ref->alias_name_used); ref->field_name, ref->alias_name_used);
if (!new_ref) if (!new_ref)
return TRUE; return TRUE;
ref->outer_ref= new_ref; ref->outer_ref= new_ref;
@ -773,11 +773,11 @@ Item* period_get_condition(THD *thd, TABLE_LIST *table, SELECT_LEX *select,
const LEX_CSTRING &fend= period->end_field(share)->field_name; const LEX_CSTRING &fend= period->end_field(share)->field_name;
conds->field_start= newx Item_field(thd, &select->context, conds->field_start= newx Item_field(thd, &select->context,
table->db.str, table->alias.str, table->db, table->alias,
thd->make_clex_string(fstart)); thd->strmake_lex_cstring(fstart));
conds->field_end= newx Item_field(thd, &select->context, conds->field_end= newx Item_field(thd, &select->context,
table->db.str, table->alias.str, table->db, table->alias,
thd->make_clex_string(fend)); thd->strmake_lex_cstring(fend));
Item *cond1= NULL, *cond2= NULL, *cond3= NULL, *curr= NULL; Item *cond1= NULL, *cond2= NULL, *cond3= NULL, *curr= NULL;
if (timestamp) if (timestamp)
@ -25349,8 +25349,9 @@ static bool change_group_ref(THD *thd, Item_func *expr, ORDER *group_list,
{ {
Item *new_item; Item *new_item;
if (!(new_item= new (thd->mem_root) Item_ref(thd, context, if (!(new_item= new (thd->mem_root) Item_ref(thd, context,
group_tmp->item, 0, group_tmp->item,
&item->name))) null_clex_str,
item->name)))
return 1; // fatal_error is set return 1; // fatal_error is set
thd->change_item_tree(arg, new_item); thd->change_item_tree(arg, new_item);
arg_changed= TRUE; arg_changed= TRUE;

View File

@ -8239,7 +8239,7 @@ static int make_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
{ {
LEX_CSTRING field_name= field_info->get_name(); LEX_CSTRING field_name= field_info->get_name();
Item_field *field= new (thd->mem_root) Item_field *field= new (thd->mem_root)
Item_field(thd, context, NullS, NullS, &field_name); Item_field(thd, context, field_name);
if (field) if (field)
{ {
field->set_name(thd, field_info->get_old_name()); field->set_name(thd, field_info->get_old_name());
@ -8263,9 +8263,8 @@ int make_schemata_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
{ {
ST_FIELD_INFO *field_info= &schema_table->fields_info[1]; ST_FIELD_INFO *field_info= &schema_table->fields_info[1];
String buffer(tmp,sizeof(tmp), system_charset_info); String buffer(tmp,sizeof(tmp), system_charset_info);
LEX_CSTRING field_name= field_info->get_name();
Item_field *field= new (thd->mem_root) Item_field(thd, context, Item_field *field= new (thd->mem_root) Item_field(thd, context,
NullS, NullS, &field_name); field_info->get_name());
if (!field || add_item_to_list(thd, field)) if (!field || add_item_to_list(thd, field))
return 1; return 1;
buffer.length(0); buffer.length(0);
@ -8289,8 +8288,7 @@ int make_table_names_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
LEX *lex= thd->lex; LEX *lex= thd->lex;
Name_resolution_context *context= &lex->first_select_lex()->context; Name_resolution_context *context= &lex->first_select_lex()->context;
ST_FIELD_INFO *field_info= &schema_table->fields_info[2]; ST_FIELD_INFO *field_info= &schema_table->fields_info[2];
LEX_CSTRING field_name= {field_info->field_name, LEX_CSTRING field_name= Lex_cstring_strlen(field_info->field_name);
strlen(field_info->field_name) };
buffer.length(0); buffer.length(0);
buffer.append(field_info->get_old_name()); buffer.append(field_info->get_old_name());
@ -8301,18 +8299,15 @@ int make_table_names_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
buffer.append(lex->wild->ptr()); buffer.append(lex->wild->ptr());
buffer.append(')'); buffer.append(')');
} }
Item_field *field= new (thd->mem_root) Item_field(thd, context, Item_field *field= new (thd->mem_root) Item_field(thd, context, field_name);
NullS, NullS, &field_name);
if (add_item_to_list(thd, field)) if (add_item_to_list(thd, field))
return 1; return 1;
field->set_name(thd, buffer.lex_cstring()); field->set_name(thd, buffer.lex_cstring());
if (thd->lex->verbose) if (thd->lex->verbose)
{ {
field_info= &schema_table->fields_info[3]; field_info= &schema_table->fields_info[3];
LEX_CSTRING field_name2= {field_info->field_name, field= new (thd->mem_root) Item_field(thd, context,
strlen(field_info->field_name) }; Lex_cstring_strlen(field_info->field_name));
field= new (thd->mem_root) Item_field(thd, context, NullS, NullS,
&field_name2);
if (add_item_to_list(thd, field)) if (add_item_to_list(thd, field))
return 1; return 1;
field->set_name(thd, field_info->get_old_name()); field->set_name(thd, field_info->get_old_name());
@ -8331,14 +8326,12 @@ int make_columns_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
for (; *field_num >= 0; field_num++) for (; *field_num >= 0; field_num++)
{ {
field_info= &schema_table->fields_info[*field_num]; field_info= &schema_table->fields_info[*field_num];
LEX_CSTRING field_name= {field_info->field_name,
strlen(field_info->field_name)};
if (!thd->lex->verbose && (*field_num == 14 || if (!thd->lex->verbose && (*field_num == 14 ||
*field_num == 18 || *field_num == 18 ||
*field_num == 19)) *field_num == 19))
continue; continue;
Item_field *field= new (thd->mem_root) Item_field(thd, context, Item_field *field= new (thd->mem_root) Item_field(thd, context,
NullS, NullS, &field_name); Lex_cstring_strlen(field_info->field_name));
if (field) if (field)
{ {
field->set_name(thd, field_info->get_old_name()); field->set_name(thd, field_info->get_old_name());
@ -8360,10 +8353,8 @@ int make_character_sets_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
for (; *field_num >= 0; field_num++) for (; *field_num >= 0; field_num++)
{ {
field_info= &schema_table->fields_info[*field_num]; field_info= &schema_table->fields_info[*field_num];
LEX_CSTRING field_name= {field_info->field_name,
strlen(field_info->field_name)};
Item_field *field= new (thd->mem_root) Item_field(thd, context, Item_field *field= new (thd->mem_root) Item_field(thd, context,
NullS, NullS, &field_name); Lex_cstring_strlen(field_info->field_name));
if (field) if (field)
{ {
field->set_name(thd, field_info->get_old_name()); field->set_name(thd, field_info->get_old_name());
@ -8385,10 +8376,8 @@ int make_proc_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
for (; *field_num >= 0; field_num++) for (; *field_num >= 0; field_num++)
{ {
field_info= &schema_table->fields_info[*field_num]; field_info= &schema_table->fields_info[*field_num];
LEX_CSTRING field_name= {field_info->field_name,
strlen(field_info->field_name)};
Item_field *field= new (thd->mem_root) Item_field(thd, context, Item_field *field= new (thd->mem_root) Item_field(thd, context,
NullS, NullS, &field_name); Lex_cstring_strlen(field_info->field_name));
if (field) if (field)
{ {
field->set_name(thd, field_info->get_old_name()); field->set_name(thd, field_info->get_old_name());
@ -9986,7 +9975,7 @@ static bool show_create_trigger_impl(THD *thd, Trigger *trigger)
Item_datetime_literal *tmp= (new (mem_root) Item_datetime_literal *tmp= (new (mem_root)
Item_datetime_literal(thd, &zero_time, 2)); Item_datetime_literal(thd, &zero_time, 2));
tmp->set_name(thd, Lex_cstring("Created")); tmp->set_name(thd, Lex_cstring(STRING_WITH_LEN("Created")));
fields.push_back(tmp, mem_root); fields.push_back(tmp, mem_root);
if (p->send_result_set_metadata(&fields, if (p->send_result_set_metadata(&fields,

View File

@ -647,7 +647,7 @@ st_select_lex *wrap_tvc(THD *thd, st_select_lex *tvc_sl,
wrapper_sl->set_linkage(tvc_sl->get_linkage()); wrapper_sl->set_linkage(tvc_sl->get_linkage());
wrapper_sl->parsing_place= SELECT_LIST; wrapper_sl->parsing_place= SELECT_LIST;
item= new (thd->mem_root) Item_field(thd, &wrapper_sl->context, item= new (thd->mem_root) Item_field(thd, &wrapper_sl->context,
NULL, NULL, &star_clex_str); star_clex_str);
if (item == NULL || add_item_to_list(thd, item)) if (item == NULL || add_item_to_list(thd, item))
goto err; goto err;
(wrapper_sl->with_wild)++; (wrapper_sl->with_wild)++;
@ -861,7 +861,7 @@ Item *Item_func_in::in_predicate_to_in_subs_transformer(THD *thd,
sq_select= lex->current_select; sq_select= lex->current_select;
sq_select->parsing_place= SELECT_LIST; sq_select->parsing_place= SELECT_LIST;
item= new (thd->mem_root) Item_field(thd, &sq_select->context, item= new (thd->mem_root) Item_field(thd, &sq_select->context,
NULL, NULL, &star_clex_str); star_clex_str);
if (item == NULL || add_item_to_list(thd, item)) if (item == NULL || add_item_to_list(thd, item))
goto err; goto err;
(sq_select->with_wild)++; (sq_select->with_wild)++;

View File

@ -3444,7 +3444,7 @@ Field *Type_handler_float::make_schema_field(TABLE *table,
const ST_FIELD_INFO &def, const ST_FIELD_INFO &def,
bool show_field) const bool show_field) const
{ {
Lex_cstring name(def.field_name); Lex_cstring_strlen name(def.field_name);
return new (table->in_use->mem_root) return new (table->in_use->mem_root)
Field_float(addr.ptr(), def.field_length, Field_float(addr.ptr(), def.field_length,
addr.null_ptr(), addr.null_bit(), addr.null_ptr(), addr.null_bit(),
@ -3459,7 +3459,7 @@ Field *Type_handler_double::make_schema_field(TABLE *table,
const ST_FIELD_INFO &def, const ST_FIELD_INFO &def,
bool show_field) const bool show_field) const
{ {
Lex_cstring name(def.field_name); Lex_cstring_strlen name(def.field_name);
return new (table->in_use->mem_root) return new (table->in_use->mem_root)
Field_double(addr.ptr(), def.field_length, Field_double(addr.ptr(), def.field_length,
addr.null_ptr(), addr.null_bit(), addr.null_ptr(), addr.null_bit(),
@ -3474,7 +3474,7 @@ Field *Type_handler_decimal_result::make_schema_field(TABLE *table,
const ST_FIELD_INFO &def, const ST_FIELD_INFO &def,
bool show_field) const bool show_field) const
{ {
Lex_cstring name(def.field_name); Lex_cstring_strlen name(def.field_name);
uint dec= def.field_length % 10; uint dec= def.field_length % 10;
uint prec= (def.field_length / 100) % 100; uint prec= (def.field_length / 100) % 100;
DBUG_ASSERT(dec <= DECIMAL_MAX_SCALE); DBUG_ASSERT(dec <= DECIMAL_MAX_SCALE);
@ -3491,7 +3491,7 @@ Field *Type_handler_blob_common::make_schema_field(TABLE *table,
const ST_FIELD_INFO &def, const ST_FIELD_INFO &def,
bool show_field) const bool show_field) const
{ {
Lex_cstring name(def.field_name); Lex_cstring_strlen name(def.field_name);
if (show_field) if (show_field)
{ {
return new (table->in_use->mem_root) return new (table->in_use->mem_root)
@ -3512,7 +3512,7 @@ Field *Type_handler_string::make_schema_field(TABLE *table,
bool show_field) const bool show_field) const
{ {
DBUG_ASSERT(def.field_length); DBUG_ASSERT(def.field_length);
Lex_cstring name(def.field_name); Lex_cstring_strlen name(def.field_name);
uint32 octet_length= (uint32) def.field_length * 3; uint32 octet_length= (uint32) def.field_length * 3;
if (def.field_length * 3 > MAX_FIELD_VARCHARLENGTH) if (def.field_length * 3 > MAX_FIELD_VARCHARLENGTH)
{ {
@ -3543,7 +3543,7 @@ Field *Type_handler_tiny::make_schema_field(TABLE *table,
const ST_FIELD_INFO &def, const ST_FIELD_INFO &def,
bool show_field) const bool show_field) const
{ {
Lex_cstring name(def.field_name); Lex_cstring_strlen name(def.field_name);
return new (table->in_use->mem_root) return new (table->in_use->mem_root)
Field_tiny(addr.ptr(), def.field_length, Field_tiny(addr.ptr(), def.field_length,
addr.null_ptr(), addr.null_bit(), Field::NONE, &name, addr.null_ptr(), addr.null_bit(), Field::NONE, &name,
@ -3556,7 +3556,7 @@ Field *Type_handler_short::make_schema_field(TABLE *table,
const ST_FIELD_INFO &def, const ST_FIELD_INFO &def,
bool show_field) const bool show_field) const
{ {
Lex_cstring name(def.field_name); Lex_cstring_strlen name(def.field_name);
return new (table->in_use->mem_root) return new (table->in_use->mem_root)
Field_short(addr.ptr(), def.field_length, Field_short(addr.ptr(), def.field_length,
addr.null_ptr(), addr.null_bit(), Field::NONE, &name, addr.null_ptr(), addr.null_bit(), Field::NONE, &name,
@ -3569,7 +3569,7 @@ Field *Type_handler_long::make_schema_field(TABLE *table,
const ST_FIELD_INFO &def, const ST_FIELD_INFO &def,
bool show_field) const bool show_field) const
{ {
Lex_cstring name(def.field_name); Lex_cstring_strlen name(def.field_name);
return new (table->in_use->mem_root) return new (table->in_use->mem_root)
Field_long(addr.ptr(), def.field_length, Field_long(addr.ptr(), def.field_length,
addr.null_ptr(), addr.null_bit(), Field::NONE, &name, addr.null_ptr(), addr.null_bit(), Field::NONE, &name,
@ -3582,7 +3582,7 @@ Field *Type_handler_longlong::make_schema_field(TABLE *table,
const ST_FIELD_INFO &def, const ST_FIELD_INFO &def,
bool show_field) const bool show_field) const
{ {
Lex_cstring name(def.field_name); Lex_cstring_strlen name(def.field_name);
return new (table->in_use->mem_root) return new (table->in_use->mem_root)
Field_longlong(addr.ptr(), def.field_length, Field_longlong(addr.ptr(), def.field_length,
addr.null_ptr(), addr.null_bit(), Field::NONE, &name, addr.null_ptr(), addr.null_bit(), Field::NONE, &name,
@ -3595,7 +3595,7 @@ Field *Type_handler_date_common::make_schema_field(TABLE *table,
const ST_FIELD_INFO &def, const ST_FIELD_INFO &def,
bool show_field) const bool show_field) const
{ {
Lex_cstring name(def.field_name); Lex_cstring_strlen name(def.field_name);
return new (table->in_use->mem_root) return new (table->in_use->mem_root)
Field_newdate(addr.ptr(), addr.null_ptr(), addr.null_bit(), Field_newdate(addr.ptr(), addr.null_ptr(), addr.null_bit(),
Field::NONE, &name); Field::NONE, &name);
@ -3607,7 +3607,7 @@ Field *Type_handler_time_common::make_schema_field(TABLE *table,
const ST_FIELD_INFO &def, const ST_FIELD_INFO &def,
bool show_field) const bool show_field) const
{ {
Lex_cstring name(def.field_name); Lex_cstring_strlen name(def.field_name);
return new_Field_time(table->in_use->mem_root, return new_Field_time(table->in_use->mem_root,
addr.ptr(), addr.null_ptr(), addr.null_bit(), addr.ptr(), addr.null_ptr(), addr.null_bit(),
Field::NONE, &name, def.fsp()); Field::NONE, &name, def.fsp());
@ -3619,7 +3619,7 @@ Field *Type_handler_datetime_common::make_schema_field(TABLE *table,
const ST_FIELD_INFO &def, const ST_FIELD_INFO &def,
bool show_field) const bool show_field) const
{ {
Lex_cstring name(def.field_name); Lex_cstring_strlen name(def.field_name);
return new_Field_datetime(table->in_use->mem_root, return new_Field_datetime(table->in_use->mem_root,
addr.ptr(), addr.null_ptr(), addr.null_bit(), addr.ptr(), addr.null_ptr(), addr.null_bit(),
Field::NONE, &name, def.fsp()); Field::NONE, &name, def.fsp());

View File

@ -35,8 +35,10 @@ Type_handler_json_longtext::make_json_valid_expr(THD *thd,
Lex_ident_sys_st str; Lex_ident_sys_st str;
Item *field, *expr; Item *field, *expr;
str.set_valid_utf8(field_name); str.set_valid_utf8(field_name);
if (unlikely(!(field= thd->lex->create_item_ident_field(thd, NullS, NullS, if (unlikely(!(field= thd->lex->create_item_ident_field(thd,
&str)))) Lex_ident_sys(),
Lex_ident_sys(),
str))))
return 0; return 0;
if (unlikely(!(expr= new (thd->mem_root) Item_func_json_valid(thd, field)))) if (unlikely(!(expr= new (thd->mem_root) Item_func_json_valid(thd, field))))
return 0; return 0;

View File

@ -299,7 +299,7 @@ LEX::set_system_variable(enum enum_var_type var_type,
sphead->m_flags|= sp_head::HAS_SET_AUTOCOMMIT_STMT; sphead->m_flags|= sp_head::HAS_SET_AUTOCOMMIT_STMT;
if (val && val->type() == Item::FIELD_ITEM && if (val && val->type() == Item::FIELD_ITEM &&
((Item_field*)val)->table_name) ((Item_field*)val)->table_name.str)
{ {
my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), sysvar->name.str); my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), sysvar->name.str);
return TRUE; return TRUE;
@ -339,7 +339,7 @@ bool LEX::set_trigger_new_row(const LEX_CSTRING *name, Item *val)
trg_fld= new (thd->mem_root) trg_fld= new (thd->mem_root)
Item_trigger_field(thd, current_context(), Item_trigger_field(thd, current_context(),
Item_trigger_field::NEW_ROW, Item_trigger_field::NEW_ROW,
name, UPDATE_ACL, FALSE); *name, UPDATE_ACL, FALSE);
if (unlikely(trg_fld == NULL)) if (unlikely(trg_fld == NULL))
return TRUE; return TRUE;
@ -9543,7 +9543,7 @@ select_item_list:
{ {
Item *item= new (thd->mem_root) Item *item= new (thd->mem_root)
Item_field(thd, &thd->lex->current_select->context, Item_field(thd, &thd->lex->current_select->context,
NULL, NULL, &star_clex_str); star_clex_str);
if (unlikely(item == NULL)) if (unlikely(item == NULL))
MYSQL_YYABORT; MYSQL_YYABORT;
if (unlikely(add_item_to_list(thd, item))) if (unlikely(add_item_to_list(thd, item)))
@ -12918,7 +12918,7 @@ procedure_clause:
lex->proc_list.next= &lex->proc_list.first; lex->proc_list.next= &lex->proc_list.first;
Item_field *item= new (thd->mem_root) Item_field *item= new (thd->mem_root)
Item_field(thd, &lex->current_select->context, Item_field(thd, &lex->current_select->context,
NULL, NULL, &$2); $2);
if (unlikely(item == NULL)) if (unlikely(item == NULL))
MYSQL_YYABORT; MYSQL_YYABORT;
if (unlikely(add_proc_to_list(thd, item))) if (unlikely(add_proc_to_list(thd, item)))

View File

@ -9660,7 +9660,7 @@ select_item_list:
{ {
Item *item= new (thd->mem_root) Item *item= new (thd->mem_root)
Item_field(thd, &thd->lex->current_select->context, Item_field(thd, &thd->lex->current_select->context,
NULL, NULL, &star_clex_str); star_clex_str);
if (unlikely(item == NULL)) if (unlikely(item == NULL))
MYSQL_YYABORT; MYSQL_YYABORT;
if (unlikely(add_item_to_list(thd, item))) if (unlikely(add_item_to_list(thd, item)))
@ -13044,7 +13044,7 @@ procedure_clause:
lex->proc_list.next= &lex->proc_list.first; lex->proc_list.next= &lex->proc_list.first;
Item_field *item= new (thd->mem_root) Item_field *item= new (thd->mem_root)
Item_field(thd, &lex->current_select->context, Item_field(thd, &lex->current_select->context,
NULL, NULL, &$2); $2);
if (unlikely(item == NULL)) if (unlikely(item == NULL))
MYSQL_YYABORT; MYSQL_YYABORT;
if (unlikely(add_proc_to_list(thd, item))) if (unlikely(add_proc_to_list(thd, item)))

View File

@ -6388,8 +6388,8 @@ Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
&view->view->first_select_lex()->context: &view->view->first_select_lex()->context:
&thd->lex->first_select_lex()->context); &thd->lex->first_select_lex()->context);
Item *item= (new (thd->mem_root) Item *item= (new (thd->mem_root)
Item_direct_view_ref(thd, context, field_ref, view->alias.str, Item_direct_view_ref(thd, context, field_ref, view->alias,
name, view)); *name, view));
if (!item) if (!item)
return NULL; return NULL;
/* /*

View File

@ -53,11 +53,6 @@ class Lex_cstring : public LEX_CSTRING
str= NULL; str= NULL;
length= 0; length= 0;
} }
Lex_cstring(const char *_str)
{
str= _str;
length= strlen(_str);
}
Lex_cstring(const char *_str, size_t _len) Lex_cstring(const char *_str, size_t _len)
{ {
str= _str; str= _str;
@ -76,6 +71,16 @@ class Lex_cstring : public LEX_CSTRING
} }
}; };
class Lex_cstring_strlen: public Lex_cstring
{
public:
Lex_cstring_strlen(const char *from)
:Lex_cstring(from, from ? strlen(from) : 0)
{ }
};
template <class Compare> template <class Compare>
struct Lex_cstring_with_compare : public Lex_cstring struct Lex_cstring_with_compare : public Lex_cstring
{ {

View File

@ -9137,7 +9137,7 @@ int spider_db_open_item_ref(
if ( if (
(*(item_ref->ref))->type() != Item::CACHE_ITEM && (*(item_ref->ref))->type() != Item::CACHE_ITEM &&
item_ref->ref_type() != Item_ref::VIEW_REF && item_ref->ref_type() != Item_ref::VIEW_REF &&
!item_ref->table_name && !item_ref->table_name.str &&
item_ref->name.str && item_ref->name.str &&
item_ref->alias_name_used item_ref->alias_name_used
) )