Commit 31e42be6 authored by unknown's avatar unknown

fixed BUG#1645

  all calls of fix_fields() are inspected
(copy of cset which I lost in accidatly tree delete)


mysql-test/r/subselect.result:
  test of BUG#1645
mysql-test/t/subselect.test:
  test of BUG#1645
sql/item_subselect.cc:
  removed passing left_expr through parameters, because it present in class fields
  fixed fix_fields() call
sql/item_subselect.h:
  removed passing left_expr through parameters, because it present in class fields
sql/set_var.cc:
  comments added
sql/sql_select.cc:
  fixed BUG#1645 (thd can be used in fix_fields of subqueries)
parent f6e7570f
...@@ -1477,3 +1477,10 @@ phone code ...@@ -1477,3 +1477,10 @@ phone code
89356874041 NULL 89356874041 NULL
95895001874 NULL 95895001874 NULL
drop table t1, t2; drop table t1, t2;
CREATE TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB));
CREATE TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA));
INSERT INTO t1 VALUES (1,1,'1A3240'), (1,2,'4W2365');
INSERT INTO t2 VALUES (100, 200, 'C');
SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
COLC
DROP TABLE t1, t2;
...@@ -986,3 +986,13 @@ CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) TYPE=M ...@@ -986,3 +986,13 @@ CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) TYPE=M
INSERT INTO t2 VALUES ('1'),('1226'),('1245'),('1862'),('18623'),('1874'),('1967'),('6'); INSERT INTO t2 VALUES ('1'),('1226'),('1245'),('1862'),('18623'),('1874'),('1967'),('6');
select c.number as phone,(select p.code from t2 p where c.number like concat(p.code, '%') order by length(p.code) desc limit 1) as code from t1 c; select c.number as phone,(select p.code from t2 p where c.number like concat(p.code, '%') order by length(p.code) desc limit 1) as code from t1 c;
drop table t1, t2; drop table t1, t2;
#
# fix_fields() in add_ref_to_table_cond()
#
CREATE TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB));
CREATE TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA));
INSERT INTO t1 VALUES (1,1,'1A3240'), (1,2,'4W2365');
INSERT INTO t2 VALUES (100, 200, 'C');
SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
DROP TABLE t1, t2;
\ No newline at end of file
...@@ -512,7 +512,6 @@ String *Item_in_subselect::val_str(String *str) ...@@ -512,7 +512,6 @@ String *Item_in_subselect::val_str(String *str)
Item_subselect::trans_res Item_subselect::trans_res
Item_in_subselect::single_value_transformer(JOIN *join, Item_in_subselect::single_value_transformer(JOIN *join,
Item *left_expr,
compare_func_creator func) compare_func_creator func)
{ {
DBUG_ENTER("Item_in_subselect::single_value_transformer"); DBUG_ENTER("Item_in_subselect::single_value_transformer");
...@@ -587,7 +586,7 @@ Item_in_subselect::single_value_transformer(JOIN *join, ...@@ -587,7 +586,7 @@ Item_in_subselect::single_value_transformer(JOIN *join,
// left expression belong to outer select // left expression belong to outer select
SELECT_LEX *current= thd->lex.current_select, *up; SELECT_LEX *current= thd->lex.current_select, *up;
thd->lex.current_select= up= current->return_after_parsing(); thd->lex.current_select= up= current->return_after_parsing();
if (left_expr->fix_fields(thd, up->get_table_list(), 0)) if (left_expr->fix_fields(thd, up->get_table_list(), &left_expr))
{ {
thd->lex.current_select= current; thd->lex.current_select= current;
DBUG_RETURN(RES_ERROR); DBUG_RETURN(RES_ERROR);
...@@ -716,8 +715,7 @@ Item_in_subselect::single_value_transformer(JOIN *join, ...@@ -716,8 +715,7 @@ Item_in_subselect::single_value_transformer(JOIN *join,
} }
Item_subselect::trans_res Item_subselect::trans_res
Item_in_subselect::row_value_transformer(JOIN *join, Item_in_subselect::row_value_transformer(JOIN *join)
Item *left_expr)
{ {
DBUG_ENTER("Item_in_subselect::row_value_transformer"); DBUG_ENTER("Item_in_subselect::row_value_transformer");
...@@ -800,16 +798,16 @@ Item_subselect::trans_res ...@@ -800,16 +798,16 @@ Item_subselect::trans_res
Item_in_subselect::select_transformer(JOIN *join) Item_in_subselect::select_transformer(JOIN *join)
{ {
if (left_expr->cols() == 1) if (left_expr->cols() == 1)
return single_value_transformer(join, left_expr, return single_value_transformer(join,
&Item_bool_func2::eq_creator); &Item_bool_func2::eq_creator);
return row_value_transformer(join, left_expr); return row_value_transformer(join);
} }
Item_subselect::trans_res Item_subselect::trans_res
Item_allany_subselect::select_transformer(JOIN *join) Item_allany_subselect::select_transformer(JOIN *join)
{ {
return single_value_transformer(join, left_expr, func); return single_value_transformer(join, func);
} }
subselect_single_select_engine:: subselect_single_select_engine::
......
...@@ -210,10 +210,8 @@ class Item_in_subselect :public Item_exists_subselect ...@@ -210,10 +210,8 @@ class Item_in_subselect :public Item_exists_subselect
} }
trans_res select_transformer(JOIN *join); trans_res select_transformer(JOIN *join);
trans_res single_value_transformer(JOIN *join, trans_res single_value_transformer(JOIN *join,
Item *left_expr,
compare_func_creator func); compare_func_creator func);
trans_res row_value_transformer(JOIN * join, trans_res row_value_transformer(JOIN * join);
Item *left_expr);
longlong val_int(); longlong val_int();
double val(); double val();
String *val_str(String*); String *val_str(String*);
......
...@@ -2279,7 +2279,11 @@ int set_var::update(THD *thd) ...@@ -2279,7 +2279,11 @@ int set_var::update(THD *thd)
int set_var_user::check(THD *thd) int set_var_user::check(THD *thd)
{ {
return (user_var_item->fix_fields(thd,0, (Item**) 0) || /*
Item_func_set_user_var can't substitute something else on its place =>
0 can be passed as last argument
*/
return (user_var_item->fix_fields(thd, 0, (Item**) 0) ||
user_var_item->check()) ? -1 : 0; user_var_item->check()) ? -1 : 0;
} }
......
...@@ -8525,11 +8525,7 @@ static bool add_ref_to_table_cond(THD *thd, JOIN_TAB *join_tab) ...@@ -8525,11 +8525,7 @@ static bool add_ref_to_table_cond(THD *thd, JOIN_TAB *join_tab)
if (thd->is_fatal_error) if (thd->is_fatal_error)
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
/* cond->fix_fields(thd,(TABLE_LIST *) 0, (Item**)&cond);
Here we pass 0 as the first argument to fix_fields that don't need
to do any stack checking (This is already done in the initial fix_fields).
*/
cond->fix_fields((THD *) 0,(TABLE_LIST *) 0, (Item**)&cond);
if (join_tab->select) if (join_tab->select)
{ {
error=(int) cond->add(join_tab->select->cond); error=(int) cond->add(join_tab->select->cond);
......
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