Skip to content

Commit

Permalink
MDEV-8010 - Avoid sql_alloc() in Items (Patch #1)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Sergey Vojtovich committed Aug 21, 2015
1 parent 4374da6 commit 31e365e
Show file tree
Hide file tree
Showing 71 changed files with 2,720 additions and 2,470 deletions.
8 changes: 4 additions & 4 deletions plugin/feedback/feedback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions plugin/handler_socket/handlersocket/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions sql/events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 2 additions & 3 deletions sql/field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]
}
Expand Down
2 changes: 1 addition & 1 deletion sql/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -3050,7 +3050,7 @@ class Create_field :public Sql_alloc
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);
Expand Down
18 changes: 11 additions & 7 deletions sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
Loading

0 comments on commit 31e365e

Please sign in to comment.