Foreign keys and cluster
I have a schema that uses InnoDB table type and foreign keys. I am planning to use mysql Cluster and I just want to make sure that I can use "InnoDB" table type and foreign key constraints will be still valid.
Update:
As per the documentation:
It is possible to create tables using other storage engines (such as MyISAM or InnoDB) on a MySQL server being used with a MySQL Cluster, but these non-NDB tables do not participate in clustering; each such table is strictly local to the individual MySQL server instance on which it is created.
Does it mean that if I create an Inn开发者_如何学编程oDB table, I can have foreign key constraint? I understand those tables will not participate in clustering.
No, they all use NDBCLUSTER
as a storage engine, and foreign key constraints are not available before 5.6/ MySQL Cluster NDB 7.3. Starting with MySQL Cluster NDB 7.3 foreign keys are possible.
Tables that do not participate in clustering can be InnoDB (or any other ), but are local to the server only (i.e. the other servers are not aware of that table), so the table can only be queried on one of the nodes (which kind of defeats the advantages of clustering).
All features of the engine are then of course available, so indeed, the InnoDB table can have foreign key constraints, but the same rules apply with InnoDB<>NDB as InnoDB<>MyISAM: MySQL won't complain if you mention a column located in an NDB/MyISAM table in an InnoDB table definition, but won't enforce the integrity either.
It is possible to programmatically enforce foreign keys in NDB (or any mysql storage engine which does not natively support them): http://dev.mysql.com/tech-resources/articles/mysql-enforcing-foreign-keys.html
Or if you can wait for MySQL Cluster 7.3 : https://blogs.oracle.com/MySQL/entry/mysql_cluster_7_3_labs
MySQL cluster does not support foreign keys as imposing foreign key constraint may reduce the performance of cluster .You can design your database in such a fashion that operations on database would keep the required checks.
精彩评论