Commit 31e365ef authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-8010 - Avoid sql_alloc() in Items (Patch #1)

Added mandatory thd parameter to Item (and all derivative classes) constructor.
Added thd parameter to all routines that may create items.
Also removed "current_thd" from Item::Item. This reduced number of
pthread_getspecific() calls from 290 to 177 per OLTP RO transaction.
parent 4374da63
......@@ -99,20 +99,20 @@ static COND* make_cond(THD *thd, TABLE_LIST *tables, LEX_STRING *filter)
nrc.init();
nrc.resolve_in_table_list_only(tables);
res= new Item_cond_or();
res= new Item_cond_or(thd);
if (!res)
return OOM;
for (; filter->str; filter++)
{
Item_field *fld= new Item_field(thd, &nrc, db, table, field);
Item_string *pattern= new Item_string(filter->str, filter->length, cs);
Item_string *escape= new Item_string("\\", 1, cs);
Item_string *pattern= new Item_string(thd, filter->str, filter->length, cs);
Item_string *escape= new Item_string(thd, "\\", 1, cs);
if (!fld || !pattern || !escape)
return OOM;
Item_func_like *like= new Item_func_like(fld, pattern, escape, 0);
Item_func_like *like= new Item_func_like(thd, fld, pattern, escape, 0);
if (!like)
return OOM;
......
......@@ -106,10 +106,10 @@ struct tablevec_entry {
struct expr_user_lock : private noncopyable {
expr_user_lock(THD *thd, int timeout)
: lck_key("handlersocket_wr", 16, &my_charset_latin1),
lck_timeout(timeout),
lck_func_get_lock(&lck_key, &lck_timeout),
lck_func_release_lock(&lck_key)
: lck_key(thd, "handlersocket_wr", 16, &my_charset_latin1),
lck_timeout(thd, timeout),
lck_func_get_lock(thd, &lck_key, &lck_timeout),
lck_func_release_lock(thd, &lck_key)
{
lck_key.fix_fields(thd, 0);
lck_timeout.fix_fields(thd, 0);
......
......@@ -639,29 +639,30 @@ send_show_create_event(THD *thd, Event_timed *et, Protocol *protocol)
if (et->get_create_event(thd, &show_str))
DBUG_RETURN(TRUE);
field_list.push_back(new Item_empty_string("Event", NAME_CHAR_LEN));
field_list.push_back(new Item_empty_string(thd, "Event", NAME_CHAR_LEN));
if (sql_mode_string_representation(thd, et->sql_mode, &sql_mode))
DBUG_RETURN(TRUE);
field_list.push_back(new Item_empty_string("sql_mode", (uint) sql_mode.length));
field_list.push_back(new Item_empty_string(thd, "sql_mode",
(uint) sql_mode.length));
tz_name= et->time_zone->get_name();
field_list.push_back(new Item_empty_string("time_zone",
field_list.push_back(new Item_empty_string(thd, "time_zone",
tz_name->length()));
field_list.push_back(new Item_empty_string("Create Event",
field_list.push_back(new Item_empty_string(thd, "Create Event",
show_str.length()));
field_list.push_back(
new Item_empty_string("character_set_client", MY_CS_NAME_SIZE));
new Item_empty_string(thd, "character_set_client", MY_CS_NAME_SIZE));
field_list.push_back(
new Item_empty_string("collation_connection", MY_CS_NAME_SIZE));
new Item_empty_string(thd, "collation_connection", MY_CS_NAME_SIZE));
field_list.push_back(
new Item_empty_string("Database Collation", MY_CS_NAME_SIZE));
new Item_empty_string(thd, "Database Collation", MY_CS_NAME_SIZE));
if (protocol->send_result_set_metadata(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
......
......@@ -9987,7 +9987,7 @@ Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32 field_length,
/** Create a field suitable for create of table. */
Create_field::Create_field(Field *old_field,Field *orig_field)
Create_field::Create_field(THD *thd, Field *old_field, Field *orig_field)
{
field= old_field;
field_name=change=old_field->field_name;
......@@ -10039,7 +10039,6 @@ Create_field::Create_field(Field *old_field,Field *orig_field)
case MYSQL_TYPE_YEAR:
if (length != 4)
{
THD *thd= current_thd;
char buff[sizeof("YEAR()") + MY_INT64_NUM_DECIMAL_DIGITS + 1];
my_snprintf(buff, sizeof(buff), "YEAR(%lu)", length);
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
......@@ -10098,7 +10097,7 @@ Create_field::Create_field(Field *old_field,Field *orig_field)
StringBuffer<MAX_FIELD_WIDTH> tmp(charset);
String *res= orig_field->val_str(&tmp);
char *pos= (char*) sql_strmake(res->ptr(), res->length());
def= new Item_string(pos, res->length(), charset);
def= new Item_string(thd, pos, res->length(), charset);
}
orig_field->move_field_offset(-diff); // Back to record[0]
}
......
......@@ -3050,7 +3050,7 @@ public:
interval_list.empty();
}
Create_field(Field *field, Field *orig_field);
Create_field(THD *thd, Field *field, Field *orig_field);
/* Used to make a clone of this object for ALTER/CREATE TABLE */
Create_field *clone(MEM_ROOT *mem_root) const;
void create_length_to_internal_length(void);
......
......@@ -1983,10 +1983,14 @@ bool mysql_xa_recover(THD *thd)
Protocol *protocol= thd->protocol;
DBUG_ENTER("mysql_xa_recover");
field_list.push_back(new Item_int("formatID", 0, MY_INT32_NUM_DECIMAL_DIGITS));
field_list.push_back(new Item_int("gtrid_length", 0, MY_INT32_NUM_DECIMAL_DIGITS));
field_list.push_back(new Item_int("bqual_length", 0, MY_INT32_NUM_DECIMAL_DIGITS));
field_list.push_back(new Item_empty_string("data",XIDDATASIZE));
field_list.push_back(new Item_int(thd, "formatID", 0,
MY_INT32_NUM_DECIMAL_DIGITS));
field_list.push_back(new Item_int(thd, "gtrid_length", 0,
MY_INT32_NUM_DECIMAL_DIGITS));
field_list.push_back(new Item_int(thd, "bqual_length", 0,
MY_INT32_NUM_DECIMAL_DIGITS));
field_list.push_back(new Item_empty_string(thd, "data",
XIDDATASIZE));
if (protocol->send_result_set_metadata(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
......@@ -5523,9 +5527,9 @@ bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat)
Protocol *protocol= thd->protocol;
bool result;
field_list.push_back(new Item_empty_string("Type",10));
field_list.push_back(new Item_empty_string("Name",FN_REFLEN));
field_list.push_back(new Item_empty_string("Status",10));
field_list.push_back(new Item_empty_string(thd, "Type", 10));
field_list.push_back(new Item_empty_string(thd, "Name", FN_REFLEN));
field_list.push_back(new Item_empty_string(thd, "Status", 10));
if (protocol->send_result_set_metadata(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -319,11 +319,11 @@ void Item_func::traverse_cond(Cond_traverser traverser,
}
bool Item_args::transform_args(Item_transformer transformer, uchar *arg)
bool Item_args::transform_args(THD *thd, Item_transformer transformer, uchar *arg)
{
for (uint i= 0; i < arg_count; i++)
{
Item *new_item= args[i]->transform(transformer, arg);
Item *new_item= args[i]->transform(thd, transformer, arg);
if (!new_item)
return true;
/*
......@@ -333,7 +333,7 @@ bool Item_args::transform_args(Item_transformer transformer, uchar *arg)
change records at each execution.
*/
if (args[i] != new_item)
current_thd->change_item_tree(&args[i], new_item);
thd->change_item_tree(&args[i], new_item);
}
return false;
}
......@@ -356,12 +356,12 @@ bool Item_args::transform_args(Item_transformer transformer, uchar *arg)
Item returned as the result of transformation of the root node
*/
Item *Item_func::transform(Item_transformer transformer, uchar *argument)
Item *Item_func::transform(THD *thd, Item_transformer transformer, uchar *argument)
{
DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare());
if (transform_args(transformer, argument))
DBUG_ASSERT(!thd->stmt_arena->is_stmt_prepare());
if (transform_args(thd, transformer, argument))
return 0;
return (this->*transformer)(argument);
return (this->*transformer)(thd, argument);
}
......@@ -391,7 +391,7 @@ Item *Item_func::transform(Item_transformer transformer, uchar *argument)
Item returned as the result of transformation of the root node
*/
Item *Item_func::compile(Item_analyzer analyzer, uchar **arg_p,
Item *Item_func::compile(THD *thd, Item_analyzer analyzer, uchar **arg_p,
Item_transformer transformer, uchar *arg_t)
{
if (!(this->*analyzer)(arg_p))
......@@ -406,12 +406,13 @@ Item *Item_func::compile(Item_analyzer analyzer, uchar **arg_p,
to analyze any argument of the condition formula.
*/
uchar *arg_v= *arg_p;
Item *new_item= (*arg)->compile(analyzer, &arg_v, transformer, arg_t);
Item *new_item= (*arg)->compile(thd, analyzer, &arg_v, transformer,
arg_t);
if (new_item && *arg != new_item)
current_thd->change_item_tree(arg, new_item);
thd->change_item_tree(arg, new_item);
}
}
return (this->*transformer)(arg_t);
return (this->*transformer)(thd, arg_t);
}
/**
......@@ -726,7 +727,7 @@ void Item_func::signal_divide_by_null()
Item *Item_func::get_tmp_table_item(THD *thd)
{
if (!with_sum_func && !const_item())
return new Item_field(result_field);
return new Item_field(thd, result_field);
return copy_or_same(thd);
}
......@@ -5533,8 +5534,8 @@ get_var_with_binlog(THD *thd, enum_sql_command sql_command,
LEX *sav_lex= thd->lex, lex_tmp;
thd->lex= &lex_tmp;
lex_start(thd);
tmp_var_list.push_back(new set_var_user(new Item_func_set_user_var(name,
new Item_null())));
tmp_var_list.push_back(new set_var_user(new Item_func_set_user_var(thd, name,
new Item_null(thd))));
/* Create the variable */
if (sql_set_variables(thd, &tmp_var_list, false))
{
......@@ -5698,7 +5699,7 @@ bool Item_func_get_user_var::eq(const Item *item, bool binary_cmp) const
bool Item_func_get_user_var::set_value(THD *thd,
sp_rcontext * /*ctx*/, Item **it)
{
Item_func_set_user_var *suv= new Item_func_set_user_var(get_name(), *it);
Item_func_set_user_var *suv= new Item_func_set_user_var(thd, get_name(), *it);
/*
Item_func_set_user_var is not fixed after construction, call
fix_fields().
......@@ -5779,11 +5780,11 @@ void Item_user_var_as_out_param::print_for_load(THD *thd, String *str)
Item_func_get_system_var::
Item_func_get_system_var(sys_var *var_arg, enum_var_type var_type_arg,
Item_func_get_system_var(THD *thd, sys_var *var_arg, enum_var_type var_type_arg,
LEX_STRING *component_arg, const char *name_arg,
size_t name_len_arg)
:var(var_arg), var_type(var_type_arg), orig_var_type(var_type_arg),
component(*component_arg), cache_present(0)
size_t name_len_arg):
Item_func(thd), var(var_arg), var_type(var_type_arg),
orig_var_type(var_type_arg), component(*component_arg), cache_present(0)
{
/* set_name() will allocate the name */
set_name(name_arg, (uint) name_len_arg, system_charset_info);
......@@ -6095,7 +6096,7 @@ void Item_func_get_system_var::cleanup()
}
void Item_func_match::init_search(bool no_order)
void Item_func_match::init_search(THD *thd, bool no_order)
{
DBUG_ENTER("Item_func_match::init_search");
......@@ -6113,10 +6114,10 @@ void Item_func_match::init_search(bool no_order)
if (key == NO_SUCH_KEY)
{
List<Item> fields;
fields.push_back(new Item_string(" ", 1, cmp_collation.collation));
fields.push_back(new Item_string(thd, " ", 1, cmp_collation.collation));
for (uint i= 1; i < arg_count; i++)
fields.push_back(args[i]);
concat_ws= new Item_func_concat_ws(fields);
concat_ws= new Item_func_concat_ws(thd, fields);
/*
Above function used only to get value and do not need fix_fields for it:
Item_string - basic constant
......@@ -6129,7 +6130,7 @@ void Item_func_match::init_search(bool no_order)
if (master)
{
join_key= master->join_key= join_key | master->join_key;
master->init_search(no_order);
master->init_search(thd, no_order);
ft_handler= master->ft_handler;
join_key= master->join_key;
DBUG_VOID_RETURN;
......@@ -6464,7 +6465,7 @@ Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name,
set_if_smaller(component_name->length, MAX_SYS_VAR_LENGTH);
return new Item_func_get_system_var(var, var_type, component_name,
return new Item_func_get_system_var(thd, var, var_type, component_name,
NULL, 0);
}
......@@ -6480,8 +6481,9 @@ longlong Item_func_row_count::val_int()
Item_func_sp::Item_func_sp(Name_resolution_context *context_arg, sp_name *name)
:Item_func(), context(context_arg), m_name(name), m_sp(NULL), sp_result_field(NULL)
Item_func_sp::Item_func_sp(THD *thd, Name_resolution_context *context_arg,
sp_name *name):
Item_func(thd), context(context_arg), m_name(name), m_sp(NULL), sp_result_field(NULL)
{
maybe_null= 1;
m_name->init_qname(current_thd);
......@@ -6490,10 +6492,10 @@ Item_func_sp::Item_func_sp(Name_resolution_context *context_arg, sp_name *name)
}
Item_func_sp::Item_func_sp(Name_resolution_context *context_arg,
sp_name *name_arg, List<Item> &list)
:Item_func(list), context(context_arg), m_name(name_arg), m_sp(NULL),
sp_result_field(NULL)
Item_func_sp::Item_func_sp(THD *thd, Name_resolution_context *context_arg,
sp_name *name_arg, List<Item> &list):
Item_func(thd, list), context(context_arg), m_name(name_arg), m_sp(NULL),
sp_result_field(NULL)
{
maybe_null= 1;
m_name->init_qname(current_thd);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -146,13 +146,13 @@ void Item_row::print(String *str, enum_query_type query_type)
}
Item *Item_row::transform(Item_transformer transformer, uchar *arg)
Item *Item_row::transform(THD *thd, Item_transformer transformer, uchar *arg)
{
DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare());
DBUG_ASSERT(!thd->stmt_arena->is_stmt_prepare());
if (transform_args(transformer, arg))
if (transform_args(thd, transformer, arg))
return 0;
return (this->*transformer)(arg);
return (this->*transformer)(thd, arg);
}
void Item_row::bring_value()
......
......@@ -35,10 +35,11 @@ class Item_row: public Item,
table_map not_null_tables_cache;
bool with_null;
public:
Item_row(List<Item> &list)
:Item_args(list), not_null_tables_cache(0), with_null(0)
Item_row(THD *thd, List<Item> &list):
Item(thd), Item_args(list), not_null_tables_cache(0), with_null(0)
{ }
Item_row(Item_row *item):
Item_row(THD *thd, Item_row *item):
Item(thd),
Item_args(item),
Used_tables_and_const_cache(item),
not_null_tables_cache(0),
......@@ -95,7 +96,7 @@ public:
return true;
return (this->*processor)(arg);
}
Item *transform(Item_transformer transformer, uchar *arg);
Item *transform(THD *thd, Item_transformer transformer, uchar *arg);
bool eval_not_null_tables(uchar *opt_arg);
uint cols() { return arg_count; }
......
......@@ -4273,9 +4273,9 @@ String *Item_func_uuid::val_str(String *str)
}
Item_func_dyncol_create::Item_func_dyncol_create(List<Item> &args,
DYNCALL_CREATE_DEF *dfs)
: Item_str_func(args), defs(dfs), vals(0), keys_num(NULL), keys_str(NULL),
Item_func_dyncol_create::Item_func_dyncol_create(THD *thd, List<Item> &args,
DYNCALL_CREATE_DEF *dfs):
Item_str_func(thd, args), defs(dfs), vals(0), keys_num(NULL), keys_str(NULL),
names(FALSE), force_names(FALSE)
{
DBUG_ASSERT((args.elements & 0x1) == 0); // even number of arguments
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -76,13 +76,12 @@ protected:
return xml_arg->parse(args[0], cache);
}
public:
Item_xml_str_func(Item *a, Item *b):
Item_str_func(a,b)
Item_xml_str_func(THD *thd, Item *a, Item *b): Item_str_func(thd, a, b)
{
maybe_null= TRUE;
}
Item_xml_str_func(Item *a, Item *b, Item *c):
Item_str_func(a,b,c)
Item_xml_str_func(THD *thd, Item *a, Item *b, Item *c):
Item_str_func(thd, a, b, c)
{
maybe_null= TRUE;
}
......@@ -102,7 +101,8 @@ public:
class Item_func_xml_extractvalue: public Item_xml_str_func
{
public:
Item_func_xml_extractvalue(Item *a,Item *b) :Item_xml_str_func(a,b) {}
Item_func_xml_extractvalue(THD *thd, Item *a, Item *b):
Item_xml_str_func(thd, a, b) {}
const char *func_name() const { return "extractvalue"; }
String *val_str(String *);
};
......@@ -115,7 +115,8 @@ class Item_func_xml_update: public Item_xml_str_func
const MY_XML_NODE *cut,
const String *replace);
public:
Item_func_xml_update(Item *a,Item *b,Item *c) :Item_xml_str_func(a,b,c) {}
Item_func_xml_update(THD *thd, Item *a, Item *b, Item *c):
Item_xml_str_func(thd, a, b, c) {}
const char *func_name() const { return "updatexml"; }
String *val_str(String *);
};
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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