Skip to content

Commit 7ab205b

Browse files
committed
MDEV-34928 CREATE TABLE does not check valid engine for log tables
Log tables cannot work with transactional InnoDB or Aria, that is checked by ALTER TABLE for ER_UNSUPORTED_LOG_ENGINE. But it was possible to circumvent this check with CREATE TABLE. The patch makes the check of supported engine common for ALTER TABLE and CREATE TABLE.
1 parent 1dedd2a commit 7ab205b

File tree

5 files changed

+82
-14
lines changed

5 files changed

+82
-14
lines changed

mysql-test/main/log_tables.result

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,37 @@ select 'evil-doing', sleep(1.1)
10221022
select 'after evil-doing', sleep(0.2)
10231023
set global log_output=default;
10241024
drop user u@localhost;
1025+
# End of 10.5 tests
1026+
#
1027+
# MDEV-34928 CREATE TABLE does not check valid engine for log tables
1028+
#
1029+
set global general_log='on';
1030+
show create table mysql.general_log;
1031+
Table Create Table
1032+
general_log CREATE TABLE `general_log` (
1033+
`event_time` timestamp(6) NOT NULL DEFAULT current_timestamp(6) ON UPDATE current_timestamp(6),
1034+
`user_host` mediumtext NOT NULL,
1035+
`thread_id` bigint(21) unsigned NOT NULL,
1036+
`server_id` int(10) unsigned NOT NULL,
1037+
`command_type` varchar(64) NOT NULL,
1038+
`argument` mediumtext NOT NULL
1039+
) ENGINE=CSV DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='General log'
1040+
create or replace table mysql.general_log (a int) engine=innodb;
1041+
ERROR HY000: Storage engine InnoDB cannot be used for log tables
1042+
create or replace table mysql.slow_log (a int) engine=innodb;
1043+
ERROR HY000: Storage engine InnoDB cannot be used for log tables
1044+
create temporary table t (c int) engine=innodb;
1045+
insert into t values (1);
1046+
set global log_output='table';
1047+
set session autocommit=0;
1048+
update t set c=0;
1049+
truncate t;
1050+
select a;
1051+
ERROR 42S22: Unknown column 'a' in 'SELECT'
1052+
drop temporary table t;
1053+
set @@global.log_output= @old_log_output;
1054+
set @@global.general_log= @old_general_log;
1055+
# End of 10.6 tests
10251056
SET @@global.log_output= @old_log_output;
10261057
SET @@global.slow_query_log= @old_slow_query_log;
10271058
SET @@global.general_log= @old_general_log;

mysql-test/main/log_tables.test

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
-- source include/not_embedded.inc
33

44
--source include/have_csv.inc
5+
--source include/have_innodb.inc
56

67
SET SQL_MODE="";
78
SET @old_log_output= @@global.log_output;
@@ -1060,6 +1061,31 @@ set global log_output=default;
10601061
drop user u@localhost;
10611062
--enable_cursor_protocol
10621063

1064+
--echo # End of 10.5 tests
1065+
1066+
--echo #
1067+
--echo # MDEV-34928 CREATE TABLE does not check valid engine for log tables
1068+
--echo #
1069+
set global general_log='on';
1070+
show create table mysql.general_log;
1071+
--error ER_UNSUPORTED_LOG_ENGINE
1072+
create or replace table mysql.general_log (a int) engine=innodb;
1073+
--error ER_UNSUPORTED_LOG_ENGINE
1074+
create or replace table mysql.slow_log (a int) engine=innodb;
1075+
create temporary table t (c int) engine=innodb;
1076+
insert into t values (1);
1077+
set global log_output='table';
1078+
set session autocommit=0;
1079+
update t set c=0;
1080+
truncate t;
1081+
--error ER_BAD_FIELD_ERROR
1082+
select a;
1083+
drop temporary table t;
1084+
set @@global.log_output= @old_log_output;
1085+
set @@global.general_log= @old_general_log;
1086+
1087+
--echo # End of 10.6 tests
1088+
10631089
SET @@global.log_output= @old_log_output;
10641090
SET @@global.slow_query_log= @old_slow_query_log;
10651091
SET @@global.general_log= @old_general_log;

