MCPcopy Create free account
hub / github.com/MariaDB/server / open_tables

Function open_tables

sql/sql_base.cc:4660–5011  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4658*/
4659
4660bool open_tables(THD *thd, const DDL_options_st &options,
4661 TABLE_LIST **start, uint *counter, uint flags,
4662 Prelocking_strategy *prelocking_strategy)
4663{
4664 /*
4665 We use pointers to "next_global" member in the last processed
4666 TABLE_LIST element and to the "next" member in the last processed
4667 Sroutine_hash_entry element as iterators over, correspondingly,
4668 the table list and stored routines list which stay valid and allow
4669 to continue iteration when new elements are added to the tail of
4670 the lists.
4671 */
4672 TABLE_LIST **table_to_open;
4673 Sroutine_hash_entry **sroutine_to_open;
4674 TABLE_LIST *tables;
4675 Open_table_context ot_ctx(thd, flags);
4676 bool error= FALSE;
4677 bool some_routine_modifies_data= FALSE;
4678 bool has_prelocking_list;
4679 DBUG_ENTER("open_tables");
4680
4681 /* Data access in XA transaction is only allowed when it is active. */
4682 for (TABLE_LIST *table= *start; table; table= table->next_global)
4683 if (!table->schema_table)
4684 {
4685 if (thd->transaction->xid_state.check_has_uncommitted_xa())
4686 DBUG_RETURN(true);
4687 else
4688 break;
4689 }
4690
4691 thd->current_tablenr= 0;
4692 sroutine_to_open= &thd->lex->sroutines_list.first;
4693
4694restart:
4695 /*
4696 Close HANDLER tables which are marked for flush or against which there
4697 are pending exclusive metadata locks. This is needed both in order to
4698 avoid deadlocks and to have a point during statement execution at
4699 which such HANDLERs are closed even if they don't create problems for
4700 the current session (i.e. to avoid having a DDL blocked by HANDLERs
4701 opened for a long time).
4702 */
4703 if (thd->handler_tables_hash.records)
4704 mysql_ha_flush(thd);
4705
4706 has_prelocking_list= thd->lex->requires_prelocking();
4707 table_to_open= start;
4708 *counter= 0;
4709 THD_STAGE_INFO(thd, stage_opening_tables);
4710 prelocking_strategy->reset(thd);
4711
4712 /*
4713 If we are executing LOCK TABLES statement or a DDL statement
4714 (in non-LOCK TABLES mode) we might have to acquire upgradable
4715 semi-exclusive metadata locks (SNW or SNRW) on some of the
4716 tables to be opened.
4717 When executing CREATE TABLE .. If NOT EXISTS .. SELECT, the

Callers 4

open_and_lock_tablesFunction · 0.70
open_tables_for_queryFunction · 0.70

Calls 15

mysql_ha_flushFunction · 0.85
open_and_process_tableFunction · 0.85
close_tables_for_reopenFunction · 0.85
open_and_process_routineFunction · 0.85
read_lock_type_for_tableFunction · 0.85
wsrep_check_modeFunction · 0.85
is_temporary_tableFunction · 0.85
my_errorFunction · 0.85
push_warning_printfFunction · 0.85

Tested by

no test coverage detected