List:Commits« Previous MessageNext Message »
From:Hakan Kuecuekyilmaz Date:March 31 2009 11:24pm
Subject:bzr push into mysql-6.0-falcon-team branch (hky:3090)
View as plain text  
 3090 Hakan Kuecuekyilmaz	2009-03-31 [merge]
      Automerge.

    modified:
      storage/falcon/CmdGen.cpp
      storage/falcon/Configuration.cpp
      storage/falcon/StorageHandler.cpp
      storage/falcon/StorageTable.cpp
      storage/falcon/ha_falcon.cpp
=== modified file 'client/mysqldump.c'
--- a/client/mysqldump.c	2009-03-12 16:18:40 +0000
+++ b/client/mysqldump.c	2009-03-27 22:06:26 +0000
@@ -1318,120 +1318,68 @@ static int switch_character_set_results(
 }
 
 /**
-  Rewrite CREATE TRIGGER statement, enclosing DEFINER clause in
-  version-specific comment.
+  Rewrite statement, enclosing DEFINER clause in version-specific comment.
 
-  This function parses the CREATE TRIGGER statement and encloses
-  DEFINER-clause in version-specific comment:
-    input query:     CREATE DEFINER=a@b TRIGGER ...
-    rewritten query: CREATE * / / *!50017 DEFINER=a@b * / / *!50003 TRIGGER ...
-
-  @note This function will go away when WL#3995 is implemented.
-
-  @param[in] trigger_def_str    CREATE TRIGGER statement string.
-  @param[in] trigger_def_length length of the trigger_def_str.
-
-  @return pointer to the new allocated query string.
-*/
-
-static char *cover_definer_clause_in_trigger(const char *trigger_def_str,
-                                             uint trigger_def_length)
-{
-  char *query_str= NULL;
-  char *definer_begin= my_case_str(trigger_def_str, trigger_def_length,
-                                   C_STRING_WITH_LEN(" DEFINER"));
-  char *definer_end;
-
-  if (!definer_begin)
-    return NULL;
-

-  definer_end= my_case_str(definer_begin, strlen(definer_begin),
-                           C_STRING_WITH_LEN(" TRIGGER"));
-
-  if (definer_end)
-  {
-    char *query_str_tail;
-
-    /*
-       Allocate memory for new query string: original string
-       from SHOW statement and version-specific comments.
-     */
-    query_str= alloc_query_str(trigger_def_length + 23);
-
-    query_str_tail= strnmov(query_str,
-                            trigger_def_str,
-                            definer_begin - trigger_def_str);
-
-    query_str_tail= strmov(query_str_tail,
-                           "*/ /*!50017");
-
-    query_str_tail= strnmov(query_str_tail,
-                            definer_begin,
-                            definer_end - definer_begin);
-
-    query_str_tail= strxmov(query_str_tail,
-                            "*/ /*!50003",
-                            definer_end,
-                            NullS);
-  }
-
-  return query_str;
-}
-
-/**
-  Rewrite CREATE FUNCTION or CREATE PROCEDURE statement, enclosing DEFINER
-  clause in version-specific comment.
-
-  This function parses the CREATE FUNCTION | PROCEDURE statement and
-  encloses DEFINER-clause in version-specific comment:
+  This function parses any CREATE statement and encloses DEFINER-clause in
+  version-specific comment:
     input query:     CREATE DEFINER=a@b FUNCTION ...
     rewritten query: CREATE * / / *!50020 DEFINER=a@b * / / *!50003 FUNCTION ...
 
   @note This function will go away when WL#3995 is implemented.
 
-  @param[in] def_str        CREATE FUNCTION|PROCEDURE statement string.
-  @param[in] def_str_length length of the def_str.
+  @param[in] stmt_str                 CREATE statement string.
+  @param[in] stmt_length              Length of the stmt_str.
+  @param[in] definer_version_str      Minimal MySQL version number when
+                                      DEFINER clause is supported in the
+                                      given statement.
+  @param[in] definer_version_length   Length of definer_version_str.
+  @param[in] stmt_version_str         Minimal MySQL version number when the
+                                      given statement is supported.
+  @param[in] stmt_version_length      Length of stmt_version_str.
+  @param[in] keyword_str              Keyword to look for after CREATE.
+  @param[in] keyword_length           Length of keyword_str.
 
   @return pointer to the new allocated query string.
 */
 
-static char *cover_definer_clause_in_sp(const char *def_str,
-                                        uint def_str_length)
+static char *cover_definer_clause(const char *stmt_str,
+                                  uint stmt_length,
+                                  const char *definer_version_str,
+                                  uint definer_version_length,
+                                  const char *stmt_version_str,
+                                  uint stmt_version_length,
+                                  const char *keyword_str,
+                                  uint keyword_length)
 {
-  char *query_str= NULL;
-  char *definer_begin= my_case_str(def_str, def_str_length,
+  char *definer_begin= my_case_str(stmt_str, stmt_length,
                                    C_STRING_WITH_LEN(" DEFINER"));
-  char *definer_end;
+  char *definer_end= NULL;
+
+  char *query_str= NULL;
+  char *query_ptr;
 
   if (!definer_begin)
     return NULL;
 
   definer_end= my_case_str(definer_begin, strlen(definer_begin),
-                           C_STRING_WITH_LEN(" PROCEDURE"));
+                           keyword_str, keyword_length);
 
   if (!definer_end)
-  {
-    definer_end= my_case_str(definer_begin, strlen(definer_begin),
-                             C_STRING_WITH_LEN(" FUNCTION"));
-  }
-
-  if (definer_end)
-  {
-    char *query_str_tail;
+    return NULL;
 
-    /*
-      Allocate memory for new query string: original string
-      from SHOW statement and version-specific comments.
-    */
-    query_str= alloc_query_str(def_str_length + 23);
+  /*
+    Allocate memory for new query string: original string
+    from SHOW statement and version-specific comments.
+  */
+  query_str= alloc_query_str(stmt_length + 23);
 
-    query_str_tail= strnmov(query_str, def_str, definer_begin - def_str);
-    query_str_tail= strmov(query_str_tail, "*/ /*!50020");
-    query_str_tail= strnmov(query_str_tail, definer_begin,
-                            definer_end - definer_begin);
-    query_str_tail= strxmov(query_str_tail, "*/ /*!50003",
-                            definer_end, NullS);
-  }
+  query_ptr= strnmov(query_str, stmt_str, definer_begin - stmt_str);
+  query_ptr= strnmov(query_ptr, C_STRING_WITH_LEN("*/ /*!"));
+  query_ptr= strnmov(query_ptr, definer_version_str, definer_version_length);
+  query_ptr= strnmov(query_ptr, definer_begin, definer_end - definer_begin);
+  query_ptr= strnmov(query_ptr, C_STRING_WITH_LEN("*/ /*!"));
+  query_ptr= strnmov(query_ptr, stmt_version_str, stmt_version_length);
+  query_ptr= strxmov(query_ptr, definer_end, NullS);
 
   return query_str;
 }
@@ -1966,6 +1914,8 @@ static uint dump_events_for_db(char *db)
         */
         if (strlen(row[3]) != 0)
         {
+          char *query_str;
+
           if (opt_drop)
             fprintf(sql_file, "/*!50106 DROP EVENT IF EXISTS %s */%s\n", 
                 event_name, delimiter);
@@ -1992,31 +1942,36 @@ static uint dump_events_for_db(char *db)
                                 row[4],   /* character_set_results */
                                 row[5]);  /* collation_connection */
           }
-            else
-            {
-              /*
-                mysqldump is being run against the server, that does not
-                provide character set information in SHOW CREATE
-                statements.
+          else
+          {
+            /*
+              mysqldump is being run against the server, that does not
+              provide character set information in SHOW CREATE
+              statements.
 
-                NOTE: the dump may be incorrect, since character set
-                information is required in order to restore event properly.
-              */
+              NOTE: the dump may be incorrect, since character set
+              information is required in order to restore event properly.
+            */
 
-              fprintf(sql_file,
-                      "--\n"
-                      "-- WARNING: old server version. "
-                        "The following dump may be incomplete.\n"
-                      "--\n");
-            }
+            fprintf(sql_file,
+                    "--\n"
+                    "-- WARNING: old server version. "
+                      "The following dump may be incomplete.\n"
+                    "--\n");
+          }
 
           switch_sql_mode(sql_file, delimiter, row[1]);
 
           switch_time_zone(sql_file, delimiter, row[2]);
 
+          query_str= cover_definer_clause(row[3], strlen(row[3]),
+                                          C_STRING_WITH_LEN("50117"),
+                                          C_STRING_WITH_LEN("50106"),
+                                          C_STRING_WITH_LEN(" EVENT"));
+
           fprintf(sql_file,
                   "/*!50106 %s */ %s\n",
-                  (const char *) row[3],
+                  (const char *) (query_str != NULL ? query_str : row[3]),
                   (const char *) delimiter);
 
           restore_time_zone(sql_file, delimiter);
