What would be an appropriate way to do this, since mySQL obviously doesnt enjoy this.
To leave either partitioning or the foreign keys out from the database design would not seem like a good idea to me. I’ll guess that there is a workaround for this?
Update 03/24:
http://opendba.blogspot.com/2008/10/mysql-partitioned-tables-with-trigger.html
How to handle foreign key while partitioning
Thanks!
It depends on the extent to which the size of rows in the partitioned table is the reason for partitions being necessary.
If the row size is small and the reason for partitioning is the sheer number of rows, then I’m not sure what you should do.
If the row size is quite big, then have you considered the following:
Let
Pbe the partitioned table andFbe the table referenced in the would-be foreign key. Create a new tableX:and crucially, create a stored procedure for adding rows to table
P. Your stored procedure should make certain (use transactions) that whenever a row is added to tableP, a corresponding row is added to tableX. You must not allow rows to be added toPin the “normal” way! You can only guarantee that referential integrity will be maintained if you keep to using your stored procedure for adding rows. You can freely delete fromPin the normal way, though.The idea here is that your table
Xhas sufficiently small rows that you should hopefully not need to partition it, even though it has many many rows. The index on the table will nevertheless take up quite a large chunk of memory, I guess.Should you need to query
Pon the foreign key, you will of course queryXinstead, as that is where the foreign key actually is.