gpt4 book ai didi

MySQL 分区唯一键

转载 作者:行者123 更新时间:2023-11-29 13:51:12 25 4
gpt4 key购买 nike

我正在关注这篇文章:

http://www.chrismoos.com/2010/01/31/mysql-partitioning-tables-with-millions-of-rows

但是当我运行查询对产品表(包含 500,000 行)进行分区时,我收到错误:

#1503 - A UNIQUE INDEX must include all columns in the table's partitioning function

我的查询是:

ALTER TABLE parts_library PARTITION by HASH(manufacturerId) PARTITIONS 200

我的主键是 id 和ManufacturerId 的复合键,与文章中的相同,所以我不明白为什么会收到此错误。

这是我的表的创建语句:

CREATE TABLE IF NOT EXISTS `parts_library` (
`id` int(11) NOT NULL,
`dateAdded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`typeId` int(3) NOT NULL COMMENT 'Reference to part_types',
`manufacturerId` int(11) NOT NULL DEFAULT '0',
`familyId` int(11) NOT NULL DEFAULT '454',
`partNumber` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'e.g. 6ES5123B62',
`idealForm` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'E.g. 6ES5-123-B6/2',
`comCodeId` int(11) DEFAULT NULL,
`countryOriginId` int(3) NOT NULL DEFAULT '258',
`minStockLevel` int(11) DEFAULT NULL,
`weight` decimal(11,2) DEFAULT NULL,
`width` decimal(11,2) DEFAULT NULL,
`height` decimal(11,2) DEFAULT NULL,
`depth` decimal(11,2) DEFAULT NULL,
`validated` tinyint(1) NOT NULL DEFAULT '0',
`onWeb` tinyint(1) DEFAULT '0',
`indexed` tinyint(1) NOT NULL DEFAULT '1',
`averageMargin` decimal(11,2) NOT NULL,
PRIMARY KEY (`id`,`manufacturerId`),
UNIQUE KEY `partNumber` (`partNumber`),
KEY `fk_parts_library_parts_categories1` (`typeId`),
KEY `fk_parts_library_manufacturers1` (`manufacturerId`),
KEY `fk_parts_library_geo_countries1` (`countryOriginId`),
KEY `fk_parts_library_parts_families1` (`familyId`),
KEY `indexed` (`indexed`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

如何对表进行分区?

最佳答案

你的代码和 arcticle 之间的区别 - 你有一个

唯一键“partNumber”(“partNumber”)

文章中没有提到。 DB 提示您需要将用于分区的列包含到键定义中,例如:

唯一键“partNumber”(“manufacturerId”,“partNumber”)

关于MySQL 分区唯一键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16644046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com