Skip to content

Commit f136291

Browse files
committed
cleanup: sp_head::add_used_tables_to_table_list()
Use TABLE::init_one_table(), don't duplicate it. Put additional initializations into TABLE::init_one_table_for_prelocking()
1 parent a3614d3 commit f136291

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

sql/sp_head.cc

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4256,7 +4256,7 @@ sp_head::add_used_tables_to_table_list(THD *thd,
42564256
if (stab->temp)
42574257
continue;
42584258

4259-
if (!(tab_buff= (char *)thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST)) *
4259+
if (!(tab_buff= (char *)thd->alloc(ALIGN_SIZE(sizeof(TABLE_LIST)) *
42604260
stab->lock_count)) ||
42614261
!(key_buff= (char*)thd->memdup(stab->qname.str,
42624262
stab->qname.length)))
@@ -4265,32 +4265,11 @@ sp_head::add_used_tables_to_table_list(THD *thd,
42654265
for (uint j= 0; j < stab->lock_count; j++)
42664266
{
42674267
table= (TABLE_LIST *)tab_buff;
4268-
4269-
table->db= key_buff;
4270-
table->db_length= stab->db_length;
4271-
table->table_name= table->db + table->db_length + 1;
4272-
table->table_name_length= stab->table_name_length;
4273-
table->alias= table->table_name + table->table_name_length + 1;
4274-
table->lock_type= stab->lock_type;
4275-
table->cacheable_table= 1;
4276-
table->prelocking_placeholder= 1;
4277-
table->belong_to_view= belong_to_view;
4278-
table->trg_event_map= stab->trg_event_map;
4279-
/*
4280-
Since we don't allow DDL on base tables in prelocked mode it
4281-
is safe to infer the type of metadata lock from the type of
4282-
table lock.
4283-
*/
4284-
table->mdl_request.init(MDL_key::TABLE, table->db, table->table_name,
4285-
table->lock_type >= TL_WRITE_ALLOW_WRITE ?
4286-
MDL_SHARED_WRITE : MDL_SHARED_READ,
4287-
MDL_TRANSACTION);
4288-
4289-
/* Everyting else should be zeroed */
4290-
4291-
**query_tables_last_ptr= table;
4292-
table->prev_global= *query_tables_last_ptr;
4293-
*query_tables_last_ptr= &table->next_global;
4268+
table->init_one_table_for_prelocking(key_buff, stab->db_length,
4269+
key_buff + stab->db_length + 1, stab->table_name_length,
4270+
key_buff + stab->db_length + stab->table_name_length + 2,
4271+
stab->lock_type, belong_to_view, stab->trg_event_map,
4272+
query_tables_last_ptr);
42944273

42954274
tab_buff+= ALIGN_SIZE(sizeof(TABLE_LIST));
42964275
result= TRUE;

sql/table.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,28 @@ struct TABLE_LIST
17571757
MDL_TRANSACTION);
17581758
}
17591759

1760+
inline void init_one_table_for_prelocking(const char *db_name_arg,
1761+
size_t db_length_arg,
1762+
const char *table_name_arg,
1763+
size_t table_name_length_arg,
1764+
const char *alias_arg,
1765+
enum thr_lock_type lock_type_arg,
1766+
TABLE_LIST *belong_to_view_arg,
1767+
uint8 trg_event_map_arg,
1768+
TABLE_LIST ***last_ptr)
1769+
{
1770+
init_one_table(db_name_arg, db_length_arg, table_name_arg,
1771+
table_name_length_arg, alias_arg, lock_type_arg);
1772+
cacheable_table= 1;
1773+
prelocking_placeholder= 1;
1774+
belong_to_view= belong_to_view_arg;
1775+
trg_event_map= trg_event_map_arg;
1776+
1777+
**last_ptr= this;
1778+
prev_global= *last_ptr;
1779+
*last_ptr= &next_global;
1780+
}
1781+
17601782
/*
17611783
List of tables local to a subquery (used by SQL_I_List). Considers
17621784
views as leaves (unlike 'next_leaf' below). Created at parse time

0 commit comments

Comments
 (0)