mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
subselects in insert/replace (SCRUM)
This commit is contained in:
@ -335,7 +335,6 @@ a b
|
||||
1 21
|
||||
2 22
|
||||
drop table t1, t2;
|
||||
drop table if exists t1, t2;
|
||||
create table t1 (a int NOT NULL, b int, primary key (a));
|
||||
create table t2 (a int NOT NULL, b int, primary key (a));
|
||||
insert into t1 values (0, 10),(1, 11),(2, 12);
|
||||
@ -354,3 +353,64 @@ a b
|
||||
0 10
|
||||
1 11
|
||||
drop table t1, t2;
|
||||
CREATE TABLE t1 (x int);
|
||||
create table t2 (a int);
|
||||
insert into t2 values (1);
|
||||
INSERT INTO t1 (x) VALUES ((SELECT a FROM t2));
|
||||
select * from t1;
|
||||
x
|
||||
1
|
||||
insert into t2 values (1);
|
||||
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
|
||||
select * from t1;
|
||||
x
|
||||
1
|
||||
2
|
||||
INSERT INTO t1 (x) select (SELECT SUM(a)+1 FROM t2) FROM t2;
|
||||
select * from t1;
|
||||
x
|
||||
1
|
||||
2
|
||||
3
|
||||
3
|
||||
INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2;
|
||||
INSERT TABLE 't1' isn't allowed in FROM table list
|
||||
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t1));
|
||||
select * from t1;
|
||||
x
|
||||
1
|
||||
2
|
||||
3
|
||||
3
|
||||
9
|
||||
drop table t1, t2;
|
||||
CREATE TABLE t1 (x int not null, y int, primary key (x));
|
||||
create table t2 (a int);
|
||||
insert into t2 values (1);
|
||||
select * from t1;
|
||||
x y
|
||||
replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+1 FROM t2));
|
||||
select * from t1;
|
||||
x y
|
||||
1 2
|
||||
replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+2 FROM t2));
|
||||
select * from t1;
|
||||
x y
|
||||
1 3
|
||||
replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a FROM t2));
|
||||
select * from t1;
|
||||
x y
|
||||
1 3
|
||||
4 1
|
||||
replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a+1 FROM t2));
|
||||
select * from t1;
|
||||
x y
|
||||
1 3
|
||||
4 2
|
||||
replace LOW_PRIORITY into t1 (x, y) VALUES ((SELECT a+1 FROM t2), (SELECT a FROM t2));
|
||||
select * from t1;
|
||||
x y
|
||||
1 3
|
||||
4 2
|
||||
2 1
|
||||
drop table t1, t2;
|
||||
|
@ -216,7 +216,6 @@ select * from t1;
|
||||
drop table t1, t2;
|
||||
|
||||
#delete with subselects
|
||||
drop table if exists t1, t2;
|
||||
create table t1 (a int NOT NULL, b int, primary key (a));
|
||||
create table t2 (a int NOT NULL, b int, primary key (a));
|
||||
insert into t1 values (0, 10),(1, 11),(2, 12);
|
||||
@ -226,3 +225,41 @@ select * from t1 where b = (select b from t2 where t1.a = t2.a);
|
||||
delete from t1 where b = (select b from t2 where t1.a = t2.a);
|
||||
select * from t1;
|
||||
drop table t1, t2;
|
||||
|
||||
#insert with subselects
|
||||
CREATE TABLE t1 (x int);
|
||||
create table t2 (a int);
|
||||
insert into t2 values (1);
|
||||
INSERT INTO t1 (x) VALUES ((SELECT a FROM t2));
|
||||
select * from t1;
|
||||
insert into t2 values (1);
|
||||
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
|
||||
-- sleep 1
|
||||
select * from t1;
|
||||
INSERT INTO t1 (x) select (SELECT SUM(a)+1 FROM t2) FROM t2;
|
||||
select * from t1;
|
||||
-- error 1093
|
||||
INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2;
|
||||
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t1));
|
||||
-- sleep 1
|
||||
select * from t1;
|
||||
drop table t1, t2;
|
||||
|
||||
#replace with subselects
|
||||
CREATE TABLE t1 (x int not null, y int, primary key (x));
|
||||
create table t2 (a int);
|
||||
insert into t2 values (1);
|
||||
select * from t1;
|
||||
replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+1 FROM t2));
|
||||
select * from t1;
|
||||
replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+2 FROM t2));
|
||||
select * from t1;
|
||||
replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a FROM t2));
|
||||
-- sleep 1
|
||||
select * from t1;
|
||||
replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a+1 FROM t2));
|
||||
-- sleep 1
|
||||
select * from t1;
|
||||
replace LOW_PRIORITY into t1 (x, y) VALUES ((SELECT a+1 FROM t2), (SELECT a FROM t2));
|
||||
select * from t1;
|
||||
drop table t1, t2;
|
||||
|
Reference in New Issue
Block a user