forked from radondb/radon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*.: complete delete syntax radondb#713
[summary] 1. complete single-table syntax, add delete options and parition. 2. add support to parse multi-table syntax. 3. add support to delete without where clause, like "delete from t1 limit 2" [test case] sqlparser/ast_test.go sqlparser/parse_test.go sqlparser/ast_test.go src/planner/builder/expr_test.go src/planner/delete_plan_test.go [patch codecov] sqlparser/ast.go 96.1% sqlparser/ast_funcs.go 94.4% src/planner/delete_plan.go 93.9% src/planner/update_plan.go 95.1%
- Loading branch information
Showing
17 changed files
with
3,828 additions
and
3,065 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
create database if not exists integrate_test DEFAULT CHARSET=utf8; | ||
|
||
drop table if exists integrate_test.t1, integrate_test.t2; | ||
|
||
|
||
CREATE /*test hash*/ TABLE integrate_test.t1 (a tinyint(3) key, b tinyint(5)); | ||
|
||
INSERT INTO integrate_test.t1 VALUES (1,1); | ||
|
||
INSERT LOW_PRIORITY INTO integrate_test.t1 VALUES (2,2); | ||
|
||
INSERT INTO integrate_test.t1 VALUES (3,3); | ||
|
||
DELETE from integrate_test.t1 where a=1 limit 1; | ||
|
||
DELETE LOW_PRIORITY from integrate_test.t1 where a=2; | ||
|
||
select * from integrate_test.t1; | ||
a b | ||
3 3 | ||
|
||
INSERT INTO integrate_test.t1 VALUES (1,1); | ||
|
||
DELETE quick from integrate_test.t1; | ||
|
||
select * from integrate_test.t1; | ||
|
||
drop table integrate_test.t1; | ||
|
||
|
||
create table integrate_test.t2 ( | ||
a bigint not null, | ||
b bigint not null default 0, | ||
c bigint not null default 0, | ||
d bigint not null default 0, | ||
e bigint not null default 0, | ||
f bigint not null default 0, | ||
g bigint not null default 0, | ||
h bigint not null default 0, | ||
i bigint not null default 0, | ||
j bigint not null default 0, | ||
primary key (a,b,c,d,e,f,g,h,i,j)); | ||
|
||
insert into integrate_test.t2 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23); | ||
|
||
delete from integrate_test.t2 where a=26; | ||
|
||
select * from integrate_test.t2 order by a; | ||
a b c d e f g h i j | ||
2 0 0 0 0 0 0 0 0 0 | ||
4 0 0 0 0 0 0 0 0 0 | ||
6 0 0 0 0 0 0 0 0 0 | ||
8 0 0 0 0 0 0 0 0 0 | ||
10 0 0 0 0 0 0 0 0 0 | ||
12 0 0 0 0 0 0 0 0 0 | ||
14 0 0 0 0 0 0 0 0 0 | ||
16 0 0 0 0 0 0 0 0 0 | ||
18 0 0 0 0 0 0 0 0 0 | ||
20 0 0 0 0 0 0 0 0 0 | ||
22 0 0 0 0 0 0 0 0 0 | ||
23 0 0 0 0 0 0 0 0 0 | ||
24 0 0 0 0 0 0 0 0 0 | ||
|
||
drop table integrate_test.t2; | ||
|
||
create table integrate_test.t1 ( | ||
a bigint not null, | ||
b bigint not null default 0, | ||
c bigint not null default 0, | ||
d bigint not null default 0, | ||
e bigint not null default 0, | ||
f bigint not null default 0, | ||
g bigint not null default 0, | ||
h bigint not null default 0, | ||
i bigint not null default 0, | ||
j bigint not null default 0, | ||
primary key (a,b,c,d,e,f,g,h,i,j)); | ||
|
||
insert into integrate_test.t1 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23),(27); | ||
|
||
delete from integrate_test.t1 where a=27; | ||
|
||
select * from integrate_test.t1 order by a; | ||
a b c d e f g h i j | ||
2 0 0 0 0 0 0 0 0 0 | ||
4 0 0 0 0 0 0 0 0 0 | ||
6 0 0 0 0 0 0 0 0 0 | ||
8 0 0 0 0 0 0 0 0 0 | ||
10 0 0 0 0 0 0 0 0 0 | ||
12 0 0 0 0 0 0 0 0 0 | ||
14 0 0 0 0 0 0 0 0 0 | ||
16 0 0 0 0 0 0 0 0 0 | ||
18 0 0 0 0 0 0 0 0 0 | ||
20 0 0 0 0 0 0 0 0 0 | ||
22 0 0 0 0 0 0 0 0 0 | ||
23 0 0 0 0 0 0 0 0 0 | ||
24 0 0 0 0 0 0 0 0 0 | ||
26 0 0 0 0 0 0 0 0 0 | ||
|
||
drop table integrate_test.t1; | ||
|
||
|
||
CREATE /*test error, column not exist*/ TABLE integrate_test.t1 ( | ||
`i` int(10) NOT NULL default '0', | ||
`i2` int(10) NOT NULL default '0', | ||
PRIMARY KEY (`i`) | ||
); | ||
|
||
DELETE FROM integrate_test.t1 WHERE post='1'; | ||
ERROR 1054 (42S22): Unknown column 'post' in 'where clause' | ||
|
||
drop table integrate_test.t1; | ||
|
||
|
||
create /*test global*/ table integrate_test.t2 (a bigint not null auto_increment primary key, b char(32)) global; | ||
|
||
insert into integrate_test.t2 (a,b) values (1,'apple'), (2,'apple'); | ||
|
||
select * from integrate_test.t2; | ||
a b | ||
1 apple | ||
2 apple | ||
|
||
delete /*test unsupport, currently not support delete multitables*/ integrate_test.t2 from integrate_test.t2, integrate_test.t2 as t1 where integrate_test.t2.b = integrate_test.t1.b and integrate_test.t2.a > integrate_test.t1.a; | ||
ERROR 1105 (HY000): unsupported: currently.not.support.multitables.in.delete | ||
|
||
delete /*test unsupport, currently not support delete with partition*/ from integrate_test.t2 partition (p0) where a = 1; | ||
ERROR 1105 (HY000): unsupported: currently.not.support.partitions.in.delete | ||
|
||
DELETE /*test unsupport, currently not support delete with subquery*/ FROM integrate_test.t2 ORDER BY (SELECT x); | ||
ERROR 1105 (HY000): unsupported: subqueries.in.delete | ||
|
||
drop table integrate_test.t2; | ||
|
||
|
||
CREATE TABLE integrate_test.t1(a INTEGER PRIMARY KEY) single; | ||
|
||
INSERT INTO integrate_test.t1 VALUES(10),(20); | ||
|
||
CREATE TABLE integrate_test.t2(b INTEGER key); | ||
|
||
INSERT INTO integrate_test.t2 VALUES(10),(20); | ||
|
||
DELETE /*test unsupport with join, not support delete with multitables*/ integrate_test.t1 FROM integrate_test.t1 JOIN integrate_test.t2 WHERE integrate_test.t1.a = 10; | ||
ERROR 1105 (HY000): unsupported: currently.not.support.multitables.in.delete | ||
|
||
DELETE /*test parse error*/ FROM integrate_test.t1 alias USING integrate_test.t1, integrate_test.t2 alias WHERE integrate_test.t1.a = alias.a; | ||
ERROR 1149 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use, syntax error at position 43 near 'using' | ||
|
||
DELETE /*test parse error*/ FROM integrate_test.t1 alias USING integrate_test.t1, integrate_test.t1 alias WHERE integrate_test.t1.a = alias.a; | ||
ERROR 1149 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use, syntax error at position 43 near 'using' | ||
|
||
DELETE /*test parse error*/ FROM integrate_test.t1 alias USING integrate_test.t1 alias WHERE a = 2; | ||
ERROR 1149 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use, syntax error at position 43 near 'using' | ||
|
||
drop table integrate_test.t1, integrate_test.t2; | ||
|
||
|
||
CREATE /*test list*/ TABLE integrate_test.t1 ( a int PRIMARY KEY ) ENGINE=InnoDB DEFAULT CHARSET=utf8 partition by list(a) (partition backend1 values in (0,1,3), partition backend2 values in (2,5,8)); | ||
|
||
DELETE FROM integrate_test.t1 WHERE a > 0 ORDER BY a; | ||
|
||
INSERT INTO integrate_test.t1 VALUES (0),(1),(2); | ||
|
||
DELETE FROM integrate_test.t1 WHERE a > 0 ORDER BY a LIMIT 1; | ||
|
||
SELECT * FROM integrate_test.t1; | ||
a | ||
0 | ||
|
||
DROP TABLE integrate_test.t1; | ||
|
||
|
||
drop database integrate_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
create database if not exists integrate_test DEFAULT CHARSET=utf8; | ||
drop table if exists integrate_test.t1, integrate_test.t2; | ||
|
||
CREATE /*test hash*/ TABLE integrate_test.t1 (a tinyint(3) key, b tinyint(5)); | ||
INSERT INTO integrate_test.t1 VALUES (1,1); | ||
INSERT LOW_PRIORITY INTO integrate_test.t1 VALUES (2,2); | ||
INSERT INTO integrate_test.t1 VALUES (3,3); | ||
DELETE from integrate_test.t1 where a=1 limit 1; | ||
DELETE LOW_PRIORITY from integrate_test.t1 where a=2; | ||
select * from integrate_test.t1; | ||
INSERT INTO integrate_test.t1 VALUES (1,1); | ||
DELETE quick from integrate_test.t1; | ||
select * from integrate_test.t1; | ||
drop table integrate_test.t1; | ||
|
||
create table integrate_test.t2 ( | ||
a bigint not null, | ||
b bigint not null default 0, | ||
c bigint not null default 0, | ||
d bigint not null default 0, | ||
e bigint not null default 0, | ||
f bigint not null default 0, | ||
g bigint not null default 0, | ||
h bigint not null default 0, | ||
i bigint not null default 0, | ||
j bigint not null default 0, | ||
primary key (a,b,c,d,e,f,g,h,i,j)); | ||
insert into integrate_test.t2 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23); | ||
delete from integrate_test.t2 where a=26; | ||
select * from integrate_test.t2 order by a; | ||
drop table integrate_test.t2; | ||
create table integrate_test.t1 ( | ||
a bigint not null, | ||
b bigint not null default 0, | ||
c bigint not null default 0, | ||
d bigint not null default 0, | ||
e bigint not null default 0, | ||
f bigint not null default 0, | ||
g bigint not null default 0, | ||
h bigint not null default 0, | ||
i bigint not null default 0, | ||
j bigint not null default 0, | ||
primary key (a,b,c,d,e,f,g,h,i,j)); | ||
insert into integrate_test.t1 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23),(27); | ||
delete from integrate_test.t1 where a=27; | ||
select * from integrate_test.t1 order by a; | ||
drop table integrate_test.t1; | ||
|
||
CREATE /*test error, column not exist*/ TABLE integrate_test.t1 ( | ||
`i` int(10) NOT NULL default '0', | ||
`i2` int(10) NOT NULL default '0', | ||
PRIMARY KEY (`i`) | ||
); | ||
DELETE FROM integrate_test.t1 WHERE post='1'; | ||
drop table integrate_test.t1; | ||
|
||
create /*test global*/ table integrate_test.t2 (a bigint not null auto_increment primary key, b char(32)) global; | ||
insert into integrate_test.t2 (a,b) values (1,'apple'), (2,'apple'); | ||
select * from integrate_test.t2; | ||
delete /*test unsupport, currently not support delete multitables*/ integrate_test.t2 from integrate_test.t2, integrate_test.t2 as t1 where integrate_test.t2.b = integrate_test.t1.b and integrate_test.t2.a > integrate_test.t1.a; | ||
delete /*test unsupport, currently not support delete with partition*/ from integrate_test.t2 partition (p0) where a = 1; | ||
DELETE /*test unsupport, currently not support delete with subquery*/ FROM integrate_test.t2 ORDER BY (SELECT x); | ||
drop table integrate_test.t2; | ||
|
||
CREATE TABLE integrate_test.t1(a INTEGER PRIMARY KEY) single; | ||
INSERT INTO integrate_test.t1 VALUES(10),(20); | ||
CREATE TABLE integrate_test.t2(b INTEGER key); | ||
INSERT INTO integrate_test.t2 VALUES(10),(20); | ||
DELETE /*test unsupport with join, not support delete with multitables*/ integrate_test.t1 FROM integrate_test.t1 JOIN integrate_test.t2 WHERE integrate_test.t1.a = 10; | ||
DELETE /*test parse error*/ FROM integrate_test.t1 alias USING integrate_test.t1, integrate_test.t2 alias WHERE integrate_test.t1.a = alias.a; | ||
DELETE /*test parse error*/ FROM integrate_test.t1 alias USING integrate_test.t1, integrate_test.t1 alias WHERE integrate_test.t1.a = alias.a; | ||
DELETE /*test parse error*/ FROM integrate_test.t1 alias USING integrate_test.t1 alias WHERE a = 2; | ||
drop table integrate_test.t1, integrate_test.t2; | ||
|
||
CREATE /*test list*/ TABLE integrate_test.t1 ( a int PRIMARY KEY ) ENGINE=InnoDB DEFAULT CHARSET=utf8 partition by list(a) (partition backend1 values in (0,1,3), partition backend2 values in (2,5,8)); | ||
DELETE FROM integrate_test.t1 WHERE a > 0 ORDER BY a; | ||
INSERT INTO integrate_test.t1 VALUES (0),(1),(2); | ||
DELETE FROM integrate_test.t1 WHERE a > 0 ORDER BY a LIMIT 1; | ||
SELECT * FROM integrate_test.t1; | ||
DROP TABLE integrate_test.t1; | ||
|
||
drop database integrate_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.