-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PS-9222 ALTER TABLE ALGORITHM=INSTANT FIX #2
https://perconadev.atlassian.net/browse/PS-9222 Problem ======= When writing to the redo log, an issue of column order change not being recorded with INSTANT DDL was fixed by checking if the fields are also reordered, then adding the columns into the list. However when calculating the size of the buffer this fix doesn't take account the extra fields that may be logged, and causing the assertion on the buffer size failed eventually. Solution ======== To calculate the buffer size correctly, we move the logic of finding reordered fiedls before buffer size calculation, then count the number of fields with the same logic when deciding if a field needs to be logged.
- Loading branch information
1 parent
b59be72
commit 7d42d75
Showing
3 changed files
with
149 additions
and
37 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
mysql-test/suite/innodb/r/instant_alter_stored_column_order.result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
without prefix field in the index | ||
CREATE TABLE t1 (c1 TINYTEXT COLLATE ascii_bin NOT NULL, c2 DATETIME(3) NOT NULL, c3 TEXT, UNIQUE KEY (c1(30))); | ||
INSERT INTO t1 (c1, c2, c3) VALUE ('k1','2021-12-21','something'); | ||
INSERT INTO t1 (c1, c2, c3) VALUE ('k3','2021-12-21','something else'); | ||
ALTER TABLE t1 | ||
CHANGE c2 c2 DATETIME(3) NOT NULL AFTER c3, | ||
ADD COLUMN c4 VARCHAR(18) NOT NULL, | ||
ALGORITHM=INSTANT; | ||
# Make sure nothing gets flushed on disk | ||
SET GLOBAL innodb_log_checkpoint_now = ON; | ||
SET GLOBAL innodb_page_cleaner_disabled_debug = 1; | ||
SET GLOBAL innodb_dict_stats_disabled_debug = 1; | ||
SET GLOBAL innodb_master_thread_disabled_debug = 1; | ||
SET GLOBAL innodb_checkpoint_disabled = ON; | ||
UPDATE t1 SET c4 = 'value' WHERE c1 = 'k1'; | ||
# Restart the server and reload the table to see if tables are corrupted. | ||
# Kill and restart | ||
# Run a select to confirm that the database started up successfully | ||
SELECT * FROM t1; | ||
c1 c3 c2 c4 | ||
k1 something 2021-12-21 00:00:00.000 value | ||
k3 something else 2021-12-21 00:00:00.000 | ||
DROP TABLE t1; | ||
with prefix field in the index | ||
CREATE TABLE t1 (c1 TINYTEXT COLLATE ascii_bin NOT NULL, c2 DATETIME(3) NOT NULL, c3 TEXT, PRIMARY KEY (c1(30))); | ||
INSERT INTO t1 (c1, c2, c3) VALUE ('k1','2021-12-21','something'); | ||
INSERT INTO t1 (c1, c2, c3) VALUE ('k3','2021-12-21','something else'); | ||
ALTER TABLE t1 | ||
CHANGE c2 c2 DATETIME(3) NOT NULL AFTER c3, | ||
ADD COLUMN c4 VARCHAR(18) NOT NULL, | ||
ALGORITHM=INSTANT; | ||
# Make sure nothing gets flushed on disk | ||
SET GLOBAL innodb_log_checkpoint_now = ON; | ||
SET GLOBAL innodb_page_cleaner_disabled_debug = 1; | ||
SET GLOBAL innodb_dict_stats_disabled_debug = 1; | ||
SET GLOBAL innodb_master_thread_disabled_debug = 1; | ||
SET GLOBAL innodb_checkpoint_disabled = ON; | ||
UPDATE t1 SET c4 = 'value' WHERE c1 = 'k1'; | ||
# Restart the server and reload the table to see if tables are corrupted. | ||
# Kill and restart | ||
# Run a select to confirm that the database started up successfully | ||
SELECT * FROM t1; | ||
c1 c3 c2 c4 | ||
k1 something 2021-12-21 00:00:00.000 value | ||
k3 something else 2021-12-21 00:00:00.000 | ||
DROP TABLE t1; |
57 changes: 57 additions & 0 deletions
57
mysql-test/suite/innodb/t/instant_alter_stored_column_order.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# PS-9222 Testing if ALGORITHM=INSTANT crashes server | ||
|
||
--echo without prefix field in the index | ||
CREATE TABLE t1 (c1 TINYTEXT COLLATE ascii_bin NOT NULL, c2 DATETIME(3) NOT NULL, c3 TEXT, UNIQUE KEY (c1(30))); | ||
INSERT INTO t1 (c1, c2, c3) VALUE ('k1','2021-12-21','something'); | ||
INSERT INTO t1 (c1, c2, c3) VALUE ('k3','2021-12-21','something else'); | ||
|
||
ALTER TABLE t1 | ||
CHANGE c2 c2 DATETIME(3) NOT NULL AFTER c3, | ||
ADD COLUMN c4 VARCHAR(18) NOT NULL, | ||
ALGORITHM=INSTANT; | ||
|
||
--echo # Make sure nothing gets flushed on disk | ||
SET GLOBAL innodb_log_checkpoint_now = ON; | ||
SET GLOBAL innodb_page_cleaner_disabled_debug = 1; | ||
SET GLOBAL innodb_dict_stats_disabled_debug = 1; | ||
SET GLOBAL innodb_master_thread_disabled_debug = 1; | ||
SET GLOBAL innodb_checkpoint_disabled = ON; | ||
|
||
UPDATE t1 SET c4 = 'value' WHERE c1 = 'k1'; | ||
|
||
--echo # Restart the server and reload the table to see if tables are corrupted. | ||
--source include/kill_and_restart_mysqld.inc | ||
|
||
-- echo # Run a select to confirm that the database started up successfully | ||
SELECT * FROM t1; | ||
|
||
# cleanup | ||
DROP TABLE t1; | ||
|
||
--echo with prefix field in the index | ||
CREATE TABLE t1 (c1 TINYTEXT COLLATE ascii_bin NOT NULL, c2 DATETIME(3) NOT NULL, c3 TEXT, PRIMARY KEY (c1(30))); | ||
INSERT INTO t1 (c1, c2, c3) VALUE ('k1','2021-12-21','something'); | ||
INSERT INTO t1 (c1, c2, c3) VALUE ('k3','2021-12-21','something else'); | ||
|
||
ALTER TABLE t1 | ||
CHANGE c2 c2 DATETIME(3) NOT NULL AFTER c3, | ||
ADD COLUMN c4 VARCHAR(18) NOT NULL, | ||
ALGORITHM=INSTANT; | ||
|
||
--echo # Make sure nothing gets flushed on disk | ||
SET GLOBAL innodb_log_checkpoint_now = ON; | ||
SET GLOBAL innodb_page_cleaner_disabled_debug = 1; | ||
SET GLOBAL innodb_dict_stats_disabled_debug = 1; | ||
SET GLOBAL innodb_master_thread_disabled_debug = 1; | ||
SET GLOBAL innodb_checkpoint_disabled = ON; | ||
|
||
UPDATE t1 SET c4 = 'value' WHERE c1 = 'k1'; | ||
|
||
--echo # Restart the server and reload the table to see if tables are corrupted. | ||
--source include/kill_and_restart_mysqld.inc | ||
|
||
-- echo # Run a select to confirm that the database started up successfully | ||
SELECT * FROM t1; | ||
|
||
# cleanup | ||
DROP TABLE t1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters