Skip to content

Commit c769510

Browse files
authored
PSTRESS-157 Add support for ALTER ENGINE DDL in pstress (#97)
ALTER TABLE tbl_name ENGINE=InnoDB, ALGORITHM=INPLACE/COPY/INSTANT/DEFAULT
1 parent 643367e commit c769510

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/common.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct Option {
6868
NUMBER_OF_SECONDS_WORKLOAD,
6969
ALTER_TABLE_ENCRYPTION,
7070
ALTER_DISCARD_TABLESPACE,
71+
ALTER_ENGINE,
7172
ALTER_TABLE_COMPRESSION,
7273
ALTER_COLUMN_MODIFY,
7374
ALTER_INSTANCE_RELOAD_KEYRING,

src/help.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,13 @@ void add_options() {
483483
opt->setSQL();
484484
opt->setDDL();
485485

486+
/* Alter table Storage Engine to Innodb with different Algorithms */
487+
opt = newOption(Option::INT, Option::ALTER_ENGINE, "alter-table-engine");
488+
opt->help = "alter table engine";
489+
opt->setInt(1);
490+
opt->setSQL();
491+
opt->setDDL();
492+
486493
/* Add column */
487494
opt = newOption(Option::INT, Option::ADD_COLUMN, "add-column");
488495
opt->help = "alter table add some random column";

src/random_test.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,7 +1980,7 @@ bool execute_sql(const std::string &sql, Thd1 *thd) {
19801980
void Table::SetEncryption(Thd1 *thd) {
19811981
std::string sql = "ALTER TABLE " + name_ + " ENCRYPTION = '";
19821982
std::string enc = g_encryption[rand_int(g_encryption.size() - 1)];
1983-
sql += enc + "'";
1983+
sql += enc + "'" + "," + pick_algorithm_lock();
19841984
if (execute_sql(sql, thd)) {
19851985
table_mutex.lock();
19861986
encryption = enc;
@@ -1992,14 +1992,19 @@ void Table::SetEncryption(Thd1 *thd) {
19921992
void Table::SetTableCompression(Thd1 *thd) {
19931993
std::string sql = "ALTER TABLE " + name_ + " COMPRESSION= '";
19941994
std::string comp = g_compression[rand_int(g_compression.size() - 1)];
1995-
sql += comp + "'";
1995+
sql += comp + "'" + "," + pick_algorithm_lock();
19961996
if (execute_sql(sql, thd)) {
19971997
table_mutex.lock();
19981998
compression = comp;
19991999
table_mutex.unlock();
20002000
}
20012001
}
20022002

2003+
void Table::SetAlterEngine(Thd1 *thd) {
2004+
std::string sql = "ALTER TABLE " + name_ + " ENGINE=InnoDB," + pick_algorithm_lock();
2005+
execute_sql(sql, thd);
2006+
}
2007+
20032008
// todo pick relevent table//
20042009
void Table::ModifyColumn(Thd1 *thd) {
20052010
std::string sql = "ALTER TABLE " + name_ + " MODIFY COLUMN ";
@@ -3593,6 +3598,9 @@ bool Thd1::run_some_query() {
35933598
case Option::ALTER_TABLE_ENCRYPTION:
35943599
table->SetEncryption(this);
35953600
break;
3601+
case Option::ALTER_ENGINE:
3602+
table->SetAlterEngine(this);
3603+
break;
35963604
case Option::ALTER_TABLE_COMPRESSION:
35973605
table->SetTableCompression(this);
35983606
break;

src/random_test.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ struct Table {
197197
void SetEncryption(Thd1 *thd);
198198
void SetEncryptionInplace(Thd1 *thd);
199199
void SetTableCompression(Thd1 *thd);
200+
void SetAlterEngine(Thd1 *thd);
200201
void ModifyColumn(Thd1 *thd);
201202
void InsertRandomRow(Thd1 *thd);
202203
bool InsertBulkRecord(Thd1 *thd, size_t number_of_records);

0 commit comments

Comments
 (0)