简体   繁体   English

Doctrine2 和 MySQL 分区

[英]Doctrine2 and MySQL Partitioning

Does anybody has experience of using partitioning feature in conjunction with the Doctrine2 library?有人有将分区功能与 Doctrine2 库结合使用的经验吗?

The first problem is that Doctrine creates foreign keys for association columns, anybody knows how to prevent or disable that?第一个问题是 Doctrine 为关联列创建外键,有人知道如何防止或禁用它吗?

And the second problem is how to specify custom table definition (PARTITION BY...)?第二个问题是如何指定自定义表定义(PARTITION BY...)?

Thanks in advance!提前致谢!

You're not out of luck!!你不是不走运!!

First , drop all foreign keys from all the tables D2 is managing.首先,从 D2 管理的所有表中删除所有外键。 Copy & execute the result of this query:复制并执行此查询的结果:

SET SESSION group_concat_max_len=8192; -- // increase this if you do not see the full list of your tables
SELECT IFNULL(REPLACE(GROUP_CONCAT('ALTER TABLE ',TABLE_NAME,' DROP FOREIGN KEY ',CONSTRAINT_NAME,'; '), ',', ''), '') FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE='FOREIGN KEY';

Then override the supportsForeignKeyConstraints() method in /vendor/doctrine-dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php (or wherever this class is located) to:然后覆盖/vendor/doctrine-dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php (或此 class 所在的任何位置)中的supportsForeignKeyConstraints()方法:

public function supportsForeignKeyConstraints()
{
    return false;
}

This will stop Doctrine from creating foreign key constraints on your next doctrine:schema:update command.这将阻止 Doctrine 在您的下一个doctrine:schema:update命令上创建外键约束。 After that you can simply execute an ALTER TABLE PARTITION BY... statement where needed (D2 doesn't support partitioning on a schema level).之后,您可以在需要的地方简单地执行ALTER TABLE PARTITION BY...语句(D2 不支持模式级别的分区)。 I recommend you backup & truncate your tables first (using --no-create-info ) in order to have the structure changes executed as fast as possible and then restore them.我建议您首先备份和截断您的表(使用--no-create-info ),以便尽快执行结构更改,然后恢复它们。

As this fellow says here , and based on my personal experience, D2 doesn't care whether you have FKs or not, as long as the proper relation definitions are in place.正如这个家伙所说,根据我的个人经验,只要有适当的关系定义,D2 并不关心您是否有 FK。

PS: I'm currently working on extending the annotation syntax to support proper table & column definitions, including ENGINE ( this might be useful), PARTITION BY & the @Column options array (ie {"fixed"=true, "unsigned"=true, "default"=0} ) PS:我目前正在扩展注释语法以支持正确的表和列定义,包括ENGINE可能有用)、 PARTITION BY和 @Column options数组(即{"fixed"=true, "unsigned"=true, "default"=0}

The overall effort amounts to a couple of sleepless nights for reverse-engineering & code patches, hope you do it faster:)逆向工程和代码补丁的总体努力相当于几个不眠之夜,希望你做得更快:)

PARTITION engine in MySQL has major limitations with regard to keys. MySQL 中的 PARTITION 引擎在密钥方面存在重大限制。 Please see latest docs, currently here: http://dev.mysql.com/doc/refman/5.1/en/partitioning-limitations-partitioning-keys-unique-keys.html请在此处查看最新文档: http://dev.mysql.com/doc/refman/5.1/en/partitioning-limitations-partitioning-keys-unique-keys.ZFC35FDC70D5FC69D252EZ8

If Doctrine requires keys that Partition does not support, you are out of luck.如果 Doctrine 需要 Partition 不支持的密钥,那你就不走运了。 Partition engine is very limited by design - it's intended for archival storage which is infrequently read.分区引擎的设计非常有限 - 它旨在用于不经常读取的存档存储。 Few MySQL-aware apps will work with Partition, unless you make changes.除非您进行更改,否则很少有 MySQL 感知应用程序可以与 Partition 一起使用。

I would suggest using Partition as it was intended - archiving.我建议按预期使用分区 - 归档。 Store your data in a more mainstream MySQL data engine would be the answer.将您的数据存储在更主流的 MySQL 数据引擎中就是答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM