Skip to content

Commit

Permalink
feat(tianmu):DDL function filtering optimization is not supported(#1325)
Browse files Browse the repository at this point in the history
Modify points:
1. Fix the error of judgment logic
2. Fix the value problem of (sql_mode) in the slave thread
  • Loading branch information
konghaiya authored and mergify[bot] committed Feb 28, 2023
1 parent 0f42505 commit 2321f0a
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 19 deletions.
159 changes: 159 additions & 0 deletions mysql-test/suite/tianmu/r/issue1325.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
include/master-slave.inc
[connection master]
DROP DATABASE IF EXISTS issue1325_test;
include/sync_slave_sql_with_master.inc
# on master:
CREATE DATABASE issue1325_test;
USE issue1325_test;
include/sync_slave_sql_with_master.inc
# on slave:
USE issue1325_test;
show databases;
Database
information_schema
cache
issue1325_test
mtr
mysql
performance_schema
sys
sys_tianmu
test
set global sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,MANDATORY_TIANMU,NO_KEY_ERROR';
#
# Secondary INDEX
#
# on master:
create table ttt(id int primary key,name varchar(10),key idx_name(name))engine=innodb;
drop table ttt;
create table ttt(id int primary key,name varchar(10))engine=innodb;
create index idx_name on ttt(name);
drop index idx_name on ttt;
show create table ttt;
Table Create Table
ttt CREATE TABLE `ttt` (
`id` int(11) NOT NULL,
`name` varchar(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
include/sync_slave_sql_with_master.inc
# on slave:
# on master:
show create table ttt;
Table Create Table
ttt CREATE TABLE `ttt` (
`id` int(11) NOT NULL,
`name` varchar(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
#
# UNIQUE INDEX
#
# on master:
create table xxx(id int,name varchar(10),unique key idx_id(id))engine=innodb;
drop table xxx;
create table xxx(id int,name varchar(10))engine=innodb;
create unique index idx_id on xxx(id);
drop index idx_id on xxx;
show create table xxx;
Table Create Table
xxx CREATE TABLE `xxx` (
`id` int(11) DEFAULT NULL,
`name` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
include/sync_slave_sql_with_master.inc
# on slave:
show create table xxx;
Table Create Table
xxx CREATE TABLE `xxx` (
`id` int(11) DEFAULT NULL,
`name` varchar(10) DEFAULT NULL
) ENGINE=TIANMU DEFAULT CHARSET=latin1
#
# Full-text index
#
# on master:
drop table ttt;
create table ttt(id int primary key,name text,fulltext key idx_name(name))engine=innodb;
drop table ttt;
create table ttt(id int primary key,name text)engine=innodb;
create fulltext index idx_name on ttt(name);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
show create table ttt;
Table Create Table
ttt CREATE TABLE `ttt` (
`id` int(11) NOT NULL,
`name` text,
PRIMARY KEY (`id`),
FULLTEXT KEY `idx_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
include/sync_slave_sql_with_master.inc
# on slave:
show create table ttt;
Table Create Table
ttt CREATE TABLE `ttt` (
`id` int(11) NOT NULL,
`name` text,
PRIMARY KEY (`id`),
FULLTEXT KEY `idx_name` (`name`)
) ENGINE=TIANMU DEFAULT CHARSET=latin1
#
# foreign key
#
# on master:
CREATE TABLE student
(id int (11) primary key,
name char(10),
sex char(100),
age int(11)
)engine=innodb;
create table student_score
(id int primary key,
class varchar(10),
score char(100),
student_id int,
address text,
unique key idx_uk(class),
key idx_score(score),
fulltext key idx_address(address),
constraint s_id foreign key (student_id) references student(id)
)engine=innodb;
drop index idx_uk on student_score;
drop index idx_score on student_score;
include/sync_slave_sql_with_master.inc
# on slave:
show tables;
Tables_in_issue1325_test
student
student_score
ttt
xxx
show create table student_score;
Table Create Table
student_score CREATE TABLE `student_score` (
`id` int(11) NOT NULL,
`class` varchar(10) DEFAULT NULL,
`score` char(100) DEFAULT NULL,
`student_id` int(11) DEFAULT NULL,
`address` text,
PRIMARY KEY (`id`),
KEY `s_id` (`student_id`),
FULLTEXT KEY `idx_address` (`address`)
) ENGINE=TIANMU DEFAULT CHARSET=latin1
# on master:
DROP DATABASE issue1325_test;
include/sync_slave_sql_with_master.inc
# on slave:
show databases;
Database
information_schema
cache
mtr
mysql
performance_schema
sys
sys_tianmu
test
tianmu_data
stop slave;
121 changes: 121 additions & 0 deletions mysql-test/suite/tianmu/t/issue1325.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
--source include/have_tianmu.inc
--source include/have_binlog_format_row.inc

--disable_warnings
-- source include/master-slave.inc
DROP DATABASE IF EXISTS issue1325_test;
--enable_warnings

--source include/sync_slave_sql_with_master.inc

connection master;
--echo # on master:

CREATE DATABASE issue1325_test;

USE issue1325_test;

--source include/sync_slave_sql_with_master.inc
--echo # on slave:
USE issue1325_test;
show databases;
--disable_warnings
set global sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,MANDATORY_TIANMU,NO_KEY_ERROR';
--enable_warnings

--echo #
--echo # Secondary INDEX
--echo #

connection master;
--echo # on master:

create table ttt(id int primary key,name varchar(10),key idx_name(name))engine=innodb;
drop table ttt;
create table ttt(id int primary key,name varchar(10))engine=innodb;
create index idx_name on ttt(name);
drop index idx_name on ttt;
show create table ttt;

--source include/sync_slave_sql_with_master.inc
--echo # on slave:
connection master;
--echo # on master:
show create table ttt;

--echo #
--echo # UNIQUE INDEX
--echo #
connection master;
--echo # on master:

create table xxx(id int,name varchar(10),unique key idx_id(id))engine=innodb;
drop table xxx;
create table xxx(id int,name varchar(10))engine=innodb;
create unique index idx_id on xxx(id);
drop index idx_id on xxx;
show create table xxx;

--source include/sync_slave_sql_with_master.inc
--echo # on slave:
show create table xxx;


--echo #
--echo # Full-text index
--echo #
connection master;
--echo # on master:
drop table ttt;
create table ttt(id int primary key,name text,fulltext key idx_name(name))engine=innodb;
drop table ttt;
create table ttt(id int primary key,name text)engine=innodb;
create fulltext index idx_name on ttt(name);

show create table ttt;
--source include/sync_slave_sql_with_master.inc
--echo # on slave:
show create table ttt;


--echo #
--echo # foreign key
--echo #
connection master;
--echo # on master:
CREATE TABLE student
(id int (11) primary key,
name char(10),
sex char(100),
age int(11)
)engine=innodb;

create table student_score
(id int primary key,
class varchar(10),
score char(100),
student_id int,
address text,
unique key idx_uk(class),
key idx_score(score),
fulltext key idx_address(address),
constraint s_id foreign key (student_id) references student(id)
)engine=innodb;

drop index idx_uk on student_score;
drop index idx_score on student_score;

--source include/sync_slave_sql_with_master.inc
--echo # on slave:
show tables;

show create table student_score;

connection master;
--echo # on master:
DROP DATABASE issue1325_test;

--source include/sync_slave_sql_with_master.inc
--echo # on slave:
show databases;
stop slave;
4 changes: 3 additions & 1 deletion sql/auth/sql_authorization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4389,9 +4389,11 @@ bool check_fk_parent_table_access(THD *thd,

// Return if engine does not support Foreign key Constraint.
if (!ha_check_storage_engine_flag(db_type, HTON_SUPPORTS_FOREIGN_KEYS)) {
sql_mode_t sql_mode = thd->variables.sql_mode;
if(thd->slave_thread) sql_mode = global_system_variables.sql_mode;
if (db_type == tianmu_hton &&
(alter_info->flags & Alter_info::ADD_FOREIGN_KEY) &&
(!(thd->variables.sql_mode & MODE_NO_KEY_ERROR))) {
(!(sql_mode & MODE_NO_KEY_ERROR))) {
my_error(ER_TIANMU_NOT_SUPPORTED_FOREIGN_KEY, MYF(0));
return true;
}
Expand Down
38 changes: 25 additions & 13 deletions sql/sql_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3934,16 +3934,18 @@ mysql_prepare_create_table(THD *thd, const char *error_schema_name,
(*key_count)++;
tmp=file->max_key_parts();

sql_mode_t sql_mode = thd->variables.sql_mode;
if(thd->slave_thread) sql_mode = global_system_variables.sql_mode;
if ((create_info->db_type->db_type == DB_TYPE_TIANMU)) {
if ((file->ha_table_flags() & HA_NON_SECONDARY_KEY) &&
(key->type == KEYTYPE_MULTIPLE) &&
!(thd->variables.sql_mode & MODE_NO_KEY_ERROR)) {
!(sql_mode & MODE_NO_KEY_ERROR)) {
my_error(ER_TIANMU_NOT_SUPPORTED_SECONDARY_INDEX, MYF(0));
DBUG_RETURN(TRUE);
}
if ((file->ha_table_flags() & HA_NON_UNIQUE_KEY) &&
(key->type == KEYTYPE_UNIQUE) &&
(!(thd->variables.sql_mode & MODE_NO_KEY_ERROR))) {
(!(sql_mode & MODE_NO_KEY_ERROR))) {
my_error(ER_TIANMU_NOT_SUPPORTED_UNIQUE_INDEX, MYF(0));
DBUG_RETURN(TRUE);
}
Expand Down Expand Up @@ -4080,15 +4082,19 @@ mysql_prepare_create_table(THD *thd, const char *error_schema_name,
MYF(0));
DBUG_RETURN(TRUE);
}
if ((create_info->db_type->db_type == DB_TYPE_TIANMU) &&
(!(thd->variables.sql_mode & MODE_NO_KEY_ERROR))) {
my_message(ER_TIANMU_NOT_SUPPORTED_FULLTEXT_INDEX,
ER(ER_TIANMU_NOT_SUPPORTED_FULLTEXT_INDEX), MYF(0));
if (create_info->db_type->db_type == DB_TYPE_TIANMU){
sql_mode_t sql_mode = thd->variables.sql_mode;
if(thd->slave_thread) sql_mode = global_system_variables.sql_mode;
if(!(sql_mode & MODE_NO_KEY_ERROR)) {
my_message(ER_TIANMU_NOT_SUPPORTED_FULLTEXT_INDEX,
ER(ER_TIANMU_NOT_SUPPORTED_FULLTEXT_INDEX), MYF(0));
DBUG_RETURN(TRUE);
}
} else {
my_message(ER_TABLE_CANT_HANDLE_FT, ER(ER_TABLE_CANT_HANDLE_FT),
MYF(0));
DBUG_RETURN(TRUE);
}
DBUG_RETURN(TRUE);
}
}
/*
Expand Down Expand Up @@ -8493,11 +8499,13 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
// Now this contains only DROP for foreign keys and not-found objects
Alter_drop *drop;
drop_it.rewind();
sql_mode_t sql_mode = thd->variables.sql_mode;
if(thd->slave_thread) sql_mode = global_system_variables.sql_mode;
while ((drop=drop_it++)) {
switch (drop->type) {
case Alter_drop::KEY:
if ((create_info->db_type->db_type == DB_TYPE_TIANMU) &&
(!(thd->variables.sql_mode & MODE_NO_KEY_ERROR))) {
(!(sql_mode & MODE_NO_KEY_ERROR))) {
my_error(ER_TIANMU_NOT_FOUND_INDEX, MYF(0));
goto err;
}
Expand All @@ -8508,7 +8516,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
goto err;
case Alter_drop::FOREIGN_KEY:
if ((create_info->db_type->db_type == DB_TYPE_TIANMU) &&
(!(thd->variables.sql_mode & MODE_NO_KEY_ERROR))) {
(!(sql_mode & MODE_NO_KEY_ERROR))) {
my_error(ER_TIANMU_NOT_SUPPORTED_FOREIGN_KEY, MYF(0));
}
break;
Expand All @@ -8522,14 +8530,18 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
}
if (rename_key_list.elements)
{
if ((create_info->db_type->db_type == DB_TYPE_TIANMU) &&
(!(thd->variables.sql_mode & MODE_NO_KEY_ERROR))) {
my_error(ER_TIANMU_NOT_FOUND_INDEX, MYF(0));
if (create_info->db_type->db_type == DB_TYPE_TIANMU){
sql_mode_t sql_mode = thd->variables.sql_mode;
if(thd->slave_thread) sql_mode = global_system_variables.sql_mode;
if(!(sql_mode & MODE_NO_KEY_ERROR)){
my_error(ER_TIANMU_NOT_FOUND_INDEX, MYF(0));
goto err;
}
} else {
my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), rename_key_list.head()->old_name,
table->s->table_name.str);
goto err;
}
goto err;
}

if (!create_info->comment.str)
Expand Down
Loading

0 comments on commit 2321f0a

Please sign in to comment.