Drupal MySql数据库设计问题

时间:2009-07-12 09:49:33

标签: mysql innodb

I was just looking at the MySql database created by drupal after I installed it.
All the tables are in MyISAM.

With a complex software like drupal, wouldn't it make more sense to 
use foreign keys and hence InnoDB tables to enforce referential integrity?

Without foreign keys all the constraint checking will happen at the 
PHP end.

1 个答案:

答案 0 :(得分:3)

MySQL出于某种原因提供各种数据库引擎 - 不同的引擎提供不同的优点和缺点。 InnoDB是一个很棒的引擎,可以提供参照完整性和事务安全性,但是对于网站的用例而言,它的优化程度很低,在这种情况下你会有更多的读取次数。

MyISAM为网站提供最佳性能,其中大多数点击只需要对数据库的读访问权。在这种情况下,通常可以通过编写数据插入和删除来保持参照完整性,如果它们损害完整性,它们将无法成功。 例如,而不是写

DELETE FROM mytable WHERE id = 5

你可以写

删除mytable FROM mytable LEFT JOIN linkedtable ON mytable.id = linkedtable.ref WHERE id = 5 AND linkedtable.ref IS NULL

只有当没有外部引用时才会成功删除该行。