Commit f312ef9b authored by Nikita Malyavin's avatar Nikita Malyavin

further suggestions on optimizing opening tables

parent 5a3d78d8
...@@ -704,6 +704,7 @@ class MDL_ticket : public MDL_wait_for_subgraph, public ilist_node<> ...@@ -704,6 +704,7 @@ class MDL_ticket : public MDL_wait_for_subgraph, public ilist_node<>
*/ */
MDL_ticket *next_in_context; MDL_ticket *next_in_context;
MDL_ticket **prev_in_context; MDL_ticket **prev_in_context;
TABLE *object;
public: public:
#ifdef WITH_WSREP #ifdef WITH_WSREP
void wsrep_report(bool debug) const; void wsrep_report(bool debug) const;
...@@ -1093,7 +1094,7 @@ class MDL_context ...@@ -1093,7 +1094,7 @@ class MDL_context
bool try_acquire_lock_impl(MDL_request *mdl_request, bool try_acquire_lock_impl(MDL_request *mdl_request,
MDL_ticket **out_ticket); MDL_ticket **out_ticket);
bool fix_pins(); bool fix_pins();
public:
/** /**
Ticket hash. Stores only locked tickets. Ticket hash. Stores only locked tickets.
*/ */
......
...@@ -1954,11 +1954,15 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx) ...@@ -1954,11 +1954,15 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
! (flags & MYSQL_OPEN_GET_NEW_TABLE)) ! (flags & MYSQL_OPEN_GET_NEW_TABLE))
{ // Using table locks { // Using table locks
TABLE *best_table= 0; TABLE *best_table= 0;
int best_distance= INT_MIN;
for (table=thd->open_tables; table ; table=table->next) thd->mdl_context.ticket_hash.find(table_list->mdl_request.key,
[thd, &best_table, alias, key, key_length, table_list]
(const MDL_ticket *t)
{ {
if (table->s->table_cache_key.length == key_length && TABLE *table= t->object;
!memcmp(table->s->table_cache_key.str, key, key_length)) int best_distance= INT_MIN;
if (!memcmp(t->get_key()->ptr(), key, key_length))
{ {
if (!my_strcasecmp(system_charset_info, table->alias.c_ptr(), alias) && if (!my_strcasecmp(system_charset_info, table->alias.c_ptr(), alias) &&
table->query_id != thd->query_id && /* skip tables already used */ table->query_id != thd->query_id && /* skip tables already used */
...@@ -1993,12 +1997,13 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx) ...@@ -1993,12 +1997,13 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
between calling statement and SP/trigger is done in between calling statement and SP/trigger is done in
lock_tables(). lock_tables().
*/ */
break; return true;
} }
} }
} }
} }
} return false;
});
if (best_table) if (best_table)
{ {
table= best_table; table= best_table;
......
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