Skip to content

Commit cec1066

Browse files
author
Havard Dybvik
committed
Bug#28523841: IMPLEMENT SECONDARY_LOAD/SECONDARY_UNLOAD AS STANDALONE SQL COMMANDS
Moves handling of loading into and unloading from secondary engine out of mysql_alter_table. A new SQL command class, Sql_cmd_secondary_load_unload, has been added instead, to follow the same approach taken for IMPORT/DISCARD TABLESPACE. Change-Id: If2940635b7ce691da0832d685a9a100d86873b81
1 parent 7f6ec0f commit cec1066

File tree

14 files changed

+291
-114
lines changed

14 files changed

+291
-114
lines changed

mysql-test/suite/secondary_engine/r/define.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ DROP TABLE t1;
135135
#
136136
CREATE TABLE t1 (i INT);
137137
ALTER TABLE t1 SECONDARY_LOAD, ADD KEY idx(i);
138-
ERROR HY000: Secondary engine operation failed. No secondary engine defined.
138+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', ADD KEY idx(i)' at line 1
139139
ALTER TABLE t1 SECONDARY_ENGINE NONEXISTENT;
140140
ALTER TABLE t1 SECONDARY_LOAD, ADD KEY idx(i);
141-
ERROR HY000: DDLs on a table with a secondary engine defined are not allowed.
141+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', ADD KEY idx(i)' at line 1
142142
DROP TABLE t1;

mysql-test/suite/secondary_engine/r/load.result

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,21 @@ DROP TABLE t1;
3636
#
3737
CREATE TABLE t1 (a INT) SECONDARY_ENGINE MOCK;
3838
ALTER TABLE t1 SECONDARY_LOAD, FORCE;
39-
ERROR HY000: DDLs on a table with a secondary engine defined are not allowed.
39+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', FORCE' at line 1
4040
DROP TABLE t1;
4141
#
4242
# Perform alterations related to secondary engine using differing
4343
# algorithms.
4444
#
4545
CREATE TABLE t1 (a INT) SECONDARY_ENGINE MOCK;
4646
ALTER TABLE t1 SECONDARY_LOAD, ALGORITHM=INPLACE;
47+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', ALGORITHM=INPLACE' at line 1
4748
ALTER TABLE t1 SECONDARY_UNLOAD, ALGORITHM=INPLACE;
49+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', ALGORITHM=INPLACE' at line 1
4850
ALTER TABLE t1 SECONDARY_LOAD, ALGORITHM=COPY;
51+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', ALGORITHM=COPY' at line 1
4952
ALTER TABLE t1 SECONDARY_UNLOAD, ALGORITHM=COPY;
53+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', ALGORITHM=COPY' at line 1
5054
ALTER TABLE t1 SECONDARY_ENGINE NULL, ALGORITHM=INPLACE;
5155
ALTER TABLE t1 SECONDARY_ENGINE MOCK, ALGORITHM=INPLACE;
5256
ALTER TABLE t1 SECONDARY_ENGINE NULL, ALGORITHM=COPY;
@@ -63,3 +67,23 @@ DROP TABLE t1;
6367
#
6468
CREATE TABLE t1 (a INT) SECONDARY_ENGINE MOCK;
6569
DROP TABLE t1;
70+
#
71+
# Attempt to LOCK TABLE before loading a table into secondary engine.
72+
#
73+
CREATE TABLE t1 (a INT) SECONDARY_ENGINE MOCK;
74+
LOCK TABLES t1 WRITE;
75+
ALTER TABLE t1 SECONDARY_LOAD;
76+
ALTER TABLE t1 SECONDARY_UNLOAD;
77+
UNLOCK TABLES;
78+
LOCK TABLES t1 READ;
79+
ALTER TABLE t1 SECONDARY_LOAD;
80+
ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
81+
ALTER TABLE t1 SECONDARY_UNLOAD;
82+
ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
83+
LOCK TABLES t1 WRITE;
84+
ALTER TABLE t1 SECONDARY_LOAD;
85+
ALTER TABLE t1 SECONDARY_UNLOAD;
86+
UNLOCK TABLES;
87+
ALTER TABLE t1 SECONDARY_LOAD;
88+
ALTER TABLE t1 SECONDARY_UNLOAD;
89+
DROP TABLE t1;