sql/handler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,6 +2315,7 @@ struct HA_CREATE_INFO: public Table_scope_and_contents_source_st,
23152315
const Lex_table_charset_collation_attrs_st &default_cscl,
23162316
const Lex_table_charset_collation_attrs_st &convert_cscl,
23172317
const Charset_collation_context &ctx);
2318+
bool check_if_valid_log_table();
23182319
};
23192320

23202321

sql/log.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,18 @@ int check_if_log_table(const TABLE_LIST *table)
745745
}
746746

747747

748+
bool HA_CREATE_INFO::check_if_valid_log_table()
749+
{
750+
if (!(db_type->flags & HTON_SUPPORT_LOG_TABLES) ||
751+
(db_type == maria_hton && transactional != HA_CHOICE_NO))
752+
{
753+
my_error(ER_UNSUPORTED_LOG_ENGINE, MYF(0), hton_name(db_type)->str);
754+
return true;
755+
}
756+
return false;
757+
}
758+
759+
748760
/**
749761
Check if a given table is opened log table
750762

sql/sql_table.cc

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4629,6 +4629,12 @@ int create_table_impl(THD *thd,
46294629
goto err;
46304630
}
46314631

4632+
TABLE_LIST table_list;
4633+
table_list.init_one_table(&db, &table_name, 0, TL_WRITE_ALLOW_WRITE);
4634+
int log_table= check_if_log_table(&table_list);
4635+
if (log_table && create_info->check_if_valid_log_table())
4636+
goto err;
4637+
46324638
handlerton *db_type;
46334639
if (!internal_tmp_table &&
46344640
ha_table_exists(thd, &db, &table_name,
@@ -4645,12 +4651,13 @@ int create_table_impl(THD *thd,
46454651
{
46464652
(void) delete_statistics_for_table(thd, &db, &table_name);
46474653

4648-
TABLE_LIST table_list;
4649-
table_list.init_one_table(&db, &table_name, 0, TL_WRITE_ALLOW_WRITE);
46504654
table_list.table= create_info->table;
46514655

4652-
if (check_if_log_table(&table_list, TRUE, "CREATE OR REPLACE"))
4656+
if (log_table && logger.is_log_table_enabled(log_table))
4657+
{
4658+
my_error(ER_BAD_LOG_STATEMENT, MYF(0), "CREATE OR REPLACE");
46534659
goto err;
4660+
}
46544661

46554662
/*
46564663
Rollback the empty transaction started in mysql_create_table()
@@ -10417,7 +10424,7 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db,
1041710424
it is the case.
1041810425
TODO: this design is obsolete and will be removed.
1041910426
*/
10420-
int table_kind= check_if_log_table(table_list, FALSE, NullS);
10427+
int table_kind= check_if_log_table(table_list);
1042110428
const bool used_engine= create_info->used_fields & HA_CREATE_USED_ENGINE;
1042210429

1042310430
if (table_kind)
@@ -10432,17 +10439,8 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db,
1043210439
/* Disable alter of log tables to unsupported engine */
1043310440
if ((used_engine) &&
1043410441
(!create_info->db_type || /* unknown engine */
10435-
!(create_info->db_type->flags & HTON_SUPPORT_LOG_TABLES)))
10436-
{
10437-
unsupported:
10438-
my_error(ER_UNSUPORTED_LOG_ENGINE, MYF(0),
10439-
hton_name(create_info->db_type)->str);
10442+
create_info->check_if_valid_log_table()))
1044010443
DBUG_RETURN(true);
10441-
}
10442-
10443-
if (create_info->db_type == maria_hton &&
10444-
create_info->transactional != HA_CHOICE_NO)
10445-
goto unsupported;
1044610444

1044710445
#ifdef WITH_PARTITION_STORAGE_ENGINE
1044810446
if (alter_info->partition_flags & ALTER_PARTITION_INFO)

0 commit comments

Comments
 (0)