简体   繁体   English

InnoDB 外键和 MySQL 分区

[英]InnoDB foreign keys and MySQL partitioning

I am usign MySQL Server version: 5.7.32-0ubuntu0.16.04.1 (Ubuntu).我使用 MySQL 服务器版本:5.7.32-0ubuntu0.16.04.1(Ubuntu)。 In my DB i have this table with million records:在我的数据库中,我有这张包含百万条记录的表:

CREATE TABLE `tableA` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `timestamp` timestamp NULL DEFAULT NULL,
  `value` int(11) NOT NULL,
  `tableB_id` bigint(20) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `UK_sjfet8dx50bhix3ub1dwocpcx` (`timestamp`,`tableB_id`),
  KEY `FK_su2f3awnwvdpq1h3x5x0drjaw` (`tableB_id`),
  CONSTRAINT `FK_su2f3awnwvdpq1h3x5x0drjaw` FOREIGN KEY (`tableB_id`) REFERENCES `tableB` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Is it possible using PARTITIONING by RANGE (in this case by YEAR)?是否可以按范围使用分区(在这种情况下按年份)?

Is it possible to partition even if a foreign key is present?即使存在外键也可以分区吗?

Thanks!谢谢!

NO.不。

https://dev.mysql.com/doc/refman/8.0/en/partitioning-limitations.html says: https://dev.mysql.com/doc/refman/8.0/en/partitioning-limitations.html说:

Foreign keys not supported for partitioned InnoDB tables.分区 InnoDB 表不支持外键。 Partitioned tables using the InnoDB storage engine do not support foreign keys.使用 InnoDB 存储引擎的分区表不支持外键。

You can't partition this table by year anyway, because every unique key on the table must use every column in the table's partitioning expression.无论如何,您不能按年份对该表进行分区,因为表上的每个唯一键都必须使用表分区表达式中的每一列。

Read https://dev.mysql.com/doc/refman/8.0/en/partitioning-limitations-partitioning-keys-unique-keys.html for details on that.阅读https://dev.mysql.com/doc/refman/8.0/en/partitioning-limitations-partitioning-keys-unique-keys.ZFC35FDC70D5FC69D2539883A822C7了解详情。

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

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