1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

A cleanup for MDEV-10914 ROW data type for stored routine variables

Changing datatypes for:
- Item_spvar_args::m_table
- sp_rcontext::m_var_table
- return value of create_virtual_tmp_table()
from TABLE* to Virtual_tmp_table*

Advantages:
- Stricter data type control
- Removing the duplicate code (a loop with free_blobs)
  from destructors ~sp_rcontext() and ~Item_spvar_args(),
  using "delete m_(var_)table" in both instead.
- Using Virtual_tmp_table::delete makes the code call Field::delete,
  which calls TRASH() for the freed fields,
  which is good for valgrind test runs.
This commit is contained in:
Alexander Barkov
2017-10-03 07:54:22 +04:00
parent 8ae8cd6348
commit fcf631eafb
4 changed files with 19 additions and 14 deletions

View File

@ -89,6 +89,7 @@ public:
const char *dbug_print_item(Item *item); const char *dbug_print_item(Item *item);
class Virtual_tmp_table;
class sp_head; class sp_head;
class Protocol; class Protocol;
struct TABLE_LIST; struct TABLE_LIST;
@ -2093,16 +2094,12 @@ public:
class Item_spvar_args: public Item_args class Item_spvar_args: public Item_args
{ {
TABLE *m_table; Virtual_tmp_table *m_table;
public: public:
Item_spvar_args():Item_args(), m_table(NULL) { } Item_spvar_args():Item_args(), m_table(NULL) { }
~Item_spvar_args(); ~Item_spvar_args();
bool row_create_items(THD *thd, List<Spvar_definition> *list); bool row_create_items(THD *thd, List<Spvar_definition> *list);
Field *get_row_field(uint i) const Field *get_row_field(uint i) const;
{
DBUG_ASSERT(m_table);
return m_table->field[i];
}
}; };

View File

@ -51,9 +51,7 @@ sp_rcontext::sp_rcontext(const sp_pcontext *root_parsing_ctx,
sp_rcontext::~sp_rcontext() sp_rcontext::~sp_rcontext()
{ {
if (m_var_table) delete m_var_table;
free_blobs(m_var_table);
// Leave m_handlers, m_handler_call_stack, m_var_items, m_cstack // Leave m_handlers, m_handler_call_stack, m_var_items, m_cstack
// and m_case_expr_holders untouched. // and m_case_expr_holders untouched.
// They are allocated in mem roots and will be freed accordingly. // They are allocated in mem roots and will be freed accordingly.
@ -375,10 +373,16 @@ bool Item_spvar_args::row_create_items(THD *thd, List<Spvar_definition> *list)
} }
Field *Item_spvar_args::get_row_field(uint i) const
{
DBUG_ASSERT(m_table);
return m_table->field[i];
}
Item_spvar_args::~Item_spvar_args() Item_spvar_args::~Item_spvar_args()
{ {
if (m_table) delete m_table;
free_blobs(m_table);
} }

View File

@ -34,6 +34,7 @@ class sp_instr_cpush;
class Query_arena; class Query_arena;
class sp_head; class sp_head;
class Item_cache; class Item_cache;
class Virtual_tmp_table;
/* /*
@ -365,7 +366,7 @@ private:
const sp_pcontext *m_root_parsing_ctx; const sp_pcontext *m_root_parsing_ctx;
/// Virtual table for storing SP-variables. /// Virtual table for storing SP-variables.
TABLE *m_var_table; Virtual_tmp_table *m_var_table;
/// Collection of Item_field proxies, each of them points to the /// Collection of Item_field proxies, each of them points to the
/// corresponding field in m_var_table. /// corresponding field in m_var_table.

View File

@ -2013,7 +2013,7 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
class Virtual_tmp_table: public TABLE class Virtual_tmp_table: public TABLE
{ {
/** /**
Destruct collected fields. This method is called on errors only, Destruct collected fields. This method can be called on errors,
when we could not make the virtual temporary table completely, when we could not make the virtual temporary table completely,
e.g. when some of the fields could not be created or added. e.g. when some of the fields could not be created or added.
@ -2024,7 +2024,10 @@ class Virtual_tmp_table: public TABLE
void destruct_fields() void destruct_fields()
{ {
for (uint i= 0; i < s->fields; i++) for (uint i= 0; i < s->fields; i++)
{
field[i]->free();
delete field[i]; // to invoke the field destructor delete field[i]; // to invoke the field destructor
}
s->fields= 0; // safety s->fields= 0; // safety
} }
@ -2144,7 +2147,7 @@ public:
TABLE object ready for read and write in case of success TABLE object ready for read and write in case of success
*/ */
inline TABLE * inline Virtual_tmp_table *
create_virtual_tmp_table(THD *thd, List<Spvar_definition> &field_list) create_virtual_tmp_table(THD *thd, List<Spvar_definition> &field_list)
{ {
Virtual_tmp_table *table; Virtual_tmp_table *table;