Commit c672d355 authored by unknown's avatar unknown

BUG#8807 Select crash server

 - Add function Item_param::fix_fields which will update any subselect they are part of and indicate that the subsleect is not const during prepare phase, and thus should not be executed during prepare.


mysql-test/include/ps_query.inc:
  Adde new test case
mysql-test/r/ps_2myisam.result:
  Update test result
mysql-test/r/ps_3innodb.result:
  Update test result
mysql-test/r/ps_4heap.result:
  Update test result
mysql-test/r/ps_5merge.result:
  Update test result
mysql-test/r/ps_6bdb.result:
  Update test result
mysql-test/r/ps_7ndb.result:
  Update test result
sql/item.cc:
  Add function Item_param::fix_fields, which will mark any subselects they are part of as not being a constant expression unless the param value is specified, ie. it will be not be constant during prepare phase.
sql/item.h:
  Adde Item_param::fix_fields
sql/item_subselect.h:
  Make Item_param::fix_field friend of Item_subselect
parent 84aeb4d3
...@@ -421,6 +421,11 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where ...@@ -421,6 +421,11 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where
b=? and a = (select ? from t1 where b = ? ) ' ; b=? and a = (select ? from t1 where b = ? ) ' ;
execute stmt1 using @arg00, @arg01, @arg02, @arg03 ; execute stmt1 using @arg00, @arg01, @arg02, @arg03 ;
# Bug#8807
prepare stmt1 from 'select c4 FROM t9 where
c13 = (select MAX(b) from t1 where a = ?) and c22 = ? ' ;
execute stmt1 using @arg01, @arg02;
######## correlated subquery ######## correlated subquery
# no parameter # no parameter
prepare stmt1 from ' select a, b FROM t1 outer_table where prepare stmt1 from ' select a, b FROM t1 outer_table where
......
...@@ -768,6 +768,10 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where ...@@ -768,6 +768,10 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where
execute stmt1 using @arg00, @arg01, @arg02, @arg03 ; execute stmt1 using @arg00, @arg01, @arg02, @arg03 ;
a ? b a ? b
2 1 two 2 1 two
prepare stmt1 from 'select c4 FROM t9 where
c13 = (select MAX(b) from t1 where a = ?) and c22 = ? ' ;
execute stmt1 using @arg01, @arg02;
c4
prepare stmt1 from ' select a, b FROM t1 outer_table where prepare stmt1 from ' select a, b FROM t1 outer_table where
a = (select a from t1 where b = outer_table.b ) order by a '; a = (select a from t1 where b = outer_table.b ) order by a ';
execute stmt1 ; execute stmt1 ;
......
...@@ -768,6 +768,10 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where ...@@ -768,6 +768,10 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where
execute stmt1 using @arg00, @arg01, @arg02, @arg03 ; execute stmt1 using @arg00, @arg01, @arg02, @arg03 ;
a ? b a ? b
2 1 two 2 1 two
prepare stmt1 from 'select c4 FROM t9 where
c13 = (select MAX(b) from t1 where a = ?) and c22 = ? ' ;
execute stmt1 using @arg01, @arg02;
c4
prepare stmt1 from ' select a, b FROM t1 outer_table where prepare stmt1 from ' select a, b FROM t1 outer_table where
a = (select a from t1 where b = outer_table.b ) order by a '; a = (select a from t1 where b = outer_table.b ) order by a ';
execute stmt1 ; execute stmt1 ;
......
...@@ -769,6 +769,10 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where ...@@ -769,6 +769,10 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where
execute stmt1 using @arg00, @arg01, @arg02, @arg03 ; execute stmt1 using @arg00, @arg01, @arg02, @arg03 ;
a ? b a ? b
2 1 two 2 1 two
prepare stmt1 from 'select c4 FROM t9 where
c13 = (select MAX(b) from t1 where a = ?) and c22 = ? ' ;
execute stmt1 using @arg01, @arg02;
c4
prepare stmt1 from ' select a, b FROM t1 outer_table where prepare stmt1 from ' select a, b FROM t1 outer_table where
a = (select a from t1 where b = outer_table.b ) order by a '; a = (select a from t1 where b = outer_table.b ) order by a ';
execute stmt1 ; execute stmt1 ;
......
...@@ -811,6 +811,10 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where ...@@ -811,6 +811,10 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where
execute stmt1 using @arg00, @arg01, @arg02, @arg03 ; execute stmt1 using @arg00, @arg01, @arg02, @arg03 ;
a ? b a ? b
2 1 two 2 1 two
prepare stmt1 from 'select c4 FROM t9 where
c13 = (select MAX(b) from t1 where a = ?) and c22 = ? ' ;
execute stmt1 using @arg01, @arg02;
c4
prepare stmt1 from ' select a, b FROM t1 outer_table where prepare stmt1 from ' select a, b FROM t1 outer_table where
a = (select a from t1 where b = outer_table.b ) order by a '; a = (select a from t1 where b = outer_table.b ) order by a ';
execute stmt1 ; execute stmt1 ;
...@@ -3821,6 +3825,10 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where ...@@ -3821,6 +3825,10 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where
execute stmt1 using @arg00, @arg01, @arg02, @arg03 ; execute stmt1 using @arg00, @arg01, @arg02, @arg03 ;
a ? b a ? b
2 1 two 2 1 two
prepare stmt1 from 'select c4 FROM t9 where
c13 = (select MAX(b) from t1 where a = ?) and c22 = ? ' ;
execute stmt1 using @arg01, @arg02;
c4
prepare stmt1 from ' select a, b FROM t1 outer_table where prepare stmt1 from ' select a, b FROM t1 outer_table where
a = (select a from t1 where b = outer_table.b ) order by a '; a = (select a from t1 where b = outer_table.b ) order by a ';
execute stmt1 ; execute stmt1 ;
......
...@@ -768,6 +768,10 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where ...@@ -768,6 +768,10 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where
execute stmt1 using @arg00, @arg01, @arg02, @arg03 ; execute stmt1 using @arg00, @arg01, @arg02, @arg03 ;
a ? b a ? b
2 1 two 2 1 two
prepare stmt1 from 'select c4 FROM t9 where
c13 = (select MAX(b) from t1 where a = ?) and c22 = ? ' ;
execute stmt1 using @arg01, @arg02;
c4
prepare stmt1 from ' select a, b FROM t1 outer_table where prepare stmt1 from ' select a, b FROM t1 outer_table where
a = (select a from t1 where b = outer_table.b ) order by a '; a = (select a from t1 where b = outer_table.b ) order by a ';
execute stmt1 ; execute stmt1 ;
......
...@@ -768,6 +768,10 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where ...@@ -768,6 +768,10 @@ prepare stmt1 from ' select a, ?, b FROM t1 outer_table where
execute stmt1 using @arg00, @arg01, @arg02, @arg03 ; execute stmt1 using @arg00, @arg01, @arg02, @arg03 ;
a ? b a ? b
2 1 two 2 1 two
prepare stmt1 from 'select c4 FROM t9 where
c13 = (select MAX(b) from t1 where a = ?) and c22 = ? ' ;
execute stmt1 using @arg01, @arg02;
c4
prepare stmt1 from ' select a, b FROM t1 outer_table where prepare stmt1 from ' select a, b FROM t1 outer_table where
a = (select a from t1 where b = outer_table.b ) order by a '; a = (select a from t1 where b = outer_table.b ) order by a ';
execute stmt1 ; execute stmt1 ;
......
...@@ -1319,6 +1319,34 @@ bool Item_param::convert_str_value(THD *thd) ...@@ -1319,6 +1319,34 @@ bool Item_param::convert_str_value(THD *thd)
return rc; return rc;
} }
bool Item_param::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{
DBUG_ASSERT(fixed == 0);
SELECT_LEX *cursel= (SELECT_LEX *) thd->lex->current_select;
/*
Parameters in a subselect should mark the subselect as not constant
during prepare
*/
if (state == NO_VALUE)
{
/*
SELECT_LEX_UNIT::item set only for subqueries, so test of it presence
can be barrier to stop before derived table SELECT or very outer SELECT
*/
for(;
cursel->master_unit()->item;
cursel= cursel->outer_select())
{
Item_subselect *subselect_item= cursel->master_unit()->item;
subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
subselect_item->const_item_cache= 0;
}
}
fixed= 1;
return 0;
}
/* End of Item_param related */ /* End of Item_param related */
......
...@@ -559,6 +559,7 @@ class Item_param :public Item ...@@ -559,6 +559,7 @@ class Item_param :public Item
bool get_time(TIME *tm); bool get_time(TIME *tm);
bool get_date(TIME *tm, uint fuzzydate); bool get_date(TIME *tm, uint fuzzydate);
int save_in_field(Field *field, bool no_conversions); int save_in_field(Field *field, bool no_conversions);
bool fix_fields(THD *, struct st_table_list *, Item **);
void set_null(); void set_null();
void set_int(longlong i, uint32 max_length_arg); void set_int(longlong i, uint32 max_length_arg);
......
...@@ -119,6 +119,7 @@ class Item_subselect :public Item_result_field ...@@ -119,6 +119,7 @@ class Item_subselect :public Item_result_field
friend class Item_in_optimizer; friend class Item_in_optimizer;
friend bool Item_field::fix_fields(THD *, TABLE_LIST *, Item **); friend bool Item_field::fix_fields(THD *, TABLE_LIST *, Item **);
friend bool Item_ref::fix_fields(THD *, TABLE_LIST *, Item **); friend bool Item_ref::fix_fields(THD *, TABLE_LIST *, Item **);
friend bool Item_param::fix_fields(THD *, TABLE_LIST *, Item **);
}; };
/* single value subselect */ /* single value subselect */
......
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