MDEV-6152: Remove calls to current_thd while creating Item

Part 5: Removing calls to current_thd in net_read calls, creating fields,
        query_cache, acl and some other places where thd was available
This commit is contained in:
Monty 2015-08-31 12:57:46 +03:00
commit 56aa19989f
32 changed files with 396 additions and 309 deletions

View file

@ -502,23 +502,27 @@ Field *Item_sum::create_tmp_field(bool group, TABLE *table,
uint convert_blob_length)
{
Field *UNINIT_VAR(field);
MEM_ROOT *mem_root= table->in_use->mem_root;
switch (result_type()) {
case REAL_RESULT:
field= new Field_double(max_length, maybe_null, name, decimals, TRUE);
field= new (mem_root)
Field_double(max_length, maybe_null, name, decimals, TRUE);
break;
case INT_RESULT:
field= new Field_longlong(max_length, maybe_null, name, unsigned_flag);
field= new (mem_root)
Field_longlong(max_length, maybe_null, name, unsigned_flag);
break;
case STRING_RESULT:
if (max_length/collation.collation->mbmaxlen <= 255 ||
convert_blob_length > Field_varstring::MAX_SIZE ||
!convert_blob_length)
return make_string_field(table);
field= new Field_varstring(convert_blob_length, maybe_null,
name, table->s, collation.collation);
field= new (mem_root) Field_varstring(convert_blob_length, maybe_null,
name, table->s, collation.collation);
break;
case DECIMAL_RESULT:
field= Field_new_decimal::create_from_item(this);
field= Field_new_decimal::create_from_item(mem_root, this);
break;
case ROW_RESULT:
case TIME_RESULT:
@ -1266,33 +1270,37 @@ Field *Item_sum_hybrid::create_tmp_field(bool group, TABLE *table,
uint convert_blob_length)
{
Field *field;
MEM_ROOT *mem_root;
if (args[0]->type() == Item::FIELD_ITEM)
{
field= ((Item_field*) args[0])->field;
if ((field= create_tmp_field_from_field(current_thd, field, name, table,
if ((field= create_tmp_field_from_field(table->in_use, field, name, table,
NULL, convert_blob_length)))
field->flags&= ~NOT_NULL_FLAG;
return field;
}
/*
DATE/TIME fields have STRING_RESULT result types.
In order to preserve field type, it's needed to handle DATE/TIME
fields creations separately.
*/
mem_root= table->in_use->mem_root;
switch (args[0]->field_type()) {
case MYSQL_TYPE_DATE:
field= new Field_newdate(0, maybe_null ? (uchar*)"" : 0, 0, Field::NONE,
name);
field= new (mem_root)
Field_newdate(0, maybe_null ? (uchar*)"" : 0, 0, Field::NONE, name);
break;
case MYSQL_TYPE_TIME:
field= new_Field_time(0, maybe_null ? (uchar*)"" : 0, 0, Field::NONE,
name, decimals);
field= new_Field_time(mem_root, 0, maybe_null ? (uchar*)"" : 0, 0,
Field::NONE, name, decimals);
break;
case MYSQL_TYPE_TIMESTAMP:
case MYSQL_TYPE_DATETIME:
field= new_Field_datetime(0, maybe_null ? (uchar*)"" : 0, 0, Field::NONE,
name, decimals);
field= new_Field_datetime(mem_root, 0, maybe_null ? (uchar*)"" : 0, 0,
Field::NONE, name, decimals);
break;
default:
return Item_sum::create_tmp_field(group, table, convert_blob_length);
@ -1657,6 +1665,8 @@ Field *Item_sum_avg::create_tmp_field(bool group, TABLE *table,
uint convert_blob_len)
{
Field *field;
MEM_ROOT *mem_root= table->in_use->mem_root;
if (group)
{
/*
@ -1664,14 +1674,16 @@ Field *Item_sum_avg::create_tmp_field(bool group, TABLE *table,
The easiest way is to do this is to store both value in a string
and unpack on access.
*/
field= new Field_string(((hybrid_type == DECIMAL_RESULT) ?
dec_bin_size : sizeof(double)) + sizeof(longlong),
0, name, &my_charset_bin);
field= new (mem_root)
Field_string(((hybrid_type == DECIMAL_RESULT) ?
dec_bin_size : sizeof(double)) + sizeof(longlong),
0, name, &my_charset_bin);
}
else if (hybrid_type == DECIMAL_RESULT)
field= Field_new_decimal::create_from_item(this);
field= Field_new_decimal::create_from_item(mem_root, this);
else
field= new Field_double(max_length, maybe_null, name, decimals, TRUE);
field= new (mem_root) Field_double(max_length, maybe_null, name, decimals,
TRUE);
if (field)
field->init(table);
return field;