Skip to content

Commit 3099a75

Browse files
committed
don't do DROP SYSTEM VERSIONING online
because ALTER TABLE ... DROP SYSTEM VERSIONING is not just a change in the table structure, it also deletes all historical rows
1 parent 32c3d77 commit 3099a75

File tree

3 files changed

+50
-95
lines changed

3 files changed

+50
-95
lines changed

mysql-test/main/alter_table_online.result

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -408,55 +408,8 @@ a b UNIX_TIMESTAMP(row_start) UNIX_TIMESTAMP(row_end)
408408
1 55 1.000000 2147483647.999999
409409
3 44 1.000000 2147483647.999999
410410
6 77 1.000000 2147483647.999999
411-
connection con2;
412-
set debug_sync= 'now WAIT_FOR ended';
413-
connection default;
414-
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
415-
alter table t1 drop system versioning,
416-
algorithm= copy, lock= none;
417-
connection con2;
418-
update t1 set b= 88 where a = 1;
419-
set debug_sync= 'now SIGNAL end';
420-
connection default;
421-
# Can't UPDATE versioned -> plain (and can't DELETE)
422-
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
423-
show create table t1;
424-
Table Create Table
425-
t1 CREATE TABLE `t1` (
426-
`a` int(11) NOT NULL,
427-
`b` int(11) DEFAULT NULL,
428-
PRIMARY KEY (`a`)
429-
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
430-
select *, UNIX_TIMESTAMP(row_start), UNIX_TIMESTAMP(row_end) from t1 for system_time all;
431-
a b UNIX_TIMESTAMP(row_start) UNIX_TIMESTAMP(row_end)
432-
1 55 1.000000 3.000000
433-
1 88 3.000000 2147483647.999999
434-
3 44 1.000000 2147483647.999999
435-
6 77 1.000000 2147483647.999999
436-
connection con2;
437-
set debug_sync= 'now WAIT_FOR ended';
438-
connection default;
439-
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
440-
alter table t1 drop system versioning,
441-
algorithm= copy, lock= none;
442-
connection con2;
443-
insert into t1 values (8, 99);
444-
set debug_sync= 'now SIGNAL end';
445-
connection default;
446-
# INSERT versioned -> plain works fine since it is a single versioned op.
447-
show create table t1;
448-
Table Create Table
449-
t1 CREATE TABLE `t1` (
450-
`a` int(11) NOT NULL,
451-
`b` int(11) DEFAULT NULL,
452-
PRIMARY KEY (`a`)
453-
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
454-
select * from t1;
455-
a b
456-
1 88
457-
3 44
458-
6 77
459-
8 99
411+
alter table t1 drop system versioning, algorithm= copy, lock= none;
412+
ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
460413
#
461414
# Test ROLLBACK TO SAVEPOINT
462415
#

mysql-test/main/alter_table_online.test

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -492,52 +492,53 @@ set debug_sync= 'now SIGNAL end';
492492
show create table t1;
493493
select *, UNIX_TIMESTAMP(row_start), UNIX_TIMESTAMP(row_end) from t1 for system_time all;
494494

495-
--connection con2
496-
--send
497-
set debug_sync= 'now WAIT_FOR ended';
498-
499-
--connection default
500-
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
501-
502-
--send
503-
alter table t1 drop system versioning,
504-
algorithm= copy, lock= none;
505-
506-
--connection con2
507-
--reap
508-
update t1 set b= 88 where a = 1;
509-
510-
set debug_sync= 'now SIGNAL end';
511-
512-
--connection default
513-
--echo # Can't UPDATE versioned -> plain (and can't DELETE)
514-
--error ER_DUP_ENTRY
515-
--reap
516-
show create table t1;
517-
select *, UNIX_TIMESTAMP(row_start), UNIX_TIMESTAMP(row_end) from t1 for system_time all;
518-
519-
--connection con2
520-
--send
521-
set debug_sync= 'now WAIT_FOR ended';
522-
523-
--connection default
524-
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
525-
526-
--send
527-
alter table t1 drop system versioning,
528-
algorithm= copy, lock= none;
529-
530-
--connection con2
531-
--reap
532-
insert into t1 values (8, 99);
533-
534-
set debug_sync= 'now SIGNAL end';
535-
536-
--connection default
537-
--echo # INSERT versioned -> plain works fine since it is a single versioned op.
538-
--reap
539-
show create table t1;
540-
select * from t1;
495+
## at the moment DROP SYSTEM VERSIONING cannot be done online
496+
## because it not only alters the structure, but also deletes history rows
497+
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
498+
alter table t1 drop system versioning, algorithm= copy, lock= none;
499+
#--connection con2
500+
#--send
501+
#set debug_sync= 'now WAIT_FOR ended';
502+
#
503+
#--connection default
504+
#set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
505+
#
506+
#--send
507+
#alter table t1 drop system versioning,
508+
# algorithm= copy, lock= none;
509+
#
510+
#--connection con2
511+
#--reap
512+
#update t1 set b= 88 where a = 1;
513+
#
514+
#set debug_sync= 'now SIGNAL end';
515+
#
516+
#--connection default
517+
#--reap
518+
#show create table t1;
519+
#select *, UNIX_TIMESTAMP(row_start), UNIX_TIMESTAMP(row_end) from t1 for system_time all;
520+
#
521+
#--connection con2
522+
#--send
523+
#set debug_sync= 'now WAIT_FOR ended';
524+
#
525+
#--connection default
526+
#set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
527+
#
528+
#--send
529+
#alter table t1 drop system versioning,
530+
# algorithm= copy, lock= none;
531+
#
532+
#--connection con2
533+
#--reap
534+
#insert into t1 values (8, 99);
535+
#
536+
#set debug_sync= 'now SIGNAL end';
537+
#
538+
#--connection default
539+
#--reap
540+
#show create table t1;
541+
#select * from t1;
541542

542543
--echo #
543544
--echo # Test ROLLBACK TO SAVEPOINT

sql/sql_table.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10028,6 +10028,7 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db,
1002810028

1002910029
if (alter_info->requested_lock == Alter_info::ALTER_TABLE_LOCK_SHARED
1003010030
|| alter_info->requested_lock > Alter_info::ALTER_TABLE_LOCK_NONE
10031+
|| alter_info->flags & ALTER_DROP_SYSTEM_VERSIONING
1003110032
|| thd->locked_tables_mode == LTM_LOCK_TABLES
1003210033
|| thd->lex->sql_command == SQLCOM_OPTIMIZE
1003310034
|| alter_info->algorithm(thd) > Alter_info::ALTER_TABLE_ALGORITHM_COPY)

0 commit comments

Comments
 (0)