summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <bell@sanja.is.com.ua>2003-08-01 18:24:27 +0300
committerunknown <bell@sanja.is.com.ua>2003-08-01 18:24:27 +0300
commit875a26d50a7685def420be8712068f8e880adf7e (patch)
treede5617c39a1d780f524e2dd50c59216b6e5d6290
parentc44af18bd59a2ab4ff80fe1d82a6053dbccc8647 (diff)
parent668cd9729f8f1a35ebd6eb95bec9b612b7596f16 (diff)
downloadmariadb-git-875a26d50a7685def420be8712068f8e880adf7e.tar.gz
merge
sql/item.cc: Auto merged sql/sql_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_parse.cc: Auto merged sql/sql_yacc.yy: Auto merged
-rw-r--r--mysql-test/r/subselect.result21
-rw-r--r--mysql-test/t/subselect.test22
-rw-r--r--sql/item.cc11
-rw-r--r--sql/sql_lex.cc3
-rw-r--r--sql/sql_lex.h17
-rw-r--r--sql/sql_parse.cc2
-rw-r--r--sql/sql_yacc.yy13
7 files changed, 54 insertions, 35 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index d6e33ac6227..41fba93db5b 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -1225,20 +1225,6 @@ a (select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 an
2 2
1 2
drop table t1,t2,t3;
-create table t1 (a char(10) character set koi8r collate koi8r_bin);
-create table t2 select (select a from t1);
-show create table t2;
-Table Create Table
-t2 CREATE TABLE `t2` (
- `(select a from t1)` char(10) character set koi8r collate koi8r_bin default NULL
-) TYPE=MyISAM CHARSET=latin1
-drop table t1,t2;
-CREATE TABLE t1
-(s1 CHAR(5) COLLATE latin1_german1_ci,
-s2 CHAR(5) COLLATE latin1_swedish_ci);
-SELECT * FROM t1 WHERE s1 = (SELECT s2 FROM t1);
-ERROR HY000: Illegal mix of collations (latin1_german1_ci,IMPLICIT) and (latin1_swedish_ci,IMPLICIT) for operation '='
-drop table t1;
create table t1 (s1 int);
create table t2 (s1 int);
insert into t1 values (1);
@@ -1246,3 +1232,10 @@ insert into t2 values (1);
select * from t1 where exists (select s1 from t2 having max(t2.s1)=t1.s1);
s1
drop table t1,t2;
+create table t1 (s1 int);
+create table t2 (s1 int);
+insert into t1 values (1);
+insert into t2 values (1);
+update t1 set s1 = s1 + 1 where 1 = (select x.s1 as A from t2 WHERE t2.s1 > t1.s1 order by A);
+ERROR 42S02: Unknown table 'x' in field list
+DROP TABLE t1, t2;
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index a53415e4ffd..c6cc82e5f92 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -820,16 +820,6 @@ insert into t3 values (3,3), (2,2), (1,1);
select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3;
drop table t1,t2,t3;
-create table t1 (a char(10) character set koi8r collate koi8r_bin);
-create table t2 select (select a from t1);
-show create table t2;
-drop table t1,t2;
-
-CREATE TABLE t1
-(s1 CHAR(5) COLLATE latin1_german1_ci,
- s2 CHAR(5) COLLATE latin1_swedish_ci);
---error 1265
-SELECT * FROM t1 WHERE s1 = (SELECT s2 FROM t1);
drop table t1;
#
@@ -841,3 +831,15 @@ insert into t1 values (1);
insert into t2 values (1);
select * from t1 where exists (select s1 from t2 having max(t2.s1)=t1.s1);
drop table t1,t2;
+#
+# update subquery with wrong field (to force name resolving
+# in UPDATE name space)
+#
+create table t1 (s1 int);
+create table t2 (s1 int);
+insert into t1 values (1);
+insert into t2 values (1);
+-- error 1109
+update t1 set s1 = s1 + 1 where 1 = (select x.s1 as A from t2 WHERE t2.s1 > t1.s1 order by A);
+DROP TABLE t1, t2;
+
diff --git a/sql/item.cc b/sql/item.cc
index 0a3ed39bac7..48f9dfea4e1 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -870,7 +870,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
sl= sl->outer_select())
{
table_list= (last= sl)->get_table_list();
- if (sl->insert_select && table_list)
+ if (sl->resolve_mode == SELECT_LEX::INSERT_MODE && table_list)
{
// it is primary INSERT st_select_lex => skip first table resolving
table_list= table_list->next;
@@ -879,7 +879,8 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
table_list, &where,
0)) != not_found_field)
break;
- if ((refer= find_item_in_list(this, sl->item_list, &counter,
+ if (sl->resolve_mode == SELECT_LEX::SELECT_MODE &&
+ (refer= find_item_in_list(this, sl->item_list, &counter,
REPORT_EXCEPT_NOT_FOUND)) !=
(Item **) not_found_item)
break;
@@ -1356,13 +1357,15 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
SELECT_LEX *last=0;
for ( ; sl ; sl= sl->outer_select())
{
- if ((ref= find_item_in_list(this, (last= sl)->item_list,
+ last= sl;
+ if (sl->resolve_mode == SELECT_LEX::SELECT_MODE &&
+ (ref= find_item_in_list(this, sl->item_list,
&counter,
REPORT_EXCEPT_NOT_FOUND)) !=
(Item **)not_found_item)
break;
table_list= sl->get_table_list();
- if (sl->insert_select && table_list)
+ if (sl->resolve_mode == SELECT_LEX::INSERT_MODE && table_list)
{
// it is primary INSERT st_select_lex => skip first table resolving
table_list= table_list->next;
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index d4bb3bf12a2..57e39a0dc83 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -986,7 +986,8 @@ void st_select_lex::init_query()
join= 0;
where= 0;
olap= UNSPECIFIED_OLAP_TYPE;
- insert_select= having_fix_field= 0;
+ having_fix_field= 0;
+ resolve_mode= NOMATTER_MODE;
with_wild= 0;
}
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 3b9f5906c21..6b3da620fc1 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -364,14 +364,27 @@ public:
bool braces; /* SELECT ... UNION (SELECT ... ) <- this braces */
/* TRUE when having fix field called in processing of this SELECT */
bool having_fix_field;
+
/*
- TRUE for primary st_select_lex structure of simple INSERT/REPLACE
+ SELECT for SELECT command st_select_lex. Used to privent scaning
+ item_list of non-SELECT st_select_lex (no sense find to finding
+ reference in it (all should be in tables, it is dangerouse due
+ to order of fix_fields calling for non-SELECTs commands (item list
+ can be not fix_fieldsd)). This value will be assigned for
+ primary select (sql_yac.yy) and for any subquery and
+ UNION SELECT (sql_parse.cc mysql_new_select())
+
+
+ INSERT for primary st_select_lex structure of simple INSERT/REPLACE
(used for name resolution, see Item_fiels & Item_ref fix_fields,
FALSE for INSERT/REPLACE ... SELECT, because it's
st_select_lex->table_list will be preprocessed (first table removed)
before passing to handle_select)
+
+ NOMATTER for other
*/
- bool insert_select;
+ enum {NOMATTER_MODE, SELECT_MODE, INSERT_MODE} resolve_mode;
+
void init_query();
void init_select();
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 720017f399f..5880a9d4c8a 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -3561,6 +3561,7 @@ mysql_new_select(LEX *lex, bool move_down)
unit->link_prev= 0;
unit->return_to= lex->current_select;
select_lex->include_down(unit);
+ // TODO: assign resolve_mode for fake subquery after merging with new tree
}
else
select_lex->include_neighbour(lex->current_select);
@@ -3568,6 +3569,7 @@ mysql_new_select(LEX *lex, bool move_down)
select_lex->master_unit()->global_parameters= select_lex;
select_lex->include_global((st_select_lex_node**)&lex->all_selects_list);
lex->current_select= select_lex;
+ select_lex->resolve_mode= SELECT_LEX::SELECT_MODE;
return 0;
}
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 90c586dc2f1..aef58e6cb94 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1910,7 +1910,12 @@ opt_ignore_leaves:
select:
- select_init { Lex->sql_command=SQLCOM_SELECT; };
+ select_init
+ {
+ LEX *lex= Lex;
+ lex->sql_command= SQLCOM_SELECT;
+ lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE;
+ };
/* Need select_init2 for subselects. */
select_init:
@@ -3401,7 +3406,7 @@ insert:
lex->sql_command = SQLCOM_INSERT;
/* for subselects */
lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
- lex->select_lex.insert_select= 1;
+ lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
} insert_lock_option
opt_ignore insert2
{
@@ -3417,7 +3422,7 @@ replace:
LEX *lex=Lex;
lex->sql_command = SQLCOM_REPLACE;
lex->duplicates= DUP_REPLACE;
- lex->select_lex.insert_select= 1;
+ lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
}
replace_lock_option insert2
{
@@ -3486,7 +3491,7 @@ insert_values:
it is not simple select => table list will be
preprocessed before passing to handle_select
*/
- lex->select_lex.insert_select= 0;
+ lex->select_lex.resolve_mode= SELECT_LEX::NOMATTER_MODE;
lex->current_select->parsing_place= SELECT_LEX_NODE::SELECT_LIST;
}
select_options select_item_list