List:Internals« Previous MessageNext Message »
From:pem Date:September 21 2005 1:45pm
Subject:bk commit into 5.0 tree (pem:1.1989) BUG#6127
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of pem. When pem 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.1989 05/09/21 13:11:04 pem@stripped +5 -0
  Fixed BUG#6127: Stored procedure handlers within handlers don't work
    Replaced the dumb in-handler/not-in-handler check with a proper recursion
    check of handlers being executed.

  sql/sp_rcontext.h
    1.24 05/09/21 13:10:57 pem@stripped +20 -7
    Replaced the boolean in_handler flag with a stack of handlers being exectuted,
    for proper recursion check.
    (And added some comments in the sp_rcontext class.)

  sql/sp_rcontext.cc
    1.33 05/09/21 13:10:57 pem@stripped +9 -4
    Replaced the boolean in_handler flag with a stack of handlers being exectuted,
    for proper recursion check.

  sql/sp_head.cc
    1.185 05/09/21 13:10:57 pem@stripped +2 -2
    Replaced the setting of ctx->in_handler with a enter/exit handler methods.

  mysql-test/t/sp.test
    1.153 05/09/21 13:10:57 pem@stripped +36 -0
    New test case for BUG#6127.

  mysql-test/r/sp.result
    1.157 05/09/21 13:10:57 pem@stripped +30 -0
    New test case for BUG#6127.

# 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:	pem
# Host:	mysql.comhem.se
# Root:	/usr/home/pem/mysql-5.0

--- 1.156/mysql-test/r/sp.result	2005-09-20 14:15:43 +02:00
+++ 1.157/mysql-test/r/sp.result	2005-09-21 13:10:57 +02:00
@@ -3393,4 +3393,34 @@
 tm1	CREATE TEMPORARY TABLE `tm1` (
   `spv1` decimal(6,3) default NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
+drop table if exists t3|
+drop procedure if exists bug6127|
+create table t3 (s1 int unique)|
+set @sm=@@sql_mode|
+set sql_mode='traditional'|
+create procedure bug6127()
+begin
+declare continue handler for sqlstate '23000'
+    begin
+declare continue handler for sqlstate '22003'
+        insert into t3 values (0);
+insert into t3 values (1000000000000000);
+end;
+insert into t3 values (1);
+insert into t3 values (1);
+end|
+call bug6127()|
+select * from t3|
+s1
+0
+1
+call bug6127()|
+ERROR 23000: Duplicate entry '0' for key 1
+select * from t3|
+s1
+0
+1
+set sql_mode=@sm|
+drop table t3|
+drop procedure bug6127|
 drop table t1,t2;

--- 1.152/mysql-test/t/sp.test	2005-09-20 14:15:43 +02:00
+++ 1.153/mysql-test/t/sp.test	2005-09-21 13:10:57 +02:00
@@ -4259,6 +4259,42 @@
 
 
 #
+# BUG#6127: Stored procedure handlers within handlers don't work
+#
+--disable_warnings
+drop table if exists t3|
+drop procedure if exists bug6127|
+--enable_warnings
+create table t3 (s1 int unique)|
+
+set @sm=@@sql_mode|
+set sql_mode='traditional'|
+
+create procedure bug6127()
+begin
+  declare continue handler for sqlstate '23000'
+    begin
+      declare continue handler for sqlstate '22003'
+        insert into t3 values (0);
+
+      insert into t3 values (1000000000000000);
+    end;
+
+  insert into t3 values (1);
+  insert into t3 values (1);
+end|
+
+call bug6127()|
+select * from t3|
+--error ER_DUP_ENTRY
+call bug6127()|
+select * from t3|
+set sql_mode=@sm|
+drop table t3|
+drop procedure bug6127|
+
+
+#
 # BUG#NNNN: New bug synopsis
 #
 #--disable_warnings

--- 1.184/sql/sp_head.cc	2005-09-15 01:57:52 +02:00
+++ 1.185/sql/sp_head.cc	2005-09-21 13:10:57 +02:00
@@ -1000,7 +1000,7 @@
 	ip= hip;
 	ret= 0;
 	ctx->clear_handler();
-	ctx->in_handler= TRUE;
+	ctx->enter_handler(hip);
         thd->clear_error();
 	thd->killed= THD::NOT_KILLED;
 	continue;
@@ -2378,7 +2378,7 @@
     thd->spcont->restore_variables(m_frame);
     *nextp= thd->spcont->pop_hstack();
   }
