From f8c9d2afd779bec578b553e6e8ed6e8afbb4ef8a Mon Sep 17 00:00:00 2001 From: augety Date: Tue, 9 May 2023 15:47:50 +0800 Subject: [PATCH] feat(tianmu): support alter table xxx modify xxx type(length) default null(#1671) --- .../suite/tianmu/r/alter_table_null.result | 155 ++++++++++++++++++ .../suite/tianmu/t/alter_table_null.test | 60 +++++++ storage/tianmu/handler/ha_tianmu.cpp | 14 +- 3 files changed, 225 insertions(+), 4 deletions(-) create mode 100644 mysql-test/suite/tianmu/r/alter_table_null.result create mode 100644 mysql-test/suite/tianmu/t/alter_table_null.test diff --git a/mysql-test/suite/tianmu/r/alter_table_null.result b/mysql-test/suite/tianmu/r/alter_table_null.result new file mode 100644 index 000000000..e8681771a --- /dev/null +++ b/mysql-test/suite/tianmu/r/alter_table_null.result @@ -0,0 +1,155 @@ +create database alter_table_null; +use alter_table_null; +CREATE TABLE `alter_table_null_test` ( +`c_tinyint` tinyint DEFAULT NULL COMMENT 'tinyint', +`c_smallint` smallint NOT NULL COMMENT 'smallint', +`c_mediumint` mediumint DEFAULT NULL COMMENT 'mediumint', +`c_int` int DEFAULT NULL COMMENT 'int', +`c_bigint` bigint DEFAULT NULL COMMENT 'bigint', +`c_float` float DEFAULT NULL COMMENT 'float', +`c_double` double DEFAULT NULL COMMENT 'double', +`c_decimal` decimal(10,5) DEFAULT NULL COMMENT 'decimal', +`c_date` date DEFAULT NULL COMMENT 'date', +`c_datetime` datetime DEFAULT NULL COMMENT 'datetime', +`c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp', +`c_time` time DEFAULT NULL COMMENT 'time', +`c_char` char(10) DEFAULT NULL COMMENT 'char', +`c_varchar` varchar(10) DEFAULT NULL COMMENT 'varchar', +`c_blob` blob COMMENT 'blob', +`c_text` text COMMENT 'text', +`c_longblob` longblob COMMENT 'longblob' +) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +show create table alter_table_null_test; +Table Create Table +alter_table_null_test CREATE TABLE `alter_table_null_test` ( + `c_tinyint` tinyint DEFAULT NULL COMMENT 'tinyint', + `c_smallint` smallint NOT NULL COMMENT 'smallint', + `c_mediumint` mediumint DEFAULT NULL COMMENT 'mediumint', + `c_int` int DEFAULT NULL COMMENT 'int', + `c_bigint` bigint DEFAULT NULL COMMENT 'bigint', + `c_float` float DEFAULT NULL COMMENT 'float', + `c_double` double DEFAULT NULL COMMENT 'double', + `c_decimal` decimal(10,5) DEFAULT NULL COMMENT 'decimal', + `c_date` date DEFAULT NULL COMMENT 'date', + `c_datetime` datetime DEFAULT NULL COMMENT 'datetime', + `c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp', + `c_time` time DEFAULT NULL COMMENT 'time', + `c_char` char(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'char', + `c_varchar` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'varchar', + `c_blob` blob COMMENT 'blob', + `c_text` text COLLATE utf8mb4_unicode_ci COMMENT 'text', + `c_longblob` longblob COMMENT 'longblob' +) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci +alter table alter_table_null_test modify c_smallint smallint NOT NULL; +show create table alter_table_null_test; +Table Create Table +alter_table_null_test CREATE TABLE `alter_table_null_test` ( + `c_tinyint` tinyint DEFAULT NULL COMMENT 'tinyint', + `c_smallint` smallint NOT NULL, + `c_mediumint` mediumint DEFAULT NULL COMMENT 'mediumint', + `c_int` int DEFAULT NULL COMMENT 'int', + `c_bigint` bigint DEFAULT NULL COMMENT 'bigint', + `c_float` float DEFAULT NULL COMMENT 'float', + `c_double` double DEFAULT NULL COMMENT 'double', + `c_decimal` decimal(10,5) DEFAULT NULL COMMENT 'decimal', + `c_date` date DEFAULT NULL COMMENT 'date', + `c_datetime` datetime DEFAULT NULL COMMENT 'datetime', + `c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp', + `c_time` time DEFAULT NULL COMMENT 'time', + `c_char` char(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'char', + `c_varchar` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'varchar', + `c_blob` blob COMMENT 'blob', + `c_text` text COLLATE utf8mb4_unicode_ci COMMENT 'text', + `c_longblob` longblob COMMENT 'longblob' +) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci +insert into alter_table_null_test(c_tinyint,c_smallint,c_mediumint,c_int,c_bigint,c_float,c_double,c_decimal,c_date,c_datetime,c_timestamp,c_time,c_char,c_varchar,c_text) +values(105,105,105,105,105,5.2,10.88,105.083,'2016-02-25','2016-02-25 10:20:01','2016-02-25 05:20:01','10:20:01','stoneatom1','hello1','bcdefghijklmn'); +show create table alter_table_null_test; +Table Create Table +alter_table_null_test CREATE TABLE `alter_table_null_test` ( + `c_tinyint` tinyint DEFAULT NULL COMMENT 'tinyint', + `c_smallint` smallint NOT NULL, + `c_mediumint` mediumint DEFAULT NULL COMMENT 'mediumint', + `c_int` int DEFAULT NULL COMMENT 'int', + `c_bigint` bigint DEFAULT NULL COMMENT 'bigint', + `c_float` float DEFAULT NULL COMMENT 'float', + `c_double` double DEFAULT NULL COMMENT 'double', + `c_decimal` decimal(10,5) DEFAULT NULL COMMENT 'decimal', + `c_date` date DEFAULT NULL COMMENT 'date', + `c_datetime` datetime DEFAULT NULL COMMENT 'datetime', + `c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp', + `c_time` time DEFAULT NULL COMMENT 'time', + `c_char` char(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'char', + `c_varchar` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'varchar', + `c_blob` blob COMMENT 'blob', + `c_text` text COLLATE utf8mb4_unicode_ci COMMENT 'text', + `c_longblob` longblob COMMENT 'longblob' +) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci +show create table alter_table_null_test; +Table Create Table +alter_table_null_test CREATE TABLE `alter_table_null_test` ( + `c_tinyint` tinyint DEFAULT NULL COMMENT 'tinyint', + `c_smallint` smallint NOT NULL, + `c_mediumint` mediumint DEFAULT NULL COMMENT 'mediumint', + `c_int` int DEFAULT NULL COMMENT 'int', + `c_bigint` bigint DEFAULT NULL COMMENT 'bigint', + `c_float` float DEFAULT NULL COMMENT 'float', + `c_double` double DEFAULT NULL COMMENT 'double', + `c_decimal` decimal(10,5) DEFAULT NULL COMMENT 'decimal', + `c_date` date DEFAULT NULL COMMENT 'date', + `c_datetime` datetime DEFAULT NULL COMMENT 'datetime', + `c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp', + `c_time` time DEFAULT NULL COMMENT 'time', + `c_char` char(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'char', + `c_varchar` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'varchar', + `c_blob` blob COMMENT 'blob', + `c_text` text COLLATE utf8mb4_unicode_ci COMMENT 'text', + `c_longblob` longblob COMMENT 'longblob' +) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci +alter table alter_table_null_test modify c_tinyint tinyint NOT NULL; +show create table alter_table_null_test; +Table Create Table +alter_table_null_test CREATE TABLE `alter_table_null_test` ( + `c_tinyint` tinyint NOT NULL, + `c_smallint` smallint NOT NULL, + `c_mediumint` mediumint DEFAULT NULL COMMENT 'mediumint', + `c_int` int DEFAULT NULL COMMENT 'int', + `c_bigint` bigint DEFAULT NULL COMMENT 'bigint', + `c_float` float DEFAULT NULL COMMENT 'float', + `c_double` double DEFAULT NULL COMMENT 'double', + `c_decimal` decimal(10,5) DEFAULT NULL COMMENT 'decimal', + `c_date` date DEFAULT NULL COMMENT 'date', + `c_datetime` datetime DEFAULT NULL COMMENT 'datetime', + `c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp', + `c_time` time DEFAULT NULL COMMENT 'time', + `c_char` char(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'char', + `c_varchar` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'varchar', + `c_blob` blob COMMENT 'blob', + `c_text` text COLLATE utf8mb4_unicode_ci COMMENT 'text', + `c_longblob` longblob COMMENT 'longblob' +) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci +insert into alter_table_null_test(c_tinyint,c_smallint,c_mediumint,c_int,c_bigint,c_float,c_double,c_decimal,c_date,c_datetime,c_timestamp,c_time,c_char,c_varchar,c_text) +values(105,105,105,105,105,5.2,10.88,105.083,'2016-02-25','2016-02-25 10:20:01','2016-02-25 05:20:01','10:20:01','stoneatom1','hello1','bcdefghijklmn'); +show create table alter_table_null_test; +Table Create Table +alter_table_null_test CREATE TABLE `alter_table_null_test` ( + `c_tinyint` tinyint NOT NULL, + `c_smallint` smallint NOT NULL, + `c_mediumint` mediumint DEFAULT NULL COMMENT 'mediumint', + `c_int` int DEFAULT NULL COMMENT 'int', + `c_bigint` bigint DEFAULT NULL COMMENT 'bigint', + `c_float` float DEFAULT NULL COMMENT 'float', + `c_double` double DEFAULT NULL COMMENT 'double', + `c_decimal` decimal(10,5) DEFAULT NULL COMMENT 'decimal', + `c_date` date DEFAULT NULL COMMENT 'date', + `c_datetime` datetime DEFAULT NULL COMMENT 'datetime', + `c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp', + `c_time` time DEFAULT NULL COMMENT 'time', + `c_char` char(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'char', + `c_varchar` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'varchar', + `c_blob` blob COMMENT 'blob', + `c_text` text COLLATE utf8mb4_unicode_ci COMMENT 'text', + `c_longblob` longblob COMMENT 'longblob' +) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci +drop table alter_table_null_test; +drop database alter_table_null; diff --git a/mysql-test/suite/tianmu/t/alter_table_null.test b/mysql-test/suite/tianmu/t/alter_table_null.test new file mode 100644 index 000000000..f8bd1707c --- /dev/null +++ b/mysql-test/suite/tianmu/t/alter_table_null.test @@ -0,0 +1,60 @@ +--source include/have_tianmu.inc + +# +#ALTER TABLE table_name NOT NULL to NULL or NULL to NOT NULL ... +# +create database alter_table_null; +use alter_table_null; + +CREATE TABLE `alter_table_null_test` ( + `c_tinyint` tinyint DEFAULT NULL COMMENT 'tinyint', + `c_smallint` smallint NOT NULL COMMENT 'smallint', + `c_mediumint` mediumint DEFAULT NULL COMMENT 'mediumint', + `c_int` int DEFAULT NULL COMMENT 'int', + `c_bigint` bigint DEFAULT NULL COMMENT 'bigint', + `c_float` float DEFAULT NULL COMMENT 'float', + `c_double` double DEFAULT NULL COMMENT 'double', + `c_decimal` decimal(10,5) DEFAULT NULL COMMENT 'decimal', + `c_date` date DEFAULT NULL COMMENT 'date', + `c_datetime` datetime DEFAULT NULL COMMENT 'datetime', + `c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp', + `c_time` time DEFAULT NULL COMMENT 'time', + `c_char` char(10) DEFAULT NULL COMMENT 'char', + `c_varchar` varchar(10) DEFAULT NULL COMMENT 'varchar', + `c_blob` blob COMMENT 'blob', + `c_text` text COMMENT 'text', + `c_longblob` longblob COMMENT 'longblob' +) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +# +#ALTER TABLE: NOT NULL to NULL +# + +show create table alter_table_null_test; + +alter table alter_table_null_test modify c_smallint smallint NOT NULL; + +show create table alter_table_null_test; + +insert into alter_table_null_test(c_tinyint,c_smallint,c_mediumint,c_int,c_bigint,c_float,c_double,c_decimal,c_date,c_datetime,c_timestamp,c_time,c_char,c_varchar,c_text) +values(105,105,105,105,105,5.2,10.88,105.083,'2016-02-25','2016-02-25 10:20:01','2016-02-25 05:20:01','10:20:01','stoneatom1','hello1','bcdefghijklmn'); + +show create table alter_table_null_test; + +# +#ALTER TABLE: NULL to NOT NULL +# + +show create table alter_table_null_test; + +alter table alter_table_null_test modify c_tinyint tinyint NOT NULL; + +show create table alter_table_null_test; + +insert into alter_table_null_test(c_tinyint,c_smallint,c_mediumint,c_int,c_bigint,c_float,c_double,c_decimal,c_date,c_datetime,c_timestamp,c_time,c_char,c_varchar,c_text) +values(105,105,105,105,105,5.2,10.88,105.083,'2016-02-25','2016-02-25 10:20:01','2016-02-25 05:20:01','10:20:01','stoneatom1','hello1','bcdefghijklmn'); + +show create table alter_table_null_test; + +drop table alter_table_null_test; +drop database alter_table_null; \ No newline at end of file diff --git a/storage/tianmu/handler/ha_tianmu.cpp b/storage/tianmu/handler/ha_tianmu.cpp index 5284f57d6..3ad222b32 100644 --- a/storage/tianmu/handler/ha_tianmu.cpp +++ b/storage/tianmu/handler/ha_tianmu.cpp @@ -316,7 +316,7 @@ int ha_tianmu::external_lock(THD *thd, int lock_type) { namespace { inline bool has_dup_key(std::shared_ptr &indextab, TABLE *table, size_t &row) { - common::ErrorCode ret; + common::ErrorCode ret = common::ErrorCode::SUCCESS; std::vector records; KEY *key = table->key_info + table->s->primary_key; @@ -612,9 +612,10 @@ int ha_tianmu::delete_all_rows() { int ha_tianmu::rename_table(const char *from, const char *to, const dd::Table *from_table_def, dd::Table *to_table_def) { // stonedb8 TODO + DBUG_ENTER(__PRETTY_FUNCTION__); try { ha_rcengine_->RenameTable(current_txn_, from, to, from_table_def, to_table_def, ha_thd()); - return 0; + DBUG_RETURN(false); } catch (std::exception &e) { my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); TIANMU_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); @@ -622,7 +623,7 @@ int ha_tianmu::rename_table(const char *from, const char *to, const dd::Table *f my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "An unknown system exception error caught.", MYF(0)); TIANMU_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); } - return 1; + DBUG_RETURN(true); } void ha_tianmu::update_create_info([[maybe_unused]] HA_CREATE_INFO *create_info) {} @@ -769,8 +770,9 @@ int ha_tianmu::open(const char *name, [[maybe_unused]] int mode, [[maybe_unused] } int ha_tianmu::free_share() { + DBUG_ENTER(__PRETTY_FUNCTION__); share_.reset(); - return 0; + DBUG_RETURN(0); } /* @@ -1522,6 +1524,10 @@ enum_alter_inplace_result ha_tianmu::check_if_supported_inplace_alter([[maybe_un // support alter table column default if (ha_alter_info->handler_flags & Alter_inplace_info::ALTER_COLUMN_DEFAULT) DBUG_RETURN(HA_ALTER_INPLACE_NOT_SUPPORTED); + // support alter table NULL to NOT NULL or NOT NULL to NULL + if (ha_alter_info->handler_flags & Alter_inplace_info::ALTER_COLUMN_NULLABLE || + ha_alter_info->handler_flags & Alter_inplace_info::ALTER_COLUMN_NOT_NULLABLE) + DBUG_RETURN(HA_ALTER_INPLACE_NOT_SUPPORTED); DBUG_RETURN(HA_ALTER_ERROR); }