Bug #46489 Foreign keys: MERGE engine should be disallowed.
Submitted: 31 Jul 2009 11:39 Modified: 20 Dec 2013 7:04
Reporter: Konstantin Osipov (OCA) Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: DDL Severity:S3 (Non-critical)
Version:6.1-fk-stage OS:Any
Assigned to: Dmitry Lenev CPU Architecture:Any

[31 Jul 2009 11:39] Konstantin Osipov
Description:
I'm using mysql-6.1-fk-stage.
I start the server with mysqld --foreign-key-all-engines=1.

I create a primary-key table.
I create a MERGE engine table that uses the primary-key table.
I create a child table, referencing the merge table.
I insert parent and child values. 
I can delete parent from the merge source, there is no constraint check.

mysql> create table t1 (a int primary key);
Query OK, 0 rows affected (0.06 sec)

mysql> create table t2 (a int primary key) union (t1) engine=merge;
Query OK, 0 rows affected (0.10 sec)

mysql> create table t3 (a int references t2 (a) on update restrict on delete restrict);
Query OK, 0 rows affected (0.23 sec)

mysql> insert into t1 (a) values (1);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t2;
+---+
| a |
+---+
| 1 | 
+---+
1 row in set (0.00 sec)

mysql> insert into t3 (a) values (1);
Query OK, 1 row affected (0.00 sec)

mysql> delete from t2;
ERROR 1807 (23000): Foreign key error: constraint 'fk_t3_aiscn': cannot change because foreign key refers to value '1'
mysql> delete from t1;
Query OK, 1 row affected (0.00 sec)

mysql> select * from t3;
+------+
| a    |
+------+
|    1 | 
+------+
1 row in set (0.00 sec)

How to repeat:
create table t1 (a int primary key);
create table t2 (a int primary key) union (t1) engine=merge;
create table t3 (a int references t2 (a) on update restrict on delete restrict);

Suggested fix:
Do not allow child tables reference MERGE engine tables.
[31 Jul 2009 15:03] MySQL Verification Team
Are you tested against the latest source tree?. I couldn't test because I am getting a crash with latest source tree:

miguel@lara:~/dbs$ 6.1stage/bin/mysql -uroot test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 6.1.0-alpha-debug Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create table t1 (a int primary key);
Query OK, 0 rows affected (0.01 sec)

mysql> create table t2 (a int primary key) union (t1) engine=merge;
Query OK, 0 rows affected (0.01 sec)

mysql> create table t3 (a int references t2 (a) on update restrict on delete restrict);
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql> 

Version: '6.1.0-alpha-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
090731 11:50:21 - mysqld got signal 11 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=8384512
read_buffer_size=131072
max_used_connections=1
max_threads=151
thread_count=1
connection_count=1
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 338545 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd: 0x49b5c28
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0x7f0536e690f0 thread_stack 0x40000
6.1stage/libexec/mysqld(my_print_stacktrace+0x32) [0xe20d2c]
6.1stage/libexec/mysqld(handle_segfault+0x2a6) [0x77acac]
/lib/libpthread.so.0 [0x7f053668a080]
6.1stage/libexec/mysqld(I_P_List_iterator<MDL_request, I_P_List_adapter<MDL_request, &(MDL_request::next_in_context), &(MDL_request::prev_in_context)> >::operator++(int)+0x2f) [0x7ed7ab]
6.1stage/libexec/mysqld(MDL_context::remove_all_requests()+0x3f) [0x9bf28d]
6.1stage/libexec/mysqld(close_thread_tables(THD*, bool)+0x3ac) [0x7e7e6d]
6.1stage/libexec/mysqld(mysql_create_table(THD*, TABLE_LIST*, TABLE_LIST*, st_ha_create_information*, Alter_info*)+0x542) [0x90c348]
6.1stage/libexec/mysqld(mysql_execute_command(THD*)+0x1f24) [0x78fabc]
6.1stage/libexec/mysqld(mysql_parse(THD*, char const*, unsigned int, char const**)+0x276) [0x796b85]
6.1stage/libexec/mysqld(dispatch_command(enum_server_command, THD*, char*, unsigned int)+0xa65) [0x79777e]
6.1stage/libexec/mysqld(do_command(THD*)+0x22b) [0x798cfa]
6.1stage/libexec/mysqld(handle_one_connection+0x11c) [0x784c2d]
/lib/libpthread.so.0 [0x7f05366823ba]
/lib/libc.so.6(clone+0x6d) [0x7f05355f0fcd]
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0x4a02090 = create table t3 (a int references t2 (a) on update restrict on delete restrict)
thd->thread_id=1
thd->killed=NOT_KILLED
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
miguel@lara:~/dbs$ 

I am testing on Ubuntu 9.04 64-bit.
[31 Jul 2009 15:29] Konstantin Osipov
I used 6.1-fk-stage.
A crash at create is just as good reason to prohibit them, I suggest you set to "Verified" ;-)
[31 Jul 2009 16:27] MySQL Verification Team
Thank you for the feedback.
[16 Sep 2010 5:46] Konstantin Osipov
6.1-fk is not being worked on.
[20 Dec 2013 7:04] Erlend Dahl
The 6.x project was abandoned years ago.