summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbell@sanja.is.com.ua <>2004-06-22 13:48:51 +0300
committerbell@sanja.is.com.ua <>2004-06-22 13:48:51 +0300
commit5ed07df98aea29d96212450df7d022c8aeb9dd21 (patch)
tree92eea4c21905c7120aecb6844fffb778f477f48b
parentdc6465cc38e8f91517ac3210a9624917abd46aca (diff)
parentc6cd51798bb68b839dcfefa48d409cd117c4c743 (diff)
downloadmariadb-git-5ed07df98aea29d96212450df7d022c8aeb9dd21.tar.gz
Merge
-rw-r--r--mysql-test/r/subselect.result41
-rw-r--r--mysql-test/t/subselect.test22
-rw-r--r--sql/sql_parse.cc14
-rw-r--r--sql/sql_prepare.cc13
4 files changed, 87 insertions, 3 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 7571dfffc41..5ab36dacaaf 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -1850,3 +1850,44 @@ id name id pet
2 Rebecca 2 Spot
3 NULL 3 Felix
drop table t1,t2;
+CREATE TABLE t1 ( a int, b int );
+CREATE TABLE t2 ( c int, d int );
+INSERT INTO t1 VALUES (1,2), (2,3), (3,4);
+SELECT a AS abc, b FROM t1 WHERE b = (SELECT MIN(b) FROM t1 WHERE a=abc);
+abc b
+1 2
+2 3
+3 4
+INSERT INTO t2 SELECT a AS abc, b FROM t1 WHERE b = (SELECT MIN(b) FROM t1 WHERE a=abc);
+select * from t2;
+c d
+1 2
+2 3
+3 4
+CREATE TABLE t3 SELECT a AS abc, b FROM t1 WHERE b = (SELECT MIN(b) FROM t1 WHERE a=abc);
+select * from t3;
+abc b
+1 2
+2 3
+3 4
+prepare stmt1 from "INSERT INTO t2 SELECT a AS abc, b FROM t1 WHERE b = (SELECT MIN(b) FROM t1 WHERE a=abc);";
+execute stmt1;
+deallocate prepare stmt1;
+select * from t2;
+c d
+1 2
+2 3
+3 4
+1 2
+2 3
+3 4
+drop table t3;
+prepare stmt1 from "CREATE TABLE t3 SELECT a AS abc, b FROM t1 WHERE b = (SELECT MIN(b) FROM t1 WHERE a=abc);";
+execute stmt1;
+select * from t3;
+abc b
+1 2
+2 3
+3 4
+deallocate prepare stmt1;
+DROP TABLE t1, t2, t3;
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index 930f339e26c..0c093c4ae3e 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -1190,3 +1190,25 @@ CREATE TABLE t2 (id int(11) default NULL, pet varchar(10) default NULL);
INSERT INTO t2 VALUES (1,'Fido'),(2,'Spot'),(3,'Felix');
SELECT a.*, b.* FROM (SELECT * FROM t1) AS a JOIN t2 as b on a.id=b.id;
drop table t1,t2;
+
+#
+# outer fields resolving in INSERT/REPLACE and CRETE with SELECT
+#
+CREATE TABLE t1 ( a int, b int );
+CREATE TABLE t2 ( c int, d int );
+INSERT INTO t1 VALUES (1,2), (2,3), (3,4);
+SELECT a AS abc, b FROM t1 WHERE b = (SELECT MIN(b) FROM t1 WHERE a=abc);
+INSERT INTO t2 SELECT a AS abc, b FROM t1 WHERE b = (SELECT MIN(b) FROM t1 WHERE a=abc);
+select * from t2;
+CREATE TABLE t3 SELECT a AS abc, b FROM t1 WHERE b = (SELECT MIN(b) FROM t1 WHERE a=abc);
+select * from t3;
+prepare stmt1 from "INSERT INTO t2 SELECT a AS abc, b FROM t1 WHERE b = (SELECT MIN(b) FROM t1 WHERE a=abc);";
+execute stmt1;
+deallocate prepare stmt1;
+select * from t2;
+drop table t3;
+prepare stmt1 from "CREATE TABLE t3 SELECT a AS abc, b FROM t1 WHERE b = (SELECT MIN(b) FROM t1 WHERE a=abc);";
+execute stmt1;
+select * from t3;
+deallocate prepare stmt1;
+DROP TABLE t1, t2, t3;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index bada2464639..2d8facfa63f 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -2354,7 +2354,15 @@ mysql_execute_command(THD *thd)
lex->create_list,
lex->key_list,
select_lex->item_list,lex->duplicates)))
+ {
+ /*
+ CREATE from SELECT give its SELECT_LEX for SELECT,
+ and item_list belong to SELECT
+ */
+ select_lex->resolve_mode= SELECT_LEX::SELECT_MODE;
res=handle_select(thd, lex, result);
+ select_lex->resolve_mode= SELECT_LEX::NOMATTER_MODE;
+ }
//reset for PS
lex->create_list.empty();
lex->key_list.empty();
@@ -2704,7 +2712,11 @@ unsent_create_error:
lex->duplicates)))
/* Skip first table, which is the table we are inserting in */
lex->select_lex.table_list.first= (byte*) first_local_table->next;
- lex->select_lex.resolve_mode= SELECT_LEX::NOMATTER_MODE;
+ /*
+ insert/replace from SELECT give its SELECT_LEX for SELECT,
+ and item_list belong to SELECT
+ */
+ lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE;
res=handle_select(thd,lex,result);
/* revert changes for SP */
lex->select_lex.table_list.first= (byte*) first_local_table;
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index fac2d32d152..09b442f8dfc 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -1307,6 +1307,7 @@ static int mysql_test_create_table(Prepared_statement *stmt,
DBUG_ENTER("mysql_test_create_table");
THD *thd= stmt->thd;
LEX *lex= stmt->lex;
+ SELECT_LEX *select_lex= &lex->select_lex;
int res= 0;
/* Skip first table, which is the table we are creating */
@@ -1315,8 +1316,12 @@ static int mysql_test_create_table(Prepared_statement *stmt,
&create_table_local);
if (!(res= create_table_precheck(thd, tables, create_table)) &&
- lex->select_lex.item_list.elements)
+ select_lex->item_list.elements)
+ {
+ select_lex->resolve_mode= SELECT_LEX::SELECT_MODE;
res= select_like_statement_test(stmt, tables);
+ select_lex->resolve_mode= SELECT_LEX::NOMATTER_MODE;
+ }
/* put tables back for PS rexecuting */
tables= lex->link_first_table_back(tables, create_table,
@@ -1400,7 +1405,11 @@ static int mysql_test_insert_select(Prepared_statement *stmt,
(TABLE_LIST *)lex->select_lex.table_list.first;
/* Skip first table, which is the table we are inserting in */
lex->select_lex.table_list.first= (byte*) first_local_table->next;
- lex->select_lex.resolve_mode= SELECT_LEX::NOMATTER_MODE;
+ /*
+ insert/replace from SELECT give its SELECT_LEX for SELECT,
+ and item_list belong to SELECT
+ */
+ lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE;
res= select_like_statement_test(stmt, tables);
/* revert changes*/
lex->select_lex.table_list.first= (byte*) first_local_table;