mysql-test/suite/secondary_engine/t/define.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ DROP TABLE t1;
124124
--echo # Attempt to use SECONDARY_LOAD in conjunction with another DDL.
125125
--echo #
126126
CREATE TABLE t1 (i INT);
127-
--error ER_SECONDARY_ENGINE
127+
--error ER_PARSE_ERROR
128128
ALTER TABLE t1 SECONDARY_LOAD, ADD KEY idx(i);
129129
ALTER TABLE t1 SECONDARY_ENGINE NONEXISTENT;
130-
--error ER_SECONDARY_ENGINE_DDL
130+
--error ER_PARSE_ERROR
131131
ALTER TABLE t1 SECONDARY_LOAD, ADD KEY idx(i);
132132
DROP TABLE t1;

mysql-test/suite/secondary_engine/t/load.test

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ DROP TABLE t1;
3838
--echo # operations.
3939
--echo #
4040
CREATE TABLE t1 (a INT) SECONDARY_ENGINE MOCK;
41-
--error ER_SECONDARY_ENGINE_DDL
41+
--error ER_PARSE_ERROR
4242
ALTER TABLE t1 SECONDARY_LOAD, FORCE;
4343
DROP TABLE t1;
4444

@@ -47,9 +47,13 @@ DROP TABLE t1;
4747
--echo # algorithms.
4848
--echo #
4949
CREATE TABLE t1 (a INT) SECONDARY_ENGINE MOCK;
50+
--error ER_PARSE_ERROR
5051
ALTER TABLE t1 SECONDARY_LOAD, ALGORITHM=INPLACE;
52+
--error ER_PARSE_ERROR
5153
ALTER TABLE t1 SECONDARY_UNLOAD, ALGORITHM=INPLACE;
54+
--error ER_PARSE_ERROR
5255
ALTER TABLE t1 SECONDARY_LOAD, ALGORITHM=COPY;
56+
--error ER_PARSE_ERROR
5357
ALTER TABLE t1 SECONDARY_UNLOAD, ALGORITHM=COPY;
5458
ALTER TABLE t1 SECONDARY_ENGINE NULL, ALGORITHM=INPLACE;
5559
ALTER TABLE t1 SECONDARY_ENGINE MOCK, ALGORITHM=INPLACE;
@@ -86,6 +90,27 @@ connection default;
8690
--enable_result_log
8791
DROP TABLE t1;
8892

93+
--echo #
94+
--echo # Attempt to LOCK TABLE before loading a table into secondary engine.
95+
--echo #
96+
CREATE TABLE t1 (a INT) SECONDARY_ENGINE MOCK;
97+
LOCK TABLES t1 WRITE;
98+
ALTER TABLE t1 SECONDARY_LOAD;
99+
ALTER TABLE t1 SECONDARY_UNLOAD;
100+
UNLOCK TABLES;
101+
LOCK TABLES t1 READ;
102+
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
103+
ALTER TABLE t1 SECONDARY_LOAD;
104+
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
105+
ALTER TABLE t1 SECONDARY_UNLOAD;
106+
LOCK TABLES t1 WRITE;
107+
ALTER TABLE t1 SECONDARY_LOAD;
108+
ALTER TABLE t1 SECONDARY_UNLOAD;
109+
UNLOCK TABLES;
110+
ALTER TABLE t1 SECONDARY_LOAD;
111+
ALTER TABLE t1 SECONDARY_UNLOAD;
112+
DROP TABLE t1;
113+
89114
--disable_query_log
90115
UNINSTALL PLUGIN mock;
91116
--enable_query_log

sql/handler.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4732,8 +4732,7 @@ enum_alter_inplace_result handler::check_if_supported_inplace_alter(
47324732
Alter_inplace_info::ALTER_RENAME | Alter_inplace_info::RENAME_INDEX |
47334733
Alter_inplace_info::ALTER_INDEX_COMMENT |
47344734
Alter_inplace_info::CHANGE_INDEX_OPTION |
4735-
Alter_inplace_info::ALTER_COLUMN_INDEX_LENGTH |
4736-
Alter_inplace_info::SECONDARY_LOAD | Alter_inplace_info::SECONDARY_UNLOAD;
4735+
Alter_inplace_info::ALTER_COLUMN_INDEX_LENGTH;
47374736

47384737
/* Is there at least one operation that requires copy algorithm? */
47394738
if (ha_alter_info->handler_flags & ~inplace_offline_operations)
@@ -8624,7 +8623,7 @@ void ha_post_recover(void) {
86248623
}
86258624

86268625
void handler::ha_set_primary_handler(handler *primary_handler) {
8627-
DBUG_ASSERT((ht->flags & HTON_SUPPORTS_SECONDARY) != 0);
8626+
DBUG_ASSERT((ht->flags & HTON_IS_SECONDARY_ENGINE) != 0);
86288627
DBUG_ASSERT(primary_handler->table->s->has_secondary());
86298628
m_primary_handler = primary_handler;
86308629
}

sql/handler.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,8 +2159,11 @@ struct handlerton {
21592159
/* Engine supports packed keys. */
21602160
#define HTON_SUPPORTS_PACKED_KEYS (1 << 13)
21612161

2162-
/** Engine supports being set as secondary storage engine. */
2163-
#define HTON_SUPPORTS_SECONDARY (1 << 14)
2162+
/** Engine is a secondary storage engine. */
2163+
#define HTON_IS_SECONDARY_ENGINE (1 << 14)
2164+
2165+
/** Engine supports secondary storage engines. */
2166+
#define HTON_SUPPORTS_SECONDARY_ENGINE (1 << 15)
21642167

21652168
inline bool ddl_is_atomic(const handlerton *hton) {
21662169
return (hton->flags & HTON_SUPPORTS_ATOMIC_DDL) != 0;
@@ -2518,12 +2521,6 @@ class Alter_inplace_info {
25182521
// Rebuild partition
25192522
static const HA_ALTER_FLAGS ALTER_REBUILD_PARTITION = 1ULL << 42;
25202523

2521-
// Load into secondary engine.
2522-
static const HA_ALTER_FLAGS SECONDARY_LOAD = 1ULL << 43;
2523-
2524-
// Unload from secondary engine.
2525-
static const HA_ALTER_FLAGS SECONDARY_UNLOAD = 1ULL << 44;
2526-
25272524
/**
25282525
Change in index length such that it does not require index rebuild.
25292526
For example, change in index length due to column expansion like

sql/parse_tree_nodes.h

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3986,21 +3986,6 @@ class PT_alter_table_remove_partitioning : public PT_alter_table_action {
39863986
: super(Alter_info::ALTER_REMOVE_PARTITIONING) {}
39873987
};
39883988

3989-
class PT_alter_table_secondary_load : public PT_alter_table_action {
3990-
using super = PT_alter_table_action;
3991-
3992-
public:
3993-
PT_alter_table_secondary_load() : super(Alter_info::ALTER_SECONDARY_LOAD) {}
3994-
};
3995-
3996-
class PT_alter_table_secondary_unload : public PT_alter_table_action {
3997-
using super = PT_alter_table_action;
3998-
3999-
public:
4000-
PT_alter_table_secondary_unload()
4001-
: super(Alter_info::ALTER_SECONDARY_UNLOAD) {}
4002-
};
4003-
40043989
class PT_alter_table_standalone_action : public PT_alter_table_action {
40053990
typedef PT_alter_table_action super;
40063991

@@ -4403,6 +4388,32 @@ class PT_alter_table_exchange_partition final
44034388
const Alter_info::enum_with_validation m_validation;
44044389
};
44054390

4391+
class PT_alter_table_secondary_load final
4392+
: public PT_alter_table_standalone_action {
4393+
using super = PT_alter_table_standalone_action;
4394+
4395+
public:
4396+
explicit PT_alter_table_secondary_load()
4397+
: super(Alter_info::ALTER_SECONDARY_LOAD) {}
4398+
4399+
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
4400+
return new (pc->mem_root) Sql_cmd_secondary_load_unload(pc->alter_info);
4401+
}
4402+
};
4403+
4404+
class PT_alter_table_secondary_unload final
4405+
: public PT_alter_table_standalone_action {
4406+
using super = PT_alter_table_standalone_action;
4407+
4408+
public:
4409+
explicit PT_alter_table_secondary_unload()
4410+
: super(Alter_info::ALTER_SECONDARY_UNLOAD) {}
4411+
4412+
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
4413+
return new (pc->mem_root) Sql_cmd_secondary_load_unload(pc->alter_info);
4414+
}
4415+
};
4416+
44064417
class PT_alter_table_discard_partition_tablespace final
44074418
: public PT_alter_table_partition_list_or_all {
44084419
typedef PT_alter_table_partition_list_or_all super;

sql/sql_alter.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,25 @@ bool Sql_cmd_discard_import_tablespace::execute(THD *thd) {
402402

403403
return mysql_discard_or_import_tablespace(thd, table_list);
404404
}
405+
406+
bool Sql_cmd_secondary_load_unload::execute(THD *thd) {
407+
// One of the SECONDARY_LOAD/SECONDARY_UNLOAD flags must have been set.
408+
DBUG_ASSERT(
409+
((m_alter_info->flags & Alter_info::ALTER_SECONDARY_LOAD) == 0) !=
410+
((m_alter_info->flags & Alter_info::ALTER_SECONDARY_UNLOAD) == 0));
411+
412+
// No other flags should've been set.
413+
DBUG_ASSERT(!(m_alter_info->flags & ~(Alter_info::ALTER_SECONDARY_LOAD |
414+
Alter_info::ALTER_SECONDARY_UNLOAD)));
415+
416+
TABLE_LIST *table_list = thd->lex->select_lex->get_table_list();
417+
418+
if (check_access(thd, ALTER_ACL, table_list->db, &table_list->grant.privilege,
419+
&table_list->grant.m_internal, 0, 0))
420+
return true;
421+
422+
if (check_grant(thd, ALTER_ACL, table_list, false, UINT_MAX, false))
423+
return true;
424+
425+
return mysql_secondary_load_or_unload(thd, table_list);
426+
}

sql/sql_alter.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ class Alter_info {
272272
/// Means that the visibility of an index is changed.
273273
ALTER_INDEX_VISIBILITY = 1UL << 29,
274274

275-
/// Set for SECONDARY LOAD
275+
/// Set for SECONDARY_LOAD
276276
ALTER_SECONDARY_LOAD = 1UL << 30,
277277

278-
/// Set for SECONDARY UNLOAD
278+
/// Set for SECONDARY_UNLOAD
279279
ALTER_SECONDARY_UNLOAD = 1UL << 31,
280280
};
281281

@@ -555,4 +555,18 @@ class Sql_cmd_discard_import_tablespace : public Sql_cmd_common_alter_table {
555555
bool mysql_discard_or_import_tablespace(THD *thd, TABLE_LIST *table_list);
556556
};
557557

558+
/**
559+
Represents ALTER TABLE SECONDARY_LOAD/SECONDARY_UNLOAD statements.
560+
*/
561+
class Sql_cmd_secondary_load_unload final : public Sql_cmd_common_alter_table {
562+
public:
563+
// Inherit the constructors from the parent class.
564+
using Sql_cmd_common_alter_table::Sql_cmd_common_alter_table;
565+
566+
bool execute(THD *thd) override;
567+
568+
private:
569+
bool mysql_secondary_load_or_unload(THD *thd, TABLE_LIST *table_list);
570+
};
571+
558572
#endif

0 commit comments

Comments
 (0)