3455 Jon Olav Hauglid 2011-12-19
WL#5534 Online ALTER, Phase 1.
Patch #67: Review changes:
- Make IMPORT/DISCARD tablespace a separate Sql_cmd.
- Remove related code from Alter_info and mysql_alter_table().
- Remove unneeded Alter_info parameter in
Alter_table_prelocking_strategy.
modified:
sql/sql_alter.cc
sql/sql_alter.h
sql/sql_base.h
sql/sql_partition_admin.cc
sql/sql_table.cc
sql/sql_table.h
sql/sql_yacc.yy
3454 Jon Olav Hauglid 2011-12-19
WL#5534 Online ALTER, Phase 1.
Patch #68:
Don't downgrade to MDL_SHARED_UPGRADABLE under LOCK TABLES
mode as this will allow other connections to read/write
the table thus breaking LOCK TABLES. It would also trigger
an assert in MDL_ticket::downgrade_lock().
modified:
sql/sql_table.cc
=== modified file 'sql/sql_alter.cc'
--- a/sql/sql_alter.cc 2011-12-14 18:48:50 +0000
+++ b/sql/sql_alter.cc 2011-12-19 14:38:42 +0000
@@ -27,7 +27,6 @@ Alter_info::Alter_info(const Alter_info
create_list(rhs.create_list, mem_root),
flags(rhs.flags),
keys_onoff(rhs.keys_onoff),
- tablespace_op(rhs.tablespace_op),
partition_names(rhs.partition_names, mem_root),
num_parts(rhs.num_parts),
datetime_field(rhs.datetime_field),
@@ -212,3 +211,50 @@ bool Sql_cmd_alter_table::execute(THD *t
DBUG_RETURN(result);
}
+
+
+bool Sql_cmd_discard_import_tablespace::execute(THD *thd)
+{
+ /* first SELECT_LEX (have special meaning for many of non-SELECTcommands) */
+ SELECT_LEX *select_lex= &thd->lex->select_lex;
+ /* first table of first SELECT_LEX */
+ TABLE_LIST *table_list= (TABLE_LIST*) select_lex->table_list.first;
+
+ if (check_access(thd, ALTER_ACL, table_list->db,
+ &table_list->grant.privilege,
+ &table_list->grant.m_internal,
+ 0, 0))
+ return true;
+
+ if (check_grant(thd, ALTER_ACL, table_list, false, UINT_MAX, false))
+ return true;
+
+ thd->enable_slow_log= opt_log_slow_admin_statements;
+
+ /*
+ Check if we attempt to alter mysql.slow_log or
+ mysql.general_log table and return an error if
+ it is the case.
+ TODO: this design is obsolete and will be removed.
+ */
+ if (table_list && table_list->db && table_list->table_name)
+ {
+ int table_kind= check_if_log_table(table_list->db_length, table_list->db,
+ table_list->table_name_length,
+ table_list->table_name, false);
+
+ if (table_kind)
+ {
+ /* Disable alter of enabled log tables */
+ if (logger.is_log_table_enabled(table_kind))
+ {
+ my_error(ER_BAD_LOG_STATEMENT, MYF(0), "ALTER");
+ return true;
+ }
+ }
+ }
+
+ return
+ mysql_discard_or_import_tablespace(thd, table_list,
+ m_tablespace_op == DISCARD_TABLESPACE);
+}
=== modified file 'sql/sql_alter.h'
--- a/sql/sql_alter.h 2011-12-14 18:48:50 +0000
+++ b/sql/sql_alter.h 2011-12-19 14:38:42 +0000
@@ -126,12 +126,6 @@ public:
enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE };
- enum enum_tablespace_op_type
- {
- NO_TABLESPACE_OP, DISCARD_TABLESPACE, IMPORT_TABLESPACE
- };
-
-
/**
The different values of the ALGORITHM clause.
Describes which algorithm to use when altering the table.
@@ -174,7 +168,6 @@ public:
List<Create_field> create_list;
uint flags;
enum_enable_or_disable keys_onoff;
- enum_tablespace_op_type tablespace_op;
List<char> partition_names;
uint num_parts;
Create_field *datetime_field;
@@ -186,7 +179,6 @@ public:
Alter_info() :
flags(0),
keys_onoff(LEAVE_AS_IS),
- tablespace_op(NO_TABLESPACE_OP),
num_parts(0),
datetime_field(NULL),
error_if_not_empty(FALSE),
@@ -202,7 +194,6 @@ public:
create_list.empty();
flags= 0;
keys_onoff= LEAVE_AS_IS;
- tablespace_op= NO_TABLESPACE_OP;
num_parts= 0;
partition_names.empty();
datetime_field= 0;
@@ -302,4 +293,27 @@ public:
bool execute(THD *thd);
};
+
+/**
+ Sql_cmd_alter_table_tablespace represents ALTER TABLE
+ IMPORT/DISCARD TABLESPACE statements.
+*/
+class Sql_cmd_discard_import_tablespace : public Sql_cmd_common_alter_table
+{
+public:
+ enum enum_tablespace_op_type
+ {
+ DISCARD_TABLESPACE, IMPORT_TABLESPACE
+ };
+
+ Sql_cmd_discard_import_tablespace(enum_tablespace_op_type tablespace_op_arg)
+ : m_tablespace_op(tablespace_op_arg)
+ {}
+
+ bool execute(THD *thd);
+
+private:
+ const enum_tablespace_op_type m_tablespace_op;
+};
+
#endif
=== modified file 'sql/sql_base.h'
--- a/sql/sql_base.h 2011-12-07 11:40:21 +0000
+++ b/sql/sql_base.h 2011-12-19 14:38:42 +0000
@@ -430,11 +430,6 @@ class Lock_tables_prelocking_strategy :
class Alter_table_prelocking_strategy : public Prelocking_strategy
{
public:
-
- Alter_table_prelocking_strategy(Alter_info *alter_info)
- : m_alter_info(alter_info)
- {}
-
virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
Sroutine_hash_entry *rt, sp_head *sp,
bool *need_prelocking);
@@ -442,9 +437,6 @@ public:
TABLE_LIST *table_list, bool *need_prelocking);
virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
TABLE_LIST *table_list, bool *need_prelocking);
-
-private:
- Alter_info *m_alter_info;
};
=== modified file 'sql/sql_partition_admin.cc'
--- a/sql/sql_partition_admin.cc 2011-12-13 10:32:06 +0000
+++ b/sql/sql_partition_admin.cc 2011-12-19 14:38:42 +0000
@@ -476,7 +476,7 @@ bool Sql_cmd_alter_table_exchange_partit
char temp_file_name[FN_REFLEN+1];
uint swap_part_id;
uint part_file_name_len;
- Alter_table_prelocking_strategy alter_prelocking_strategy(alter_info);
+ Alter_table_prelocking_strategy alter_prelocking_strategy;
MDL_ticket *swap_table_mdl_ticket= NULL;
MDL_ticket *part_table_mdl_ticket= NULL;
bool error= TRUE;
=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc 2011-12-19 13:19:36 +0000
+++ b/sql/sql_table.cc 2011-12-19 14:38:42 +0000
@@ -4909,13 +4909,11 @@ err:
/* table_list should contain just one table */
-static int
-mysql_discard_or_import_tablespace(THD *thd,
- TABLE_LIST *table_list,
- Alter_info *alter_info)
+int mysql_discard_or_import_tablespace(THD *thd,
+ TABLE_LIST *table_list,
+ bool discard)
{
- Alter_table_prelocking_strategy alter_prelocking_strategy(alter_info);
- my_bool discard;
+ Alter_table_prelocking_strategy alter_prelocking_strategy;
int error;
DBUG_ENTER("mysql_discard_or_import_tablespace");
@@ -4926,8 +4924,6 @@ mysql_discard_or_import_tablespace(THD *
THD_STAGE_INFO(thd, stage_discard_or_import_tablespace);
- discard= test(alter_info->tablespace_op == Alter_info::DISCARD_TABLESPACE);
-
/*
We set this flag so that ha_innobase::open and ::external_lock() do
not complain when we lock the table
@@ -6660,19 +6656,6 @@ bool mysql_alter_table(THD *thd,char *ne
}
}
- /* DISCARD/IMPORT TABLESPACE is always alone in an ALTER TABLE */
- if (alter_info->tablespace_op != Alter_info::NO_TABLESPACE_OP)
- {
- // ALGORITHM and LOCK clauses are not allowed in the parser.
- DBUG_ASSERT(alter_info->requested_lock ==
- Alter_info::ALTER_TABLE_LOCK_DEFAULT &&
- alter_info->requested_algorithm ==
- Alter_info::ALTER_TABLE_ALGORITHM_DEFAULT);
- /* Conditionally writes to binlog. */
- DBUG_RETURN(mysql_discard_or_import_tablespace(thd,table_list,
- alter_info));
- }
-
THD_STAGE_INFO(thd, stage_init);
/*
@@ -6682,7 +6665,7 @@ bool mysql_alter_table(THD *thd,char *ne
*/
table_list->required_type= FRMTYPE_TABLE;
- Alter_table_prelocking_strategy alter_prelocking_strategy(alter_info);
+ Alter_table_prelocking_strategy alter_prelocking_strategy;
DEBUG_SYNC(thd, "alter_table_before_open_tables");
uint tables_opened;
=== modified file 'sql/sql_table.h'
--- a/sql/sql_table.h 2011-12-13 10:32:06 +0000
+++ b/sql/sql_table.h 2011-12-19 14:38:42 +0000
@@ -157,6 +157,9 @@ bool mysql_create_table_no_lock(THD *thd
bool tmp_table, uint select_field_count,
bool *is_trans,
bool no_ha_table);
+int mysql_discard_or_import_tablespace(THD *thd,
+ TABLE_LIST *table_list,
+ bool discard);
bool mysql_prepare_alter_table(THD *thd, TABLE *table,
HA_CREATE_INFO *create_info,
Alter_info *alter_info);
=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy 2011-12-16 16:40:15 +0000
+++ b/sql/sql_yacc.yy 2011-12-19 14:38:42 +0000
@@ -6765,9 +6765,21 @@ ident_or_empty:
alter_commands:
/* empty */
| DISCARD TABLESPACE
- { Lex->alter_info.tablespace_op= Alter_info::DISCARD_TABLESPACE; }
+ {
+ Lex->m_sql_cmd= new (YYTHD->mem_root)
+ Sql_cmd_discard_import_tablespace(
+ Sql_cmd_discard_import_tablespace::DISCARD_TABLESPACE);
+ if (Lex->m_sql_cmd == NULL)
+ MYSQL_YYABORT;
+ }
| IMPORT TABLESPACE
- { Lex->alter_info.tablespace_op= Alter_info::IMPORT_TABLESPACE; }
+ {
+ Lex->m_sql_cmd= new (YYTHD->mem_root)
+ Sql_cmd_discard_import_tablespace(
+ Sql_cmd_discard_import_tablespace::IMPORT_TABLESPACE);
+ if (Lex->m_sql_cmd == NULL)
+ MYSQL_YYABORT;
+ }
| alter_list
opt_partitioning
| alter_list
No bundle (reason: useless for push emails).
| Thread |
|---|
| • bzr push into mysql-trunk-wl5534 branch (jon.hauglid:3454 to 3455) WL#5534 | Jon Olav Hauglid | 19 Dec |