-  thd->spcont->in_handler= FALSE;
+  thd->spcont->exit_handler();
   DBUG_RETURN(0);
 }
 

--- 1.32/sql/sp_rcontext.cc	2005-08-18 11:23:47 +02:00
+++ 1.33/sql/sp_rcontext.cc	2005-09-21 13:10:57 +02:00
@@ -30,12 +30,12 @@
 
 sp_rcontext::sp_rcontext(uint fsize, uint hmax, uint cmax)
   : m_count(0), m_fsize(fsize), m_result(NULL), m_hcount(0), m_hsp(0),
-    m_hfound(-1), m_ccount(0)
+    m_ihsp(0), m_hfound(-1), m_ccount(0)
 {
-  in_handler= FALSE;
   m_frame= (Item **)sql_alloc(fsize * sizeof(Item*));
   m_handler= (sp_handler_t *)sql_alloc(hmax * sizeof(sp_handler_t));
   m_hstack= (uint *)sql_alloc(hmax * sizeof(uint));
+  m_in_handler= (uint *)sql_alloc(hmax * sizeof(uint));
   m_cstack= (sp_cursor **)sql_alloc(cmax * sizeof(sp_cursor *));
   m_saved.empty();
 }
@@ -80,8 +80,6 @@
 sp_rcontext::find_handler(uint sql_errno,
                           MYSQL_ERROR::enum_warning_level level)
 {
-  if (in_handler)
-    return 0;			// Already executing a handler
   if (m_hfound >= 0)
     return 1;			// Already got one
 
@@ -91,6 +89,13 @@
   while (i--)
   {
     sp_cond_type_t *cond= m_handler[i].cond;
+    int j= m_ihsp;
+
+    while (j--)
+      if (m_in_handler[j] == m_handler[i].handler)
+	break;
+    if (j >= 0)
+      continue;                 // Already executing this handler
 
     switch (cond->type)
     {

--- 1.23/sql/sp_rcontext.h	2005-08-25 15:34:13 +02:00
+++ 1.24/sql/sp_rcontext.h	2005-09-21 13:10:57 +02:00
@@ -58,7 +58,6 @@
 
  public:
 
-  bool in_handler;
   /*
     Arena used to (re) allocate items on . E.g. reallocate INOUT/OUT
     SP parameters when they don't fit into prealloced items. This
@@ -169,6 +168,18 @@
     return m_hstack[--m_hsp];
   }
 
+  inline void
+  enter_handler(int hid)
+  {
+    m_in_handler[m_ihsp++]= hid;
+  }
+
+  inline void
+  exit_handler()
+  {
+    m_ihsp-= 1;
+  }
+
   // Save variables starting at fp and up
   void
   save_variables(uint fp);
@@ -203,12 +214,14 @@
 
   Item *m_result;		// For FUNCTIONs
 
-  sp_handler_t *m_handler;
-  uint m_hcount;
-  uint *m_hstack;
-  uint m_hsp;
-  int m_hfound;			// Set by find_handler; -1 if not found
-  List<Item> m_saved;		// Saved variables
+  sp_handler_t *m_handler;      // Visible handlers
+  uint m_hcount;                // Stack pointer for m_handler
+  uint *m_hstack;               // Return stack for continue handlers
+  uint m_hsp;                   // Stack pointer for m_hstack
+  uint *m_in_handler;           // Active handler, for recursion check
+  uint m_ihsp;                  // Stack pointer for m_in_handler
+  int m_hfound;                 // Set by find_handler; -1 if not found
+  List<Item> m_saved;           // Saved variables during handler exec.
 
   sp_cursor **m_cstack;
   uint m_ccount;
Thread
bk commit into 5.0 tree (pem:1.1989) BUG#6127pem21 Sep