Skip to content

Commit

Permalink
SQL: prohibit ALTER ... AS ROW START|END [fixes #429]
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgs committed Dec 25, 2017
1 parent ea49441 commit d8aabb4
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 32 deletions.
4 changes: 2 additions & 2 deletions mysql-test/suite/versioning/r/alter.result
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ alter table t1 engine=myisam;
# MDEV-14692 crash in MDL_context::upgrade_shared_lock()
create or replace temporary table t (a int);
alter table t change column if exists b c bigint unsigned generated always as row start;
ERROR HY000: GENERATED AS ROW START prohibited for TEMPORARY tables
ERROR HY000: This is not yet supported for generated columns
alter table t change column if exists b c bigint unsigned generated always as row end;
ERROR HY000: GENERATED AS ROW END prohibited for TEMPORARY tables
ERROR HY000: This is not yet supported for generated columns
drop database test;
create database test;
2 changes: 1 addition & 1 deletion mysql-test/suite/versioning/r/insert.result
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ insert into t1(x) values (1);
ERROR HY000: Temporal operation requires `mysql.transaction_registry` (@@system_versioning_transaction_registry).
set global system_versioning_transaction_registry= on;
Warnings:
Warning 4144 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
Warning 4143 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
create or replace table t1 (
x int,
y int as (x) virtual,
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/versioning/r/online.result
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ alter table t drop system versioning, algorithm=inplace;
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Not implemented for system-versioned tables. Try ALGORITHM=COPY
set global system_versioning_transaction_registry=on;
Warnings:
Warning 4144 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
Warning 4143 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
create or replace table t (a int, b int) engine=innodb;
alter table t
add s bigint unsigned as row start,
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/suite/versioning/r/trx_id.result
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ period for system_time (sys_trx_start, sys_trx_end)
ERROR HY000: Temporal operation requires `mysql.transaction_registry` (@@system_versioning_transaction_registry).
set global system_versioning_transaction_registry= 1;
Warnings:
Warning 4144 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
Warning 4143 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
create or replace table t1 (
x int,
sys_trx_start bigint(20) unsigned as row start invisible,
Expand All @@ -32,7 +32,7 @@ return if(cond = 1, '[CORRECT]', '[INCORRECT]');
set @@system_versioning_alter_history=keep;
set global system_versioning_transaction_registry=on;
Warnings:
Warning 4144 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
Warning 4143 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
create or replace table t1 (x int) engine innodb;
insert into t1 values (1);
alter table t1
Expand Down
8 changes: 4 additions & 4 deletions mysql-test/suite/versioning/t/alter.test
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ create or replace table non_empty (
) engine innodb;
insert into non_empty values (1, 100, 200);

--error ER_VERS_GENERATED_ALWAYS_NOT_EMPTY
--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
alter table non_empty
change column sys_trx_start sys_trx_start bigint(20) unsigned as row start invisible;
--error ER_VERS_GENERATED_ALWAYS_NOT_EMPTY
--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
alter table non_empty
change column sys_trx_end sys_trx_end bigint(20) unsigned as row end invisible;
drop table non_empty;
Expand Down Expand Up @@ -364,9 +364,9 @@ alter table t1 engine=myisam;

--echo # MDEV-14692 crash in MDL_context::upgrade_shared_lock()
create or replace temporary table t (a int);
--error ER_VERS_TEMPORARY
--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
alter table t change column if exists b c bigint unsigned generated always as row start;
--error ER_VERS_TEMPORARY
--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
alter table t change column if exists b c bigint unsigned generated always as row end;


Expand Down
21 changes: 2 additions & 19 deletions sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7295,31 +7295,14 @@ bool Vers_parse_info::fix_alter_info(THD *thd, Alter_info *alter_info,
return false;
}

if (!share->versioned)
{
List_iterator_fast<Create_field> it(alter_info->create_list);
while (Create_field *f= it++)
{
if (f->change.length && f->flags & VERS_SYSTEM_FIELD)
{
if (share->table_category == TABLE_CATEGORY_TEMPORARY) {
my_error(ER_VERS_TEMPORARY, MYF(0),
f->flags & VERS_SYS_START_FLAG ? "GENERATED AS ROW START"
: "GENERATED AS ROW END");
return true;
}
if (thd->mdl_context.upgrade_shared_lock(
table->mdl_ticket, MDL_EXCLUSIVE,
thd->variables.lock_wait_timeout))
return true;
if (table->file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME))
return true;
if (0 < table->file->records())
{
my_error(ER_VERS_GENERATED_ALWAYS_NOT_EMPTY, MYF(0), f->change.str);
return true;
}
break;
my_error(ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN, MYF(0));
return true;
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions sql/share/errmsg-utf8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7915,9 +7915,6 @@ ER_VERS_SYS_FIELD_NOT_HIDDEN
ER_NOT_LOG_TABLE
eng "Table %`s.%`s is not a log table"

ER_VERS_GENERATED_ALWAYS_NOT_EMPTY
eng "Can not modify column %`s to GENERATED ALWAYS AS ROW START/END for non-empty table"

ER_VERS_TRT_IS_DISABLED
eng "Temporal operation requires `mysql.transaction_registry` (@@system_versioning_transaction_registry)."

Expand Down

0 comments on commit d8aabb4

Please sign in to comment.