Skip to content

Commit

Permalink
feat(tianmu):support the ALTER syntax, ALTER table t1 rename t2, add …
Browse files Browse the repository at this point in the history
…c char(10) (stoneatom#760)

fix some warnings
add mtr for alter table
support alter table: mix add/drop column、order column and other syntaxs to use
  • Loading branch information
DandreChen committed Nov 8, 2022
1 parent 0af724e commit 00b05c1
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 10 deletions.
176 changes: 176 additions & 0 deletions mysql-test/suite/tianmu/r/alter_table_mix_use.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
create database alter_table_mix;
use alter_table_mix;
CREATE TABLE `alter_table_mix_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_mix_test;
Table Create Table
alter_table_mix_test CREATE TABLE `alter_table_mix_test` (
`c_tinyint` tinyint(4) DEFAULT NULL COMMENT 'tinyint',
`c_smallint` smallint(6) NOT NULL COMMENT 'smallint',
`c_mediumint` mediumint(9) DEFAULT NULL COMMENT 'mediumint',
`c_int` int(11) DEFAULT NULL COMMENT 'int',
`c_bigint` bigint(20) 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_mix_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');
alter table alter_table_mix_test rename alter_table_rename_add, add c_add char(10);
show create table alter_table_rename_add;
Table Create Table
alter_table_rename_add CREATE TABLE `alter_table_rename_add` (
`c_tinyint` tinyint(4) DEFAULT NULL COMMENT 'tinyint',
`c_smallint` smallint(6) NOT NULL COMMENT 'smallint',
`c_mediumint` mediumint(9) DEFAULT NULL COMMENT 'mediumint',
`c_int` int(11) DEFAULT NULL COMMENT 'int',
`c_bigint` bigint(20) 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',
`c_add` char(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
insert into alter_table_rename_add(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, c_add)
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', 'add');
show create table alter_table_rename_add;
Table Create Table
alter_table_rename_add CREATE TABLE `alter_table_rename_add` (
`c_tinyint` tinyint(4) DEFAULT NULL COMMENT 'tinyint',
`c_smallint` smallint(6) NOT NULL COMMENT 'smallint',
`c_mediumint` mediumint(9) DEFAULT NULL COMMENT 'mediumint',
`c_int` int(11) DEFAULT NULL COMMENT 'int',
`c_bigint` bigint(20) 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',
`c_add` char(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
CREATE TABLE `alter_table_mix_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_mix_test;
Table Create Table
alter_table_mix_test CREATE TABLE `alter_table_mix_test` (
`c_tinyint` tinyint(4) DEFAULT NULL COMMENT 'tinyint',
`c_smallint` smallint(6) NOT NULL COMMENT 'smallint',
`c_mediumint` mediumint(9) DEFAULT NULL COMMENT 'mediumint',
`c_int` int(11) DEFAULT NULL COMMENT 'int',
`c_bigint` bigint(20) 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_mix_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');
alter table alter_table_mix_test rename alter_table_rename_drop, drop c_longblob;
show create table alter_table_rename_drop;
Table Create Table
alter_table_rename_drop CREATE TABLE `alter_table_rename_drop` (
`c_tinyint` tinyint(4) DEFAULT NULL COMMENT 'tinyint',
`c_smallint` smallint(6) NOT NULL COMMENT 'smallint',
`c_mediumint` mediumint(9) DEFAULT NULL COMMENT 'mediumint',
`c_int` int(11) DEFAULT NULL COMMENT 'int',
`c_bigint` bigint(20) 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'
) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
insert into alter_table_rename_drop(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_rename_drop;
Table Create Table
alter_table_rename_drop CREATE TABLE `alter_table_rename_drop` (
`c_tinyint` tinyint(4) DEFAULT NULL COMMENT 'tinyint',
`c_smallint` smallint(6) NOT NULL COMMENT 'smallint',
`c_mediumint` mediumint(9) DEFAULT NULL COMMENT 'mediumint',
`c_int` int(11) DEFAULT NULL COMMENT 'int',
`c_bigint` bigint(20) 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'
) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
84 changes: 84 additions & 0 deletions mysql-test/suite/tianmu/t/alter_table_mix_use.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
--source include/have_tianmu.inc

#
#ALTER TABLE table_name NOT NULL to NULL or NULL to NOT NULL ...
#
create database alter_table_mix;
use alter_table_mix;

CREATE TABLE `alter_table_mix_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: RENAME TABLE and ADD COLUMN
#

show create table alter_table_mix_test;

insert into alter_table_mix_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');

alter table alter_table_mix_test rename alter_table_rename_add, add c_add char(10);

show create table alter_table_rename_add;

insert into alter_table_rename_add(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, c_add)
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', 'add');

show create table alter_table_rename_add;

#
#ALTER TABLE: RENAME TABLE and DROP COLUMN
#

CREATE TABLE `alter_table_mix_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_mix_test;

insert into alter_table_mix_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');

alter table alter_table_mix_test rename alter_table_rename_drop, drop c_longblob;

show create table alter_table_rename_drop;

insert into alter_table_rename_drop(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_rename_drop;

12 changes: 6 additions & 6 deletions storage/tianmu/core/temp_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ class TempTable : public JustATable {
// values (incl. null, if flag set)
uint64_t ExactDistinctVals([[maybe_unused]] Filter *f) override { return common::NULL_VALUE_64; }
bool IsDistinct([[maybe_unused]] Filter *f) override { return false; }
size_t MaxStringSize(Filter *f = nullptr) override; // maximal byte string length in column
int64_t RoughMin(Filter *f = nullptr, common::RSValue *rf = nullptr) override {
size_t MaxStringSize([[maybe_unused]] Filter *f = nullptr) override; // maximal byte string length in column
int64_t RoughMin([[maybe_unused]] Filter *f = nullptr, [[maybe_unused]] common::RSValue *rf = nullptr) override {
return common::MINUS_INF_64;
} // for numerical: best rough approximation of min for a given filter (or
// global min if filter is nullptr)
int64_t RoughMax(Filter *f = nullptr, common::RSValue *rf = nullptr) override {
int64_t RoughMax([[maybe_unused]] Filter *f = nullptr, [[maybe_unused]] common::RSValue *rf = nullptr) override {
return common::PLUS_INF_64;
} // for numerical: best rough approximation of max for a given filter (or
// global max if filter is nullptr)
Expand Down Expand Up @@ -265,10 +265,10 @@ class TempTable : public JustATable {
bool IsNull(int64_t obj,
int attr) override; // return true if the value of attr. is null

int64_t RoughMin([[maybe_unused]] int n_a, Filter *f = nullptr) { return common::MINUS_INF_64; }
int64_t RoughMax([[maybe_unused]] int n_a, Filter *f = nullptr) { return common::PLUS_INF_64; }
int64_t RoughMin([[maybe_unused]] int n_a, [[maybe_unused]] Filter *f = nullptr) { return common::MINUS_INF_64; }
int64_t RoughMax([[maybe_unused]] int n_a, [[maybe_unused]] Filter *f = nullptr) { return common::PLUS_INF_64; }

uint MaxStringSize(int n_a, Filter *f = nullptr) override {
uint MaxStringSize(int n_a, [[maybe_unused]] Filter *f = nullptr) override {
if (n_a < 0)
return GetFieldSize(-n_a - 1);
return GetFieldSize(n_a);
Expand Down
11 changes: 7 additions & 4 deletions storage/tianmu/handler/tianmu_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1529,19 +1529,22 @@ enum_alter_inplace_result ha_tianmu::check_if_supported_inplace_alter([[maybe_un

if ((ha_alter_info->handler_flags & ~TIANMU_SUPPORTED_ALTER_ADD_DROP_ORDER) &&
(ha_alter_info->handler_flags != TIANMU_SUPPORTED_ALTER_COLUMN_NAME)) {
// support alter table column type
// support alter table: column type
if (ha_alter_info->handler_flags & Alter_inplace_info::ALTER_STORED_COLUMN_TYPE)
DBUG_RETURN(HA_ALTER_INPLACE_NOT_SUPPORTED);
// support alter table column exceeded length
// support alter table: column exceeded length
if ((ha_alter_info->handler_flags & Alter_inplace_info::ALTER_COLUMN_EQUAL_PACK_LENGTH))
DBUG_RETURN(HA_ALTER_INPLACE_NOT_SUPPORTED);
// support alter table column default
// 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
// 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);
// support alter table: mix add/drop column、order column and other syntaxs to use
if (ha_alter_info->handler_flags & TIANMU_SUPPORTED_ALTER_ADD_DROP_ORDER)
DBUG_RETURN(HA_ALTER_INPLACE_NOT_SUPPORTED);

DBUG_RETURN(HA_ALTER_ERROR);
}
Expand Down

0 comments on commit 00b05c1

Please sign in to comment.