Commit 61acb436 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-31822 ALTER TABLE ENGINE=x started failing instead of producing warning...

MDEV-31822 ALTER TABLE ENGINE=x started failing instead of producing warning on unsupported TRANSACTIONAL=1

make TRANSACTIONAL table option behave similar to other engine-defined
table options. If the engine doesn't suport it:
* if specified expicitly in CREATE or ALTER - it's ER_UNKNOWN_OPTION
* an error or a warning depending on sql_mode IGNORE_BAD_TABLE_OPTIONS
* in ALTER TABLE from the engine that suppors it to the engine that
  doesn't - silently preserved (no warning)
* it is commented out in SHOW CREATE unless IGNORE_BAD_TABLE_OPTIONS
parent da09ae05
...@@ -1221,7 +1221,7 @@ drop table if exists t1,t2,t3; ...@@ -1221,7 +1221,7 @@ drop table if exists t1,t2,t3;
# Fix modified for MariaDB: we support this syntax # Fix modified for MariaDB: we support this syntax
create table t1 (a int) transactional=0; create table t1 (a int) transactional=0;
Warnings: Warnings:
Warning 1478 Table storage engine 'MyISAM' does not support the create option 'TRANSACTIONAL=0' Warning 1911 Unknown option 'transactional'
create table t2 (a int) page_checksum=1; create table t2 (a int) page_checksum=1;
create table t3 (a int) row_format=page; create table t3 (a int) row_format=page;
drop table t1,t2,t3; drop table t1,t2,t3;
...@@ -2019,7 +2019,7 @@ drop table t1; ...@@ -2019,7 +2019,7 @@ drop table t1;
# MDEV-18428 Memory: If transactional=0 is specified in CREATE TABLE, it is not possible to ALTER TABLE # MDEV-18428 Memory: If transactional=0 is specified in CREATE TABLE, it is not possible to ALTER TABLE
# #
create table t1 (c int(10) unsigned) engine=memory transactional=0; create table t1 (c int(10) unsigned) engine=memory transactional=0;
ERROR HY000: Table storage engine 'MEMORY' does not support the create option 'TRANSACTIONAL=0' ERROR HY000: Unknown option 'transactional'
# #
# End of 10.2 tests # End of 10.2 tests
# #
......
...@@ -1879,7 +1879,7 @@ drop table t1; ...@@ -1879,7 +1879,7 @@ drop table t1;
--echo # --echo #
--echo # MDEV-18428 Memory: If transactional=0 is specified in CREATE TABLE, it is not possible to ALTER TABLE --echo # MDEV-18428 Memory: If transactional=0 is specified in CREATE TABLE, it is not possible to ALTER TABLE
--echo # --echo #
--error ER_ILLEGAL_HA_CREATE_OPTION --error ER_UNKNOWN_OPTION
create table t1 (c int(10) unsigned) engine=memory transactional=0; create table t1 (c int(10) unsigned) engine=memory transactional=0;
--echo # --echo #
......
...@@ -2415,13 +2415,13 @@ DROP TABLE t1; ...@@ -2415,13 +2415,13 @@ DROP TABLE t1;
set statement sql_mode='' for set statement sql_mode='' for
create table t1 (n int not null, c char(1)) transactional=1; create table t1 (n int not null, c char(1)) transactional=1;
Warnings: Warnings:
Warning 1478 Table storage engine 'MyISAM' does not support the create option 'TRANSACTIONAL=1' Warning 1911 Unknown option 'transactional'
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`n` int(11) NOT NULL, `n` int(11) NOT NULL,
`c` char(1) DEFAULT NULL `c` char(1) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci TRANSACTIONAL=1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci /* TRANSACTIONAL=1 */
drop table t1; drop table t1;
CREATE TABLE t1 (line LINESTRING NOT NULL) engine=myisam; CREATE TABLE t1 (line LINESTRING NOT NULL) engine=myisam;
INSERT INTO t1 VALUES (GeomFromText("LINESTRING(0 0)")); INSERT INTO t1 VALUES (GeomFromText("LINESTRING(0 0)"));
......
drop table if exists t1;
SET @OLD_SQL_MODE=@@SQL_MODE; SET @OLD_SQL_MODE=@@SQL_MODE;
SET SQL_MODE='IGNORE_BAD_TABLE_OPTIONS'; SET SQL_MODE='IGNORE_BAD_TABLE_OPTIONS';
create table t1 (a int fkey=vvv, key akey (a) dff=vvv) tkey1='1v1'; create table t1 (a int fkey=vvv, key akey (a) dff=vvv) tkey1='1v1';
...@@ -180,3 +179,103 @@ SET SQL_MODE=''; ...@@ -180,3 +179,103 @@ SET SQL_MODE='';
create table t1 (a int fkey=vvv, key akey (a) dff=vvv) tkey1=1v1; create table t1 (a int fkey=vvv, key akey (a) dff=vvv) tkey1=1v1;
ERROR HY000: Unknown option 'fkey' ERROR HY000: Unknown option 'fkey'
SET @@SQL_MODE=@OLD_SQL_MODE; SET @@SQL_MODE=@OLD_SQL_MODE;
#
# End of 5.5 tests
#
#
# MDEV-31822 ALTER TABLE ENGINE=x started failing instead of producing warning on unsupported TRANSACTIONAL=1
#
create table t0 (a int) transactional=0 engine=aria;
create table t1 (a int) transactional=1 engine=aria;
create table t2 (a int) transactional=default engine=aria;
show create table t0;
Table Create Table
t0 CREATE TABLE `t0` (
`a` int(11) DEFAULT NULL
) ENGINE=Aria DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci PAGE_CHECKSUM=1 TRANSACTIONAL=0
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL
) ENGINE=Aria DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci PAGE_CHECKSUM=1 TRANSACTIONAL=1
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) DEFAULT NULL
) ENGINE=Aria DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci PAGE_CHECKSUM=1
alter table t0 engine=myisam;
alter table t1 engine=myisam;
alter table t2 engine=myisam;
show create table t0;
Table Create Table
t0 CREATE TABLE `t0` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci PAGE_CHECKSUM=1 /* TRANSACTIONAL=0 */
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci PAGE_CHECKSUM=1 /* TRANSACTIONAL=1 */
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci PAGE_CHECKSUM=1
alter table t0 engine=myisam transactional=0;
ERROR HY000: Unknown option 'transactional'
alter table t1 engine=myisam transactional=1;
ERROR HY000: Unknown option 'transactional'
alter table t2 engine=myisam transactional=default;
ERROR HY000: Unknown option 'transactional'
set sql_mode=IGNORE_BAD_TABLE_OPTIONS;
alter table t0 engine=myisam transactional=0;
Warnings:
Warning 1911 Unknown option 'transactional'
alter table t1 engine=myisam transactional=1;
Warnings:
Warning 1911 Unknown option 'transactional'
alter table t2 engine=myisam transactional=default;
Warnings:
Warning 1911 Unknown option 'transactional'
show create table t0;
Table Create Table
t0 CREATE TABLE `t0` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci TRANSACTIONAL=0
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci TRANSACTIONAL=1
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop table t0,t1,t2;
create table t1 (a int) foo=bar;
Warnings:
Warning 1911 Unknown option 'foo'
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci `foo`=bar
set sql_mode=default;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci /* `foo`=bar */
alter table t1 engine=aria bar=foo;
ERROR HY000: Unknown option 'bar'
alter table t1 engine=aria;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL
) ENGINE=Aria DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci PAGE_CHECKSUM=1 /* `foo`=bar */
drop table t1;
#
# End of 10.5 tests
#
--disable_warnings
drop table if exists t1;
--enable_warnings
SET @OLD_SQL_MODE=@@SQL_MODE; SET @OLD_SQL_MODE=@@SQL_MODE;
SET SQL_MODE='IGNORE_BAD_TABLE_OPTIONS'; SET SQL_MODE='IGNORE_BAD_TABLE_OPTIONS';
...@@ -66,3 +62,52 @@ SET SQL_MODE=''; ...@@ -66,3 +62,52 @@ SET SQL_MODE='';
create table t1 (a int fkey=vvv, key akey (a) dff=vvv) tkey1=1v1; create table t1 (a int fkey=vvv, key akey (a) dff=vvv) tkey1=1v1;
SET @@SQL_MODE=@OLD_SQL_MODE; SET @@SQL_MODE=@OLD_SQL_MODE;
--echo #
--echo # End of 5.5 tests
--echo #
--echo #
--echo # MDEV-31822 ALTER TABLE ENGINE=x started failing instead of producing warning on unsupported TRANSACTIONAL=1
--echo #
create table t0 (a int) transactional=0 engine=aria;
create table t1 (a int) transactional=1 engine=aria;
create table t2 (a int) transactional=default engine=aria;
show create table t0;
show create table t1;
show create table t2;
alter table t0 engine=myisam;
alter table t1 engine=myisam;
alter table t2 engine=myisam;
show create table t0;
show create table t1;
show create table t2;
--error ER_UNKNOWN_OPTION
alter table t0 engine=myisam transactional=0;
--error ER_UNKNOWN_OPTION
alter table t1 engine=myisam transactional=1;
--error ER_UNKNOWN_OPTION
alter table t2 engine=myisam transactional=default;
set sql_mode=IGNORE_BAD_TABLE_OPTIONS;
alter table t0 engine=myisam transactional=0;
alter table t1 engine=myisam transactional=1;
alter table t2 engine=myisam transactional=default;
show create table t0;
show create table t1;
show create table t2;
drop table t0,t1,t2;
# same behavior for other unknown options:
create table t1 (a int) foo=bar;
show create table t1;
set sql_mode=default;
show create table t1;
--error ER_UNKNOWN_OPTION
alter table t1 engine=aria bar=foo;
alter table t1 engine=aria;
show create table t1;
drop table t1;
--echo #
--echo # End of 10.5 tests
--echo #
...@@ -521,8 +521,6 @@ t1 CREATE TABLE `t1` ( ...@@ -521,8 +521,6 @@ t1 CREATE TABLE `t1` (
drop table t1; drop table t1;
create table t1 (n int not null, c char(1)) engine=aria transactional=1; create table t1 (n int not null, c char(1)) engine=aria transactional=1;
alter table t1 engine=myisam; alter table t1 engine=myisam;
Warnings:
Warning 1478 Table storage engine 'MyISAM' does not support the create option 'TRANSACTIONAL=1'
alter table t1 engine=aria; alter table t1 engine=aria;
show create table t1; show create table t1;
Table Create Table Table Create Table
...@@ -533,7 +531,7 @@ t1 CREATE TABLE `t1` ( ...@@ -533,7 +531,7 @@ t1 CREATE TABLE `t1` (
drop table t1; drop table t1;
create table t1 (n int not null, c char(1)) engine=myisam transactional=1; create table t1 (n int not null, c char(1)) engine=myisam transactional=1;
Warnings: Warnings:
Warning 1478 Table storage engine 'MyISAM' does not support the create option 'TRANSACTIONAL=1' Warning 1911 Unknown option 'transactional'
alter table t1 engine=aria; alter table t1 engine=aria;
show create table t1; show create table t1;
Table Create Table Table Create Table
......
set @old_sql_mode= @@sql_mode;
set @@sql_mode= '';
alter table mysql.plugin engine=myisam; alter table mysql.plugin engine=myisam;
Warnings:
Warning 1478 Table storage engine 'MyISAM' does not support the create option 'TRANSACTIONAL=1'
set @@sql_mode= @old_sql_mode;
set @old_dbug=@@debug_dbug; set @old_dbug=@@debug_dbug;
call mtr.add_suppression("Index for table.*mysql.plugin.MYI"); call mtr.add_suppression("Index for table.*mysql.plugin.MYI");
call mtr.add_suppression("Index for table 'plugin' is corrupt; try to repair it"); call mtr.add_suppression("Index for table 'plugin' is corrupt; try to repair it");
......
...@@ -5,10 +5,7 @@ if (!$ADT_NULL_SO) { ...@@ -5,10 +5,7 @@ if (!$ADT_NULL_SO) {
skip No NULL_AUDIT plugin; skip No NULL_AUDIT plugin;
} }
set @old_sql_mode= @@sql_mode;
set @@sql_mode= '';
alter table mysql.plugin engine=myisam; alter table mysql.plugin engine=myisam;
set @@sql_mode= @old_sql_mode;
set @old_dbug=@@debug_dbug; set @old_dbug=@@debug_dbug;
call mtr.add_suppression("Index for table.*mysql.plugin.MYI"); call mtr.add_suppression("Index for table.*mysql.plugin.MYI");
......
...@@ -3548,7 +3548,7 @@ class handler :public Sql_alloc ...@@ -3548,7 +3548,7 @@ class handler :public Sql_alloc
- How things are tracked in trx and in add_changed_table(). - How things are tracked in trx and in add_changed_table().
- If we can combine several statements under one commit in the binary log. - If we can combine several statements under one commit in the binary log.
*/ */
bool has_transactions() bool has_transactions() const
{ {
return ((ha_table_flags() & (HA_NO_TRANSACTIONS | HA_PERSISTENT_TABLE)) return ((ha_table_flags() & (HA_NO_TRANSACTIONS | HA_PERSISTENT_TABLE))
== 0); == 0);
...@@ -3559,24 +3559,33 @@ class handler :public Sql_alloc ...@@ -3559,24 +3559,33 @@ class handler :public Sql_alloc
we don't have to write failed statements to the log as they can be we don't have to write failed statements to the log as they can be
rolled back. rolled back.
*/ */
bool has_transactions_and_rollback() bool has_transactions_and_rollback() const
{ {
return has_transactions() && has_rollback(); return has_transactions() && has_rollback();
} }
/* /*
True if the underlaying table support transactions and rollback True if the underlaying table support transactions and rollback
*/ */
bool has_transaction_manager() bool has_transaction_manager() const
{ {
return ((ha_table_flags() & HA_NO_TRANSACTIONS) == 0 && has_rollback()); return ((ha_table_flags() & HA_NO_TRANSACTIONS) == 0 && has_rollback());
} }
/*
True if the underlaying table support TRANSACTIONAL table option
*/
bool has_transactional_option() const
{
extern handlerton *maria_hton;
return partition_ht() == maria_hton || has_transaction_manager();
}
/* /*
True if table has rollback. Used to check if an update on the table True if table has rollback. Used to check if an update on the table
can be killed fast. can be killed fast.
*/ */
bool has_rollback() bool has_rollback() const
{ {
return ((ht->flags & HTON_NO_ROLLBACK) == 0); return ((ht->flags & HTON_NO_ROLLBACK) == 0);
} }
......
...@@ -1956,8 +1956,13 @@ static void add_table_options(THD *thd, TABLE *table, ...@@ -1956,8 +1956,13 @@ static void add_table_options(THD *thd, TABLE *table,
} }
if (share->transactional != HA_CHOICE_UNDEF) if (share->transactional != HA_CHOICE_UNDEF)
{ {
bool do_comment= !table->file->has_transactional_option() && check_options;
if (do_comment)
packet->append(STRING_WITH_LEN(" /*"));
packet->append(STRING_WITH_LEN(" TRANSACTIONAL=")); packet->append(STRING_WITH_LEN(" TRANSACTIONAL="));
packet->append(ha_choice_values[(uint) share->transactional], 1); packet->append(ha_choice_values[(uint) share->transactional], 1);
if (do_comment)
packet->append(STRING_WITH_LEN(" */"));
} }
if (share->table_type == TABLE_TYPE_SEQUENCE) if (share->table_type == TABLE_TYPE_SEQUENCE)
packet->append(STRING_WITH_LEN(" SEQUENCE=1")); packet->append(STRING_WITH_LEN(" SEQUENCE=1"));
......
...@@ -4577,15 +4577,10 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, ...@@ -4577,15 +4577,10 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
} }
/* Give warnings for not supported table options */ /* Give warnings for not supported table options */
extern handlerton *maria_hton; if (create_info->used_fields & HA_CREATE_USED_TRANSACTIONAL &&
if (file->partition_ht() != maria_hton && create_info->transactional && !file->has_transactional_option())
!file->has_transaction_manager()) push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_UNKNOWN_OPTION,
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_THD(thd, ER_UNKNOWN_OPTION), "transactional");
ER_ILLEGAL_HA_CREATE_OPTION,
ER_THD(thd, ER_ILLEGAL_HA_CREATE_OPTION),
file->engine_name()->str,
create_info->transactional == HA_CHOICE_YES
? "TRANSACTIONAL=1" : "TRANSACTIONAL=0");
if (parse_option_list(thd, file->partition_ht(), &create_info->option_struct, if (parse_option_list(thd, file->partition_ht(), &create_info->option_struct,
&create_info->option_list, &create_info->option_list,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment