Commit c7320830 authored by Sergei Golubchik's avatar Sergei Golubchik

outer references in subqueries in INSERT

remove inconsistent limitation
parent 173ae631
......@@ -751,3 +751,19 @@ REPLACE INTO v1 SET f = NULL;
ERROR 22007: Truncated incorrect DOUBLE value: 'foo'
DROP VIEW v1;
DROP TABLE t1;
create table t1 (a int default 5);
insert t1 values (1);
insert t1 values (a);
insert t1 values ((select a+1));
insert t1 set a=2;
insert t1 set a=a+2;
insert t1 set a=(select a+3);
select * from t1;
a
1
5
6
2
7
8
drop table t1;
......@@ -612,3 +612,16 @@ CREATE VIEW v1 AS SELECT * FROM t1 WHERE f <=> 'foo' WITH CHECK OPTION;
REPLACE INTO v1 SET f = NULL;
DROP VIEW v1;
DROP TABLE t1;
#
# outer referencesin subqueries in INSERT
#
create table t1 (a int default 5);
insert t1 values (1);
insert t1 values (a);
insert t1 values ((select a+1));
insert t1 set a=2;
insert t1 set a=a+2;
insert t1 set a=(select a+3);
select * from t1;
drop table t1;
......@@ -682,8 +682,6 @@ x
3
11
11
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
ERROR 42S22: Unknown column 'x' in 'field list'
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
select * from t1;
x
......
......@@ -394,8 +394,6 @@ select * from t1;
# After this, only data based on old t1 records should have been added.
INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2;
select * from t1;
-- error ER_BAD_FIELD_ERROR
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
let $row_count_before= `SELECT COUNT(*) FROM t1`;
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
let $wait_condition= SELECT COUNT(*) <> $row_count_before FROM t1;
......
......@@ -686,8 +686,6 @@ x
3
11
11
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
ERROR 42S22: Unknown column 'x' in 'field list'
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
select * from t1;
x
......
......@@ -689,8 +689,6 @@ x
3
11
11
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
ERROR 42S22: Unknown column 'x' in 'field list'
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
select * from t1;
x
......
......@@ -685,8 +685,6 @@ x
3
11
11
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
ERROR 42S22: Unknown column 'x' in 'field list'
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
select * from t1;
x
......
......@@ -688,8 +688,6 @@ x
3
11
11
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
ERROR 42S22: Unknown column 'x' in 'field list'
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
select * from t1;
x
......
......@@ -685,8 +685,6 @@ x
3
11
11
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
ERROR 42S22: Unknown column 'x' in 'field list'
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
select * from t1;
x
......
......@@ -1512,25 +1512,6 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
DBUG_RETURN(TRUE);
if (thd->lex->handle_list_of_derived(table_list, DT_PREPARE))
DBUG_RETURN(TRUE);
/*
For subqueries in VALUES() we should not see the table in which we are
inserting (for INSERT ... SELECT this is done by changing table_list,
because INSERT ... SELECT share SELECT_LEX it with SELECT.
*/
if (!select_insert)
{
for (SELECT_LEX_UNIT *un= select_lex->first_inner_unit();
un;
un= un->next_unit())
{
for (SELECT_LEX *sl= un->first_select();
sl;
sl= sl->next_select())
{
sl->context.outer_context= 0;
}
}
}
if (duplic == DUP_UPDATE)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment