Skip to content

Commit

Permalink
fix(tianmu)Fix delete from Multiple-Table, Failed to delete the data (s…
Browse files Browse the repository at this point in the history
…toneatom#663)(stoneatom#678)

Cause:
At present, the primary key of the tianmu engine does not fully support delete and update statements.
Temporary solution:
Modify the execution plan of the SQL layer so that the delete and update statements do not follow the primary key logic
  • Loading branch information
konghaiya committed Oct 18, 2022
1 parent 5d996f9 commit 86ed23f
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 7 deletions.
6 changes: 0 additions & 6 deletions mysql-test/suite/tianmu/r/delete.result
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,16 @@ select * from t11;
a b
0 10
1 11
2 12
select * from t12;
a b
33 10
0 11
2 12
delete from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
ERROR 21000: Subquery returns more than 1 row
select * from t11;
a b
0 10
1 11
2 12
delete ignore from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
Warnings:
Warning 1242 Subquery returns more than 1 row
Expand Down Expand Up @@ -263,9 +260,6 @@ a b a b a b
delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
select * from t3;
a b
1 1
2 1
1 3
drop table t1,t2,t3;
create table t1(a date not null)ENGINE=TIANMU;
insert into t1 values (0);
Expand Down
37 changes: 37 additions & 0 deletions mysql-test/suite/tianmu/r/issue663.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# Fix delete from Multiple-Table, Failed to delete the data #663,#678
#
create table t11 (a int NOT NULL, b int, primary key (a))ENGINE=TIANMU;
create table t12 (a int NOT NULL, b int, primary key (a))ENGINE=TIANMU;
insert into t11 values (0, 10),(1, 11),(2, 12);
insert into t12 values (33, 10),(0, 11),(2, 12);
select t11.*,t12.* from t11,t12 where t11.a = t12.a;
a b a b
0 10 0 11
2 12 2 12
delete t11.*,t12.* from t11,t12 where t11.a = t12.a;
select * from t11;
a b
1 11
select * from t12;
a b
33 10
drop table t11,t12;
CREATE TABLE t1 (a int not null,b int not null)ENGINE=TIANMU;
CREATE TABLE t2 (a int not null, b int not null, primary key (a,b))ENGINE=TIANMU;
CREATE TABLE t3 (a int not null, b int not null, primary key (a,b))ENGINE=TIANMU;
insert into t1 values (1,1),(2,1),(1,3);
insert into t2 values (1,1),(2,2),(3,3);
insert into t3 values (1,1),(2,1),(1,3);
delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
select * from t1;
a b
1 1
2 1
1 3
select * from t2;
a b
3 3
select * from t3;
a b
drop table t1,t2,t3;
32 changes: 32 additions & 0 deletions mysql-test/suite/tianmu/t/issue663.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--source include/have_tianmu.inc

--echo #
--echo # Fix delete from Multiple-Table, Failed to delete the data #663,#678
--echo #

create table t11 (a int NOT NULL, b int, primary key (a))ENGINE=TIANMU;
create table t12 (a int NOT NULL, b int, primary key (a))ENGINE=TIANMU;
insert into t11 values (0, 10),(1, 11),(2, 12);
insert into t12 values (33, 10),(0, 11),(2, 12);

select t11.*,t12.* from t11,t12 where t11.a = t12.a;
delete t11.*,t12.* from t11,t12 where t11.a = t12.a;

select * from t11;
select * from t12;

drop table t11,t12;

CREATE TABLE t1 (a int not null,b int not null)ENGINE=TIANMU;
CREATE TABLE t2 (a int not null, b int not null, primary key (a,b))ENGINE=TIANMU;
CREATE TABLE t3 (a int not null, b int not null, primary key (a,b))ENGINE=TIANMU;
insert into t1 values (1,1),(2,1),(1,3);
insert into t2 values (1,1),(2,2),(3,3);
insert into t3 values (1,1),(2,1),(1,3);
delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;

select * from t1;
select * from t2;
select * from t3;

drop table t1,t2,t3;
13 changes: 12 additions & 1 deletion sql/sql_planner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,18 @@ void Optimize_table_order::best_access_path(JOIN_TAB *tab,
table_map ref_depend_map= 0;
uint used_key_parts= 0;

if (tab->keyuse() != NULL)
/*
The primary key of the tianmu engine does not support delete and update statements.
The following codes can be deleted after subsequent support
*/
bool tianmu_engine = table->s->db_type() ? table->s->db_type()->db_type == DB_TYPE_TIANMU: false;
enum_sql_command sqlCommand = table->in_use->lex->sql_command;
bool tianmuDeleteOrUpdate = (tianmu_engine && (sqlCommand == SQLCOM_DELETE ||
sqlCommand == SQLCOM_DELETE_MULTI ||
sqlCommand == SQLCOM_UPDATE ||
sqlCommand == SQLCOM_UPDATE_MULTI));

if (tab->keyuse() != NULL && !tianmuDeleteOrUpdate)
best_ref= find_best_ref(tab, remaining_tables, idx, prefix_rowcount,
&found_condition, &ref_depend_map, &used_key_parts);

Expand Down

0 comments on commit 86ed23f

Please sign in to comment.