外键与分区
由于分区 mySQL 数据库目前不支持外键,因此我想听听对于每个表将处理大约 1-400 000 行的读取密集型应用程序的一些优点和缺点。不幸的是,我在这方面还没有足够的经验来自己得出结论......
非常感谢!
参考文献:
Since foreign keys are not supported by partitioned mySQL databases for the moment, I would like to hear some pro's and con's for a read-heavy application that will handle around 1-400 000 rows per table. Unfortunately, I dont have enough experience yet in this area to make the conclusion by myself...
Thanks a lot!
References:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,如果您需要对小至 400.000 行的表进行分区,请使用 MySQL 以外的另一个数据库。严重地。按照现代标准,任何低于 1.000.000 行的表的大小通常可以忽略不计(甚至不算小),除非您也没有任何索引等。而现代标准在这方面已有大约 10 年的历史。
Well, if you need partitioning for a table as small as 400.000 rows get another database than MySQL. Seriously. By modern standards any table below 1.000.000 rows is normally neglegible in size (not even small), unless you also dont have any index etc. And modern standards are about 10 years old in this regard.
对于复杂的数据模型来说,分区并不是一个好的解决方案。如果你只有 2 到 3 个相互依赖的表,你也许可以做到,但效果并不好。每个表必须有一个确定分区的列。然后,每个表必须有一个触发器来创建新表、设置外键和唯一约束。
例如,
audittransaction<-auditentry
每个audittransaction有0到n个auditentry。表auditentry包含事务的外键。两个表都必须具有创建日期列,因为它用于对两个表进行分区。
------ 创建一个触发器,在触发器内插入audittransaction
----- 然后,为autientry 创建一个触发器
Well, partition is not a good solution for complicate data model. If you only have 2 to 3 tables depending on each other, you may be able to do it but it is not pretty. Each table must have an column that determine the partition. Then, each table must have a trigger to create the new table, set the foreign key and unique constraint.
For example,
audittransaction<- auditentry
Each audittransactionhas 0 to n auditentry. table auditentry contains the foreign key of transaction. Both table have to have column creationDate since it is used for partition both tables.
------ create a trigger to insert audittransaction within the trigger
----- then, create a trigger for autientry