List:Commits« Previous MessageNext Message »
From:konstantin Date:June 16 2006 3:57am
Subject:bk commit into 5.0 tree (konstantin:1.2168) BUG#15217
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of kostja. When kostja does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2168 06/06/16 05:57:15 konstantin@stripped +3 -0
  A fix and a test case for Bug#15217 "Using a SP cursor on a table created
   with PREPARE fails with weird error": move assignment of stmt_arena->state
  to reset_lex_and_exec_core. When using a cursor, we always use stmt_arena of
  sp_instr_cpush, not sp_instr_copen. The substitution happens in
  sp_instr_copen::execute. Therefore, we need to update the state of 
  sp_instr_cpush to EXECUTED after first execution: this didn't work as
  the state was updated after i->execute has restored the arena pointer back
  to sp_instr_copen.

  sql/sp_head.cc
    1.215 06/06/16 05:57:12 konstantin@stripped +2 -1
    Move assignment of stmt_arena->state to reset_lex_and_exec_core

  mysql-test/t/sp-dynamic.test
    1.4 06/06/16 05:57:12 konstantin@stripped +59 -1
    Add a test case for Bug#15217

  mysql-test/r/sp-dynamic.result
    1.6 06/06/16 05:57:12 konstantin@stripped +58 -0
    Test results fixed (Bug#15217)

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	konstantin
# Host:	bodhi.netgear
# Root:	/opt/local/work/mysql-5.0-15217

--- 1.5/mysql-test/r/sp-dynamic.result	2006-05-12 20:58:48 +04:00
+++ 1.6/mysql-test/r/sp-dynamic.result	2006-06-16 05:57:12 +04:00
@@ -373,3 +373,61 @@
 @a
 0
 drop procedure if exists p1|
+create table t1(c1 int)|
+insert into t1 values(1)|
+create procedure bug15217(tab varchar(64))
+begin
+drop table if exists t2;
+set @stmt= concat('create table t2 as select * from ', tab);
+prepare p1 from @stmt;
+execute p1;
+deallocate  prepare p1;
+begin
+declare var1 char(255);
+declare cur1 cursor for select * from t2;
+open cur1;
+fetch cur1 into var1;
+select concat('data was: /', var1, '/');
+close cur1;
+end;
+end|
+call bug15217('t1')|
+concat('data was: /', var1, '/')
+data was: /1/
+Warnings:
+Note	1051	Unknown table 't2'
+call bug15217('t1')|
+concat('data was: /', var1, '/')
+data was: /1/
+drop table t2|
+drop procedure bug15217|
+create procedure bug15217(tab varchar(64))
+begin
+declare var1 char(255);
+drop temporary table if exists t2;
+set @stmt = concat('create temporary table t2 like ', tab);
+prepare p1 from @stmt;
+execute p1;
+deallocate prepare p1;
+set @stmt = concat('insert into t2 select * from ', tab);
+prepare p1 from @stmt;
+execute p1;
+deallocate  prepare p1;
+begin
+declare cur1 cursor for select * from t2;
+open cur1;
+fetch cur1 into var1;
+select concat('data was: /', var1, '/');
+close cur1;
+end;
+end|
+call bug15217('t1')|
+concat('data was: /', var1, '/')
+data was: /1/
+Warnings:
+Note	1051	Unknown table 't2'
+call bug15217('t1')|
+concat('data was: /', var1, '/')
+data was: /1/
+drop table t1,t2|
+drop procedure bug15217|

--- 1.3/mysql-test/t/sp-dynamic.test	2005-12-07 17:01:07 +03:00
+++ 1.4/mysql-test/t/sp-dynamic.test	2006-06-16 05:57:12 +04:00
@@ -348,5 +348,63 @@
 select @a|
 drop procedure if exists p1|
 
+
+#
+# Bug#15217 "Using a SP cursor on a table created with PREPARE fails with
+#           weird error". Check that the code that is supposed to work at
+#           the first execution of a stored procedure actually works for
+#           sp_instr_copen.
+#
+create table t1(c1 int)|
+insert into t1 values(1)|
+# A reduced test case
+create procedure bug15217(tab varchar(64))
+begin
+  drop table if exists t2;
+  set @stmt= concat('create table t2 as select * from ', tab);
+  prepare p1 from @stmt;
+  execute p1;
+  deallocate  prepare p1;
+  begin
+    declare var1 char(255);
+    declare cur1 cursor for select * from t2;
+    open cur1;
+    fetch cur1 into var1;
+    select concat('data was: /', var1, '/');
+    close cur1;
+  end;
+end|
+call bug15217('t1')|
+call bug15217('t1')|
+drop table t2|
+drop procedure bug15217|
+# The original test case
+create procedure bug15217(tab varchar(64))
+begin
+  declare var1 char(255);
+
+  drop temporary table if exists t2;
+  set @stmt = concat('create temporary table t2 like ', tab);
+  prepare p1 from @stmt;
+  execute p1;
+  deallocate prepare p1;
+  set @stmt = concat('insert into t2 select * from ', tab);
+  prepare p1 from @stmt;
+  execute p1;
+  deallocate  prepare p1;
+
+  begin
+    declare cur1 cursor for select * from t2;
+    open cur1;
+    fetch cur1 into var1;
+    select concat('data was: /', var1, '/');
+    close cur1;
+  end;
+end|
+call bug15217('t1')|
+call bug15217('t1')|
+drop table t1,t2|
+drop procedure bug15217|
+
 # End of the test
-delimiter ;|
+ delimiter ;|

--- 1.214/sql/sp_head.cc	2006-05-23 23:00:59 +04:00
+++ 1.215/sql/sp_head.cc	2006-06-16 05:57:12 +04:00
@@ -1075,7 +1075,6 @@
     thd->net.no_send_error= 0;
     if (i->free_list)
       cleanup_items(i->free_list);
-    i->state= Query_arena::EXECUTED;
     
     /* 
       If we've set thd->user_var_events_alloc to mem_root of this SP
@@ -2210,6 +2209,8 @@
     m_lex->mark_as_requiring_prelocking(NULL);
   }
   thd->rollback_item_tree_changes();
+  /* Update the state of the active arena */
+  thd->stmt_arena->state= Query_arena::EXECUTED;
 
   /*
     Unlike for PS we should not call Item's destructors for newly created
Thread
bk commit into 5.0 tree (konstantin:1.2168) BUG#15217konstantin16 Jun