21

Does anybody has experience of using partitioning feature in conjunction with the Doctrine2 library?

The first problem is that Doctrine creates foreign keys for association columns, anybody knows how to prevent or disable that?

And the second problem is how to specify custom table definition (PARTITION BY ...)?

Thanks in advance!

Vladimir Kartaviy
  • 666
  • 1
  • 7
  • 24
  • 3
    You will probably get better results if you split this out into two questions. –  May 26 '11 at 18:38
  • 1
    If you up for fast performance gain with partitions and doctrine - don't do it. More powerful server is cheaper. And partitions will only bring confusion. – Ernestas Stankevičius Nov 27 '17 at 06:55

2 Answers2

7

You're not out of luck!!

First, drop all foreign keys from all the tables D2 is managing. 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:

public function supportsForeignKeyConstraints()
{
    return false;
}

This will stop Doctrine from creating foreign key constraints on your next doctrine:schema:update command. After that you can simply execute an ALTER TABLE PARTITION BY... statement where needed (D2 doesn't support partitioning on a schema level). 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.

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.

P.S.: 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 (i.e. {"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 :)

Community
  • 1
  • 1
Shellcat
  • 71
  • 1
  • 5
2

PARTITION engine in MySQL has major limitations with regard to keys. Please see latest docs, currently here: http://dev.mysql.com/doc/refman/5.1/en/partitioning-limitations-partitioning-keys-unique-keys.html

If Doctrine requires keys that Partition does not support, you are out of luck. 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.

I would suggest using Partition as it was intended - archiving. Store your data in a more mainstream MySQL data engine would be the answer.

Scott Prive
  • 801
  • 11
  • 16