Skip to content

Commit

Permalink
Merge branch 'mysql-8.0' into mysql-trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
Bin Su committed Jun 29, 2018
2 parents 3c309f5 + 217c404 commit 8276646
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 7 deletions.
33 changes: 33 additions & 0 deletions mysql-test/suite/innodb/r/instant_add_column_autoinc.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
CREATE PROCEDURE test.sp2 (IN start BIGINT)
BEGIN
SET @idx =start;
WHILE (@idx > 0) DO
ALTER TABLE test.t1 ADD n2 BIGINT;
ALTER TABLE test.t1 DROP COLUMN n2;
SET @idx = @idx - 1;
END WHILE;
END|
CREATE PROCEDURE test.sp1 (IN start BIGINT)
BEGIN
SET @idx =start;
WHILE (@idx > 0) DO
INSERT INTO test.t1 (c2,c3) VALUES(repeat('q',10),@idx);
SET @idx = @idx - 1;
END WHILE;
END|
CREATE TABLE t1 (c1 INT AUTO_INCREMENT PRIMARY KEY, c2 TEXT(1024), c3 INT);
call test.sp2(30);;
call test.sp1(300);;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
DROP TABLE t1;
CREATE TABLE t1 (c1 INT AUTO_INCREMENT PRIMARY KEY, c2 TEXT(1024), c3 INT) PARTITION BY HASH (c1) PARTITIONS 2;
call test.sp2(30);;
call test.sp1(300);;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
DROP PROCEDURE IF EXISTS test.sp1;
DROP PROCEDURE IF EXISTS test.sp2;
DROP TABLE t1;
63 changes: 63 additions & 0 deletions mysql-test/suite/innodb/t/instant_add_column_autoinc.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
--source include/count_sessions.inc

delimiter |;
#Procedure for alter(DDL)
CREATE PROCEDURE test.sp2 (IN start BIGINT)
BEGIN
SET @idx =start;
WHILE (@idx > 0) DO
ALTER TABLE test.t1 ADD n2 BIGINT;
ALTER TABLE test.t1 DROP COLUMN n2;
SET @idx = @idx - 1;
END WHILE;
END|

#Procedure for INSERT
CREATE PROCEDURE test.sp1 (IN start BIGINT)
BEGIN
SET @idx =start;
WHILE (@idx > 0) DO
INSERT INTO test.t1 (c2,c3) VALUES(repeat('q',10),@idx);
SET @idx = @idx - 1;
END WHILE;
END|

delimiter ;|


connect (con1,localhost,root,,);

connection default;
CREATE TABLE t1 (c1 INT AUTO_INCREMENT PRIMARY KEY, c2 TEXT(1024), c3 INT);
--send call test.sp2(30);

connection con1;
--send call test.sp1(300);
--reap

connection default;
--reap

CHECK TABLE t1;
DROP TABLE t1;

CREATE TABLE t1 (c1 INT AUTO_INCREMENT PRIMARY KEY, c2 TEXT(1024), c3 INT) PARTITION BY HASH (c1) PARTITIONS 2;
--send call test.sp2(30);

connection con1;
--send call test.sp1(300);
--reap

connection default;
--reap

CHECK TABLE t1;

disconnect con1;

DROP PROCEDURE IF EXISTS test.sp1;
DROP PROCEDURE IF EXISTS test.sp2;

DROP TABLE t1;

--source include/wait_until_count_sessions.inc
31 changes: 24 additions & 7 deletions storage/innobase/handler/handler0alter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1065,14 +1065,16 @@ static void dd_commit_inplace_no_change(const Table *old_dd_tab,
@param[in] old_table MySQL table as it is before the ALTER operation
@param[in] altered_table MySQL table that is being altered
@param[in] old_dd_tab Old dd::Table or dd::Partition
@param[in,out] new_dd_tab New dd::Table or dd::Partition */
@param[in,out] new_dd_tab New dd::Table or dd::Partition
@param[in] autoinc autoinc counter pointer if AUTO_INCREMENT
is defined for the table, otherwise nullptr */
template <typename Table>
static void dd_commit_inplace_instant(Alter_inplace_info *ha_alter_info,
THD *thd, trx_t *trx, dict_table_t *table,
const TABLE *old_table,
const TABLE *altered_table,
const Table *old_dd_tab,
Table *new_dd_tab);
Table *new_dd_tab, uint64_t *autoinc);

/** Update table level instant metadata in commit phase
@param[in] table InnoDB table object
Expand Down Expand Up @@ -1220,7 +1222,10 @@ bool ha_innobase::commit_inplace_alter_table(TABLE *altered_table,
ut_ad(!res);
dd_commit_inplace_instant(ha_alter_info, m_user_thd, m_prebuilt->trx,
m_prebuilt->table, table, altered_table,
old_dd_tab, new_dd_tab);
old_dd_tab, new_dd_tab,
altered_table->found_next_number_field != nullptr
? &m_prebuilt->table->autoinc
: nullptr);
} else if (!(ha_alter_info->handler_flags & ~INNOBASE_INPLACE_IGNORE) ||
ctx == nullptr) {
ut_ad(!res);
Expand Down Expand Up @@ -4012,7 +4017,7 @@ static void dd_commit_inplace_instant(Alter_inplace_info *ha_alter_info,
const TABLE *old_table,
const TABLE *altered_table,
const Table *old_dd_tab,
Table *new_dd_tab) {
Table *new_dd_tab, uint64_t *autoinc) {
ut_ad(is_instant(ha_alter_info));

Instant_Type type =
Expand Down Expand Up @@ -4056,6 +4061,14 @@ static void dd_commit_inplace_instant(Alter_inplace_info *ha_alter_info,
default:
ut_ad(0);
}

if (autoinc != nullptr) {
ut_ad(altered_table->found_next_number_field != nullptr);
if (!dd_table_is_partitioned(new_dd_tab->table()) ||
dd_part_is_first(reinterpret_cast<dd::Partition *>(new_dd_tab))) {
dd_set_autoinc(new_dd_tab->table().se_private_data(), *autoinc);
}
}
}

/** Check if a new table's index will exceed the index limit for the table
Expand Down Expand Up @@ -9986,9 +9999,13 @@ bool ha_innopart::commit_inplace_alter_table(TABLE *altered_table,
static_cast<ha_innobase_inplace_ctx *>(ctx_parts->ctx_array[i]);

if (is_instant(ha_alter_info)) {
dd_commit_inplace_instant(ha_alter_info, m_user_thd, m_prebuilt->trx,
m_part_share->get_table_part(i), table,
altered_table, old_part, new_part);
dd_commit_inplace_instant(
ha_alter_info, m_user_thd, m_prebuilt->trx,
m_part_share->get_table_part(i), table, altered_table, old_part,
new_part,
altered_table->found_next_number_field != nullptr
? reinterpret_cast<uint64_t *>(&m_part_share->next_auto_inc_val)
: nullptr);
} else if (!(ha_alter_info->handler_flags & ~INNOBASE_INPLACE_IGNORE) ||
ctx == nullptr) {
dd_commit_inplace_no_change(old_part, new_part, true);
Expand Down

0 comments on commit 8276646

Please sign in to comment.