@@ -2171,7 +2126,16 @@ static uint dump_routines_for_db(char *d
               fprintf(sql_file, "/*!50003 DROP %s IF EXISTS %s */;\n",
                       routine_type[i], routine_name);
 
-            query_str= cover_definer_clause_in_sp(row[2], strlen(row[2]));
+            query_str= cover_definer_clause(row[2], strlen(row[2]),
+                                            C_STRING_WITH_LEN("50020"),
+                                            C_STRING_WITH_LEN("50003"),
+                                            C_STRING_WITH_LEN(" FUNCTION"));
+
+            if (!query_str)
+              query_str= cover_definer_clause(row[2], strlen(row[2]),
+                                              C_STRING_WITH_LEN("50020"),
+                                              C_STRING_WITH_LEN("50003"),
+                                              C_STRING_WITH_LEN(" PROCEDURE"));
 
             if (mysql_num_fields(routine_res) >= 6)
             {
@@ -2856,8 +2820,10 @@ static int dump_trigger(MYSQL_RES *show_
 
   while ((row= mysql_fetch_row(show_create_trigger_rs)))
   {
-    char *query_str= cover_definer_clause_in_trigger(row[2], strlen(row[2]));
-
+    char *query_str= cover_definer_clause(row[2], strlen(row[2]),
+                                          C_STRING_WITH_LEN("50017"),
+                                          C_STRING_WITH_LEN("50003"),
+                                          C_STRING_WITH_LEN(" TRIGGER"));
 
     if (switch_db_collation(sql_file, db_name, ";",
                             db_cl_name, row[5], &db_cl_altered))

=== modified file 'dbug/dbug.c'
--- a/dbug/dbug.c	2009-02-13 16:30:54 +0000
+++ b/dbug/dbug.c	2009-03-25 16:51:28 +0000
@@ -836,8 +836,9 @@ yuck:
  *  DESCRIPTION
  *
  *      Given pointer to a debug control string in "control",
- *      parses the control string, and sets
- *      up a current debug settings.
+ *      parses the control string, and sets up a current debug
+ *      settings. Pushes a new debug settings if the current is
+ *      set to the initial debugger settings.
  *
  */
 
@@ -847,6 +848,8 @@ void _db_set_(const char *control)
   uint old_fflags;
   get_code_state_or_return;
   old_fflags=fflags(cs);
+  if (cs->stack == &init_settings)
+    PushState(cs);
   if (DbugParse(cs, control))
     FixTraceFlags(old_fflags, cs);
 }
@@ -865,7 +868,7 @@ void _db_set_(const char *control)
  *
  *      Given pointer to a debug control string in "control", pushes
  *      the current debug settings, parses the control string, and sets
- *      up a new debug settings
+ *      up a new debug settings with DbugParse()
  *
  */
 

=== added file 'mysql-test/extra/binlog_tests/drop_table.test'
--- a/mysql-test/extra/binlog_tests/drop_table.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/extra/binlog_tests/drop_table.test	2009-03-06 22:17:00 +0000
@@ -0,0 +1,34 @@
+#
+# Bug#989: If DROP TABLE while there's an active transaction, wrong binlog order
+#
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+connect (con1,localhost,root,,);
+connect (con2,localhost,root,,);
+
+connection con1;
+RESET MASTER;
+CREATE TABLE t1 (a INT);
+SET AUTOCOMMIT=OFF;
+BEGIN;
+INSERT INTO t1 VALUES(1);
+
+connection con2;
+--send DROP TABLE t1;
+
+connection con1;
+COMMIT;
+
+connection con2;
+--reap
+
+connection default;
+
+--disconnect con1
+--disconnect con2
+
+let $VERSION=`select version()`;
+source include/show_binlog_events.inc;

=== modified file 'mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test'
--- a/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test	2008-07-22 14:16:22 +0000
+++ b/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test	2009-03-06 22:17:00 +0000
@@ -204,6 +204,10 @@ select (@after:=unix_timestamp())*0; # a
 # the bug, the reap would return immediately after the insert into t2.
 select (@after-@before) >= 2;
 
+connection con3;
+commit;
+
+connection con2;
 drop table t1,t2;
 commit;
 

=== added file 'mysql-test/include/bug38347.inc'
--- a/mysql-test/include/bug38347.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/bug38347.inc	2009-03-26 06:08:24 +0000
@@ -0,0 +1,21 @@
+
+--echo
+SHOW GRANTS FOR mysqltest_u1@localhost;
+
+--echo
+--echo # connection: con1 (mysqltest_u1@mysqltest_db1)
+--connect (con1,localhost,mysqltest_u1,,mysqltest_db1)
+--connection con1
+
+--echo
+SHOW CREATE TABLE t1;
+
+--echo
+--echo # connection: default
+--connection default
+
+--disconnect con1
+
+--echo
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;

=== modified file 'mysql-test/include/locktrans.inc'
--- a/mysql-test/include/locktrans.inc	2008-05-23 13:54:03 +0000
+++ b/mysql-test/include/locktrans.inc	2009-03-06 22:17:00 +0000
@@ -1050,6 +1050,19 @@ COMMIT;
 DROP TRIGGER t1_ai;
 }
 
+--echo #
+--echo # WL#4284: Transactional DDL locking
+--echo #
+
+SET AUTOCOMMIT= 0;
+LOCK TABLES t1 WRITE, t2 WRITE;
+SAVEPOINT sp1;
+INSERT INTO t1 VALUES (1);
+SAVEPOINT sp2;
+INSERT INTO t2 VALUES (2);
+ROLLBACK TO SAVEPOINT sp1;
+UNLOCK TABLES;
+
 #
 --echo ## Cleanup.
 connection default;

=== modified file 'mysql-test/include/mix1.inc'
--- a/mysql-test/include/mix1.inc	2009-02-20 12:37:37 +0000
+++ b/mysql-test/include/mix1.inc	2009-03-27 22:06:26 +0000
@@ -897,6 +897,8 @@ CREATE PROCEDURE p1 ()
 BEGIN
   DECLARE i INT DEFAULT 50;
   DECLARE cnt INT;
+  # Continue even in the presence of ER_LOCK_DEADLOCK.
+  DECLARE CONTINUE HANDLER FOR 1213 BEGIN END;
   START TRANSACTION;
     ALTER TABLE t1 ENGINE=InnoDB;
   COMMIT;
@@ -1331,6 +1333,7 @@ SELECT * FROM t1;
 connection con2;
 --reap
 SELECT * FROM t1;
+COMMIT;
 
 --echo # Switch to connection con1
 connection con1;

=== modified file 'mysql-test/include/mix2.inc'
--- a/mysql-test/include/mix2.inc	2007-06-06 17:57:07 +0000
+++ b/mysql-test/include/mix2.inc	2009-03-06 22:17:00 +0000
@@ -1994,6 +1994,7 @@ commit;
 connection b;
 set autocommit = 0;
 update t1 set b = 5 where a = 2;
+commit;
 connection a;
 delimiter |;
 create trigger t1t before insert on t1 for each row begin set NEW.b = NEW.a * 10 + 5, NEW.c = NEW.a / 10; end |
@@ -2056,6 +2057,7 @@ update t2 set b = b + 5 where a = 1;
 update t3 set b = b + 5 where a = 1;
 update t4 set b = b + 5 where a = 1;
 insert into t5(a) values(20);
+commit;
 connection b;
 set autocommit = 0;
 insert into t1(a) values(7);

=== modified file 'mysql-test/r/ddl_i18n_koi8r.result'
--- a/mysql-test/r/ddl_i18n_koi8r.result	2009-02-19 17:36:09 +0000
+++ b/mysql-test/r/ddl_i18n_koi8r.result	2009-03-27 22:06:26 +0000
@@ -2226,7 +2226,7 @@ END|
 
 SHOW CREATE EVENT ev1|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev1		SYSTEM	CREATE EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev1		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE ��� CHAR(10);
 SELECT
 COLLATION(���) AS c1,
@@ -2239,7 +2239,7 @@ END	koi8r	koi8r_general_ci	utf8_unicode_
 
 SHOW CREATE EVENT ev2|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev2		SYSTEM	CREATE EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev2		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE ��� CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(���) AS c1,
@@ -2252,7 +2252,7 @@ END	koi8r	koi8r_general_ci	utf8_unicode_
 
 SHOW CREATE EVENT mysqltest2.ev3|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev3		SYSTEM	CREATE EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev3		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE ��� CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(���) AS c1,
@@ -2265,7 +2265,7 @@ END	koi8r	koi8r_general_ci	utf8_unicode_
 
 SHOW CREATE EVENT mysqltest2.ev3|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev3		SYSTEM	CREATE EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev3		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE �LATION(���) AS c1,
@@ -2361,7 +2361,7 @@ set names koi8r|
 
 SHOW CREATE EVENT ev1|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev1		SYSTEM	CREATE EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev1		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE ��� CHAR(10);
 SELECT
 COLLATION(���) AS c1,
@@ -2374,7 +2374,7 @@ END	koi8r	koi8r_general_ci	utf8_unicode_
 
 SHOW CREATE EVENT ev2|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev2		SYSTEM	CREATE EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev2		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE ��� CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(���) AS c1,
@@ -2387,7 +2387,7 @@ END	koi8r	koi8r_general_ci	utf8_unicode_
 
 SHOW CREATE EVENT mysqltest2.ev3|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev3		SYSTEM	CREATE EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev3		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE ��� CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(��r_general_ci	utf8_unicode_
 
 SHOW CREATE EVENT mysqltest2.ev3|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev3		SYSTEM	CREATE EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev3		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE COLLATION(���) AS c1,
@@ -2497,7 +2497,7 @@ ALTER DATABASE mysqltest1 CHARACTER SET 
 /*!50003 SET sql_mode              = '' */ ;;
 /*!50003 SET @saved_time_zone      = @@time_zone */ ;;
 /*!50003 SET time_zone             = 'SYSTEM' */ ;;
-/*!50106 CREATE EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE ��� CHAR(10);
 SELECT
 COLLATION(�SE mysqltest1 CHARACTER SET 
 /*!50003 SET sql_mode              = '' */ ;;
 /*!50003 SET @saved_time_zone      = @@time_zone */ ;;
 /*!50003 SET time_zone             = 'SYSTEM' */ ;;
-/*!50106 CREATE EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE ��� CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(TABASE mysqltest2 CHARACTER SET 
 /*!50003 SET sql_mode              = '' */ ;;
 /*!50003 SET @saved_time_zone      = @@time_zone */ ;;
 /*!50003 SET time_zone             = 'SYSTEM' */ ;;
-/*!50106 CREATE EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE ��� CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(���) AS c1,
@@ -2592,7 +2592,7 @@ ALTER DATABASE mysqltest2 CHARACTER SET 
 /*!50003 SET sql_mode              = '' */ ;;
 /*!50003 SET @saved_time_zone      = @@time_zone */ ;;
 /*!50003 SET time_zone             = 'SYSTEM' */ ;;
-/*!50106 CREATE EVENT `ev4` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `ev4` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE �LATION(���) AS c1,
@@ -2634,7 +2634,7 @@ set names koi8r|
 
 SHOW CREATE EVENT ev1|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev1		SYSTEM	CREATE EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev1		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE ��� CHAR(10);
 SELECT
 COLLATION(���) AS c1,
@@ -2647,7 +2647,7 @@ END	koi8r	koi8r_general_ci	utf8_unicode_
 
 SHOW CREATE EVENT ev2|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev2		SYSTEM	CREATE EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev2		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE ��� CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(���) AS c1,
@@ -2660,7 +2660,7 @@ END	koi8r	koi8r_general_ci	utf8_unicode_
 
 SHOW CREATE EVENT mysqltest2.ev3|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev3		SYSTEM	CREATE EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev3		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE ��� CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(��r_general_ci	utf8_unicode_
 
 SHOW CREATE EVENT mysqltest2.ev3|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev3		SYSTEM	CREATE EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev3		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE COLLATION(���) AS c1,

=== modified file 'mysql-test/r/ddl_i18n_utf8.result'
--- a/mysql-test/r/ddl_i18n_utf8.result	2009-02-19 17:36:09 +0000
+++ b/mysql-test/r/ddl_i18n_utf8.result	2009-03-27 22:06:26 +0000
@@ -2226,7 +2226,7 @@ END|
 
 SHOW CREATE EVENT ev1|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev1		SYSTEM	CREATE EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev1		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE перем1 CHAR(10);
 SELECT
 COLLATION(перем1) AS c1,
@@ -2239,7 +2239,7 @@ END	utf8	utf8_general_ci	utf8_unicode_ci
 
 SHOW CREATE EVENT ev2|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev2		SYSTEM	CREATE EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev2		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE перем1 CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(перем1) AS c1,
@@ -2252,7 +2252,7 @@ END	utf8	utf8_general_ci	utf8_unicode_ci
 
 SHOW CREATE EVENT mysqltest2.ev3|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev3		SYSTEM	CREATE EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev3		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE перем1 CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(пер8_general_ci	utf8_unicode_ci
 
 SHOW CREATE EVENT mysqltest2.ev3|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev3		SYSTEM	CREATE EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev3		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE перем1 CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(перем1) AS c1,
@@ -2361,7 +2361,7 @@ set names utf8|
 
 SHOW CREATE EVENT ev1|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev1		SYSTEM	CREATE EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev1		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE перем1 CHAR(10);
 SELECT
 COLLATION(перем1) AS c1,
@@ -2374,7 +2374,7 @@ END	utf8	utf8_general_ci	utf8_unicode_ci
 
 SHOW CREATE EVENT ev2|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev2		SYSTEM	CREATE EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev2		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE перем1 CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(перем1) AS c1,
@@ -2387,7 +2387,7 @@ END	utf8	utf8_general_ci	utf8_unicode_ci
 
 SHOW CREATE EVENT mysqltest2.ev3|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev3		SYSTEM	CREATE EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev3		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE п COLLATION(перем1) AS c1,
@@ -2400,7 +2400,7 @@ END	utf8	utf8_general_ci	utf8_unicode_ci
 
 SHOW CREATE EVENT mysqltest2.ev3|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev3		SYSTEM	CREATE EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev3		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE перем1 CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(перем1) AS c1,
@@ -2497,7 +2497,7 @@ ALTER DATABASE mysqltest1 CHARACTER SET 
 /*!50003 SET sql_mode              = '' */ ;;
 /*!50003 SET @saved_time_zone      = @@time_zone */ ;;
 /*!50003 SET time_zone             = 'SYSTEM' */ ;;
-/*!50106 CREATE EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE перем1 CHAR(10);
 SELECT
 COLLATION(перем1) AS c1,
@@ -2525,7 +2525,7 @@ ALTER DATABASE mysqltest1 CHARACTER SET 
 /*!50003 SET sql_mode              = '' */ ;;
 /*!50003 SET @saved_time_zone      = @@time_zone */ ;;
 /*!50003 SET time_zone             = 'SYSTEM' */ ;;
-/*!50106 CREATE EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE перем1 CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(перем1) AS c1,
@@ -2564,7 +2564,7 @@ ALTER DATABASE mysqltest2 CHARACTER SET 
 /*!50003 SET sql_mode              = '' */ ;;
 /*!50003 SET @saved_time_zone      = @@time_zone */ ;;
 /*!50003 SET time_zone             = 'SYSTEM' */ ;;
-/*!50106 CREATE EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE перем1 CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(перем1) AS c1,
@@ -2592,7 +2592,7 @@ ALTER DATABASE mysqltest2 CHARACTER SET 
 /*!50003 SET sql_mode              = '' */ ;;
 /*!50003 SET @saved_time_zone      = @@time_zone */ ;;
 /*!50003 SET time_zone             = 'SYSTEM' */ ;;
-/*!50106 CREATE EVENT `ev4` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `ev4` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE перем1 CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(пs utf8|
 
 SHOW CREATE EVENT ev1|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev1		SYSTEM	CREATE EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev1		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE перем1 CHAR(10);
 SELECT
 COLLATION(перем1) AS c1,
@@ -2647,7 +2647,7 @@ END	utf8	utf8_general_ci	utf8_unicode_ci
 
 SHOW CREATE EVENT ev2|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev2		SYSTEM	CREATE EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev2		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev2` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE перем1 CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(перем1) AS c1,
@@ -2660,7 +2660,7 @@ END	utf8	utf8_general_ci	utf8_unicode_ci
 
 SHOW CREATE EVENT mysqltest2.ev3|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev3		SYSTEM	CREATE EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev3		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE перем1 CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(перем1) AS c1,
@@ -2673,7 +2673,7 @@ END	utf8	utf8_general_ci	utf8_unicode_ci
 
 SHOW CREATE EVENT mysqltest2.ev3|
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev3		SYSTEM	CREATE EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ev3		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev3` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
 DECLARE перем1 CHAR(10) CHARACTER SET utf8;
 SELECT
 COLLATION(перем1) AS c1,

=== modified file 'mysql-test/r/events_1.result'
--- a/mysql-test/r/events_1.result	2008-02-20 13:40:46 +0000
+++ b/mysql-test/r/events_1.result	2009-03-26 06:15:10 +0000
@@ -123,80 +123,80 @@ set names utf8;
 CREATE EVENT root6 ON SCHEDULE EVERY '10:20' MINUTE_SECOND ON COMPLETION PRESERVE ENABLE COMMENT 'some comment' DO select 1;
 SHOW CREATE EVENT root6;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root6		SYSTEM	CREATE EVENT `root6` ON SCHEDULE EVERY '10:20' MINUTE_SECOND STARTS '#' ON COMPLETION PRESERVE ENABLE COMMENT 'some comment' DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root6		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root6` ON SCHEDULE EVERY '10:20' MINUTE_SECOND STARTS '#' ON COMPLETION PRESERVE ENABLE COMMENT 'some comment' DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root7 on schedule every 2 year do select 1;
 SHOW CREATE EVENT root7;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root7		SYSTEM	CREATE EVENT `root7` ON SCHEDULE EVERY 2 YEAR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root7		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root7` ON SCHEDULE EVERY 2 YEAR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root8 on schedule every '2:5' year_month do select 1;
 SHOW CREATE EVENT root8;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root8		SYSTEM	CREATE EVENT `root8` ON SCHEDULE EVERY '2-5' YEAR_MONTH STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root8		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root8` ON SCHEDULE EVERY '2-5' YEAR_MONTH STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root8_1 on schedule every '2:15' year_month do select 1;
 SHOW CREATE EVENT root8_1;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root8_1		SYSTEM	CREATE EVENT `root8_1` ON SCHEDULE EVERY '3-3' YEAR_MONTH STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root8_1		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root8_1` ON SCHEDULE EVERY '3-3' YEAR_MONTH STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root9 on schedule every 2 week ON COMPLETION PRESERVE DISABLE COMMENT 'коментар на T root9;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root9		SYSTEM	CREATE EVENT `root9` ON SCHEDULE EVERY 2 WEEK STARTS '#' ON COMPLETION PRESERVE DISABLE COMMENT 'коментар на кирилица' DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root9		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root9` ON SCHEDULE EVERY 2 WEEK STARTS '#' ON COMPLETION PRESERVE DISABLE COMMENT 'коментар на кирилица' DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root10 on schedule every '20:5' day_hour do select 1;
 SHOW CREATE EVENT root10;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root10		SYSTEM	CREATE EVENT `root10` ON SCHEDULE EVERY '20 5' DAY_HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root10		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root10` ON SCHEDULE EVERY '20 5' DAY_HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root11 on schedule every '20:25' day_hour do select 1;
 SHOW CREATE EVENT root11;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root11		SYSTEM	CREATE EVENT `root11` ON SCHEDULE EVERY '21 1' DAY_HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root11		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root11` ON SCHEDULE EVERY '21 1' DAY_HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root12 on schedule every '20:25' hour_minute do select 1;
 SHOW CREATE EVENT root12;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root12		SYSTEM	CREATE EVENT `root12` ON SCHEDULE EVERY '20:25' HOUR_MINUTE STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root12		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root12` ON SCHEDULE EVERY '20:25' HOUR_MINUTE STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root13 on schedule every '25:25' hour_minute do select 1;
 SHOW CREATE EVENT root13;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root13		SYSTEM	CREATE EVENT `root13` ON SCHEDULE EVERY '25:25' HOUR_MINUTE STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root13		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root13` ON SCHEDULE EVERY '25:25' HOUR_MINUTE STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root13_1 on schedule every '11:65' hour_minute do select 1;
 SHOW CREATE EVENT root13_1;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root13_1		SYSTEM	CREATE EVENT `root13_1` ON SCHEDULE EVERY '12:5' HOUR_MINUTE STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root13_1		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root13_1` ON SCHEDULE EVERY '12:5' HOUR_MINUTE STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root14 on schedule every '35:35' minute_second do select 1;
 SHOW CREATE EVENT root14;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root14		SYSTEM	CREATE EVENT `root14` ON SCHEDULE EVERY '35:35' MINUTE_SECOND STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root14		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root14` ON SCHEDULE EVERY '35:35' MINUTE_SECOND STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root15 on schedule every '35:66' minute_second do select 1;
 SHOW CREATE EVENT root15;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root15		SYSTEM	CREATE EVENT `root15` ON SCHEDULE EVERY '36:6' MINUTE_SECOND STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root15		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root15` ON SCHEDULE EVERY '36:6' MINUTE_SECOND STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root16 on schedule every '35:56' day_minute do select 1;
 SHOW CREATE EVENT root16;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root16		SYSTEM	CREATE EVENT `root16` ON SCHEDULE EVERY '1 11:56' DAY_MINUTE STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root16		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root16` ON SCHEDULE EVERY '1 11:56' DAY_MINUTE STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root17 on schedule every '35:12:45' day_minute do select 1;
 SHOW CREATE EVENT root17;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root17		SYSTEM	CREATE EVENT `root17` ON SCHEDULE EVERY '35 12:45' DAY_MINUTE STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root17		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root17` ON SCHEDULE EVERY '35 12:45' DAY_MINUTE STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root17_1 on schedule every '35:25:65' day_minute do select 1;
 SHOW CREATE EVENT root17_1;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root17_1		SYSTEM	CREATE EVENT `root17_1` ON SCHEDULE EVERY '36 2:5' DAY_MINUTE STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root17_1		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root17_1` ON SCHEDULE EVERY '36 2:5' DAY_MINUTE STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root18 on schedule every '35:12:45' hour_second do select 1;
 SHOW CREATE EVENT root18;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root18		SYSTEM	CREATE EVENT `root18` ON SCHEDULE EVERY '35:12:45' HOUR_SECOND STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root18		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root18` ON SCHEDULE EVERY '35:12:45' HOUR_SECOND STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root19 on schedule every '15:59:85' hour_second do select 1;
 SHOW CREATE EVENT root19;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root19		SYSTEM	CREATE EVENT `root19` ON SCHEDULE EVERY '16:0:25' HOUR_SECOND STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root19		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root19` ON SCHEDULE EVERY '16:0:25' HOUR_SECOND STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 create event root20 on schedule every '50:20:12:45' day_second do select 1;
 SHOW CREATE EVENT root20;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-root20		SYSTEM	CREATE EVENT `root20` ON SCHEDULE EVERY '50 20:12:45' DAY_SECOND STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+root20		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `root20` ON SCHEDULE EVERY '50 20:12:45' DAY_SECOND STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 set names cp1251;
 create event �21 on schedule every '50:23:59:95' day_second COMMENT '� �251 ��� do select 1;
 SHOW CREATE EVENT �21;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-�21		SYSTEM	CREATE EVENT `руут21` ON SCHEDULE EVERY '51 0:0:35' DAY_SECOND STARTS '#' ON COMPLETION NOT PRESERVE ENABLE COMMENT 'това е 1251 коментар' DO select 1	cp1251	cp1251_general_ci	latin1_swedish_ci
+�21		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `руут21` ON SCHEDULE EVERY '51 0:0:35' DAY_SECOND STARTS '#' ON COMPLETION NOT PRESERVE ENABLE COMMENT 'това е 1251 коментар' DO select 1	cp1251	cp1251_general_ci	latin1_swedish_ci
 insert into mysql.event (
 db,
 name,
@@ -271,7 +271,7 @@ event_name
 intact_check
 SHOW CREATE EVENT intact_check;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-intact_check		SYSTEM	CREATE EVENT `intact_check` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO SELECT "nothing"	latin1	latin1_swedish_ci	latin1_swedish_ci
+intact_check		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `intact_check` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO SELECT "nothing"	latin1	latin1_swedish_ci	latin1_swedish_ci
 DROP EVENT no_such_event;
 ERROR HY000: Unknown event 'no_such_event'
 CREATE EVENT intact_check_1 ON SCHEDULE EVERY 5 HOUR DO SELECT 5;

=== modified file 'mysql-test/r/events_2.result'
--- a/mysql-test/r/events_2.result	2008-08-18 11:05:51 +0000
+++ b/mysql-test/r/events_2.result	2009-03-26 06:15:10 +0000
@@ -134,7 +134,7 @@ create event e1 on schedule every 10 hou
 lock table t1 read;
 show create event e1;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-e1		SYSTEM	CREATE EVENT `e1` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+e1		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 select event_name from information_schema.events;
 event_name
 e1
@@ -152,7 +152,7 @@ unlock tables;
 lock table t1 write;
 show create event e1;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-e1		SYSTEM	CREATE EVENT `e1` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+e1		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 select event_name from information_schema.events;
 event_name
 e1
@@ -170,7 +170,7 @@ unlock tables;
 lock table t1 read, mysql.event read;
 show create event e1;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-e1		SYSTEM	CREATE EVENT `e1` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+e1		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 select event_name from information_schema.events;
 event_name
 e1
@@ -188,7 +188,7 @@ unlock tables;
 lock table t1 write, mysql.event read;
 show create event e1;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-e1		SYSTEM	CREATE EVENT `e1` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+e1		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 select event_name from information_schema.events;
 event_name
 e1
@@ -210,7 +210,7 @@ ERROR HY000: You can't combine write-loc
 lock table mysql.event write;
 show create event e1;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-e1		SYSTEM	CREATE EVENT `e1` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
+e1		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1	utf8	utf8_general_ci	latin1_swedish_ci
 select event_name from information_schema.events;
 event_name
 e1

=== modified file 'mysql-test/r/flush_block_commit.result'
--- a/mysql-test/r/flush_block_commit.result	2009-03-06 14:56:17 +0000
+++ b/mysql-test/r/flush_block_commit.result	2009-03-27 22:06:26 +0000
@@ -1,3 +1,4 @@
+# Save the initial number of concurrent sessions
 # Establish connection con1 (user=root)
 # Establish connection con2 (user=root)
 # Establish connection con3 (user=root)
@@ -8,16 +9,14 @@ BEGIN;
 INSERT INTO t1 VALUES(1);
 # Switch to connection con2
 FLUSH TABLES WITH READ LOCK;
-SELECT * FROM t1;
-a
 # Switch to connection con1
 COMMIT;
 # Switch to connection con2
 SELECT * FROM t1;
 a
+1
 UNLOCK TABLES;
 # Switch to connection con1
-# Switch to connection con1
 BEGIN;
 SELECT * FROM t1 FOR UPDATE;
 a
@@ -32,6 +31,7 @@ COMMIT;
 # Switch to connection con2
 a
 1
+COMMIT;
 # Switch to connection con3
 UNLOCK TABLES;
 # Switch to connection con2
@@ -40,8 +40,6 @@ COMMIT;
 BEGIN;
 INSERT INTO t1 VALUES(10);
 FLUSH TABLES WITH READ LOCK;
-COMMIT;
-UNLOCK TABLES;
 # Switch to connection con2
 FLUSH TABLES WITH READ LOCK;
 UNLOCK TABLES;
@@ -53,5 +51,11 @@ a
 SHOW CREATE DATABASE test;
 Database	Create Database
 test	CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET latin1 */
-DROP TABLE t1;
+COMMIT;
+# Cleanup
 # Switch to connection default and close connections con1, con2, con3
+# We commit open transactions when we disconnect: only then we can
+# drop the table.
+DROP TABLE t1;
+# End of 4.1 tests
+# Wait till all disconnects are completed

=== modified file 'mysql-test/r/flush_block_commit_notembedded.result'
--- a/mysql-test/r/flush_block_commit_notembedded.result	2009-03-06 20:33:52 +0000
+++ b/mysql-test/r/flush_block_commit_notembedded.result	2009-03-27 22:06:26 +0000
@@ -1,17 +1,19 @@
+# Save the initial number of concurrent sessions
 # Establish connection con1 (user=root)
 # Establish connection con2 (user=root)
 # Switch to connection con1
 CREATE TABLE t1 (a INT) ENGINE=innodb;
 RESET MASTER;
 SET AUTOCOMMIT=0;
-INSERT t1 VALUES (1);
+SELECT 1;
+1
+1
 # Switch to connection con2
 FLUSH TABLES WITH READ LOCK;
 SHOW MASTER STATUS;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB
 master-bin.000001	107		
-# Switch to connection con1
-COMMIT;
+INSERT INTO t1 VALUES (1);
 # Switch to connection con2
 SHOW MASTER STATUS;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB
@@ -20,4 +22,12 @@ UNLOCK TABLES;
 # Switch to connection con1
 DROP TABLE t1;
 SET AUTOCOMMIT=1;
+create table t1 (a int) engine=innodb;
+flush tables with read lock;
+begin;
+insert into t1 values (1);;
+unlock tables;
+commit;
+drop table t1;
 # Switch to connection default and close connections con1 and con2
+# Wait till all disconnects are completed

=== modified file 'mysql-test/r/grant.result'
--- a/mysql-test/r/grant.result	2009-02-25 12:42:06 +0000
+++ b/mysql-test/r/grant.result	2009-03-27 22:06:26 +0000
@@ -1359,3 +1359,690 @@ DROP USER 'userbug33464'@'localhost';
 USE test;
 DROP DATABASE dbbug33464;
 SET @@global.log_bin_trust_function_creators= @old_log_bin_trust_function_creators;
+#########################################################################
+#
+# Bug#38347: ALTER ROUTINE privilege allows SHOW CREATE TABLE.
+#
+#########################################################################
+
+# --
+# -- Prepare the environment.
+# --
+DELETE FROM mysql.user WHERE User LIKE 'mysqltest_%';
+DELETE FROM mysql.db WHERE User LIKE 'mysqltest_%';
+DELETE FROM mysql.tables_priv WHERE User LIKE 'mysqltest_%';
+DELETE FROM mysql.columns_priv WHERE User LIKE 'mysqltest_%';
+FLUSH PRIVILEGES;
+DROP DATABASE IF EXISTS mysqltest_db1;
+CREATE DATABASE mysqltest_db1;
+CREATE TABLE mysqltest_db1.t1(a INT);
+
+# --
+# -- Check that global privileges don't allow SHOW CREATE TABLE.
+# --
+GRANT EVENT                   ON mysqltest_db1.* TO mysqltest_u1@localhost;
+GRANT CREATE TEMPORARY TABLES ON mysqltest_db1.* TO mysqltest_u1@localhost;
+GRANT LOCK TABLES             ON mysqltest_db1.* TO mysqltest_u1@localhost;
+GRANT ALTER ROUTINE           ON mysqltest_db1.* TO mysqltest_u1@localhost;
+GRANT CREATE ROUTINE          ON mysqltest_db1.* TO mysqltest_u1@localhost;
+GRANT EXECUTE                 ON mysqltest_db1.* TO mysqltest_u1@localhost;
+GRANT FILE                    ON *.* TO mysqltest_u1@localhost;
+GRANT CREATE USER             ON *.* TO mysqltest_u1@localhost;
+GRANT PROCESS                 ON *.* TO mysqltest_u1@localhost;
+GRANT RELOAD                  ON *.* TO mysqltest_u1@localhost;
+GRANT REPLICATION CLIENT      ON *.* TO mysqltest_u1@localhost;
+GRANT REPLICATION SLAVE       ON *.* TO mysqltest_u1@localhost;
+GRANT SHOW DATABASES          ON *.* TO mysqltest_u1@localhost;
+GRANT SHUTDOWN                ON *.* TO mysqltest_u1@localhost;
+GRANT USAGE                   ON *.* TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT RELOAD, SHUTDOWN, PROCESS, FILE, SHOW DATABASES, REPLICATION SLAVE, REPLICATION CLIENT, CREATE USER ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE ROUTINE, ALTER ROUTINE, EVENT ON `mysqltest_db1`.* TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+ERROR 42000: SHOW command denied to user 'mysqltest_u1'@'localhost' for table 't1'
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that global SELECT allows SHOW CREATE TABLE.
+# -- 
+
+GRANT SELECT ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT SELECT ON `mysqltest_db1`.* TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that global INSERT allows SHOW CREATE TABLE.
+# -- 
+
+GRANT INSERT ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT INSERT ON `mysqltest_db1`.* TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that global UPDATE allows SHOW CREATE TABLE.
+# -- 
+
+GRANT UPDATE ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT UPDATE ON `mysqltest_db1`.* TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that global DELETE allows SHOW CREATE TABLE.
+# -- 
+
+GRANT DELETE ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT DELETE ON `mysqltest_db1`.* TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that global CREATE allows SHOW CREATE TABLE.
+# -- 
+
+GRANT CREATE ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT CREATE ON `mysqltest_db1`.* TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that global DROP allows SHOW CREATE TABLE.
+# -- 
+
+GRANT DROP ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT DROP ON `mysqltest_db1`.* TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that global ALTER allows SHOW CREATE TABLE.
+# -- 
+
+GRANT ALTER ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT ALTER ON `mysqltest_db1`.* TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that global INDEX allows SHOW CREATE TABLE.
+# -- 
+
+GRANT INDEX ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT INDEX ON `mysqltest_db1`.* TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that global REFERENCES allows SHOW CREATE TABLE.
+# -- 
+
+GRANT REFERENCES ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT REFERENCES ON `mysqltest_db1`.* TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that global GRANT OPTION allows SHOW CREATE TABLE.
+# -- 
+
+GRANT GRANT OPTION ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT USAGE ON `mysqltest_db1`.* TO 'mysqltest_u1'@'localhost' WITH GRANT OPTION
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that global CREATE VIEW allows SHOW CREATE TABLE.
+# -- 
+
+GRANT CREATE VIEW ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT CREATE VIEW ON `mysqltest_db1`.* TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that global SHOW VIEW allows SHOW CREATE TABLE.
+# -- 
+
+GRANT SHOW VIEW ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT SHOW VIEW ON `mysqltest_db1`.* TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that table-level SELECT allows SHOW CREATE TABLE.
+# -- 
+
+GRANT SELECT ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT SELECT ON `mysqltest_db1`.`t1` TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that table-level INSERT allows SHOW CREATE TABLE.
+# -- 
+
+GRANT INSERT ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT INSERT ON `mysqltest_db1`.`t1` TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that table-level UPDATE allows SHOW CREATE TABLE.
+# -- 
+
+GRANT UPDATE ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT UPDATE ON `mysqltest_db1`.`t1` TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that table-level DELETE allows SHOW CREATE TABLE.
+# -- 
+
+GRANT DELETE ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT DELETE ON `mysqltest_db1`.`t1` TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that table-level CREATE allows SHOW CREATE TABLE.
+# -- 
+
+GRANT CREATE ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT CREATE ON `mysqltest_db1`.`t1` TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that table-level DROP allows SHOW CREATE TABLE.
+# -- 
+
+GRANT DROP ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT DROP ON `mysqltest_db1`.`t1` TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that table-level ALTER allows SHOW CREATE TABLE.
+# -- 
+
+GRANT ALTER ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT ALTER ON `mysqltest_db1`.`t1` TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that table-level INDEX allows SHOW CREATE TABLE.
+# -- 
+
+GRANT INDEX ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT INDEX ON `mysqltest_db1`.`t1` TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that table-level REFERENCES allows SHOW CREATE TABLE.
+# -- 
+
+GRANT REFERENCES ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT REFERENCES ON `mysqltest_db1`.`t1` TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that table-level GRANT OPTION allows SHOW CREATE TABLE.
+# -- 
+
+GRANT GRANT OPTION ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT USAGE ON `mysqltest_db1`.`t1` TO 'mysqltest_u1'@'localhost' WITH GRANT OPTION
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that table-level CREATE VIEW allows SHOW CREATE TABLE.
+# -- 
+
+GRANT CREATE VIEW ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT CREATE VIEW ON `mysqltest_db1`.`t1` TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Check that table-level SHOW VIEW allows SHOW CREATE TABLE.
+# -- 
+
+GRANT SHOW VIEW ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+GRANT SHOW VIEW ON `mysqltest_db1`.`t1` TO 'mysqltest_u1'@'localhost'
+
+# connection: con1 (mysqltest_u1@mysqltest_db1)
+
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+
+# connection: default
+
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+Grants for mysqltest_u1@localhost
+GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
+
+# -- 
+# -- Cleanup.
+# -- 
+
+DROP DATABASE mysqltest_db1;
+DROP USER mysqltest_u1@localhost;
+
+# End of Bug#38347.
+

=== modified file 'mysql-test/r/innodb.result'
--- a/mysql-test/r/innodb.result	2009-02-28 00:31:33 +0000
+++ b/mysql-test/r/innodb.result	2009-03-27 22:06:26 +0000
@@ -2819,10 +2819,10 @@ t2	CREATE TABLE `t2` (
 DROP TABLE t2,t1;
 create table t1(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
 insert into t1(a) values (1),(2),(3);
+create trigger t1t before insert on t1 for each row begin set NEW.b = NEW.a * 10 + 5, NEW.c = NEW.a / 10; end |
 commit;
 set autocommit = 0;
 update t1 set b = 5 where a = 2;
-create trigger t1t before insert on t1 for each row begin set NEW.b = NEW.a * 10 + 5, NEW.c = NEW.a / 10; end |
 set autocommit = 0;
 insert into t1(a) values (10),(20),(30),(40),(50),(60),(70),(80),(90),(100),
 (11),(21),(31),(41),(51),(61),(71),(81),(91),(101),
@@ -2870,6 +2870,7 @@ insert into t2(a) values(8);
 delete from t2 where a = 3;
 update t4 set b = b + 1 where a = 3;
 commit;
+commit;
 drop trigger t1t;
 drop trigger t2t;
 drop trigger t3t;

=== modified file 'mysql-test/r/innodb_mysql.result'
--- a/mysql-test/r/innodb_mysql.result	2009-02-20 12:37:37 +0000
+++ b/mysql-test/r/innodb_mysql.result	2009-03-27 22:06:26 +0000
@@ -1104,6 +1104,8 @@ CREATE PROCEDURE p1 ()
 BEGIN
 DECLARE i INT DEFAULT 50;
 DECLARE cnt INT;
+# Continue even in the presence of ER_LOCK_DEADLOCK.
+DECLARE CONTINUE HANDLER FOR 1213 BEGIN END;
 START TRANSACTION;
 ALTER TABLE t1 ENGINE=InnoDB;
 COMMIT;
@@ -1564,6 +1566,7 @@ a	b
 SELECT * FROM t1;
 a	b
 1	init+con1+con2
+COMMIT;
 # Switch to connection con1
 # 3. test for updated key column:
 TRUNCATE t1;

=== modified file 'mysql-test/r/lock.result'
--- a/mysql-test/r/lock.result	2009-03-13 18:53:52 +0000
+++ b/mysql-test/r/lock.result	2009-03-27 22:06:26 +0000
@@ -262,5 +262,25 @@ unlock tables;
 drop table t1;
 drop view v1;
 #
+# WL#4284: Transactional DDL locking
+#
+drop table if exists t1;
+create table t1 (a int);
+set autocommit= 0;
+insert into t1 values (1);
+lock table t1 write;
+# Disconnect
+# Ensure that metadata locks will be released if there is an open
+# transaction (autocommit=off) in conjunction with lock tables.
+drop table t1;
+# Same problem but now for BEGIN
+drop table if exists t1;
+create table t1 (a int);
+begin;
+insert into t1 values (1);
+# Disconnect
+# Ensure that metadata locks held by the transaction are released.
+drop table t1;
+#
 # End of 6.0 tests.
 #

=== modified file 'mysql-test/r/locktrans_innodb.result'
--- a/mysql-test/r/locktrans_innodb.result	2009-03-06 12:24:03 +0000
+++ b/mysql-test/r/locktrans_innodb.result	2009-03-27 22:06:26 +0000
@@ -920,6 +920,17 @@ TRUNCATE t1;
 TRUNCATE t2;
 COMMIT;
 DROP TRIGGER t1_ai;
+#
+# WL#4284: Transactional DDL locking
+#
+SET AUTOCOMMIT= 0;
+LOCK TABLES t1 WRITE, t2 WRITE;
+SAVEPOINT sp1;
+INSERT INTO t1 VALUES (1);
+SAVEPOINT sp2;
+INSERT INTO t2 VALUES (2);
+ROLLBACK TO SAVEPOINT sp1;
+UNLOCK TABLES;
 ## Cleanup.
 SET AUTOCOMMIT= 1;
 UNLOCK TABLES;

=== modified file 'mysql-test/r/locktrans_myisam.result'
--- a/mysql-test/r/locktrans_myisam.result	2009-03-06 12:24:03 +0000
+++ b/mysql-test/r/locktrans_myisam.result	2009-03-27 22:06:26 +0000
@@ -392,6 +392,19 @@ ERROR 0A000: LOCK is not allowed in stor
 CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW
 LOCK TABLE t2 IN EXCLUSIVE MODE;
 ERROR 0A000: LOCK is not allowed in stored procedures
+#
+# WL#4284: Transactional DDL locking
+#
+SET AUTOCOMMIT= 0;
+LOCK TABLES t1 WRITE, t2 WRITE;
+SAVEPOINT sp1;
+INSERT INTO t1 VALUES (1);
+SAVEPOINT sp2;
+INSERT INTO t2 VALUES (2);
+ROLLBACK TO SAVEPOINT sp1;
+Warnings:
+Warning	1196	Some non-transactional changed tables couldn't be rolled back
+UNLOCK TABLES;
 ## Cleanup.
 SET AUTOCOMMIT= 1;
 UNLOCK TABLES;

=== modified file 'mysql-test/r/mix2_myisam.result'
--- a/mysql-test/r/mix2_myisam.result	2008-10-20 09:16:47 +0000
+++ b/mysql-test/r/mix2_myisam.result	2009-03-06 22:17:00 +0000
@@ -2063,6 +2063,7 @@ insert into t1(a) values (1),(2),(3);
 commit;
 set autocommit = 0;
 update t1 set b = 5 where a = 2;
+commit;
 create trigger t1t before insert on t1 for each row begin set NEW.b = NEW.a * 10 + 5, NEW.c = NEW.a / 10; end |
 set autocommit = 0;
 insert into t1(a) values (10),(20),(30),(40),(50),(60),(70),(80),(90),(100),
@@ -2105,6 +2106,7 @@ update t2 set b = b + 5 where a = 1;
 update t3 set b = b + 5 where a = 1;
 update t4 set b = b + 5 where a = 1;
 insert into t5(a) values(20);
+commit;
 set autocommit = 0;
 insert into t1(a) values(7);
 insert into t2(a) values(8);

=== modified file 'mysql-test/r/mysqldump.result'
--- a/mysql-test/r/mysqldump.result	2009-03-12 16:18:40 +0000
+++ b/mysql-test/r/mysqldump.result	2009-03-27 22:06:26 +0000
@@ -4020,7 +4020,7 @@ Db	Name	Definer	Time zone	Type	Execute a
 first	ee1	root@localhost	UTC	ONE TIME	2035-12-31 20:01:23	NULL	NULL	NULL	NULL	ENABLED	1	latin1	latin1_swedish_ci	latin1_swedish_ci
 show create event ee1;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ee1		UTC	CREATE EVENT `ee1` ON SCHEDULE AT '2035-12-31 20:01:23' ON COMPLETION NOT PRESERVE ENABLE DO set @a=5	latin1	latin1_swedish_ci	latin1_swedish_ci
+ee1		UTC	CREATE DEFINER=`root`@`localhost` EVENT `ee1` ON SCHEDULE AT '2035-12-31 20:01:23' ON COMPLETION NOT PRESERVE ENABLE DO set @a=5	latin1	latin1_swedish_ci	latin1_swedish_ci
 drop database first;
 create database second;
 use second;
@@ -4029,7 +4029,7 @@ Db	Name	Definer	Time zone	Type	Execute a
 second	ee1	root@localhost	UTC	ONE TIME	2035-12-31 20:01:23	NULL	NULL	NULL	NULL	ENABLED	1	latin1	latin1_swedish_ci	latin1_swedish_ci
 show create event ee1;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ee1		UTC	CREATE EVENT `ee1` ON SCHEDULE AT '2035-12-31 20:01:23' ON COMPLETION NOT PRESERVE ENABLE DO set @a=5	latin1	latin1_swedish_ci	latin1_swedish_ci
+ee1		UTC	CREATE DEFINER=`root`@`localhost` EVENT `ee1` ON SCHEDULE AT '2035-12-31 20:01:23' ON COMPLETION NOT PRESERVE ENABLE DO set @a=5	latin1	latin1_swedish_ci	latin1_swedish_ci
 create event ee2 on schedule at '2018-12-31 21:01:23' do set @a=5;
 create event ee3 on schedule at '2030-12-31 22:01:23' do set @a=5;
 show events;

=== modified file 'mysql-test/r/not_embedded_server.result'
--- a/mysql-test/r/not_embedded_server.result	2009-02-01 14:30:58 +0000
+++ b/mysql-test/r/not_embedded_server.result	2009-03-18 12:49:07 +0000
@@ -1,3 +1,12 @@
-select 1;
-1
-1
+#
+# WL#4284: Transactional DDL locking
+#
+# FLUSH PRIVILEGES should not implicitly unlock locked tables.
+#
+drop table if exists t1;
+create table t1 (c1 int);
+lock tables t1 read;
+flush privileges;
+ERROR HY000: Table 'host' was not locked with LOCK TABLES
+unlock tables;
+drop table t1;

=== modified file 'mysql-test/r/partition_innodb_semi_consistent.result'
--- a/mysql-test/r/partition_innodb_semi_consistent.result	2009-01-13 22:12:16 +0000
+++ b/mysql-test/r/partition_innodb_semi_consistent.result	2009-03-06 22:17:00 +0000
@@ -102,7 +102,7 @@ a	b
 # Switch to connection con1
 # 3. test for updated key column:
 TRUNCATE t1;
-TRUNCATE t2;
+DELETE FROM t2;
 INSERT INTO t1 VALUES (1,'init');
 BEGIN;
 UPDATE t1 SET a = 2, b = CONCAT(b, '+con1') WHERE a = 1;

=== modified file 'mysql-test/r/ps.result'
--- a/mysql-test/r/ps.result	2009-03-09 12:49:47 +0000
+++ b/mysql-test/r/ps.result	2009-03-27 22:06:26 +0000
@@ -3086,5 +3086,29 @@ DROP PROCEDURE p1;
 DROP PROCEDURE p2;
 
 # End of WL#4435.
-
-End of 6.0 tests.
+#
+# WL#4284: Transactional DDL locking
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (a INT);
+BEGIN;
+SELECT * FROM t1;
+a
+# Test that preparing a CREATE TABLE does not take a exclusive metdata lock.
+PREPARE stmt1 FROM "CREATE TABLE t1 AS SELECT 1";
+EXECUTE stmt1;
+ERROR 42S01: Table 't1' already exists
+DEALLOCATE PREPARE stmt1;
+DROP TABLE t1;
+#
+# WL#4284: Transactional DDL locking
+#
+# Test that metadata locks taken during prepare are released.
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (a INT);
+BEGIN;
+PREPARE stmt1 FROM "SELECT * FROM t1";
+DROP TABLE t1;
+#
+# End of 6.0 tests.

=== modified file 'mysql-test/r/read_only_innodb.result'
--- a/mysql-test/r/read_only_innodb.result	2008-04-08 05:20:58 +0000
+++ b/mysql-test/r/read_only_innodb.result	2009-03-06 22:17:00 +0000
@@ -7,12 +7,10 @@ insert into table_11733 values(11733);
 set global read_only=1;
 select @@global.read_only;
 @@global.read_only
-1
+0
 select * from table_11733 ;
-a
-11733
+ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
 COMMIT;
-ERROR HY000: The MySQL server is running with the --read-only option so it cannot execute this statement
 set global read_only=0;
 drop table table_11733 ;
 drop user test@localhost;

=== modified file 'mysql-test/r/show_check.result'
--- a/mysql-test/r/show_check.result	2009-03-06 20:33:52 +0000
+++ b/mysql-test/r/show_check.result	2009-03-27 22:06:26 +0000
@@ -1429,7 +1429,7 @@ FOR EACH ROW
 SET NEW.c1 = 'тест'	koi8r	koi8r_general_ci	latin1_swedish_ci
 SHOW CREATE EVENT ev1;
 Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
-ev1		SYSTEM	CREATE EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO SELECT 'тест' AS test	koi8r	koi8r_general_ci	latin1_swedish_ci
+ev1		SYSTEM	CREATE DEFINER=`root`@`localhost` EVENT `ev1` ON SCHEDULE AT '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO SELECT 'тест' AS test	koi8r	koi8r_general_ci	latin1_swedish_ci
 DROP VIEW v1;
 DROP PROCEDURE p1;
 DROP FUNCTION f1;

=== modified file 'mysql-test/r/variables_debug.result'
--- a/mysql-test/r/variables_debug.result	2008-02-26 15:03:59 +0000
+++ b/mysql-test/r/variables_debug.result	2009-03-25 16:51:28 +0000
@@ -10,3 +10,10 @@ set debug= '-P';
 select @@debug;
 @@debug
 T
+SELECT @@session.debug, @@global.debug;
+@@session.debug	@@global.debug
+T	
+SET SESSION debug = '';
+SELECT @@session.debug, @@global.debug;
+@@session.debug	@@global.debug
+	

=== modified file 'mysql-test/suite/backup/r/backup_client.result'
--- a/mysql-test/suite/backup/r/backup_client.result	2009-02-26 13:56:54 +0000
+++ b/mysql-test/suite/backup/r/backup_client.result	2009-03-28 08:42:55 +0000
@@ -607,7 +607,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t1 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t1 WHERE c1 > 100
 '
 
     Event 'mysqltest1'.'e2' statement: '16 USE `mysqltest1`
@@ -616,7 +616,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t2 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t2 WHERE c1 > 100
 '
 
     Privilege 'mysqltest1'.'<empty>' statement: '15 'bup_user1'@'%'
@@ -821,7 +821,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t1 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t1 WHERE c1 > 100
 '
 
     Event 'mysqltest2'.'e2' statement: '16 USE `mysqltest2`
@@ -830,7 +830,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t2 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t2 WHERE c1 > 100
 '
 
     Trigger 'mysqltest2'.'r1' statement: '16 USE `mysqltest2`
@@ -1311,7 +1311,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t1 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t1 WHERE c1 > 100
 '
 
   Event 'mysqltest1'.'e2' statement: '16 USE `mysqltest1`
@@ -1320,7 +1320,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t2 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t2 WHERE c1 > 100
 '
 
   Event 'mysqltest2'.'e1' statement: '16 USE `mysqltest2`
@@ -1329,7 +1329,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t1 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t1 WHERE c1 > 100
 '
 
   Event 'mysqltest2'.'e2' statement: '16 USE `mysqltest2`
@@ -1338,7 +1338,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t2 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t2 WHERE c1 > 100
 '
 
   Privilege 'mysqltest1'.'<empty>' statement: '15 'bup_user1'@'%'
@@ -2225,7 +2225,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t1 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t1 WHERE c1 > 100
 '
 
     Event 'mysqltest1'.'e2' statement: '16 USE `mysqltest1`
@@ -2234,7 +2234,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t2 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t2 WHERE c1 > 100
 '
 
     Privilege 'mysqltest1'.'<empty>' statement: '15 'bup_user1'@'%'
@@ -2439,7 +2439,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t1 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t1 WHERE c1 > 100
 '
 
     Event 'mysqltest2'.'e2' statement: '16 USE `mysqltest2`
@@ -2448,7 +2448,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t2 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t2 WHERE c1 > 100
 '
 
     Trigger 'mysqltest2'.'r1' statement: '16 USE `mysqltest2`
@@ -2888,7 +2888,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t1 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t1 WHERE c1 > 100
 '
     Event 'mysqltest1'.'e1' extra data length: 0
 
@@ -2898,7 +2898,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t2 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t2 WHERE c1 > 100
 '
     Event 'mysqltest1'.'e2' extra data length: 0
 
@@ -3135,7 +3135,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t1 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t1 WHERE c1 > 100
 '
     Event 'mysqltest2'.'e1' extra data length: 0
 
@@ -3145,7 +3145,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t2 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t2 WHERE c1 > 100
 '
     Event 'mysqltest2'.'e2' extra data length: 0
 
@@ -4551,7 +4551,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t1 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t1 WHERE c1 > 100
 '
     Event 'mysqltest1'.'e1' extra data length: 0
 
@@ -4561,7 +4561,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t2 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest1.t2 WHERE c1 > 100
 '
     Event 'mysqltest1'.'e2' extra data length: 0
 
@@ -4798,7 +4798,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t1 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t1 WHERE c1 > 100
 '
     Event 'mysqltest2'.'e1' extra data length: 0
 
@@ -4808,7 +4808,7 @@ END
 42 SET collation_database = latin1_swedish_ci
 17 SET sql_mode = ''
 24 SET time_zone = 'SYSTEM'
-149 CREATE EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t2 WHERE c1 > 100
+176 CREATE DEFINER=`root`@`localhost` EVENT `e2` ON SCHEDULE EVERY 1 YEAR STARTS 'yyyy-mm-dd HH:MM:SS' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM mysqltest2.t2 WHERE c1 > 100
 '
     Event 'mysqltest2'.'e2' extra data length: 0
 

=== modified file 'mysql-test/suite/backup/r/backup_objects_dependency.result'
--- a/mysql-test/suite/backup/r/backup_objects_dependency.result	2009-03-11 01:14:44 +0000
+++ b/mysql-test/suite/backup/r/backup_objects_dependency.result	2009-03-28 08:42:55 +0000
@@ -1021,6 +1021,8 @@ backup_id
 SHOW WARNINGS;
 Level	Code	Message
 Note	#	The user specified as a definer ('tom'@'%') does not exist
+Note	#	The user specified as a definer ('tom'@'%') does not exist
+Note	#	The user specified as a definer ('tom'@'%') does not exist
 SHOW DATABASES LIKE 'ob%';
 Database (ob%)
 ob1

=== added file 'mysql-test/suite/binlog/r/binlog_row_drop_tbl.result'
--- a/mysql-test/suite/binlog/r/binlog_row_drop_tbl.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/r/binlog_row_drop_tbl.result	2009-03-06 22:17:00 +0000
@@ -0,0 +1,16 @@
+DROP TABLE IF EXISTS t1;
+RESET MASTER;
+CREATE TABLE t1 (a INT);
+SET AUTOCOMMIT=OFF;
+BEGIN;
+INSERT INTO t1 VALUES(1);
+DROP TABLE t1;;
+COMMIT;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+master-bin.000001	#	Query	#	#	use `test`; BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	use `test`; COMMIT
+master-bin.000001	#	Query	#	#	use `test`; DROP TABLE t1

=== modified file 'mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result'
--- a/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result	2009-02-10 14:46:07 +0000
+++ b/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result	2009-03-06 22:17:00 +0000
@@ -232,6 +232,7 @@ select (@after:=unix_timestamp())*0;
 select (@after-@before) >= 2;
 (@after-@before) >= 2
 1
+commit;
 drop table t1,t2;
 commit;
 begin;
@@ -272,6 +273,10 @@ master-bin.000001	#	Query	#	#	use `test`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+master-bin.000001	#	Query	#	#	use `test`; BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t2)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	use `test`; COMMIT
 master-bin.000001	#	Query	#	#	use `test`; drop table t1,t2
 master-bin.000001	#	Query	#	#	use `test`; create table t0 (n int)
 master-bin.000001	#	Query	#	#	use `test`; BEGIN

=== added file 'mysql-test/suite/binlog/r/binlog_stm_drop_tbl.result'
--- a/mysql-test/suite/binlog/r/binlog_stm_drop_tbl.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/r/binlog_stm_drop_tbl.result	2009-03-06 22:17:00 +0000
@@ -0,0 +1,13 @@
+DROP TABLE IF EXISTS t1;
+RESET MASTER;
+CREATE TABLE t1 (a INT);
+SET AUTOCOMMIT=OFF;
+BEGIN;
+INSERT INTO t1 VALUES(1);
+DROP TABLE t1;;
+COMMIT;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES(1)
+master-bin.000001	#	Query	#	#	use `test`; DROP TABLE t1

=== modified file 'mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result'
--- a/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result	2009-02-10 14:46:07 +0000
+++ b/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result	2009-03-06 22:17:00 +0000
@@ -207,6 +207,7 @@ select (@after:=unix_timestamp())*0;
 select (@after-@before) >= 2;
 (@after-@before) >= 2
 1
+commit;
 drop table t1,t2;
 commit;
 begin;

=== added file 'mysql-test/suite/binlog/t/binlog_row_drop_tbl.test'
--- a/mysql-test/suite/binlog/t/binlog_row_drop_tbl.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/t/binlog_row_drop_tbl.test	2009-03-06 22:17:00 +0000
@@ -0,0 +1,5 @@
+# This is a wrapper for drop_table.test so that the same test case can be used
+# For both statement and row based bin logs
+
+-- source include/have_binlog_format_row.inc
+-- source extra/binlog_tests/drop_table.test

=== added file 'mysql-test/suite/binlog/t/binlog_stm_drop_tbl.test'
--- a/mysql-test/suite/binlog/t/binlog_stm_drop_tbl.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/t/binlog_stm_drop_tbl.test	2009-03-06 22:17:00 +0000
@@ -0,0 +1,5 @@
+# This is a wrapper for drop_table.test so that the same test case can be used
+# For both statement and row based bin logs
+
+-- source include/have_binlog_format_mixed_or_statement.inc
+-- source extra/binlog_tests/drop_table.test

=== modified file 'mysql-test/suite/falcon/r/falcon_bugs2.result'
--- a/mysql-test/suite/falcon/r/falcon_bugs2.result	2007-09-20 15:44:25 +0000
+++ b/mysql-test/suite/falcon/r/falcon_bugs2.result	2009-03-06 22:17:00 +0000
@@ -290,6 +290,7 @@ SET autocommit=0;
 SELECT * FROM t1;
 a
 DROP TABLE t1;
+COMMIT;
 ***************** falcon_bugs2_022 *****************
 SET autocommit=0;
 SET tx_isolation="READ-COMMITTED";
@@ -306,6 +307,8 @@ a
 SELECT * FROM t1;
 a
 1
+COMMIT;
+COMMIT;
 DROP TABLE t1;
 ***************** falcon_bugs2_023 *****************
 CREATE TABLE t1 (a int);

=== modified file 'mysql-test/suite/falcon/t/disabled.def'
--- a/mysql-test/suite/falcon/t/disabled.def	2009-03-12 20:59:34 +0000
+++ b/mysql-test/suite/falcon/t/disabled.def	2009-03-31 15:23:42 +0000
@@ -10,3 +10,5 @@
 #
 ##############################################################################
 
+falcon_bug_22972      : WL#4284: Can't drop table used by a pending transaction (there is metadata lock on the table).
+falcon_bug_24024      : WL#4284: Can't drop table used by a pending transaction (there is metadata lock on the table).

=== modified file 'mysql-test/suite/falcon/t/falcon_bugs2.test'
--- a/mysql-test/suite/falcon/t/falcon_bugs2.test	2009-01-07 10:41:07 +0000
+++ b/mysql-test/suite/falcon/t/falcon_bugs2.test	2009-03-06 22:17:00 +0000
@@ -512,7 +512,11 @@ SELECT * FROM t1;
 
 # Final cleanup
 connection default;
-DROP TABLE t1;
+send DROP TABLE t1;
+connection con1;
+COMMIT;
+connection default;
+--reap
 --disconnect con1
 
 #
@@ -539,6 +543,10 @@ SELECT * FROM t1;
 
 connection con1;
 SELECT * FROM t1;
+COMMIT;
+
+connection default;
+COMMIT;
 
 # Final cleanup
 DROP TABLE t1;

=== modified file 'mysql-test/suite/ndb/r/ndb_index_ordered.result'
--- a/mysql-test/suite/ndb/r/ndb_index_ordered.result	2007-06-27 12:28:02 +0000
+++ b/mysql-test/suite/ndb/r/ndb_index_ordered.result	2009-03-06 22:17:00 +0000
@@ -637,21 +637,6 @@ select count(*)- 4 from t1 use index (v)
 count(*)- 4
 0
 drop table t1;
-create table t1(a int primary key, b int not null, index(b));
-insert into t1 values (1,1), (2,2);
-set autocommit=0;
-begin;
-select count(*) from t1;
-count(*)
-2
-ALTER TABLE t1 ADD COLUMN c int;
-select a from t1 where b = 2;
-a
-2
-show tables;
-Tables_in_test
-t1
-drop table t1;
 create table t1 (a int, c varchar(10),
 primary key using hash (a), index(c)) engine=ndb;
 insert into t1 (a, c) values (1,'aaa'),(3,'bbb');

=== modified file 'mysql-test/suite/ndb/t/disabled.def'
--- a/mysql-test/suite/ndb/t/disabled.def	2009-02-13 16:18:07 +0000
+++ b/mysql-test/suite/ndb/t/disabled.def	2009-03-06 22:17:00 +0000
@@ -14,3 +14,5 @@ ndb_partition_error2	  : Bug#40989 msven
 # the below testcase have been reworked to avoid the bug, test contains comment, keep bug open
 #ndb_binlog_ddl_multi     : BUG#18976 2006-04-10 kent    CRBR: multiple binlog, second binlog may miss schema log events
 ndb_cache_trans           : Bug#42565 ndb_cache_trans failure since SERVER_STATUS_IN_TRANS added to hash key
+ndb_alter_table_online    : WL#4284: Needs to be reworked, tries to alter table used by a pending transaction.
+ndb_alter_table3          : WL#4284: Needs to be reworked, tries to alter table used by a pending transaction.

=== modified file 'mysql-test/suite/ndb/t/ndb_index_ordered.test'
--- a/mysql-test/suite/ndb/t/ndb_index_ordered.test	2007-07-04 20:38:53 +0000
+++ b/mysql-test/suite/ndb/t/ndb_index_ordered.test	2009-03-06 22:17:00 +0000
@@ -333,21 +333,29 @@ select count(*)- 4 from t1 use index (v)
 
 drop table t1;
 
+#
+# Disabled due to WL#4284
+#
+# Needs to be reworked. It's not possible anymore to do a non-fast alter table
+# on a table that is being used by a pending transaction (transaction holds a
+# metadata lock on the table).
+#
 # bug#7798
-create table t1(a int primary key, b int not null, index(b));
-insert into t1 values (1,1), (2,2);
-connect (con1,localhost,root,,test);
-connect (con2,localhost,root,,test);
-connection con1;
-set autocommit=0;
-begin;
-select count(*) from t1;
-connection con2;
-ALTER TABLE t1 ADD COLUMN c int;
-connection con1;
-select a from t1 where b = 2;
-show tables;
-drop table t1;
+# create table t1(a int primary key, b int not null, c int, index(b));
+# insert into t1 values (1,1,1), (2,2,2);
+# connect (con1,localhost,root,,test);
+# connect (con2,localhost,root,,test);
+# connection con1;
+# set autocommit=0;
+# begin;
+# select count(*) from t1;
+# connection con2;
+# ALTER TABLE t1 ADD COLUMN c int
+# connection con1;
+# select a from t1 where b = 2;
+# show tables;
+# drop table t1;
+#
 
 # mysqld 5.0.13 crash, no bug#
 create table t1 (a int, c varchar(10),

=== modified file 'mysql-test/suite/parts/r/partition_special_innodb.result'
--- a/mysql-test/suite/parts/r/partition_special_innodb.result	2009-01-27 11:03:30 +0000
+++ b/mysql-test/suite/parts/r/partition_special_innodb.result	2009-03-25 22:22:00 +0000
@@ -214,9 +214,4 @@ INSERT INTO t1 VALUES (NULL, 'first row 
 SET autocommit=OFF;
 ALTER TABLE t1 AUTO_INCREMENT = 10;
 ERROR HY000: Lock wait timeout exceeded; try restarting transaction
-INSERT INTO t1 VALUES (NULL, 'second row t2');
-SELECT a,b FROM t1 ORDER BY a;
-a	b
-1	first row t2
-2	second row t2
 DROP TABLE t1;

=== modified file 'mysql-test/suite/parts/t/partition_special_innodb.test'
--- a/mysql-test/suite/parts/t/partition_special_innodb.test	2008-12-10 09:20:38 +0000
+++ b/mysql-test/suite/parts/t/partition_special_innodb.test	2009-03-25 22:22:00 +0000
@@ -71,9 +71,6 @@ SET autocommit=OFF;
 --error ER_LOCK_WAIT_TIMEOUT
 ALTER TABLE t1 AUTO_INCREMENT = 10;
 
---connection con1
-INSERT INTO t1 VALUES (NULL, 'second row t2');
-SELECT a,b FROM t1 ORDER BY a;
 --disconnect con2
 --disconnect con1
 --connection default

=== modified file 'mysql-test/suite/rpl/r/rpl_locktrans_falcon.result'
--- a/mysql-test/suite/rpl/r/rpl_locktrans_falcon.result	2009-03-06 12:24:03 +0000
+++ b/mysql-test/suite/rpl/r/rpl_locktrans_falcon.result	2009-03-27 22:06:26 +0000
@@ -394,6 +394,17 @@ ERROR 0A000: LOCK is not allowed in stor
 CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW
 LOCK TABLE t2 IN EXCLUSIVE MODE;
 ERROR 0A000: LOCK is not allowed in stored procedures
+#
+# WL#4284: Transactional DDL locking
+#
+SET AUTOCOMMIT= 0;
+LOCK TABLES t1 WRITE, t2 WRITE;
+SAVEPOINT sp1;
+INSERT INTO t1 VALUES (1);
+SAVEPOINT sp2;
+INSERT INTO t2 VALUES (2);
+ROLLBACK TO SAVEPOINT sp1;
+UNLOCK TABLES;
 ## Cleanup.
 SET AUTOCOMMIT= 1;
 UNLOCK TABLES;

=== modified file 'mysql-test/suite/rpl/r/rpl_locktrans_innodb.result'
--- a/mysql-test/suite/rpl/r/rpl_locktrans_innodb.result	2009-03-06 12:24:03 +0000
+++ b/mysql-test/suite/rpl/r/rpl_locktrans_innodb.result	2009-03-27 22:06:26 +0000
@@ -926,6 +926,17 @@ TRUNCATE t1;
 TRUNCATE t2;
 COMMIT;
 DROP TRIGGER t1_ai;
+#
+# WL#4284: Transactional DDL locking
+#
+SET AUTOCOMMIT= 0;
+LOCK TABLES t1 WRITE, t2 WRITE;
+SAVEPOINT sp1;
+INSERT INTO t1 VALUES (1);
+SAVEPOINT sp2;
+INSERT INTO t2 VALUES (2);
+ROLLBACK TO SAVEPOINT sp1;
+UNLOCK TABLES;
 ## Cleanup.
 SET AUTOCOMMIT= 1;
 UNLOCK TABLES;

=== modified file 'mysql-test/suite/rpl/r/rpl_locktrans_myisam.result'
--- a/mysql-test/suite/rpl/r/rpl_locktrans_myisam.result	2009-03-06 12:24:03 +0000
+++ b/mysql-test/suite/rpl/r/rpl_locktrans_myisam.result	2009-03-27 22:06:26 +0000
@@ -439,6 +439,19 @@ ERROR 0A000: LOCK is not allowed in stor
 CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW
 LOCK TABLE t2 IN EXCLUSIVE MODE;
 ERROR 0A000: LOCK is not allowed in stored procedures
+#
+# WL#4284: Transactional DDL locking
+#
+SET AUTOCOMMIT= 0;
+LOCK TABLES t1 WRITE, t2 WRITE;
+SAVEPOINT sp1;
+INSERT INTO t1 VALUES (1);
+SAVEPOINT sp2;
+INSERT INTO t2 VALUES (2);
+ROLLBACK TO SAVEPOINT sp1;
+Warnings:
+Warning	1196	Some non-transactional changed tables couldn't be rolled back
+UNLOCK TABLES;
 ## Cleanup.
 SET AUTOCOMMIT= 1;
 UNLOCK TABLES;

=== modified file 'mysql-test/suite/rpl/t/disabled.def'
--- a/mysql-test/suite/rpl/t/disabled.def	2009-03-26 11:45:44 +0000
+++ b/mysql-test/suite/rpl/t/disabled.def	2009-03-27 22:06:26 +0000
@@ -18,3 +18,6 @@ rpl_cross_version          : Bug#42311 2
 rpl_heartbeat_basic        : Bug#43828 Sporadic failures (Serge.Kozlov@stripped)
 rpl_heartbeat_2slaves      : Bug#43828 Sporadic failrues (Serge.Kozlov@stripped)
 rpl_temp_table_mix_row     : Bug#43440 2009-03-26 alik rpl.rpl_temp_table_mix_row fails sporadicly
+rpl_log_pos                : Bug#42858 2009-02-14 alik rpl.rpl_log_pos fails, thus was disabled
+rpl_failed_optimize        : WL#4284: Can't optimize table used by a pending transaction (there is metadata lock on the table).
+rpl_read_only              : WL#4284: Setting Read only won't succeed until all metadata locks are released.

=== modified file 'mysql-test/suite/sys_vars/t/autocommit_func.test'
--- a/mysql-test/suite/sys_vars/t/autocommit_func.test	2008-12-19 15:12:15 +0000
+++ b/mysql-test/suite/sys_vars/t/autocommit_func.test	2009-03-06 22:17:00 +0000
@@ -153,6 +153,10 @@ SELECT * from t1;
 CONNECTION test_con2;
 SELECT * from t1;
 
+--echo ## Commit changes
+CONNECTION test_con1;
+COMMIT;
+
 --echo ## Dropping table t1 ##
 DROP table t1;
 

=== modified file 'mysql-test/t/flush_block_commit.test'
--- a/mysql-test/t/flush_block_commit.test	2009-03-06 14:56:17 +0000
+++ b/mysql-test/t/flush_block_commit.test	2009-03-27 22:06:26 +0000
@@ -6,7 +6,7 @@
 # And it requires InnoDB
 --source include/have_innodb.inc
 
-# Save the initial number of concurrent sessions
+--echo # Save the initial number of concurrent sessions
 --source include/count_sessions.inc
 
 --echo # Establish connection con1 (user=root)
@@ -29,19 +29,15 @@ BEGIN;
 INSERT INTO t1 VALUES(1);
 --echo # Switch to connection con2
 connection con2;
-FLUSH TABLES WITH READ LOCK;
-SELECT * FROM t1;
+--send FLUSH TABLES WITH READ LOCK
 --echo # Switch to connection con1
 connection con1;
-send COMMIT; # blocked by con2
-sleep 1;
+COMMIT;
 --echo # Switch to connection con2
 connection con2;
-SELECT * FROM t1; # verify con1 was blocked and data did not move
+--reap
+SELECT * FROM t1;
 UNLOCK TABLES;
---echo # Switch to connection con1
-connection con1;
-reap;
 
 # No deadlock ?
 
@@ -63,6 +59,7 @@ COMMIT; # should not be blocked by con3
 --echo # Switch to connection con2
 connection con2;
 reap;
+COMMIT;
 --echo # Switch to connection con3
 connection con3;
 reap;
@@ -79,8 +76,6 @@ connection con1;
 BEGIN;
 INSERT INTO t1 VALUES(10);
 FLUSH TABLES WITH READ LOCK;
-COMMIT;
-UNLOCK TABLES;
 --echo # Switch to connection con2
 connection con2;
 FLUSH TABLES WITH READ LOCK; # bug caused hang here
@@ -91,19 +86,21 @@ UNLOCK TABLES;
 BEGIN;
 SELECT * FROM t1;
 SHOW CREATE DATABASE test;
-
-DROP TABLE t1;
+COMMIT;
 
 
-# Cleanup
+--echo # Cleanup
 --echo # Switch to connection default and close connections con1, con2, con3
 connection default;
 disconnect con1;
 disconnect con2;
 disconnect con3;
 
-# End of 4.1 tests
+--echo # We commit open transactions when we disconnect: only then we can
+--echo # drop the table.
+DROP TABLE t1;
+--echo # End of 4.1 tests
 
-# Wait till all disconnects are completed
+--echo # Wait till all disconnects are completed
 --source include/wait_until_count_sessions.inc
 

=== modified file 'mysql-test/t/flush_block_commit_notembedded.test'
--- a/mysql-test/t/flush_block_commit_notembedded.test	2009-03-06 14:56:17 +0000
+++ b/mysql-test/t/flush_block_commit_notembedded.test	2009-03-27 22:06:26 +0000
@@ -9,7 +9,7 @@
 --source include/have_log_bin.inc
 --source include/have_innodb.inc
 
-# Save the initial number of concurrent sessions
+--echo # Save the initial number of concurrent sessions
 --source include/count_sessions.inc
 
 
@@ -24,14 +24,13 @@ connection con1;
 CREATE TABLE t1 (a INT) ENGINE=innodb;
 RESET MASTER;
 SET AUTOCOMMIT=0;
-INSERT t1 VALUES (1);
+SELECT 1;
 --echo # Switch to connection con2
 connection con2;
 FLUSH TABLES WITH READ LOCK;
 SHOW MASTER STATUS;
---echo # Switch to connection con1
 connection con1;
-send COMMIT;
+send INSERT INTO t1 VALUES (1);
 --echo # Switch to connection con2
 connection con2;
 sleep 1;
@@ -43,11 +42,30 @@ reap;
 DROP TABLE t1;
 SET AUTOCOMMIT=1;
 
+# GLR blocks new transactions
+create table t1 (a int) engine=innodb;
+connection con1;
+flush tables with read lock;
+connection con2;
+begin;
+--send insert into t1 values (1);
+connection con1;
+let $wait_condition=
+  select count(*) = 1 from information_schema.processlist
+  where state = "Waiting for release of readlock" and
+        info = "insert into t1 values (1)";
+--source include/wait_condition.inc
+unlock tables;
+connection con2;
+--reap
+commit;
+drop table t1;
+
 --echo # Switch to connection default and close connections con1 and con2
 connection default;
 disconnect con1;
 disconnect con2;
 
-# Wait till all disconnects are completed
+--echo # Wait till all disconnects are completed
 --source include/wait_until_count_sessions.inc
 

=== modified file 'mysql-test/t/grant.test'
--- a/mysql-test/t/grant.test	2009-02-12 21:10:28 +0000
+++ b/mysql-test/t/grant.test	2009-03-26 06:08:24 +0000
@@ -1473,3 +1473,326 @@ SET @@global.log_bin_trust_function_crea
 
 # Wait till we reached the initial number of concurrent sessions
 --source include/wait_until_count_sessions.inc
+
+--echo #########################################################################
+--echo #
+--echo # Bug#38347: ALTER ROUTINE privilege allows SHOW CREATE TABLE.
+--echo #
+--echo #########################################################################
+
+--echo
+--echo # --
+--echo # -- Prepare the environment.
+--echo # --
+
+DELETE FROM mysql.user WHERE User LIKE 'mysqltest_%';
+DELETE FROM mysql.db WHERE User LIKE 'mysqltest_%';
+DELETE FROM mysql.tables_priv WHERE User LIKE 'mysqltest_%';
+DELETE FROM mysql.columns_priv WHERE User LIKE 'mysqltest_%';
+FLUSH PRIVILEGES;
+
+--disable_warnings
+DROP DATABASE IF EXISTS mysqltest_db1;
+--enable_warnings
+
+CREATE DATABASE mysqltest_db1;
+
+CREATE TABLE mysqltest_db1.t1(a INT);
+
+--echo
+--echo # --
+--echo # -- Check that global privileges don't allow SHOW CREATE TABLE.
+--echo # --
+
+GRANT EVENT                   ON mysqltest_db1.* TO mysqltest_u1@localhost;
+GRANT CREATE TEMPORARY TABLES ON mysqltest_db1.* TO mysqltest_u1@localhost;
+GRANT LOCK TABLES             ON mysqltest_db1.* TO mysqltest_u1@localhost;
+GRANT ALTER ROUTINE           ON mysqltest_db1.* TO mysqltest_u1@localhost;
+GRANT CREATE ROUTINE          ON mysqltest_db1.* TO mysqltest_u1@localhost;
+GRANT EXECUTE                 ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+GRANT FILE                    ON *.* TO mysqltest_u1@localhost;
+GRANT CREATE USER             ON *.* TO mysqltest_u1@localhost;
+GRANT PROCESS                 ON *.* TO mysqltest_u1@localhost;
+GRANT RELOAD                  ON *.* TO mysqltest_u1@localhost;
+GRANT REPLICATION CLIENT      ON *.* TO mysqltest_u1@localhost;
+GRANT REPLICATION SLAVE       ON *.* TO mysqltest_u1@localhost;
+GRANT SHOW DATABASES          ON *.* TO mysqltest_u1@localhost;
+GRANT SHUTDOWN                ON *.* TO mysqltest_u1@localhost;
+GRANT USAGE                   ON *.* TO mysqltest_u1@localhost;
+
+--echo
+SHOW GRANTS FOR mysqltest_u1@localhost;
+
+--echo
+--echo # connection: con1 (mysqltest_u1@mysqltest_db1)
+--connect (con1,localhost,mysqltest_u1,,mysqltest_db1)
+--connection con1
+
+--echo
+--error ER_TABLEACCESS_DENIED_ERROR
+SHOW CREATE TABLE t1;
+
+--echo
+--echo # connection: default
+--connection default
+
+--disconnect con1
+
+--echo
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
+SHOW GRANTS FOR mysqltest_u1@localhost;
+
+--echo
+--echo # -- 
+--echo # -- Check that global SELECT allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT SELECT ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that global INSERT allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT INSERT ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that global UPDATE allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT UPDATE ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that global DELETE allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT DELETE ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that global CREATE allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT CREATE ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that global DROP allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT DROP ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that global ALTER allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT ALTER ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that global INDEX allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT INDEX ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that global REFERENCES allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT REFERENCES ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that global GRANT OPTION allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT GRANT OPTION ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that global CREATE VIEW allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT CREATE VIEW ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that global SHOW VIEW allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT SHOW VIEW ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that table-level SELECT allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT SELECT ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that table-level INSERT allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT INSERT ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that table-level UPDATE allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT UPDATE ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that table-level DELETE allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT DELETE ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that table-level CREATE allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT CREATE ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that table-level DROP allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT DROP ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that table-level ALTER allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT ALTER ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that table-level INDEX allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT INDEX ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that table-level REFERENCES allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT REFERENCES ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that table-level GRANT OPTION allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT GRANT OPTION ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that table-level CREATE VIEW allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT CREATE VIEW ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Check that table-level SHOW VIEW allows SHOW CREATE TABLE.
+--echo # -- 
+
+--echo
+GRANT SHOW VIEW ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
+
+--source include/bug38347.inc
+
+--echo
+--echo # -- 
+--echo # -- Cleanup.
+--echo # -- 
+
+--echo
+DROP DATABASE mysqltest_db1;
+
+DROP USER mysqltest_u1@localhost;
+
+--echo
+--echo # End of Bug#38347.
+--echo

=== modified file 'mysql-test/t/innodb.test'
--- a/mysql-test/t/innodb.test	2009-02-14 22:52:31 +0000
+++ b/mysql-test/t/innodb.test	2009-03-27 22:06:26 +0000
@@ -1797,16 +1797,15 @@ connect (b,localhost,root,,);
 connection a;
 create table t1(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
 insert into t1(a) values (1),(2),(3);
+delimiter |;
+create trigger t1t before insert on t1 for each row begin set NEW.b = NEW.a * 10 + 5, NEW.c = NEW.a / 10; end |
+delimiter ;|
 commit;
 connection b;
 set autocommit = 0;
 update t1 set b = 5 where a = 2;
 connection a;
-delimiter |;
-create trigger t1t before insert on t1 for each row begin set NEW.b = NEW.a * 10 + 5, NEW.c = NEW.a / 10; end |
-delimiter ;|
 set autocommit = 0;
-connection a;
 insert into t1(a) values (10),(20),(30),(40),(50),(60),(70),(80),(90),(100),
 (11),(21),(31),(41),(51),(61),(71),(81),(91),(101),
 (12),(22),(32),(42),(52),(62),(72),(82),(92),(102),
@@ -1870,6 +1869,9 @@ insert into t2(a) values(8);
 delete from t2 where a = 3;
 update t4 set b = b + 1 where a = 3;
 commit;
+connection a;
+commit;
+connection b;
 drop trigger t1t;
 drop trigger t2t;
 drop trigger t3t;

=== modified file 'mysql-test/t/lock.test'
--- a/mysql-test/t/lock.test	2009-03-13 18:53:52 +0000
+++ b/mysql-test/t/lock.test	2009-03-27 22:06:26 +0000
@@ -311,5 +311,39 @@ drop table t1;
 drop view v1;
 
 --echo #
+--echo # WL#4284: Transactional DDL locking
+--echo #
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+create table t1 (a int);
+connect(con1,localhost,root,,);
+set autocommit= 0;
+insert into t1 values (1);
+lock table t1 write;
+--echo # Disconnect
+--echo # Ensure that metadata locks will be released if there is an open
+--echo # transaction (autocommit=off) in conjunction with lock tables.
+disconnect con1;
+connection default;
+drop table t1;
+
+--echo # Same problem but now for BEGIN
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+create table t1 (a int);
+connect(con1,localhost,root,,);
+begin;
+insert into t1 values (1);
+--echo # Disconnect
+--echo # Ensure that metadata locks held by the transaction are released.
+disconnect con1;
+connection default;
+drop table t1;
+
+--echo #
 --echo # End of 6.0 tests.
 --echo #

=== modified file 'mysql-test/t/not_embedded_server.test'
--- a/mysql-test/t/not_embedded_server.test	2009-02-01 14:30:58 +0000
+++ b/mysql-test/t/not_embedded_server.test	2009-03-18 12:49:07 +0000
@@ -4,12 +4,6 @@
 
 -- source include/not_embedded.inc
 
-#
-# Produce output
-#
-
-select 1;
-
 # The following fails sporadically because 'check-testcase' runs
 # queries before this test and there is no way to guarantee that any
 # previous process finishes.  The purpose of the test is not clearly
@@ -37,3 +31,18 @@ select 1;
 #deallocate prepare stmt1;
 
 # End of 5.1 tests
+
+--echo #
+--echo # WL#4284: Transactional DDL locking
+--echo #
+--echo # FLUSH PRIVILEGES should not implicitly unlock locked tables.
+--echo #
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+create table t1 (c1 int);
+lock tables t1 read;
+--error ER_TABLE_NOT_LOCKED
+flush privileges;
+unlock tables;
+drop table t1;

=== modified file 'mysql-test/t/partition_innodb_semi_consistent.test'
--- a/mysql-test/t/partition_innodb_semi_consistent.test	2009-01-13 22:12:16 +0000
+++ b/mysql-test/t/partition_innodb_semi_consistent.test	2009-03-06 22:17:00 +0000
@@ -157,7 +157,7 @@ connection con1;
 --echo # 3. test for updated key column:
 
 TRUNCATE t1;
-TRUNCATE t2;
+DELETE FROM t2;
 
 INSERT INTO t1 VALUES (1,'init');
 

=== modified file 'mysql-test/t/ps.test'
--- a/mysql-test/t/ps.test	2009-02-26 07:23:54 +0000
+++ b/mysql-test/t/ps.test	2009-03-27 22:06:26 +0000
@@ -3211,7 +3211,44 @@ DROP PROCEDURE p2;
 
 ###########################################################################
 
---echo
---echo End of 6.0 tests.
+
+--echo #
+--echo # WL#4284: Transactional DDL locking
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+CREATE TABLE t1 (a INT);
+BEGIN;
+SELECT * FROM t1;
+--echo # Test that preparing a CREATE TABLE does not take a exclusive metdata lock.
+PREPARE stmt1 FROM "CREATE TABLE t1 AS SELECT 1";
+--error ER_TABLE_EXISTS_ERROR
+EXECUTE stmt1;
+DEALLOCATE PREPARE stmt1;
+DROP TABLE t1;
+
+--echo #
+--echo # WL#4284: Transactional DDL locking
+--echo #
+--echo # Test that metadata locks taken during prepare are released.
+--echo #
+
+connect(con1,localhost,root,,);
+connection default;
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+CREATE TABLE t1 (a INT);
+connection con1;
+BEGIN;
+PREPARE stmt1 FROM "SELECT * FROM t1";
+connection default;
+DROP TABLE t1;
+disconnect con1;
+
+--echo #
+--echo # End of 6.0 tests.
 
 ###########################################################################

=== modified file 'mysql-test/t/read_only_innodb.test'
--- a/mysql-test/t/read_only_innodb.test	2008-04-08 05:20:58 +0000
+++ b/mysql-test/t/read_only_innodb.test	2009-03-30 13:01:09 +0000
@@ -16,6 +16,7 @@ DROP TABLE IF EXISTS table_11733 ;
 grant CREATE, SELECT, DROP on *.* to test@localhost;
 
 connect (con1,localhost,test,,test);
+connect (con2,localhost,root,,);
 
 connection default;
 set global read_only=0;
@@ -28,20 +29,28 @@ BEGIN;
 insert into table_11733 values(11733);
 
 connection default;
-set global read_only=1;
+send set global read_only=1;
+
+connection con2;
+let $wait_condition=
+  select count(*) = 1 from information_schema.processlist
+  where state = "Flushing tables" and info = "set global read_only=1";
+--source include/wait_condition.inc
 
 connection con1;
 select @@global.read_only;
+-- error ER_LOCK_DEADLOCK
 select * from table_11733 ;
--- error ER_OPTION_PREVENTS_STATEMENT
 COMMIT;
 
 connection default;
+reap;
 set global read_only=0;
 drop table table_11733 ;
 drop user test@localhost;
 
 disconnect con1;
+disconnect con2;
 
 #
 # Bug #35732: read-only blocks SELECT statements in InnoDB

=== modified file 'mysql-test/t/user_limits.test'
--- a/mysql-test/t/user_limits.test	2009-03-06 20:33:52 +0000
+++ b/mysql-test/t/user_limits.test	2009-03-27 22:06:26 +0000
@@ -5,23 +5,7 @@
 # Requires privileges to be enabled
 --source include/not_embedded.inc
 
-# <-- Start the cut here
-# As long as
-# Bug#42384 thread_handling = pool-of-threads, wrong handling of max_questions
-#           user limit
-# is not fixed this test will fail when the server was started with
-# "pool-of-threads".
-# Please set $fixed_bug_42384 to 1 when checking if the fix for Bug#42384 works.
-# If everything is fine, please remove the lines between the markers.
-let $fixed_bug_42384 = 0;
-let $my_val= query_get_value(show variables like 'thread_handling', Value, 1);
-if (`SELECT $fixed_bug_42384 = 0 AND '$my_val' = 'pool-of-threads'`)
-{
-   --skip Bug#42384 thread_handling = pool-of-threads, wrong handling of max_questions user limit
-   exit;
-}
-# <-- End the cut here
-
+# Prepare play-ground 
 # Save the initial number of concurrent sessions
 --source include/count_sessions.inc
 

=== modified file 'mysql-test/t/variables_debug.test'
--- a/mysql-test/t/variables_debug.test	2008-02-26 15:03:59 +0000
+++ b/mysql-test/t/variables_debug.test	2009-03-25 16:51:28 +0000
@@ -10,3 +10,13 @@ set debug= '+P';
 select @@debug;
 set debug= '-P';
 select @@debug;
+
+#
+# Bug#38054: "SET SESSION debug" modifies @@global.debug variable
+#
+
+SELECT @@session.debug, @@global.debug;
+
+SET SESSION debug = '';
+
+SELECT @@session.debug, @@global.debug;

=== modified file 'mysql-test/t/xa.test'
--- a/mysql-test/t/xa.test	2009-03-03 20:34:18 +0000
+++ b/mysql-test/t/xa.test	2009-03-27 22:06:26 +0000
@@ -76,9 +76,10 @@ xa rollback 'testa','testb';
 xa start 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz';
 
 select * from t1;
-drop table t1;
 
 disconnect con1;
+connection default;
+drop table t1;
 
 #
 # Bug#28323: Server crashed in xid cache operations

=== modified file 'sql/event_data_objects.cc'
--- a/sql/event_data_objects.cc	2008-12-03 00:47:42 +0000
+++ b/sql/event_data_objects.cc	2009-03-26 06:15:10 +0000
@@ -1224,7 +1224,9 @@ Event_timed::get_create_event(THD *thd, 
                                                             expression))
     DBUG_RETURN(EVEX_MICROSECOND_UNSUP);
 
-  buf->append(STRING_WITH_LEN("CREATE EVENT "));
+  buf->append(STRING_WITH_LEN("CREATE "));
+  append_definer(thd, buf, &definer_user, &definer_host);
+  buf->append(STRING_WITH_LEN("EVENT "));
   append_identifier(thd, buf, name.str, name.length);
 
   if (expression)

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2009-03-09 12:17:41 +0000
+++ b/sql/log_event.cc	2009-03-27 22:06:26 +0000
@@ -5181,10 +5181,17 @@ void Xid_log_event::print(FILE* file, PR
 #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
 int Xid_log_event::do_apply_event(Relay_log_info const *rli)
 {
+  bool res;
   /* For a slave Xid_log_event is COMMIT */
   general_log_print(thd, COM_QUERY,
                     "COMMIT /* implicit, from Xid_log_event */");
-  return trans_commit(thd);
+  if (!(res= trans_commit(thd)))
+  {
+    close_thread_tables(thd);
+    if (!thd->locked_tables_mode)
+      thd->mdl_context.release_all_locks();
+  }
+  return res;
 }
 
 Log_event::enum_skip_reason

=== modified file 'sql/mdl.cc'
--- a/sql/mdl.cc	2009-03-05 21:39:58 +0000
+++ b/sql/mdl.cc	2009-03-31 13:00:58 +0000
@@ -101,7 +101,7 @@ public:
 
   bool is_empty() const
   {
-    return (waiting_shared == 0 && active_shared  == 0 &&
+    return (waiting_shared == 0 && active_shared == 0 &&
             active_intention_exclusive == 0);
   }
   bool is_lock_type_compatible(enum_mdl_type type, bool is_upgrade) const;
@@ -491,7 +491,7 @@ void MDL_ticket::destroy(MDL_ticket *tic
   @sa THD::enter_cond()/exit_cond()/killed.
 
   @note We can't use THD::enter_cond()/exit_cond()/killed directly here
-        since this will make metadata subsystem dependant on THD class
+        since this will make metadata subsystem dependent on THD class
         and thus prevent us from writing unit tests for it. And usage of
         wrapper functions to access THD::killed/enter_cond()/exit_cond()
         will probably introduce too much overhead.
@@ -881,6 +881,7 @@ static bool notify_shared_lock(THD *thd,
   if (conflicting_ticket->is_shared())
   {
     THD *conflicting_thd= conflicting_ticket->get_ctx()->get_thd();
+    DBUG_ASSERT(thd != conflicting_thd); /* Self-deadlock */
     woke= mysql_notify_thread_having_shared_lock(thd, conflicting_thd);
   }
   return woke;
@@ -1089,7 +1090,6 @@ MDL_ticket::upgrade_shared_lock_to_exclu
 
   old_msg= MDL_ENTER_COND(thd, mysys_var);
 
-
   /*
     Since we should have already acquired an intention exclusive
     global lock this call is only enforcing asserts.
@@ -1164,7 +1164,7 @@ MDL_ticket::upgrade_shared_lock_to_exclu
   @param conflict   [out] Indicates that conflicting lock exists
 
   @retval TRUE  Failure either conflicting lock exists or some error
-                occured (probably OOM).
+                occurred (probably OOM).
   @retval FALSE Success, lock was acquired.
 
   FIXME: Compared to lock_table_name_if_not_cached()

=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h	2009-03-24 22:39:01 +0000
+++ b/sql/mysql_priv.h	2009-03-27 22:06:26 +0000
@@ -792,7 +792,7 @@ extern my_decimal decimal_zero;
 void free_items(Item *item);
 void cleanup_items(Item *item);
 class THD;
-void close_thread_tables(THD *thd, bool skip_mdl= 0);
+void close_thread_tables(THD *thd, bool is_back_off= 0);
 
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
 bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables);

=== modified file 'sql/rpl_injector.cc'
--- a/sql/rpl_injector.cc	2008-12-13 11:02:16 +0000
+++ b/sql/rpl_injector.cc	2009-03-06 22:17:00 +0000
@@ -83,17 +83,25 @@ int injector::transaction::commit()
      explicitly.
    */
    trans_commit_stmt(m_thd);
-   trans_commit(m_thd);
+   if (!trans_commit(m_thd))
+   {
+     close_thread_tables(m_thd);
+     if (!m_thd->locked_tables_mode)
+       m_thd->mdl_context.release_all_locks();
+   }
    DBUG_RETURN(0);
 }
 
 int injector::transaction::rollback()
 {
    DBUG_ENTER("injector::transaction::rollback()");
- //psergey  ha_autocommit_or_rollback(m_thd, 1 /* error to get rollback */);
    trans_rollback_stmt(m_thd);
- //psergey  end_trans(m_thd, ROLLBACK);
-   trans_rollback(m_thd);
+   if (!trans_rollback(m_thd))
+   {
+     close_thread_tables(m_thd);
+     if (!m_thd->locked_tables_mode)
+       m_thd->mdl_context.release_all_locks();
+   }
    DBUG_RETURN(0);
 }
 

=== modified file 'sql/rpl_rli.cc'
--- a/sql/rpl_rli.cc	2009-03-23 12:46:20 +0000
+++ b/sql/rpl_rli.cc	2009-03-27 22:06:26 +0000
@@ -1183,6 +1183,8 @@ void Relay_log_info::cleanup_context(THD
   }
   m_table_map.clear_tables();
   slave_close_thread_tables(thd);
+  if (error && !thd->locked_tables_mode)
+    thd->mdl_context.release_all_locks();
   clear_flag(IN_STMT);
   /*
     Cleanup for the flags that have been set at do_apply_event.
@@ -1195,13 +1197,6 @@ void Relay_log_info::cleanup_context(THD
 
 void Relay_log_info::clear_tables_to_lock()
 {
-  /*
-    Deallocating elements of table list below will also free memory where
-    meta-data locks are stored. So we want to be sure that we don't have
-    any references to this memory left.
-  */
-  DBUG_ASSERT(!current_thd->mdl_context.has_locks());
-
   while (tables_to_lock)
   {
     uchar* to_free= reinterpret_cast<uchar*>(tables_to_lock);
@@ -1220,12 +1215,6 @@ void Relay_log_info::clear_tables_to_loc
 
 void Relay_log_info::slave_close_thread_tables(THD *thd)
 {
-  /*
-    Since we use same memory chunks for allocation of metadata lock
-    objects for tables as we use for allocating corresponding elements
-    of 'tables_to_lock' list, we have to release metadata locks by
-    closing tables before calling clear_tables_to_lock().
-  */
   close_thread_tables(thd);
   clear_tables_to_lock();
 }

=== modified file 'sql/scheduler.cc'
--- a/sql/scheduler.cc	2009-02-16 18:22:48 +0000
+++ b/sql/scheduler.cc	2009-03-26 09:04:25 +0000
@@ -461,6 +461,10 @@ static void libevent_add_connection(THD 
     libevent_connection_close(thd);
     DBUG_VOID_RETURN;
   }
+
+  thd->set_time();
+  thd->thr_create_utime= my_micro_time();
+
   threads.append(thd);
   libevent_thd_add(thd);
 

=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc	2009-03-18 21:09:40 +0000
+++ b/sql/set_var.cc	2009-03-27 22:06:26 +0000
@@ -3601,9 +3601,15 @@ static bool set_option_autocommit(THD *t
     need to commit any outstanding transactions.
    */
   if (var->save_result.ulong_value != 0 &&
-      (thd->options & OPTION_NOT_AUTOCOMMIT) &&
-      trans_commit(thd))
-    return 1;
+      (thd->options & OPTION_NOT_AUTOCOMMIT))
+  {
+    if (trans_commit(thd))
+      return TRUE;
+
+    close_thread_tables(thd);
+    if (!thd->locked_tables_mode)
+      thd->mdl_context.release_all_locks();
+  }
 
   if (var->save_result.ulong_value != 0)
     thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag;

=== modified file 'sql/slave.cc'
--- a/sql/slave.cc	2009-03-16 11:56:39 +0000
+++ b/sql/slave.cc	2009-03-27 22:06:26 +0000
@@ -2220,6 +2220,9 @@ static int exec_relay_log_event(THD* thd
           {
             exec_res= 0;
             trans_rollback(thd);
+            close_thread_tables(thd);
+            if (!thd->locked_tables_mode)
+              thd->mdl_context.release_all_locks();
             /* chance for concurrent connection to get more locks */
             safe_sleep(thd, min(rli->trans_retries, MAX_SLAVE_RETRY_PAUSE),
                        (CHECK_KILLED_FUNC)sql_slave_killed, (void*)rli);

=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc	2009-03-18 21:09:40 +0000
+++ b/sql/sql_acl.cc	2009-03-27 22:06:26 +0000
@@ -30,6 +30,7 @@
 #include <stdarg.h>
 #include "sp_head.h"
 #include "sp.h"
+#include "transaction.h"
 
 time_t mysql_db_table_last_check= 0L;
 
@@ -676,9 +677,6 @@ my_bool acl_reload(THD *thd)
   my_bool return_val= 1;
   DBUG_ENTER("acl_reload");
 
-  /* Can't have locked tables here. */
-  thd->locked_tables_list.unlock_locked_tables(thd);
-
   /*
     To avoid deadlocks we should obtain table locks before
     obtaining acl_cache->lock mutex.
@@ -732,7 +730,10 @@ my_bool acl_reload(THD *thd)
   if (old_initialized)
     pthread_mutex_unlock(&acl_cache->lock);
 end:
+  trans_commit_implicit(thd);
   close_thread_tables(thd);
+  if (!thd->locked_tables_mode)
+    thd->mdl_context.release_all_locks();
   DBUG_RETURN(return_val);
 }
 
@@ -3833,7 +3834,10 @@ my_bool grant_reload(THD *thd)
     free_root(&old_mem,MYF(0));
   }
   rw_unlock(&LOCK_grant);
+  trans_commit_implicit(thd);
   close_thread_tables(thd);
+  if (!thd->locked_tables_mode)
+    thd->mdl_context.release_all_locks();
 
   /*
     It is OK failing to load procs_priv table because we may be

=== modified file 'sql/sql_acl.h'
--- a/sql/sql_acl.h	2008-08-18 05:43:50 +0000
+++ b/sql/sql_acl.h	2009-03-26 06:08:24 +0000
@@ -86,6 +86,11 @@
 #define DEFAULT_CREATE_PROC_ACLS \
 (ALTER_PROC_ACL | EXECUTE_ACL)
 
+#define SHOW_CREATE_TABLE_ACLS \
+(SELECT_ACL | INSERT_ACL | UPDATE_ACL | DELETE_ACL | \
+ CREATE_ACL | DROP_ACL | ALTER_ACL | INDEX_ACL | \
+ TRIGGER_ACL | REFERENCES_ACL | GRANT_ACL | CREATE_VIEW_ACL | SHOW_VIEW_ACL)
+
 /*
   Defines to change the above bits to how things are stored in tables
   This is needed as the 'host' and 'db' table is missing a few privileges

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2009-03-09 12:17:41 +0000
+++ b/sql/sql_base.cc	2009-03-27 22:06:26 +0000
@@ -1475,11 +1475,22 @@ void close_thread_tables(THD *thd,
   if (thd->open_tables)
     close_open_tables(thd);
 
-  thd->mdl_context.release_all_locks();
   if (!is_back_off)
   {
     thd->mdl_context.remove_all_requests();
   }
+
+  /*
+    Defer the release of metadata locks until the current transaction
+    is either committed or rolled back. This prevents other statements
+    from modifying the table for the entire duration of this transaction.
+    This provides commitment ordering for guaranteeing serializability
+    across multiple transactions.
+  */
+  if (!thd->in_multi_stmt_transaction() ||
+      (thd->state_flags & Open_tables_state::BACKUPS_AVAIL))
+    thd->mdl_context.release_all_locks();
+
   DBUG_VOID_RETURN;
 }
 
@@ -2279,7 +2290,7 @@ open_table_get_mdl_lock(THD *thd, TABLE_
 {
   thd->mdl_context.add_request(mdl_request);
 
-  if (table_list->open_type)
+  if (table_list->lock_strategy)
   {
     /*
       In case of CREATE TABLE .. If NOT EXISTS .. SELECT, the table
@@ -2353,10 +2364,16 @@ open_table_get_mdl_lock(THD *thd, TABLE_
   IMPLEMENTATION
     Uses a cache of open tables to find a table not in use.
 
-    If table list element for the table to be opened has "open_type" set
-    to OPEN_OR_CREATE and table does not exist, this function will take
-    exclusive metadata lock on the table, also it will do this if
-    "open_type" is TAKE_EXCLUSIVE_MDL.
+    If TABLE_LIST::open_strategy is set to OPEN_IF_EXISTS, the table is opened
+    only if it exists. If the open strategy is OPEN_STUB, the underlying table
+    is never opened. In both cases, metadata locks are always taken according
+    to the lock strategy.
+
+    This function will take a exclusive metadata lock on the table if
+    TABLE_LIST::lock_strategy is EXCLUSIVE_DOWNGRADABLE_MDL or EXCLUSIVE_MDL.
+    If the lock strategy is EXCLUSIVE_DOWNGRADABLE_MDL and opening the table
+    is successful, the exclusive metadata lock is downgraded to a shared
+    lock.
 
   RETURN
     TRUE  Open failed. "action" parameter may contain type of action
@@ -2606,7 +2623,7 @@ bool open_table(THD *thd, TABLE_LIST *ta
     DBUG_RETURN(TRUE);
   }
 
-  if (table_list->open_type == TABLE_LIST::OPEN_OR_CREATE)
+  if (table_list->open_strategy == TABLE_LIST::OPEN_IF_EXISTS)
   {
     bool exists;
 
@@ -2620,7 +2637,7 @@ bool open_table(THD *thd, TABLE_LIST *ta
     }
     /* Table exists. Let us try to open it. */
   }
-  else if (table_list->open_type == TABLE_LIST::TAKE_EXCLUSIVE_MDL)
+  else if (table_list->open_strategy == TABLE_LIST::OPEN_STUB)
   {
     pthread_mutex_unlock(&LOCK_open);
     DBUG_RETURN(FALSE);
@@ -2795,7 +2812,7 @@ bool open_table(THD *thd, TABLE_LIST *ta
     table exists now we should downgrade our exclusive metadata
     lock on this table to shared metadata lock.
   */
-  if (table_list->open_type == TABLE_LIST::OPEN_OR_CREATE)
+  if (table_list->lock_strategy == TABLE_LIST::EXCLUSIVE_DOWNGRADABLE_MDL)
     mdl_ticket->downgrade_exclusive_lock();
 
   table->mdl_ticket= mdl_ticket;
@@ -3619,6 +3636,7 @@ int open_tables(THD *thd, TABLE_LIST **s
   /* Also used for indicating that prelocking is need */
   TABLE_LIST **query_tables_last_own;
   bool safe_to_ignore_table;
+  bool has_locks= thd->mdl_context.has_locks();
   DBUG_ENTER("open_tables");
 
   /*
@@ -3760,6 +3778,18 @@ int open_tables(THD *thd, TABLE_LIST **s
       if (action)
       {
         /*
+          We have met a exclusive metadata lock or a old version of table and
+          we are inside a transaction that already hold locks. We can't follow
+          the locking protocol in this scenario as it might lead to deadlocks.
+        */
+        if (thd->in_multi_stmt_transaction() && has_locks)
+        {
+          my_error(ER_LOCK_DEADLOCK, MYF(0));
+          result= -1;
+          goto err;
+        }
+
+        /*
           We have met exclusive metadata lock or old version of table. Now we
           have to close all tables which are not up to date/release metadata
           locks. We also have to throw away set of prelocked tables (and thus
@@ -3837,7 +3867,7 @@ int open_tables(THD *thd, TABLE_LIST **s
       Special types of open can succeed but still don't set
       TABLE_LIST::table to anything.
     */
-    if (tables->open_type && !tables->table)
+    if (tables->open_strategy && !tables->table)
       continue;
 
     /*
@@ -4115,7 +4145,7 @@ retry:
   if (!error)
   {
     /*
-      We can't have a view or some special "open_type" in this function
+      We can't have a view or some special "open_strategy" in this function
       so there should be a TABLE instance.
     */
     DBUG_ASSERT(table_list->table);
@@ -4626,6 +4656,8 @@ void close_tables_for_reopen(THD *thd, T
   for (TABLE_LIST *tmp= *tables; tmp; tmp= tmp->next_global)
     tmp->table= 0;
   close_thread_tables(thd, is_back_off);
+  if (!thd->locked_tables_mode)
+    thd->mdl_context.release_all_locks();
 }
 
 

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2009-03-18 21:09:40 +0000
+++ b/sql/sql_class.cc	2009-03-27 22:06:26 +0000
@@ -949,8 +949,18 @@ void THD::cleanup(void)
     trans_rollback(this);
     xid_cache_delete(&transaction.xid_state);
   }
+
   locked_tables_list.unlock_locked_tables(this);
 
+  /*
+    If the thread was in the middle of an ongoing transaction (rolled
+    back a few lines above) or under LOCK TABLES (unlocked the tables
+    and left the mode a few lines above), there will be outstanding
+    metadata locks. Release them.
+  */
+  DBUG_ASSERT(open_tables == NULL);
+  mdl_context.release_all_locks();
+
 #if defined(ENABLED_DEBUG_SYNC)
   /* End the Debug Sync Facility. See debug_sync.cc. */
   debug_sync_end_thread(this);

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2009-03-24 22:39:01 +0000
+++ b/sql/sql_parse.cc	2009-03-27 22:06:26 +0000
@@ -133,11 +133,11 @@ static bool some_non_temp_table_to_be_up
   @param mask   Bitmask used for the SQL command match.
 
 */
-static bool opt_implicit_commit(THD *thd, uint mask)
+static bool stmt_causes_implicit_commit(THD *thd, uint mask)
 {
   LEX *lex= thd->lex;
-  bool res= FALSE, skip= FALSE;
-  DBUG_ENTER("opt_implicit_commit");
+  bool skip= FALSE;
+  DBUG_ENTER("stmt_causes_implicit_commit");
 
   if (!(sql_command_flags[lex->sql_command] & mask))
     DBUG_RETURN(FALSE);
@@ -158,15 +158,7 @@ static bool opt_implicit_commit(THD *thd
     break;
   }
 
-  if (!skip)
-  {
-    /* Commit or rollback the statement transaction. */
-    thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd);
-    /* Commit the normal transaction if one is active. */
-    res= trans_commit_implicit(thd);
-  }
-
-  DBUG_RETURN(res);
+  DBUG_RETURN(!skip);
 }
 
 
@@ -1273,6 +1265,9 @@ bool dispatch_command(enum enum_server_c
     ulong options= (ulong) (uchar) packet[0];
     if (trans_commit_implicit(thd))
       break;
+    close_thread_tables(thd);
+    if (!thd->locked_tables_mode)
+      thd->mdl_context.release_all_locks();
     if (check_global_access(thd,RELOAD_ACL))
       break;
     general_log_print(thd, command, NullS);
@@ -1280,6 +1275,9 @@ bool dispatch_command(enum enum_server_c
       break;
     if (trans_commit_implicit(thd))
       break;
+    close_thread_tables(thd);
+    if (!thd->locked_tables_mode)
+      thd->mdl_context.release_all_locks();
     my_ok(thd);
     break;
   }
@@ -2053,8 +2051,18 @@ mysql_execute_command(THD *thd)
     not run in it's own transaction it may simply never appear on
     the slave in case the outside transaction rolls back.
   */
-  if (opt_implicit_commit(thd, CF_IMPLICT_COMMIT_BEGIN))
-    goto error;
+  if (stmt_causes_implicit_commit(thd, CF_IMPLICT_COMMIT_BEGIN))
+  {
+    /* Commit or rollback the statement transaction. */
+    thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd);
+    /* Commit the normal transaction if one is active. */
+    if (trans_commit_implicit(thd))
+      goto error;
+    /* Close tables and release metadata locks. */
+    close_thread_tables(thd);
+    if (!thd->locked_tables_mode)
+      thd->mdl_context.release_all_locks();
+  }
 
   /*
     If the SQL command to be executed should be blocked by BML, call 
@@ -2645,7 +2653,9 @@ mysql_execute_command(THD *thd)
       if (!(create_info.options & HA_LEX_CREATE_TMP_TABLE))
       {
         lex->link_first_table_back(create_table, link_to_local);
-        create_table->open_type= TABLE_LIST::OPEN_OR_CREATE;
+        /* Set strategies: reset default or 'prepared' values. */
+        create_table->open_strategy= TABLE_LIST::OPEN_IF_EXISTS;
+        create_table->lock_strategy= TABLE_LIST::EXCLUSIVE_DOWNGRADABLE_MDL;
         if (!thd->locked_tables_mode)
           global_schema_lock_guard.lock();
       }
@@ -2967,18 +2977,41 @@ end_with_restore_list:
       else
       {
         ulong save_priv;
-        if (check_access(thd, SELECT_ACL, first_table->db,
+
+        /*
+          If it is an INFORMATION_SCHEMA table, SELECT_ACL privilege is the
+          only privilege allowed. For any other privilege check_access()
+          reports an error. That's how internal implementation protects
+          INFORMATION_SCHEMA from updates.
+
+          For ordinary tables any privilege from the SHOW_CREATE_TABLE_ACLS
+          set is sufficient.
+        */
+
+        ulong check_privs= test(first_table->schema_table) ?
+                           SELECT_ACL : SHOW_CREATE_TABLE_ACLS;
+
+        if (check_access(thd, check_privs, first_table->db,
                          &save_priv, FALSE, FALSE,
                          test(first_table->schema_table)))
           goto error;
+
         /*
-          save_priv contains any privileges actually granted by check_access.
-          If there are no global privileges (save_priv == 0) and no table level
-          privileges, access is denied.
+          save_priv contains any privileges actually granted by check_access
+          (i.e. save_priv contains global (user- and database-level)
+          privileges).
+
+          The fact that check_access() returned FALSE does not mean that
+          access is granted. We need to check if save_priv contains any
+          table-specific privilege. If not, we need to check table-level
+          privileges.
+
+          If there are no global privileges and no table-level privileges,
+          access is denied.
         */
-        if (!save_priv &&
-            !has_any_table_level_privileges(thd, TABLE_ACLS,
-                                            first_table))
+
+        if (!(save_priv & (SHOW_CREATE_TABLE_ACLS)) &&
+            !has_any_table_level_privileges(thd, SHOW_CREATE_TABLE_ACLS, first_table))
         {
           my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0),
                   "SHOW", thd->security_ctx->priv_user,
@@ -2987,9 +3020,8 @@ end_with_restore_list:
         }
       }
 #endif /* NO_EMBDEDDED_ACCESS_CHECKS */
-      /*
-        Access is granted. Execute command.
-      */
+
+      /* Access is granted. Execute the command.  */
       res= mysqld_show_create(thd, first_table);
       break;
     }
@@ -3525,6 +3557,7 @@ end_with_restore_list:
     if (thd->options & OPTION_TABLE_LOCK)
     {
       trans_commit_implicit(thd);
+      thd->mdl_context.release_all_locks();
       thd->options&= ~(OPTION_TABLE_LOCK);
     }
     if (thd->global_read_lock)
@@ -3580,6 +3613,8 @@ end_with_restore_list:
     /* we must end the trasaction first, regardless of anything */
     if (trans_commit_implicit(thd))
       goto error;
+    /* release transactional metadata locks. */
+    thd->mdl_context.release_all_locks();
 
     alloc_mdl_requests(all_tables, thd->locked_tables_list.locked_tables_root());
 
@@ -3603,6 +3638,13 @@ end_with_restore_list:
       */
       trans_rollback_stmt(thd);
       trans_commit_implicit(thd);
+      /*
+        Close tables and release metadata locks otherwise a later call to
+        close_thread_tables might not release the locks if autocommit is off.
+      */
+      close_thread_tables(thd);
+      DBUG_ASSERT(!thd->locked_tables_mode);
+      thd->mdl_context.release_all_locks();
       thd->options&= ~(OPTION_TABLE_LOCK);
     }
     else
@@ -4093,6 +4135,8 @@ end_with_restore_list:
                 thd->locked_tables_mode == LTM_LOCK_TABLES);
     if (trans_commit(thd))
       goto error;
+    if (!thd->locked_tables_mode)
+      thd->mdl_context.release_all_locks();
     /* Begin transaction with the same isolation level. */
     if (lex->tx_chain && trans_begin(thd))
       goto error;
@@ -4107,6 +4151,8 @@ end_with_restore_list:
                 thd->locked_tables_mode == LTM_LOCK_TABLES);
     if (trans_rollback(thd))
       goto error;
+    if (!thd->locked_tables_mode)
+      thd->mdl_context.release_all_locks();
     /* Begin transaction with the same isolation level. */
     if (lex->tx_chain && trans_begin(thd))
       goto error;
@@ -4466,6 +4512,12 @@ create_sp_error:
 
         if (trans_commit_implicit(thd))
           goto error;
+
+        close_thread_tables(thd);
+
+        if (!thd->locked_tables_mode)
+          thd->mdl_context.release_all_locks();
+
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
 	if (sp_automatic_privileges && !opt_noacl &&
 	    sp_revoke_privileges(thd, db, name, 
@@ -4612,11 +4664,15 @@ create_sp_error:
   case SQLCOM_XA_COMMIT:
     if (trans_xa_commit(thd))
       goto error;
+    if (!thd->locked_tables_mode)
+      thd->mdl_context.release_all_locks();
     my_ok(thd);
     break;
   case SQLCOM_XA_ROLLBACK:
     if (trans_xa_rollback(thd))
       goto error;
+    if (!thd->locked_tables_mode)
+      thd->mdl_context.release_all_locks();
     my_ok(thd);
     break;
   case SQLCOM_XA_RECOVER:
@@ -4763,10 +4819,20 @@ finish:
     start_waiting_global_read_lock(thd);
   }
 
-  /* If commit fails, we should be able to reset the OK status. */
-  thd->stmt_da->can_overwrite_status= TRUE;
-  opt_implicit_commit(thd, CF_IMPLICIT_COMMIT_END);
-  thd->stmt_da->can_overwrite_status= FALSE;
+  if (stmt_causes_implicit_commit(thd, CF_IMPLICIT_COMMIT_END))
+  {
+    /* If commit fails, we should be able to reset the OK status. */
+    thd->stmt_da->can_overwrite_status= TRUE;
+    /* Commit or rollback the statement transaction. */
+    thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd);
+    /* Commit the normal transaction if one is active. */
+    trans_commit_implicit(thd);
+    /* Close tables and release metadata locks. */
+    close_thread_tables(thd);
+    if (!thd->locked_tables_mode)
+      thd->mdl_context.release_all_locks();
+    thd->stmt_da->can_overwrite_status= FALSE;
+  }
 
   DBUG_RETURN(res || thd->is_error());
 
@@ -6759,6 +6825,9 @@ bool reload_acl_and_cache(THD *thd, ulon
     query_cache.flush();			// RESET QUERY CACHE
   }
 #endif /*HAVE_QUERY_CACHE*/
+
+  DBUG_ASSERT(thd->locked_tables_mode || !thd->mdl_context.has_locks());
+
   /*
     Note that if REFRESH_READ_LOCK bit is set then REFRESH_TABLES is set too
     (see sql_yacc.yy)

=== modified file 'sql/sql_prepare.cc'
--- a/sql/sql_prepare.cc	2009-02-05 18:10:29 +0000
+++ b/sql/sql_prepare.cc	2009-03-23 18:17:10 +0000
@@ -1673,7 +1673,13 @@ static bool mysql_test_create_table(Prep
     if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
     {
       lex->link_first_table_back(create_table, link_to_local);
-      create_table->open_type= TABLE_LIST::OPEN_OR_CREATE;
+      /*
+        The open and lock strategies will be set again once the
+        statement is executed. These values are only meaningful
+        for the prepare phase.
+      */
+      create_table->open_strategy= TABLE_LIST::OPEN_IF_EXISTS;
+      create_table->lock_strategy= TABLE_LIST::SHARED_MDL;
     }
 
     if (open_normal_and_derived_tables(stmt->thd, lex->query_tables, 0))
@@ -3141,6 +3147,7 @@ bool Prepared_statement::prepare(const c
   bool error;
   Statement stmt_backup;
   Query_arena *old_stmt_arena;
+  MDL_ticket *mdl_savepoint= NULL;
   DBUG_ENTER("Prepared_statement::prepare");
   /*
     If this is an SQLCOM_PREPARE, we also increase Com_prepare_sql.
@@ -3199,6 +3206,13 @@ bool Prepared_statement::prepare(const c
   */
   DBUG_ASSERT(thd->change_list.is_empty());
 
+  /*
+    Marker used to release metadata locks acquired while the prepared
+    statement is being checked.
+  */
+  if (thd->in_multi_stmt_transaction())
+    mdl_savepoint= thd->mdl_context.mdl_savepoint();
+
   /* 
    The only case where we should have items in the thd->free_list is
    after stmt->set_params_from_vars(), which may in some cases create
@@ -3222,6 +3236,15 @@ bool Prepared_statement::prepare(const c
 
   lex_end(lex);
   cleanup_stmt();
+  /*
+    If not inside a multi-statement transaction, the metadata locks have
+    already been released and the rollback_to_savepoint is a nop.
+    Otherwise, release acquired locks -- a NULL mdl_savepoint means that
+    all locks are going to be released or that the transaction didn't
+    own any locks.
+  */
+  if (!thd->locked_tables_mode)
+    thd->mdl_context.rollback_to_savepoint(mdl_savepoint);
   thd->restore_backup_statement(this, &stmt_backup);
   thd->stmt_arena= old_stmt_arena;
 

=== modified file 'sql/sql_servers.cc'
--- a/sql/sql_servers.cc	2009-03-02 21:18:26 +0000
+++ b/sql/sql_servers.cc	2009-03-06 22:17:00 +0000
@@ -39,6 +39,7 @@
 #include <stdarg.h>
 #include "sp_head.h"
 #include "sp.h"
+#include "transaction.h"
 
 /*
   We only use 1 mutex to guard the data structures - THR_LOCK_servers.
@@ -223,9 +224,6 @@ bool servers_reload(THD *thd)
   bool return_val= TRUE;
   DBUG_ENTER("servers_reload");
 
-  /* Can't have locked tables here */
-  thd->locked_tables_list.unlock_locked_tables(thd);
-
   DBUG_PRINT("info", ("locking servers_cache"));
   rw_wrlock(&THR_LOCK_servers);
 
@@ -251,7 +249,10 @@ bool servers_reload(THD *thd)
   }
 
 end:
+  trans_commit_implicit(thd);
   close_thread_tables(thd);
+  if (!thd->locked_tables_mode)
+    thd->mdl_context.release_all_locks();
   DBUG_PRINT("info", ("unlocking servers_cache"));
   rw_unlock(&THR_LOCK_servers);
   DBUG_RETURN(return_val);

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2009-03-09 12:17:41 +0000
+++ b/sql/sql_table.cc	2009-03-27 22:06:26 +0000
@@ -4400,6 +4400,8 @@ static bool mysql_admin_table(THD* thd, 
       trans_commit_stmt(thd);
       trans_commit(thd);
       close_thread_tables(thd);
+      if (!thd->locked_tables_mode)
+        thd->mdl_context.release_all_locks();
       lex->reset_query_tables_list(FALSE);
       table->table=0;				// For query cache
       if (protocol->write())
@@ -4449,7 +4451,10 @@ static bool mysql_admin_table(THD* thd, 
       {
         DBUG_PRINT("admin", ("recreating table"));
         trans_rollback_stmt(thd);
+        trans_rollback(thd);
         close_thread_tables(thd);
+        if (!thd->locked_tables_mode)
+          thd->mdl_context.release_all_locks();
         tmp_disable_binlog(thd); // binlogging is done by caller if wanted
         result_code= mysql_recreate_table(thd, table);
         reenable_binlog(thd);
@@ -4563,13 +4568,16 @@ send_result_message:
         We have to end the row, so analyze could return more rows.
       */
       trans_commit_stmt(thd);
+      trans_commit(thd);
+      close_thread_tables(thd);
+      if (!thd->locked_tables_mode)
+        thd->mdl_context.release_all_locks();
       protocol->store(STRING_WITH_LEN("note"), system_charset_info);
       protocol->store(STRING_WITH_LEN(
           "Table does not support optimize, doing recreate + analyze instead"),
                       system_charset_info);
       if (protocol->write())
         goto err;
-      close_thread_tables(thd);
       DBUG_PRINT("info", ("HA_ADMIN_TRY_ALTER, trying analyze..."));
       TABLE_LIST *save_next_local= table->next_local,
                  *save_next_global= table->next_global;
@@ -4586,7 +4594,10 @@ send_result_message:
       if (thd->stmt_da->is_ok())
         thd->stmt_da->reset_diagnostics_area();
       trans_commit_stmt(thd);
+      trans_commit(thd);
       close_thread_tables(thd);
+      if (!thd->locked_tables_mode)
+        thd->mdl_context.release_all_locks();
       if (!result_code) // recreation went ok
       {
         if ((table->table= open_ltable(thd, table, lock_type, 0)) &&
@@ -4680,6 +4691,7 @@ send_result_message:
         query_cache_invalidate3(thd, table->table, 0);
       }
     }
+    /* Error path, a admin command failed. */
     trans_commit_stmt(thd);
     trans_commit_implicit(thd);
     close_thread_tables(thd);

=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc	2009-03-09 12:17:41 +0000
+++ b/sql/sql_view.cc	2009-03-27 22:06:26 +0000
@@ -394,7 +394,8 @@ bool mysql_create_view(THD *thd, TABLE_L
     goto err;
 
   lex->link_first_table_back(view, link_to_local);
-  view->open_type= TABLE_LIST::TAKE_EXCLUSIVE_MDL;
+  view->open_strategy= TABLE_LIST::OPEN_STUB;
+  view->lock_strategy= TABLE_LIST::EXCLUSIVE_MDL;
 
   if (open_and_lock_tables(thd, lex->query_tables))
   {

=== modified file 'sql/table.h'
--- a/sql/table.h	2009-03-04 20:29:16 +0000
+++ b/sql/table.h	2009-03-18 12:49:07 +0000
@@ -1305,24 +1305,33 @@ struct TABLE_LIST
   bool          prelocking_placeholder;
   /**
      Indicates that if TABLE_LIST object corresponds to the table/view
-     which requires special handling/meta-data locking.
+     which requires special handling.
   */
   enum
   {
-    /* Normal open, shared metadata lock should be taken. */
-    NORMAL_OPEN= 0,
-    /*
-      It's target table of CREATE TABLE ... SELECT so we should
-      either open table if it exists (and take shared metadata lock)
-      or take exclusive metadata lock if it doesn't exist.
-    */
-    OPEN_OR_CREATE,
+    /* Normal open. */
+    OPEN_NORMAL= 0,
+    /* Associate a table share only if the the table exists. */
+    OPEN_IF_EXISTS,
+    /* Don't associate a table share. */
+    OPEN_STUB
+  } open_strategy;
+  /**
+    Indicates the locking strategy for the object being opened:
+    whether the associated metadata lock is shared or exclusive.
+  */
+  enum
+  {
+    /* Take a shared metadata lock before the object is opened. */
+    SHARED_MDL= 0,
     /*
-      It's target view of CREATE/ALTER VIEW. We should take exclusive
-      metadata lock for this table list element.
+       Take a exclusive metadata lock before the object is opened.
+       If opening is successful, downgrade to a shared lock.
     */
-    TAKE_EXCLUSIVE_MDL
-  } open_type;
+    EXCLUSIVE_DOWNGRADABLE_MDL,
+    /* Take a exclusive metadata lock before the object is opened. */
+    EXCLUSIVE_MDL
+  } lock_strategy;
   /* For transactional locking. */
   int           lock_timeout;           /* NOWAIT or WAIT [X]               */
   bool          lock_transactional;     /* If transactional lock requested. */

=== modified file 'sql/transaction.cc'
--- a/sql/transaction.cc	2009-01-26 17:19:14 +0000
+++ b/sql/transaction.cc	2009-03-06 22:17:00 +0000
@@ -98,6 +98,10 @@ bool trans_begin(THD *thd, uint flags)
 
   thd->locked_tables_list.unlock_locked_tables(thd);
 
+  DBUG_ASSERT(!thd->locked_tables_mode);
+
+  thd->mdl_context.release_all_locks();
+
   if (trans_commit_implicit(thd))
     DBUG_RETURN(TRUE);
 
@@ -336,6 +340,13 @@ bool trans_savepoint(THD *thd, LEX_STRIN
   newsv->prev= thd->transaction.savepoints;
   thd->transaction.savepoints= newsv;
 
+  /*
+    Remember the last acquired lock before the savepoint was set.
+    This is used as a marker to only release locks acquired after
+    the setting of this savepoint.
+  */
+  newsv->mdl_savepoint = thd->mdl_context.mdl_savepoint();
+
   DBUG_RETURN(FALSE);
 }
 
@@ -380,6 +391,10 @@ bool trans_rollback_to_savepoint(THD *th
 
   thd->transaction.savepoints= sv;
 
+  /* Release metadata locks that were acquired during this savepoint unit. */
+  if (!res && !thd->locked_tables_mode)
+    thd->mdl_context.rollback_to_savepoint(sv->mdl_savepoint);
+
   DBUG_RETURN(test(res));
 }
 

=== modified file 'storage/falcon/StorageVersion.h'
--- a/storage/falcon/StorageVersion.h	2009-03-27 18:03:33 +0000
+++ b/storage/falcon/StorageVersion.h	2009-03-31 17:52:54 +0000
@@ -14,5 +14,5 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 
-#define FALCON_VERSION	"T1.5-3"
-#define FALCON_DATE		"27 March, 2009"
+#define FALCON_VERSION	"T1.5-4"
+#define FALCON_DATE		"31 March, 2009"

Attachment: [text/bzr-bundle] bzr/hky@sun.com-20090331202425-9j6894frsl0m0frp.bundle
Thread
bzr push into mysql-6.0-falcon-team branch (hky:3090)Hakan Kuecuekyilmaz1 Apr