mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Better fix for bug #3749 (bug in deleting automatic generated foreign keys)
mysql-test/r/func_encrypt.result: Update tests (left after sanjas last push) mysql-test/r/innodb.result: Added test for bug #3749 (bug in deleting automatic generated foreign keys) mysql-test/t/innodb.test: Added test for bug #3749 (bug in deleting automatic generated foreign keys) sql/sql_class.cc: Updated comment tests/client_test.c: Added missing mysql_stmt_close()
This commit is contained in:
@ -138,4 +138,4 @@ explain extended select des_decrypt(des_encrypt("hello",4),'password2'), des_dec
|
|||||||
id select_type table type possible_keys key key_len ref rows Extra
|
id select_type table type possible_keys key key_len ref rows Extra
|
||||||
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
|
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
|
||||||
Warnings:
|
Warnings:
|
||||||
Note 1003 select high_priority des_decrypt(des_encrypt(_latin1'hello',4),_latin1'password2') AS `des_decrypt(des_encrypt("hello",4),'password2')`,des_decrypt(des_encrypt(_latin1'hello',_latin1'hidden')) AS `des_decrypt(des_encrypt("hello","hidden"))`
|
Note 1003 select des_decrypt(des_encrypt(_latin1'hello',4),_latin1'password2') AS `des_decrypt(des_encrypt("hello",4),'password2')`,des_decrypt(des_encrypt(_latin1'hello',_latin1'hidden')) AS `des_decrypt(des_encrypt("hello","hidden"))`
|
||||||
|
@ -1538,6 +1538,37 @@ t2 CREATE TABLE `t2` (
|
|||||||
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
|
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1
|
||||||
drop table t2;
|
drop table t2;
|
||||||
|
create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id), primary key (id), index (id,id2)) engine = innodb;
|
||||||
|
show create table t2;
|
||||||
|
Table Create Table
|
||||||
|
t2 CREATE TABLE `t2` (
|
||||||
|
`id` int(11) NOT NULL auto_increment,
|
||||||
|
`id2` int(11) NOT NULL default '0',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `id` (`id`,`id2`),
|
||||||
|
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1
|
||||||
|
drop table t2;
|
||||||
|
create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id)) engine= innodb;
|
||||||
|
show create table t2;
|
||||||
|
Table Create Table
|
||||||
|
t2 CREATE TABLE `t2` (
|
||||||
|
`id` int(11) NOT NULL auto_increment,
|
||||||
|
`id2` int(11) NOT NULL default '0',
|
||||||
|
KEY `t1_id_fk` (`id`),
|
||||||
|
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1
|
||||||
|
alter table t2 add index id_test (id), add index id_test2 (id,id2);
|
||||||
|
show create table t2;
|
||||||
|
Table Create Table
|
||||||
|
t2 CREATE TABLE `t2` (
|
||||||
|
`id` int(11) NOT NULL auto_increment,
|
||||||
|
`id2` int(11) NOT NULL default '0',
|
||||||
|
KEY `id_test` (`id`),
|
||||||
|
KEY `id_test2` (`id`,`id2`),
|
||||||
|
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1
|
||||||
|
drop table t2;
|
||||||
create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
|
create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
|
||||||
ERROR HY000: Can't create table './test/t2.frm' (errno: 150)
|
ERROR HY000: Can't create table './test/t2.frm' (errno: 150)
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
@ -1082,6 +1082,16 @@ create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2),cons
|
|||||||
show create table t2;
|
show create table t2;
|
||||||
drop table t2;
|
drop table t2;
|
||||||
|
|
||||||
|
create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id), primary key (id), index (id,id2)) engine = innodb;
|
||||||
|
show create table t2;
|
||||||
|
drop table t2;
|
||||||
|
|
||||||
|
create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id)) engine= innodb;
|
||||||
|
show create table t2;
|
||||||
|
alter table t2 add index id_test (id), add index id_test2 (id,id2);
|
||||||
|
show create table t2;
|
||||||
|
drop table t2;
|
||||||
|
|
||||||
# Test error handling
|
# Test error handling
|
||||||
--error 1005
|
--error 1005
|
||||||
create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
|
create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
|
||||||
|
@ -86,7 +86,7 @@ bool key_part_spec::operator==(const key_part_spec& other) const
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Test if a foreign key is a prefix of the given key
|
Test if a foreign key (= generated key) is a prefix of the given key
|
||||||
(ignoring key name, key type and order of columns)
|
(ignoring key name, key type and order of columns)
|
||||||
|
|
||||||
NOTES:
|
NOTES:
|
||||||
|
@ -684,11 +684,13 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
|
|||||||
while ((key2 = key_iterator2++) != key)
|
while ((key2 = key_iterator2++) != key)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
foreign_key_prefix(key, key2) returns 0 if key or key2, or both, is
|
foreign_key_prefix(key, key2) returns 0 if key or key2, or both, is
|
||||||
'generated', and a generated key is a prefix of the other key. Then we
|
'generated', and a generated key is a prefix of the other key.
|
||||||
do not need the generated shorter key.
|
Then we do not need the generated shorter key.
|
||||||
*/
|
*/
|
||||||
if ((key2->type != Key::FOREIGN_KEY && !foreign_key_prefix(key, key2)))
|
if ((key2->type != Key::FOREIGN_KEY &&
|
||||||
|
key2->name != ignore_key &&
|
||||||
|
!foreign_key_prefix(key, key2)))
|
||||||
{
|
{
|
||||||
/* TO DO: issue warning message */
|
/* TO DO: issue warning message */
|
||||||
/* mark that the generated key should be ignored */
|
/* mark that the generated key should be ignored */
|
||||||
@ -698,17 +700,9 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
|
|||||||
key->name= ignore_key;
|
key->name= ignore_key;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
key2->name= ignore_key;
|
||||||
Remove the previous, generated key if it has not yet been
|
key_parts-= key2->columns.elements;
|
||||||
removed. Note that if we have several identical generated keys,
|
(*key_count)--;
|
||||||
the last one will remain and others get removed here.
|
|
||||||
*/
|
|
||||||
if (key2->name != ignore_key)
|
|
||||||
{
|
|
||||||
key2->name= ignore_key;
|
|
||||||
key_parts-= key2->columns.elements;
|
|
||||||
(*key_count)--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -9614,7 +9614,6 @@ union distinct \
|
|||||||
select sum(a) + 200, 1 from t1 \
|
select sum(a) + 200, 1 from t1 \
|
||||||
group by b ");
|
group by b ");
|
||||||
check_stmt(stmt);
|
check_stmt(stmt);
|
||||||
|
|
||||||
mysql_stmt_close(stmt);
|
mysql_stmt_close(stmt);
|
||||||
|
|
||||||
stmt= mysql_simple_prepare(mysql,
|
stmt= mysql_simple_prepare(mysql,
|
||||||
@ -9624,14 +9623,14 @@ union distinct \
|
|||||||
select sum(a) + 200, 1 from t1 \
|
select sum(a) + 200, 1 from t1 \
|
||||||
group by b ");
|
group by b ");
|
||||||
check_stmt(stmt);
|
check_stmt(stmt);
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
|
||||||
stmt= mysql_simple_prepare(mysql,
|
stmt= mysql_simple_prepare(mysql,
|
||||||
"select sum(a) + 200, ? from t1 \
|
"select sum(a) + 200, ? from t1 \
|
||||||
union distinct \
|
union distinct \
|
||||||
select sum(a) + 200, 1 from t1 \
|
select sum(a) + 200, 1 from t1 \
|
||||||
group by b ");
|
group by b ");
|
||||||
check_stmt(stmt);
|
check_stmt(stmt);
|
||||||
|
|
||||||
mysql_stmt_close(stmt);
|
mysql_stmt_close(stmt);
|
||||||
|
|
||||||
rc= mysql_query(mysql, "DROP TABLE t1");
|
rc= mysql_query(mysql, "DROP TABLE t1");
|
||||||
|
Reference in New Issue
Block a user