Loading mysql-test/r/innodb.result +21 −21 Original line number Diff line number Diff line Loading @@ -1378,9 +1378,9 @@ insert into `t2`values ( 1 ) ; create table `t3` (`id` int( 11 ) not null default '0',key `id` ( `id` ) ,constraint `t2_id_fk` foreign key ( `id` ) references `t2` (`id` )) engine = innodb; insert into `t3`values ( 1 ) ; delete t3,t2,t1 from t1,t2,t3 where t1.id =1 and t2.id = t1.id and t3.id = t2.id; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)) update t1,t2,t3 set t3.id=5, t2.id=6, t1.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)) update t3 set t3.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id; ERROR 42S22: Unknown column 't1.id' in 'where clause' drop table t3,t2,t1; Loading @@ -1392,7 +1392,7 @@ foreign key(pid) references t1(id) on delete cascade) engine=innodb; insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6), (8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14); delete from t1 where id=0; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`pid`) REFERENCES `t1` (`id`) ON DELETE CASCADE) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`pid`) REFERENCES `t1` (`id`) ON DELETE CASCADE) delete from t1 where id=15; delete from t1 where id=0; drop table t1; Loading Loading @@ -2633,18 +2633,18 @@ v INT, CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id) ) ENGINE=InnoDB; INSERT INTO t2 VALUES(2); ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`)) ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`)) INSERT INTO t1 VALUES(1); INSERT INTO t2 VALUES(1); DELETE FROM t1 WHERE id = 1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`)) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`)) DROP TABLE t1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails SET FOREIGN_KEY_CHECKS=0; DROP TABLE t1; SET FOREIGN_KEY_CHECKS=1; INSERT INTO t2 VALUES(3); ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`)) ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`)) DROP TABLE t2; create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1; insert into t1 values (1),(2); Loading Loading @@ -2922,23 +2922,23 @@ create table t4(a int primary key,constraint foreign key(a)references t3(a)) row insert into t1 values(1); insert into t3 values(1); insert into t2 values(2); ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test/t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) insert into t4 values(2); ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test/t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) insert into t2 values(1); insert into t4 values(1); update t1 set a=2; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) update t2 set a=2; ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test/t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) update t3 set a=2; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) update t4 set a=2; ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test/t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) truncate t1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) truncate t3; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) truncate t2; truncate t4; truncate t1; Loading Loading @@ -2993,7 +2993,7 @@ create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=innod create table t2 (s1 binary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb; insert into t1 values(1,0x4100),(2,0x41),(3,0x4120),(4,0x42); insert into t2 values(0x42); ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) insert into t2 values(0x41); select hex(s1) from t2; hex(s1) Loading @@ -3003,11 +3003,11 @@ select hex(s1) from t2; hex(s1) 4100 update t1 set s1=0x12 where a=1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) update t1 set s1=0x12345678 where a=1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) update t1 set s1=0x123457 where a=1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) update t1 set s1=0x1220 where a=1; select hex(s1) from t2; hex(s1) Loading @@ -3021,11 +3021,11 @@ select hex(s1) from t2; hex(s1) 4200 delete from t1 where a=1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) delete from t1 where a=2; update t2 set s1=0x4120; delete from t1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) delete from t1 where a!=3; select a,hex(s1) from t1; a hex(s1) Loading @@ -3051,7 +3051,7 @@ hex(s1) 12 delete from t1 where a=1; delete from t1 where a=2; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) select a,hex(s1) from t1; a hex(s1) 2 12 Loading mysql-test/t/innodb.test +13 −0 Original line number Diff line number Diff line Loading @@ -2510,3 +2510,16 @@ BEGIN; INSERT INTO t1 VALUES (1); OPTIMIZE TABLE t1; DROP TABLE t1; ####################################################################### # # # Please, DO NOT TOUCH this file as well as the innodb.result file. # # These files are to be modified ONLY BY INNOBASE guys. # # # # Use innodb_mysql.[test|result] files instead. # # # # If nevertheless you need to make some changes here, please, forward # # your commit message To: dev@innodb.com Cc: dev-innodb@mysql.com # # (otherwise your changes may be erased). # # # ####################################################################### sql/ha_innodb.cc +172 −27 Original line number Diff line number Diff line Loading @@ -134,6 +134,7 @@ extern "C" { #include "../storage/innobase/include/fil0fil.h" #include "../storage/innobase/include/trx0xa.h" #include "../storage/innobase/include/thr0loc.h" #include "../storage/innobase/include/ha_prototypes.h" } #define HA_INNOBASE_ROWS_IN_TABLE 10000 /* to get optimization right */ Loading Loading @@ -705,6 +706,61 @@ innobase_get_cset_width( } } /********************************************************************** Converts an identifier to a table name. NOTE that the exact prototype of this function has to be in /innobase/dict/dict0dict.c! */ extern "C" void innobase_convert_from_table_id( /*===========================*/ char* to, /* out: converted identifier */ const char* from, /* in: identifier to convert */ ulint len) /* in: length of 'to', in bytes */ { uint errors; strconvert(current_thd->charset(), from, &my_charset_filename, to, len, &errors); } /********************************************************************** Converts an identifier to UTF-8. NOTE that the exact prototype of this function has to be in /innobase/dict/dict0dict.c! */ extern "C" void innobase_convert_from_id( /*=====================*/ char* to, /* out: converted identifier */ const char* from, /* in: identifier to convert */ ulint len) /* in: length of 'to', in bytes */ { uint errors; strconvert(current_thd->charset(), from, system_charset_info, to, len, &errors); } /********************************************************************** Removes the filename encoding of a table or database name. NOTE that the exact prototype of this function has to be in /innobase/dict/dict0dict.c! */ extern "C" void innobase_convert_from_filename( /*===========================*/ char* s) /* in: identifier; out: decoded identifier */ { uint errors; strconvert(&my_charset_filename, s, system_charset_info, s, strlen(s), &errors); } /********************************************************************** Compares NUL-terminated UTF-8 strings case insensitively. Loading Loading @@ -735,6 +791,21 @@ innobase_casedn_str( my_casedn_str(system_charset_info, a); } /************************************************************************** Determines the connection character set. NOTE that the exact prototype of this function has to be in /innobase/dict/dict0dict.c! */ extern "C" struct charset_info_st* innobase_get_charset( /*=================*/ /* out: connection character set */ void* mysql_thd) /* in: MySQL thread handle */ { return(((THD*) mysql_thd)->charset()); } /************************************************************************* Creates a temporary file. */ extern "C" Loading Loading @@ -780,6 +851,25 @@ innobase_mysql_tmpfile(void) return(fd2); } /************************************************************************* Wrapper around MySQL's copy_and_convert function, see it for documentation. */ extern "C" ulint innobase_convert_string( /*====================*/ void* to, ulint to_length, CHARSET_INFO* to_cs, const void* from, ulint from_length, CHARSET_INFO* from_cs, uint* errors) { return(copy_and_convert((char*)to, to_length, to_cs, (const char*)from, from_length, from_cs, errors)); } /************************************************************************* Gets the InnoDB transaction handle for a MySQL handler object, creates an InnoDB transaction struct if the corresponding MySQL thread struct still Loading Loading @@ -1115,23 +1205,69 @@ innobase_invalidate_query_cache( } /********************************************************************* Get the quote character to be used in SQL identifiers. Display an SQL identifier. This definition must match the one in innobase/ut/ut0ut.c! */ extern "C" int mysql_get_identifier_quote_char( /*============================*/ /* out: quote character to be used in SQL identifiers; EOF if none */ void innobase_print_identifier( /*======================*/ FILE* f, /* in: output stream */ trx_t* trx, /* in: transaction */ ibool table_id,/* in: TRUE=decode table name */ const char* name, /* in: name to print */ ulint namelen)/* in: length of name */ { const char* s = name; char* qname = NULL; int q; if (table_id) { /* Decode the table name. The filename_to_tablename() function expects a NUL-terminated string. The input and output strings buffers must not be shared. The function only produces more output when the name contains other characters than [0-9A-Z_a-z]. */ char* temp_name = my_malloc(namelen + 1, MYF(MY_WME)); uint qnamelen = namelen + (1 + sizeof srv_mysql50_table_name_prefix); if (temp_name) { qname = my_malloc(qnamelen, MYF(MY_WME)); if (qname) { memcpy(temp_name, name, namelen); temp_name[namelen] = 0; s = qname; namelen = filename_to_tablename(temp_name, qname, qnamelen); } my_free(temp_name, MYF(0)); } } if (!trx || !trx->mysql_thd) { return(EOF); q = '"'; } else { q = get_quote_char_for_identifier((THD*) trx->mysql_thd, s, (int) namelen); } if (q == EOF) { fwrite(s, 1, namelen, f); } else { const char* e = s + namelen; putc(q, f); while (s < e) { int c = *s++; if (c == q) { putc(c, f); } return(get_quote_char_for_identifier((THD*) trx->mysql_thd, name, (int) namelen)); putc(c, f); } putc(q, f); } my_free(qname, MYF(MY_ALLOW_ZERO_PTR)); } /************************************************************************** Loading Loading @@ -1247,6 +1383,24 @@ innobase_init(void) ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)MYSQL_TYPE_VARCHAR); #ifdef UNIV_DEBUG static const char test_filename[] = "-@"; char test_tablename[sizeof test_filename + sizeof srv_mysql50_table_name_prefix]; if ((sizeof test_tablename) - 1 != filename_to_tablename(test_filename, test_tablename, sizeof test_tablename) || strncmp(test_tablename, srv_mysql50_table_name_prefix, sizeof srv_mysql50_table_name_prefix) || strcmp(test_tablename + sizeof srv_mysql50_table_name_prefix, test_filename)) { sql_print_error("tablename encoding has been changed"); goto error; } #endif /* UNIV_DEBUG */ /* Check that values don't overflow on 32-bit systems. */ if (sizeof(ulint) == 4) { if (innobase_buffer_pool_size > UINT_MAX32) { Loading Loading @@ -2215,8 +2369,7 @@ ha_innobase::open( /* Get pointer to a table object in InnoDB dictionary cache */ ib_table = dict_table_get_and_increment_handle_count( norm_name, NULL); ib_table = dict_table_get_and_increment_handle_count(norm_name); if (NULL == ib_table) { ut_print_timestamp(stderr); Loading Loading @@ -4132,6 +4285,9 @@ ha_innobase::index_prev( mysql_byte* buf) /* in/out: buffer for previous row in MySQL format */ { statistic_increment(current_thd->status_var.ha_read_prev_count, &LOCK_status); return(general_fetch(buf, ROW_SEL_PREV, 0)); } Loading Loading @@ -4668,7 +4824,7 @@ ha_innobase::create( /* Get the transaction associated with the current thd, or create one if not yet created */ parent_trx = check_trx_exists(current_thd); parent_trx = check_trx_exists(thd); /* In case MySQL calls this in the middle of a SELECT query, release possible adaptive hash latch to avoid deadlocks of threads */ Loading Loading @@ -4764,20 +4920,9 @@ ha_innobase::create( } } if (current_thd->query != NULL) { LEX_STRING q; if (thd->convert_string(&q, system_charset_info, current_thd->query, current_thd->query_length, current_thd->charset())) { error = HA_ERR_OUT_OF_MEM; goto cleanup; } if (thd->query != NULL) { error = row_table_add_foreign_constraints(trx, q.str, norm_name, thd->query, norm_name, create_info->options & HA_LEX_CREATE_TMP_TABLE); error = convert_error_code_to_mysql(error, NULL); Loading @@ -4797,7 +4942,7 @@ ha_innobase::create( log_buffer_flush_to_disk(); innobase_table = dict_table_get(norm_name, NULL); innobase_table = dict_table_get(norm_name); DBUG_ASSERT(innobase_table != 0); Loading Loading @@ -4933,7 +5078,7 @@ ha_innobase::delete_table( /* Get the transaction associated with the current thd, or create one if not yet created */ parent_trx = check_trx_exists(current_thd); parent_trx = check_trx_exists(thd); /* In case MySQL calls this in the middle of a SELECT query, release possible adaptive hash latch to avoid deadlocks of threads */ Loading storage/innobase/CMakeLists.txt +1 −1 Original line number Diff line number Diff line Loading @@ -32,4 +32,4 @@ ADD_LIBRARY(innobase btr/btr0btr.c btr/btr0cur.c btr/btr0pcur.c btr/btr0sea.c thr/thr0loc.c trx/trx0purge.c trx/trx0rec.c trx/trx0roll.c trx/trx0rseg.c trx/trx0sys.c trx/trx0trx.c trx/trx0undo.c usr/usr0sess.c ut/ut0byte.c ut/ut0dbg.c ut/ut0mem.c ut/ut0rnd.c ut/ut0ut.c ut/ut0vec.c) ut/ut0byte.c ut/ut0dbg.c ut/ut0mem.c ut/ut0rnd.c ut/ut0ut.c ut/ut0vec.c ut/ut0list.c ut/ut0wqueue.c) storage/innobase/Makefile.am +1 −1 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ EXTRA_DIST = include/btr0btr.h include/btr0btr.ic include/btr0cur.h include/btr include/univ.i include/usr0sess.h include/usr0sess.ic include/usr0types.h \ include/ut0byte.h include/ut0byte.ic include/ut0dbg.h include/ut0lst.h \ include/ut0mem.h include/ut0mem.ic include/ut0rnd.h include/ut0rnd.ic \ include/ut0sort.h include/ut0ut.h include/ut0ut.ic include/ut0vec.h include/ut0vec.ic \ include/ut0sort.h include/ut0ut.h include/ut0ut.ic include/ut0vec.h include/ut0vec.ic include/ha_prototypes.h \ CMakeLists.txt noinst_LIBRARIES = libinnobase.a Loading Loading
mysql-test/r/innodb.result +21 −21 Original line number Diff line number Diff line Loading @@ -1378,9 +1378,9 @@ insert into `t2`values ( 1 ) ; create table `t3` (`id` int( 11 ) not null default '0',key `id` ( `id` ) ,constraint `t2_id_fk` foreign key ( `id` ) references `t2` (`id` )) engine = innodb; insert into `t3`values ( 1 ) ; delete t3,t2,t1 from t1,t2,t3 where t1.id =1 and t2.id = t1.id and t3.id = t2.id; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)) update t1,t2,t3 set t3.id=5, t2.id=6, t1.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)) update t3 set t3.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id; ERROR 42S22: Unknown column 't1.id' in 'where clause' drop table t3,t2,t1; Loading @@ -1392,7 +1392,7 @@ foreign key(pid) references t1(id) on delete cascade) engine=innodb; insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6), (8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14); delete from t1 where id=0; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`pid`) REFERENCES `t1` (`id`) ON DELETE CASCADE) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`pid`) REFERENCES `t1` (`id`) ON DELETE CASCADE) delete from t1 where id=15; delete from t1 where id=0; drop table t1; Loading Loading @@ -2633,18 +2633,18 @@ v INT, CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id) ) ENGINE=InnoDB; INSERT INTO t2 VALUES(2); ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`)) ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`)) INSERT INTO t1 VALUES(1); INSERT INTO t2 VALUES(1); DELETE FROM t1 WHERE id = 1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`)) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`)) DROP TABLE t1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails SET FOREIGN_KEY_CHECKS=0; DROP TABLE t1; SET FOREIGN_KEY_CHECKS=1; INSERT INTO t2 VALUES(3); ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`)) ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`)) DROP TABLE t2; create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1; insert into t1 values (1),(2); Loading Loading @@ -2922,23 +2922,23 @@ create table t4(a int primary key,constraint foreign key(a)references t3(a)) row insert into t1 values(1); insert into t3 values(1); insert into t2 values(2); ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test/t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) insert into t4 values(2); ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test/t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) insert into t2 values(1); insert into t4 values(1); update t1 set a=2; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) update t2 set a=2; ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test/t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) update t3 set a=2; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) update t4 set a=2; ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test/t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) truncate t1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) truncate t3; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) truncate t2; truncate t4; truncate t1; Loading Loading @@ -2993,7 +2993,7 @@ create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=innod create table t2 (s1 binary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb; insert into t1 values(1,0x4100),(2,0x41),(3,0x4120),(4,0x42); insert into t2 values(0x42); ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) insert into t2 values(0x41); select hex(s1) from t2; hex(s1) Loading @@ -3003,11 +3003,11 @@ select hex(s1) from t2; hex(s1) 4100 update t1 set s1=0x12 where a=1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) update t1 set s1=0x12345678 where a=1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) update t1 set s1=0x123457 where a=1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) update t1 set s1=0x1220 where a=1; select hex(s1) from t2; hex(s1) Loading @@ -3021,11 +3021,11 @@ select hex(s1) from t2; hex(s1) 4200 delete from t1 where a=1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) delete from t1 where a=2; update t2 set s1=0x4120; delete from t1; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) delete from t1 where a!=3; select a,hex(s1) from t1; a hex(s1) Loading @@ -3051,7 +3051,7 @@ hex(s1) 12 delete from t1 where a=1; delete from t1 where a=2; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) select a,hex(s1) from t1; a hex(s1) 2 12 Loading
mysql-test/t/innodb.test +13 −0 Original line number Diff line number Diff line Loading @@ -2510,3 +2510,16 @@ BEGIN; INSERT INTO t1 VALUES (1); OPTIMIZE TABLE t1; DROP TABLE t1; ####################################################################### # # # Please, DO NOT TOUCH this file as well as the innodb.result file. # # These files are to be modified ONLY BY INNOBASE guys. # # # # Use innodb_mysql.[test|result] files instead. # # # # If nevertheless you need to make some changes here, please, forward # # your commit message To: dev@innodb.com Cc: dev-innodb@mysql.com # # (otherwise your changes may be erased). # # # #######################################################################
sql/ha_innodb.cc +172 −27 Original line number Diff line number Diff line Loading @@ -134,6 +134,7 @@ extern "C" { #include "../storage/innobase/include/fil0fil.h" #include "../storage/innobase/include/trx0xa.h" #include "../storage/innobase/include/thr0loc.h" #include "../storage/innobase/include/ha_prototypes.h" } #define HA_INNOBASE_ROWS_IN_TABLE 10000 /* to get optimization right */ Loading Loading @@ -705,6 +706,61 @@ innobase_get_cset_width( } } /********************************************************************** Converts an identifier to a table name. NOTE that the exact prototype of this function has to be in /innobase/dict/dict0dict.c! */ extern "C" void innobase_convert_from_table_id( /*===========================*/ char* to, /* out: converted identifier */ const char* from, /* in: identifier to convert */ ulint len) /* in: length of 'to', in bytes */ { uint errors; strconvert(current_thd->charset(), from, &my_charset_filename, to, len, &errors); } /********************************************************************** Converts an identifier to UTF-8. NOTE that the exact prototype of this function has to be in /innobase/dict/dict0dict.c! */ extern "C" void innobase_convert_from_id( /*=====================*/ char* to, /* out: converted identifier */ const char* from, /* in: identifier to convert */ ulint len) /* in: length of 'to', in bytes */ { uint errors; strconvert(current_thd->charset(), from, system_charset_info, to, len, &errors); } /********************************************************************** Removes the filename encoding of a table or database name. NOTE that the exact prototype of this function has to be in /innobase/dict/dict0dict.c! */ extern "C" void innobase_convert_from_filename( /*===========================*/ char* s) /* in: identifier; out: decoded identifier */ { uint errors; strconvert(&my_charset_filename, s, system_charset_info, s, strlen(s), &errors); } /********************************************************************** Compares NUL-terminated UTF-8 strings case insensitively. Loading Loading @@ -735,6 +791,21 @@ innobase_casedn_str( my_casedn_str(system_charset_info, a); } /************************************************************************** Determines the connection character set. NOTE that the exact prototype of this function has to be in /innobase/dict/dict0dict.c! */ extern "C" struct charset_info_st* innobase_get_charset( /*=================*/ /* out: connection character set */ void* mysql_thd) /* in: MySQL thread handle */ { return(((THD*) mysql_thd)->charset()); } /************************************************************************* Creates a temporary file. */ extern "C" Loading Loading @@ -780,6 +851,25 @@ innobase_mysql_tmpfile(void) return(fd2); } /************************************************************************* Wrapper around MySQL's copy_and_convert function, see it for documentation. */ extern "C" ulint innobase_convert_string( /*====================*/ void* to, ulint to_length, CHARSET_INFO* to_cs, const void* from, ulint from_length, CHARSET_INFO* from_cs, uint* errors) { return(copy_and_convert((char*)to, to_length, to_cs, (const char*)from, from_length, from_cs, errors)); } /************************************************************************* Gets the InnoDB transaction handle for a MySQL handler object, creates an InnoDB transaction struct if the corresponding MySQL thread struct still Loading Loading @@ -1115,23 +1205,69 @@ innobase_invalidate_query_cache( } /********************************************************************* Get the quote character to be used in SQL identifiers. Display an SQL identifier. This definition must match the one in innobase/ut/ut0ut.c! */ extern "C" int mysql_get_identifier_quote_char( /*============================*/ /* out: quote character to be used in SQL identifiers; EOF if none */ void innobase_print_identifier( /*======================*/ FILE* f, /* in: output stream */ trx_t* trx, /* in: transaction */ ibool table_id,/* in: TRUE=decode table name */ const char* name, /* in: name to print */ ulint namelen)/* in: length of name */ { const char* s = name; char* qname = NULL; int q; if (table_id) { /* Decode the table name. The filename_to_tablename() function expects a NUL-terminated string. The input and output strings buffers must not be shared. The function only produces more output when the name contains other characters than [0-9A-Z_a-z]. */ char* temp_name = my_malloc(namelen + 1, MYF(MY_WME)); uint qnamelen = namelen + (1 + sizeof srv_mysql50_table_name_prefix); if (temp_name) { qname = my_malloc(qnamelen, MYF(MY_WME)); if (qname) { memcpy(temp_name, name, namelen); temp_name[namelen] = 0; s = qname; namelen = filename_to_tablename(temp_name, qname, qnamelen); } my_free(temp_name, MYF(0)); } } if (!trx || !trx->mysql_thd) { return(EOF); q = '"'; } else { q = get_quote_char_for_identifier((THD*) trx->mysql_thd, s, (int) namelen); } if (q == EOF) { fwrite(s, 1, namelen, f); } else { const char* e = s + namelen; putc(q, f); while (s < e) { int c = *s++; if (c == q) { putc(c, f); } return(get_quote_char_for_identifier((THD*) trx->mysql_thd, name, (int) namelen)); putc(c, f); } putc(q, f); } my_free(qname, MYF(MY_ALLOW_ZERO_PTR)); } /************************************************************************** Loading Loading @@ -1247,6 +1383,24 @@ innobase_init(void) ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)MYSQL_TYPE_VARCHAR); #ifdef UNIV_DEBUG static const char test_filename[] = "-@"; char test_tablename[sizeof test_filename + sizeof srv_mysql50_table_name_prefix]; if ((sizeof test_tablename) - 1 != filename_to_tablename(test_filename, test_tablename, sizeof test_tablename) || strncmp(test_tablename, srv_mysql50_table_name_prefix, sizeof srv_mysql50_table_name_prefix) || strcmp(test_tablename + sizeof srv_mysql50_table_name_prefix, test_filename)) { sql_print_error("tablename encoding has been changed"); goto error; } #endif /* UNIV_DEBUG */ /* Check that values don't overflow on 32-bit systems. */ if (sizeof(ulint) == 4) { if (innobase_buffer_pool_size > UINT_MAX32) { Loading Loading @@ -2215,8 +2369,7 @@ ha_innobase::open( /* Get pointer to a table object in InnoDB dictionary cache */ ib_table = dict_table_get_and_increment_handle_count( norm_name, NULL); ib_table = dict_table_get_and_increment_handle_count(norm_name); if (NULL == ib_table) { ut_print_timestamp(stderr); Loading Loading @@ -4132,6 +4285,9 @@ ha_innobase::index_prev( mysql_byte* buf) /* in/out: buffer for previous row in MySQL format */ { statistic_increment(current_thd->status_var.ha_read_prev_count, &LOCK_status); return(general_fetch(buf, ROW_SEL_PREV, 0)); } Loading Loading @@ -4668,7 +4824,7 @@ ha_innobase::create( /* Get the transaction associated with the current thd, or create one if not yet created */ parent_trx = check_trx_exists(current_thd); parent_trx = check_trx_exists(thd); /* In case MySQL calls this in the middle of a SELECT query, release possible adaptive hash latch to avoid deadlocks of threads */ Loading Loading @@ -4764,20 +4920,9 @@ ha_innobase::create( } } if (current_thd->query != NULL) { LEX_STRING q; if (thd->convert_string(&q, system_charset_info, current_thd->query, current_thd->query_length, current_thd->charset())) { error = HA_ERR_OUT_OF_MEM; goto cleanup; } if (thd->query != NULL) { error = row_table_add_foreign_constraints(trx, q.str, norm_name, thd->query, norm_name, create_info->options & HA_LEX_CREATE_TMP_TABLE); error = convert_error_code_to_mysql(error, NULL); Loading @@ -4797,7 +4942,7 @@ ha_innobase::create( log_buffer_flush_to_disk(); innobase_table = dict_table_get(norm_name, NULL); innobase_table = dict_table_get(norm_name); DBUG_ASSERT(innobase_table != 0); Loading Loading @@ -4933,7 +5078,7 @@ ha_innobase::delete_table( /* Get the transaction associated with the current thd, or create one if not yet created */ parent_trx = check_trx_exists(current_thd); parent_trx = check_trx_exists(thd); /* In case MySQL calls this in the middle of a SELECT query, release possible adaptive hash latch to avoid deadlocks of threads */ Loading
storage/innobase/CMakeLists.txt +1 −1 Original line number Diff line number Diff line Loading @@ -32,4 +32,4 @@ ADD_LIBRARY(innobase btr/btr0btr.c btr/btr0cur.c btr/btr0pcur.c btr/btr0sea.c thr/thr0loc.c trx/trx0purge.c trx/trx0rec.c trx/trx0roll.c trx/trx0rseg.c trx/trx0sys.c trx/trx0trx.c trx/trx0undo.c usr/usr0sess.c ut/ut0byte.c ut/ut0dbg.c ut/ut0mem.c ut/ut0rnd.c ut/ut0ut.c ut/ut0vec.c) ut/ut0byte.c ut/ut0dbg.c ut/ut0mem.c ut/ut0rnd.c ut/ut0ut.c ut/ut0vec.c ut/ut0list.c ut/ut0wqueue.c)
storage/innobase/Makefile.am +1 −1 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ EXTRA_DIST = include/btr0btr.h include/btr0btr.ic include/btr0cur.h include/btr include/univ.i include/usr0sess.h include/usr0sess.ic include/usr0types.h \ include/ut0byte.h include/ut0byte.ic include/ut0dbg.h include/ut0lst.h \ include/ut0mem.h include/ut0mem.ic include/ut0rnd.h include/ut0rnd.ic \ include/ut0sort.h include/ut0ut.h include/ut0ut.ic include/ut0vec.h include/ut0vec.ic \ include/ut0sort.h include/ut0ut.h include/ut0ut.ic include/ut0vec.h include/ut0vec.ic include/ha_prototypes.h \ CMakeLists.txt noinst_LIBRARIES = libinnobase.a Loading