Skip to content

Commit

Permalink
MDEV-7112 Split HA_CREATE_INFO
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Barkov committed Dec 8, 2014
1 parent b372720 commit c6d3f80
Show file tree
Hide file tree
Showing 23 changed files with 491 additions and 219 deletions.
95 changes: 88 additions & 7 deletions sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,8 @@ enum enum_alter_inplace_result {
#define HA_KEY_BLOB_LENGTH 2

#define HA_LEX_CREATE_TMP_TABLE 1
#define HA_LEX_CREATE_IF_NOT_EXISTS 2
#define HA_LEX_CREATE_TABLE_LIKE 4
#define HA_CREATE_TMP_ALTER 8
#define HA_LEX_CREATE_REPLACE 16

#define HA_MAX_REC_LENGTH 65535

/* Table caching type */
Expand Down Expand Up @@ -1580,9 +1578,41 @@ enum enum_stats_auto_recalc { HA_STATS_AUTO_RECALC_DEFAULT= 0,
HA_STATS_AUTO_RECALC_ON,
HA_STATS_AUTO_RECALC_OFF };

struct HA_CREATE_INFO
/**
A helper struct for schema DDL statements:
CREATE SCHEMA [IF NOT EXISTS] name [ schema_specification... ]
ALTER SCHEMA name [ schema_specification... ]
It stores the "schema_specification" part of the CREATE/ALTER statements and
is passed to mysql_create_db() and mysql_alter_db().
Currently consists only of the schema default character set and collation.
*/
struct Schema_specification_st
{
CHARSET_INFO *default_table_charset;
void init()
{
bzero(this, sizeof(*this));
}
};


/**
A helper struct for table DDL statements, e.g.:
CREATE [OR REPLACE] [TEMPORARY]
TABLE [IF NOT EXISTS] tbl_name table_contents_source;
Represents a combinations of:
1. The scope, i.e. TEMPORARY or not TEMPORARY
2. The "table_contents_source" part of the table DDL statements,
which can be initialized from either of these:
- table_element_list ... // Explicit definition (column and key list)
- LIKE another_table_name ... // Copy structure from another table
- [AS] SELECT ... // Copy structure from a subquery
*/
struct Table_scope_and_contents_source_st
{
CHARSET_INFO *table_charset, *default_table_charset;
CHARSET_INFO *table_charset;
LEX_CUSTRING tabledef_version;
LEX_STRING connect_string;
const char *password, *tablespace;
Expand All @@ -1602,7 +1632,6 @@ struct HA_CREATE_INFO
uint stats_sample_pages;
uint null_bits; /* NULL bits at start of record */
uint options; /* OR of HA_CREATE_ options */
uint org_options; /* original options from query */
uint merge_insert_method;
uint extra_size; /* length of extra data segment */
SQL_I_List<TABLE_LIST> merge_list;
Expand Down Expand Up @@ -1635,7 +1664,11 @@ struct HA_CREATE_INFO
MDL_ticket *mdl_ticket;
bool table_was_deleted;

bool tmp_table() { return options & HA_LEX_CREATE_TMP_TABLE; }
void init()
{
bzero(this, sizeof(*this));
}
bool tmp_table() const { return options & HA_LEX_CREATE_TMP_TABLE; }
void use_default_db_type(THD *thd)
{
db_type= tmp_table() ? ha_default_tmp_handlerton(thd)
Expand All @@ -1644,6 +1677,54 @@ struct HA_CREATE_INFO
};


/**
This struct is passed to handler table routines, e.g. ha_create().
It does not include the "OR REPLACE" and "IF NOT EXISTS" parts, as these
parts are handled on the SQL level and are not needed on the handler level.
*/
struct HA_CREATE_INFO: public Table_scope_and_contents_source_st,
public Schema_specification_st
{
void init()
{
Table_scope_and_contents_source_st::init();
Schema_specification_st::init();
}
};


/**
This struct is passed to mysql_create_table() and similar creation functions,
as well as to show_create_table().
*/
struct Table_specification_st: public HA_CREATE_INFO,
public DDL_options_st
{
// Deep initialization
void init()
{
HA_CREATE_INFO::init();
DDL_options_st::init();
}
void init(DDL_options_st::Options options)
{
HA_CREATE_INFO::init();
DDL_options_st::init(options);
}
/*
Quick initialization, for parser.
Most of the HA_CREATE_INFO is left uninitialized.
It gets fully initialized in sql_yacc.yy, only when the parser
scans a related keyword (e.g. CREATE, ALTER).
*/
void lex_start()
{
HA_CREATE_INFO::options= 0;
DDL_options_st::init();
}
};


/**
In-place alter handler context.
Expand Down
7 changes: 4 additions & 3 deletions sql/log_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3188,13 +3188,13 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
switch (lex->sql_command)
{
case SQLCOM_DROP_TABLE:
use_cache= (lex->drop_temporary && thd->in_multi_stmt_transaction_mode());
use_cache= (lex->tmp_table() && thd->in_multi_stmt_transaction_mode());
break;

case SQLCOM_CREATE_TABLE:
trx_cache= (lex->select_lex.item_list.elements &&
thd->is_current_stmt_binlog_format_row());
use_cache= (lex->create_info.tmp_table() &&
use_cache= (lex->tmp_table() &&
thd->in_multi_stmt_transaction_mode()) || trx_cache;
break;
case SQLCOM_SET_OPTION:
Expand Down Expand Up @@ -4335,7 +4335,8 @@ START SLAVE; . Query: '%s'", expected_error, thd->query());
has already been dropped. To ignore such irrelevant "table does
not exist errors", we silently clear the error if TEMPORARY was used.
*/
if (thd->lex->sql_command == SQLCOM_DROP_TABLE && thd->lex->drop_temporary &&
if (thd->lex->sql_command == SQLCOM_DROP_TABLE &&
thd->lex->tmp_table() &&
thd->is_error() && thd->get_stmt_da()->sql_errno() == ER_BAD_TABLE_ERROR &&
!expected_error)
thd->get_stmt_da()->reset_diagnostics_area();
Expand Down
8 changes: 4 additions & 4 deletions sql/sp_head.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,13 @@ sp_get_flags_for_command(LEX *lex)
flags= sp_head::CONTAINS_DYNAMIC_SQL;
break;
case SQLCOM_CREATE_TABLE:
if (lex->create_info.tmp_table())
if (lex->tmp_table())
flags= 0;
else
flags= sp_head::HAS_COMMIT_OR_ROLLBACK;
break;
case SQLCOM_DROP_TABLE:
if (lex->drop_temporary)
if (lex->tmp_table())
flags= 0;
else
flags= sp_head::HAS_COMMIT_OR_ROLLBACK;
Expand Down Expand Up @@ -4000,7 +4000,7 @@ sp_head::merge_table_list(THD *thd, TABLE_LIST *table, LEX *lex_for_tmp_check)
SP_TABLE *tab;

if (lex_for_tmp_check->sql_command == SQLCOM_DROP_TABLE &&
lex_for_tmp_check->drop_temporary)
lex_for_tmp_check->tmp_table())
return TRUE;

for (uint i= 0 ; i < m_sptabs.records ; i++)
Expand Down Expand Up @@ -4065,7 +4065,7 @@ sp_head::merge_table_list(THD *thd, TABLE_LIST *table, LEX *lex_for_tmp_check)
return FALSE;
if (lex_for_tmp_check->sql_command == SQLCOM_CREATE_TABLE &&
lex_for_tmp_check->query_tables == table &&
lex_for_tmp_check->create_info.tmp_table())
lex_for_tmp_check->tmp_table())
{
tab->temp= TRUE;
tab->qname.length= temp_table_key_length;
Expand Down
27 changes: 16 additions & 11 deletions sql/sql_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3453,7 +3453,8 @@ Open_table_context::recover_from_failed_open()
break;
case OT_DISCOVER:
{
if ((result= lock_table_names(m_thd, m_failed_table, NULL,
if ((result= lock_table_names(m_thd, m_thd->lex->create_info,
m_failed_table, NULL,
get_timeout(), 0)))
break;

Expand Down Expand Up @@ -3484,7 +3485,8 @@ Open_table_context::recover_from_failed_open()
}
case OT_REPAIR:
{
if ((result= lock_table_names(m_thd, m_failed_table, NULL,
if ((result= lock_table_names(m_thd, m_thd->lex->create_info,
m_failed_table, NULL,
get_timeout(), 0)))
break;

Expand Down Expand Up @@ -4132,7 +4134,7 @@ extern "C" uchar *schema_set_get_key(const TABLE_LIST *table, size_t *length,
*/

bool
lock_table_names(THD *thd,
lock_table_names(THD *thd, const DDL_options_st &options,
TABLE_LIST *tables_start, TABLE_LIST *tables_end,
ulong lock_wait_timeout, uint flags)
{
Expand Down Expand Up @@ -4176,8 +4178,8 @@ lock_table_names(THD *thd,
DBUG_RETURN(FALSE);

/* Check if CREATE TABLE without REPLACE was used */
create_table= (thd->lex->sql_command == SQLCOM_CREATE_TABLE &&
!(thd->lex->create_info.options & HA_LEX_CREATE_REPLACE));
create_table= thd->lex->sql_command == SQLCOM_CREATE_TABLE &&
!options.or_replace();

if (!(flags & MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK))
{
Expand Down Expand Up @@ -4231,7 +4233,7 @@ lock_table_names(THD *thd,
*/
if (ha_table_exists(thd, tables_start->db, tables_start->table_name))
{
if (thd->lex->create_info.options & HA_LEX_CREATE_IF_NOT_EXISTS)
if (options.if_not_exists())
{
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
Expand Down Expand Up @@ -4344,8 +4346,9 @@ open_tables_check_upgradable_mdl(THD *thd, TABLE_LIST *tables_start,
@retval TRUE Error, reported.
*/

bool open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags,
Prelocking_strategy *prelocking_strategy)
bool open_tables(THD *thd, const DDL_options_st &options,
TABLE_LIST **start, uint *counter, uint flags,
Prelocking_strategy *prelocking_strategy)
{
/*
We use pointers to "next_global" member in the last processed
Expand Down Expand Up @@ -4434,7 +4437,8 @@ bool open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags,
else
{
TABLE_LIST *table;
if (lock_table_names(thd, *start, thd->lex->first_not_own_table(),
if (lock_table_names(thd, options, *start,
thd->lex->first_not_own_table(),
ot_ctx.get_timeout(), flags))
{
error= TRUE;
Expand Down Expand Up @@ -5117,7 +5121,8 @@ TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type,
@retval TRUE Error
*/

bool open_and_lock_tables(THD *thd, TABLE_LIST *tables,
bool open_and_lock_tables(THD *thd, const DDL_options_st &options,
TABLE_LIST *tables,
bool derived, uint flags,
Prelocking_strategy *prelocking_strategy)
{
Expand All @@ -5126,7 +5131,7 @@ bool open_and_lock_tables(THD *thd, TABLE_LIST *tables,
DBUG_ENTER("open_and_lock_tables");
DBUG_PRINT("enter", ("derived handling: %d", derived));

if (open_tables(thd, &tables, &counter, flags, prelocking_strategy))
if (open_tables(thd, options, &tables, &counter, flags, prelocking_strategy))
goto err;

DBUG_EXECUTE_IF("sleep_open_and_lock_after_open", {
Expand Down
59 changes: 53 additions & 6 deletions sql/sql_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,41 @@ int setup_conds(THD *thd, TABLE_LIST *tables, List<TABLE_LIST> &leaves,
void wrap_ident(THD *thd, Item **conds);
int setup_ftfuncs(SELECT_LEX* select);
int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
bool lock_table_names(THD *thd, TABLE_LIST *table_list,
bool lock_table_names(THD *thd, const DDL_options_st &options,
TABLE_LIST *table_list,
TABLE_LIST *table_list_end, ulong lock_wait_timeout,
uint flags);
bool open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags,
static inline bool
lock_table_names(THD *thd, TABLE_LIST *table_list,
TABLE_LIST *table_list_end, ulong lock_wait_timeout,
uint flags)
{
return lock_table_names(thd, thd->lex->create_info, table_list,
table_list_end, lock_wait_timeout, flags);
}
bool open_tables(THD *thd, const DDL_options_st &options,
TABLE_LIST **tables, uint *counter, uint flags,
Prelocking_strategy *prelocking_strategy);
static inline bool
open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags,
Prelocking_strategy *prelocking_strategy)
{
return open_tables(thd, thd->lex->create_info, tables, counter, flags,
prelocking_strategy);
}
/* open_and_lock_tables with optional derived handling */
bool open_and_lock_tables(THD *thd, TABLE_LIST *tables,
bool open_and_lock_tables(THD *thd, const DDL_options_st &options,
TABLE_LIST *tables,
bool derived, uint flags,
Prelocking_strategy *prelocking_strategy);
static inline bool
open_and_lock_tables(THD *thd, TABLE_LIST *tables,
bool derived, uint flags,
Prelocking_strategy *prelocking_strategy)
{
return open_and_lock_tables(thd, thd->lex->create_info,
tables, derived, flags, prelocking_strategy);
}
/* simple open_and_lock_tables without derived handling for single table */
TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
thr_lock_type lock_type, uint flags,
Expand Down Expand Up @@ -459,12 +485,22 @@ class Alter_table_prelocking_strategy : public Prelocking_strategy
};


inline bool
open_tables(THD *thd, const DDL_options_st &options,
TABLE_LIST **tables, uint *counter, uint flags)
{
DML_prelocking_strategy prelocking_strategy;

return open_tables(thd, options, tables, counter, flags,
&prelocking_strategy);
}
inline bool
open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags)
{
DML_prelocking_strategy prelocking_strategy;

return open_tables(thd, tables, counter, flags, &prelocking_strategy);
return open_tables(thd, thd->lex->create_info, tables, counter, flags,
&prelocking_strategy);
}

inline TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
Expand All @@ -478,12 +514,23 @@ inline TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,


/* open_and_lock_tables with derived handling */
inline bool open_and_lock_tables(THD *thd, TABLE_LIST *tables,
inline bool open_and_lock_tables(THD *thd,
const DDL_options_st &options,
TABLE_LIST *tables,
bool derived, uint flags)
{
DML_prelocking_strategy prelocking_strategy;

return open_and_lock_tables(thd, tables, derived, flags,
return open_and_lock_tables(thd, options, tables, derived, flags,
&prelocking_strategy);
}
inline bool open_and_lock_tables(THD *thd, TABLE_LIST *tables,
bool derived, uint flags)
{
DML_prelocking_strategy prelocking_strategy;

return open_and_lock_tables(thd, thd->lex->create_info,
tables, derived, flags,
&prelocking_strategy);
}

Expand Down
3 changes: 1 addition & 2 deletions sql/sql_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5464,8 +5464,7 @@ int THD::decide_logging_format(TABLE_LIST *tables)
flags_access_some_set |= flags;

if (lex->sql_command != SQLCOM_CREATE_TABLE ||
(lex->sql_command == SQLCOM_CREATE_TABLE &&
lex->create_info.tmp_table()))
(lex->sql_command == SQLCOM_CREATE_TABLE && lex->tmp_table()))
{
my_bool trans= table->table->file->has_transactions();

Expand Down
Loading

0 comments on commit c6d3f80

Please sign in to comment.