Commit f2571638 authored by unknown's avatar unknown

fix for bug #12651 (item of a prepared query allocated on non-permanent

are thus dangling later)


mysql-test/r/ps.result:
  test for bug #12651
  (data allocated on thd's arena but not on permanent arena)
mysql-test/t/ps.test:
  test for bug #12651
  (data allocated on thd's arena but not on permanent arena)
sql/sql_base.cc:
  if there is tree transformation then backup the current arena
  and use permanent one (for PS) otherwise the data will be deallocated
  after the prepare process is finished.
  this bug was introduced with the recent natural join patch
parent 996d4c45
......@@ -773,6 +773,14 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
select ? from t1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? from t1' at line 1
drop table t1;
CREATE TABLE b12651_T1(a int) ENGINE=MYISAM;
CREATE TABLE b12651_T2(b int) ENGINE=MYISAM;
CREATE VIEW b12651_V1 as SELECT b FROM b12651_T2;
PREPARE b12651 FROM 'SELECT 1 FROM b12651_T1 WHERE a IN (SELECT b FROM b12651_V1)';
EXECUTE b12651;
1
DROP VIEW b12651_V1;
DROP TABLE b12651_T1, b12651_T2;
prepare stmt from "select @@time_zone";
execute stmt;
@@time_zone
......
......@@ -809,6 +809,21 @@ select ??;
select ? from t1;
--enable_ps_protocol
drop table t1;
#
# Bug#12651
# (Crash on a PS including a subquery which is a select from a simple view)
#
CREATE TABLE b12651_T1(a int) ENGINE=MYISAM;
CREATE TABLE b12651_T2(b int) ENGINE=MYISAM;
CREATE VIEW b12651_V1 as SELECT b FROM b12651_T2;
PREPARE b12651 FROM 'SELECT 1 FROM b12651_T1 WHERE a IN (SELECT b FROM b12651_V1)';
EXECUTE b12651;
DROP VIEW b12651_V1;
DROP TABLE b12651_T1, b12651_T2;
#
# Bug#9359 "Prepared statements take snapshot of system vars at PREPARE
# time"
......
......@@ -2612,6 +2612,8 @@ find_field_in_view(THD *thd, TABLE_LIST *table_list,
table_list->alias, name, item_name, (ulong) ref));
Field_iterator_view field_it;
field_it.set(table_list);
Query_arena *arena, backup;
DBUG_ASSERT(table_list->schema_table_reformed ||
(ref != 0 && table_list->view != 0));
for (; !field_it.end_of_fields(); field_it.next())
......@@ -2633,7 +2635,13 @@ find_field_in_view(THD *thd, TABLE_LIST *table_list,
name, length))
DBUG_RETURN(WRONG_GRANT);
#endif
// in PS use own arena or data will be freed after prepare
if (register_tree_change)
arena= thd->activate_stmt_arena_if_needed(&backup);
Item *item= field_it.create_item(thd);
if (register_tree_change && arena)
thd->restore_active_arena(arena, &backup);
if (!item)
DBUG_RETURN(0);
/*
......@@ -2695,6 +2703,8 @@ find_field_in_natural_join(THD *thd, TABLE_LIST *table_ref, const char *name,
field_it(*(table_ref->join_columns));
Natural_join_column *nj_col;
Field *found_field;
Query_arena *arena, backup;
DBUG_ENTER("find_field_in_natural_join");
DBUG_PRINT("enter", ("field name: '%s', ref 0x%lx",
name, (ulong) ref));
......@@ -2723,7 +2733,14 @@ find_field_in_natural_join(THD *thd, TABLE_LIST *table_ref, const char *name,
The found field is a view field, we do as in find_field_in_view()
and return a pointer to pointer to the Item of that field.
*/
if (register_tree_change)
arena= thd->activate_stmt_arena_if_needed(&backup);
Item *item= nj_col->create_item(thd);
if (register_tree_change && arena)
thd->restore_active_arena(arena, &backup);
if (!item)
DBUG_RETURN(NULL);
DBUG_ASSERT(nj_col->table_field == NULL);
......
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