List:Commits« Previous MessageNext Message »
From:dlenev Date:April 25 2008 9:17am
Subject:bk commit into 6.1 tree (dlenev:1.2609) BUG#35519
View as plain text  
Below is the list of changes that have just been committed into a local
6.1 repository of dlenev.  When dlenev does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-04-25 13:16:47+04:00, dlenev@stripped +4 -0
  Fix for bug #35519 "Foreign keys: create fails with InnoDB".
  
  In --foreign-key-all-engines mode attempt to create table foreign key
  constraint for InnoDB table led to "Can't create table '...' (errno: 150)"
  error.
  
  This is happened because in addition to new SQL-layer FK we still were
  trying to create old-style, 'native' InnoDB FK.
  
  This fix disables creation of 'native' InnoDB FK in new mode. It also
  temporarily disallows to open tables with 'native' foreign keys in new
  mode in order to avoid problems until we will figure out what is the
  sensible, upgrade-friendly behavior in this case.
  
  Note to InnoDB developers: this patch probably can be ignored since it
  is unlikely to appear in the main tree as it is now.

  mysql-test/r/foreign_key_all_engines_2.result@stripped, 2008-04-25 13:08:32+04:00, dlenev@stripped +6 -0
    Added test for bug #35519 "Foreign keys: create fails with InnoDB".

  mysql-test/t/foreign_key_all_engines_2.test@stripped, 2008-04-25 13:08:32+04:00, dlenev@stripped +17 -0
    Added test for bug #35519 "Foreign keys: create fails with InnoDB".

  sql/mysql_priv.h@stripped, 2008-04-25 13:08:32+04:00, dlenev@stripped +1 -1
    Made opt_fk_all_engines available from ha_innodb.cc.

  storage/innobase/handler/ha_innodb.cc@stripped, 2008-04-25 13:08:32+04:00, dlenev@stripped +26 -1
    Do not create 'native' InnoDB foreign keys in --foreign-key-all-engines
    mode. Also added temporary hack doesn't allow to open tables with 'native'
    foreign keys in new mode. This is done in order to avoid problems until
    we will figure out what is the sensible, upgrade-friendly behavior in this
    case.

diff -Nrup a/mysql-test/r/foreign_key_all_engines_2.result b/mysql-test/r/foreign_key_all_engines_2.result
--- a/mysql-test/r/foreign_key_all_engines_2.result	2008-04-22 19:37:15 +04:00
+++ b/mysql-test/r/foreign_key_all_engines_2.result	2008-04-25 13:08:32 +04:00
@@ -1,4 +1,10 @@
 drop tables if exists t1, t2;
+create table t1 (s1 int primary key) engine=innodb;
+create table t2 (s1 int, foreign key (s1) references t1 (s1)) engine=innodb;
+drop table t2;
+create table t2 (s1 int references t1 (s1)) engine=innodb;
+drop table t1, t2;
+drop tables if exists t1, t2;
 create table t1 (s1 int primary key);
 create table t2 (s1 int, foreign key (s1) references t2 (s1))
 partition by list (s1) (partition p1 values in (1));
diff -Nrup a/mysql-test/t/foreign_key_all_engines_2.test b/mysql-test/t/foreign_key_all_engines_2.test
--- a/mysql-test/t/foreign_key_all_engines_2.test	2008-04-22 19:37:15 +04:00
+++ b/mysql-test/t/foreign_key_all_engines_2.test	2008-04-25 13:08:32 +04:00
@@ -3,7 +3,24 @@
 # WL#148 "Foreign keys". This file is for tests which depend on
 # non-trivial features or storage engines.
 #
+--source include/have_innodb.inc
 --source include/have_partition.inc
+
+
+#
+# Bug #35519 "Foreign keys: create fails with InnoDB"
+# 
+# In --foreign-key-all-engines mode attempt to create foreign key on
+# InnoDB table failed due to the fact that in addition to new SQL-layer
+# FK we were also creating native InnoDB's FKs.
+--disable_warnings
+drop tables if exists t1, t2;
+--enable_warnings
+create table t1 (s1 int primary key) engine=innodb;
+create table t2 (s1 int, foreign key (s1) references t1 (s1)) engine=innodb;
+drop table t2;
+create table t2 (s1 int references t1 (s1)) engine=innodb;
+drop table t1, t2;
 
 
 # 
diff -Nrup a/sql/mysql_priv.h b/sql/mysql_priv.h
--- a/sql/mysql_priv.h	2008-04-22 16:18:49 +04:00
+++ b/sql/mysql_priv.h	2008-04-25 13:08:32 +04:00
@@ -2006,11 +2006,11 @@ extern char *default_tz_name;
 #if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
 extern my_bool opt_large_pages;
 extern uint opt_large_page_size;
+extern my_bool opt_fk_all_engines;
 #endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
 #ifdef MYSQL_SERVER
 extern char *opt_logname, *opt_slow_logname;
 extern const char *log_output_str;
-extern my_bool opt_fk_all_engines;
 
 extern MYSQL_BIN_LOG mysql_bin_log;
 extern LOGGER logger;
diff -Nrup a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
--- a/storage/innobase/handler/ha_innodb.cc	2008-03-12 11:25:26 +03:00
+++ b/storage/innobase/handler/ha_innodb.cc	2008-04-25 13:08:32 +04:00
@@ -2360,6 +2360,29 @@ ha_innobase::open(
 		DBUG_RETURN(HA_ERR_NO_SUCH_TABLE);
 	}
 
+        if (opt_fk_all_engines &&
+            (UT_LIST_GET_FIRST(ib_table->referenced_list) ||
+             UT_LIST_GET_FIRST(ib_table->foreign_list))) {
+                /* This is a temporary hack with allows to avoid problems
+                with InnoDB tables with 'native' FKs in
+                --foreign-key-all-engines mode. It will go away once we
+                figure out how we should exactly behave in such cases in
+                order to enable sensible upgrade path. (According to LLD
+                of WL#148 native FKs should be ignored in new mode. I.e.
+                we should not perform any checks or actions for them or
+                show them in I_S tables and SHOW CREATE TABLE statement.
+                But this behavior can be problematic for mysql_upgrade
+                and therefore LLD is likely to be adjusted). */
+                sql_print_error("Attempt to open InnoDB table '%s' which has "
+                                "'native' foreign keys defined while running "
+                                "in --foreign-key-all-engines mode.\n",
+                                norm_name);
+                free_share(share);
+                my_free(upd_buff, MYF(0));
+                dict_table_decrement_handle_count(ib_table);
+                DBUG_RETURN(HA_ERR_UNSUPPORTED);
+        }
+
 	prebuilt = row_create_prebuilt(ib_table);
 
 	prebuilt->mysql_row_len = table->s->reclength;
@@ -5075,7 +5098,9 @@ ha_innobase::create(
 		}
 	}
 
-	if (*trx->mysql_query_str) {
+        /* In --foreign-key-all-engines mode creation of 'native'
+        InnoDB foreign key constraints shoudl be disabled. */
+	if (!opt_fk_all_engines && *trx->mysql_query_str) {
 		error = row_table_add_foreign_constraints(trx,
 			*trx->mysql_query_str, norm_name,
 			create_info->options & HA_LEX_CREATE_TMP_TABLE);
Thread
bk commit into 6.1 tree (dlenev:1.2609) BUG#35519dlenev25 Apr
  • Re: bk commit into 6.1 tree (dlenev:1.2609) BUG#35519Konstantin Osipov25 Apr