diff options
author | Aleksey Midenkov <midenok@gmail.com> | 2022-12-10 14:25:54 +0300 |
---|---|---|
committer | Aleksey Midenkov <midenok@gmail.com> | 2023-01-17 12:34:43 +0300 |
commit | d3cfb46080d60d57b6d9e3fa4921063efee64884 (patch) | |
tree | 68c168ae2178f5b7ccd775f91d8648a4d7a972dc | |
parent | 0306f198967398dda9d046705d63700df367d549 (diff) | |
download | mariadb-git-d3cfb46080d60d57b6d9e3fa4921063efee64884.tar.gz |
MDEV-29767 CREATE OR REPLACE bypasses S3 restriction for table creation
For CREATE .. LIKE create_info->db_type contains default value MyISAM,
so it is wrong to use it for is_atomic_replace(). The fix uses
local_create_info for that when it already contains the correct
db_type of the source table.
-rw-r--r-- | mysql-test/suite/s3/basic.result | 15 | ||||
-rw-r--r-- | mysql-test/suite/s3/basic.test | 22 | ||||
-rw-r--r-- | sql/sql_table.cc | 5 | ||||
-rw-r--r-- | sql/structs.h | 4 |
4 files changed, 44 insertions, 2 deletions
diff --git a/mysql-test/suite/s3/basic.result b/mysql-test/suite/s3/basic.result index 790806ee43c..cea68e9b6f3 100644 --- a/mysql-test/suite/s3/basic.result +++ b/mysql-test/suite/s3/basic.result @@ -154,3 +154,18 @@ S3_pagecache_blocks_unused X S3_pagecache_blocks_used X S3_pagecache_read_requests X S3_pagecache_reads X +# +# MDEV-29767 CREATE OR REPLACE bypasses S3 restriction for table creation +# +create table t (a int) engine=Aria; +insert into t values (1),(2); +alter table t engine=S3; +create table t2 (a int) engine=S3; +ERROR HY000: Can't create table `database`.`t2` (errno: 131 "Command not supported by the engine") +create table t2 like t; +ERROR HY000: Can't create table `database`.`t2` (errno: 131 "Command not supported by the engine") +create or replace table t2 like t; +ERROR HY000: Can't create table `database`.`t2` (errno: 131 "Command not supported by the engine") +show create table t2; +ERROR 42S02: Table 'database.t2' doesn't exist +drop table t; diff --git a/mysql-test/suite/s3/basic.test b/mysql-test/suite/s3/basic.test index 99c2d8adb5d..77ee8b5ef31 100644 --- a/mysql-test/suite/s3/basic.test +++ b/mysql-test/suite/s3/basic.test @@ -85,4 +85,26 @@ show status like "s3%"; # # clean up # + +--echo # +--echo # MDEV-29767 CREATE OR REPLACE bypasses S3 restriction for table creation +--echo # +create table t (a int) engine=Aria; +insert into t values (1),(2); +alter table t engine=S3; +--replace_result $database database +--error ER_CANT_CREATE_TABLE +create table t2 (a int) engine=S3; +--replace_result $database database +--error ER_CANT_CREATE_TABLE +create table t2 like t; +--replace_result $database database +--error ER_CANT_CREATE_TABLE +create or replace table t2 like t; +--replace_result $database database +--error ER_NO_SUCH_TABLE +show create table t2; +# Cleanup +drop table t; + --source drop_database.inc diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 0860394c9f5..cf8ec9260c5 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5683,7 +5683,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, uint not_used; int create_res; TABLE_LIST *orig_table= table; - const bool atomic_replace= create_info->is_atomic_replace(); + bool atomic_replace; int create_table_mode= C_ORDINARY_CREATE; LEX_CUSTRING frm= { NULL, 0 }; char path_buf[FN_REFLEN + 1]; @@ -5749,6 +5749,9 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, local_create_info.db_type= src_table->table->s->db_type(); local_create_info.row_type= src_table->table->s->row_type; local_create_info.alter_info= &local_alter_info; + local_create_info.options= create_info->options; + atomic_replace= local_create_info.is_atomic_replace(); + /* This statement: CREATE TABLE t1 LIKE t2 diff --git a/sql/structs.h b/sql/structs.h index 1c3873196da..5185210b403 100644 --- a/sql/structs.h +++ b/sql/structs.h @@ -549,7 +549,9 @@ public: Options create_like_options() const { return (DDL_options_st::Options) - (((uint) m_options) & (OPT_IF_NOT_EXISTS | OPT_OR_REPLACE)); + /* TODO: that filter is only adding problems, remove it */ + (((uint) m_options) & (OPT_IF_NOT_EXISTS | OPT_OR_REPLACE | + OPT_OR_REPLACE_SLAVE_GENERATED)); } void init() { m_options= OPT_NONE; } void init(Options options) { m_options= options; } |