通过在 mysql 表上添加索引来执行时间

发布于 2024-12-11 20:17:26 字数 2029 浏览 0 评论 0原文

我正在更改包含 200 万行以上的表的索引。 执行时间现在超过 3000 秒。 我认为我的电脑上有任何问题,因为之前的其他更改从未在同一张桌子上花费这么长时间。我已将所有索引添加到现有数据中。 有人体验过更改现有 200 万行的索引需要多长时间吗?

我如何检查本地 mysql 安装是否正常?

这是表格定义:

CREATE TABLE `sal_forwarding` (
  `sid` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `f_shop` INT(11) NOT NULL,
  `f_offer` INT(11) DEFAULT NULL,
  `link` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `offerCode` VARCHAR(255) DEFAULT NULL,
  `sub2` VARCHAR(200) CHARACTER SET latin1 COLLATE latin1_german1_ci DEFAULT NULL,
  `forwardTime` DATETIME NOT NULL,
  `cid` CHAR(32) DEFAULT NULL,
  `f_partner` VARCHAR(20) NOT NULL,
  `t` VARCHAR(30) CHARACTER SET latin1 COLLATE latin1_german1_ci DEFAULT '0',
  `toolbarUser` TINYINT(1) NOT NULL DEFAULT '0',
  `blog` TINYINT(1) DEFAULT '0',
  `clickedPosition` INT(10) UNSIGNED DEFAULT NULL,
  `usedFrame` TINYINT(1) NOT NULL DEFAULT '0',
  `sub3` VARCHAR(200) CHARACTER SET latin1 COLLATE latin1_german1_ci DEFAULT NULL,
  `sub4` VARCHAR(200) CHARACTER SET latin1 COLLATE latin1_german1_ci DEFAULT NULL,
  `sub5` VARCHAR(200) CHARACTER SET latin1 COLLATE latin1_german1_ci DEFAULT NULL,
  `sub6` VARCHAR(200) CHARACTER SET latin1 COLLATE latin1_german1_ci DEFAULT NULL,
  `sub7` VARCHAR(200) CHARACTER SET latin1 COLLATE latin1_german1_ci DEFAULT NULL,
  `f_affiliateId` TINYINT(3) UNSIGNED NOT NULL,
  `browser` VARCHAR(50) DEFAULT NULL,
  `bversion` VARCHAR(5) DEFAULT NULL,
  `os` VARCHAR(50) DEFAULT NULL,
  `forwardDate` DATE NOT NULL,
  PRIMARY KEY (`sid`),
  KEY `f_shop` (`f_shop`,`forwardDate`,`cid`),
  KEY `f_partner` (`f_partner`,`forwardDate`),
  KEY `forwardDate` (`forwardDate`,`cid`),
  KEY `forwardDate_2` (`forwardDate`,`f_shop`),
  KEY `forwardDate_3` (`forwardDate`,`f_shop`,`f_partner`),
  KEY `forwardDate_4` (`forwardDate`,`f_partner`,`cid`),
  KEY `forwardDate_5` (`forwardDate`,`f_affiliateId`),
  KEY `forwardDate_6` (`forwardDate`,`f_shop`,`sid`)
) ENGINE=INNODB AUTO_INCREMENT=10747233 DEFAULT CHARSET=latin1;

非常感谢。

I'm changing an index on a table with more the 2million rows.
The execution time is now longer then 3000 seconds.
I think anything is working wrong on my pc because other changes before never took so long on the same table. I've added all indices with existing data.
Has anybody an experience how much time does it take to change an index with 2 million existsing rows?

How can i check if anything is working fine on my local mysql installation?

Here is the table definition:

CREATE TABLE `sal_forwarding` (
  `sid` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `f_shop` INT(11) NOT NULL,
  `f_offer` INT(11) DEFAULT NULL,
  `link` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `offerCode` VARCHAR(255) DEFAULT NULL,
  `sub2` VARCHAR(200) CHARACTER SET latin1 COLLATE latin1_german1_ci DEFAULT NULL,
  `forwardTime` DATETIME NOT NULL,
  `cid` CHAR(32) DEFAULT NULL,
  `f_partner` VARCHAR(20) NOT NULL,
  `t` VARCHAR(30) CHARACTER SET latin1 COLLATE latin1_german1_ci DEFAULT '0',
  `toolbarUser` TINYINT(1) NOT NULL DEFAULT '0',
  `blog` TINYINT(1) DEFAULT '0',
  `clickedPosition` INT(10) UNSIGNED DEFAULT NULL,
  `usedFrame` TINYINT(1) NOT NULL DEFAULT '0',
  `sub3` VARCHAR(200) CHARACTER SET latin1 COLLATE latin1_german1_ci DEFAULT NULL,
  `sub4` VARCHAR(200) CHARACTER SET latin1 COLLATE latin1_german1_ci DEFAULT NULL,
  `sub5` VARCHAR(200) CHARACTER SET latin1 COLLATE latin1_german1_ci DEFAULT NULL,
  `sub6` VARCHAR(200) CHARACTER SET latin1 COLLATE latin1_german1_ci DEFAULT NULL,
  `sub7` VARCHAR(200) CHARACTER SET latin1 COLLATE latin1_german1_ci DEFAULT NULL,
  `f_affiliateId` TINYINT(3) UNSIGNED NOT NULL,
  `browser` VARCHAR(50) DEFAULT NULL,
  `bversion` VARCHAR(5) DEFAULT NULL,
  `os` VARCHAR(50) DEFAULT NULL,
  `forwardDate` DATE NOT NULL,
  PRIMARY KEY (`sid`),
  KEY `f_shop` (`f_shop`,`forwardDate`,`cid`),
  KEY `f_partner` (`f_partner`,`forwardDate`),
  KEY `forwardDate` (`forwardDate`,`cid`),
  KEY `forwardDate_2` (`forwardDate`,`f_shop`),
  KEY `forwardDate_3` (`forwardDate`,`f_shop`,`f_partner`),
  KEY `forwardDate_4` (`forwardDate`,`f_partner`,`cid`),
  KEY `forwardDate_5` (`forwardDate`,`f_affiliateId`),
  KEY `forwardDate_6` (`forwardDate`,`f_shop`,`sid`)
) ENGINE=INNODB AUTO_INCREMENT=10747233 DEFAULT CHARSET=latin1;

Thank you very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平安喜乐 2024-12-18 20:17:26

在大表上创建索引是一个相对缓慢的过程,虽然我不是专家,但我相信你在这方面无能为力。

时间不仅取决于表的大小,而且很大程度上取决于创建索引的列。
我猜花费 3000 秒是正常的,对于有 200 万行的表,我曾经在一个有近 350 万行的表上创建了复合索引,花了 2 个多小时......

以下是一些人们分享的链接MySQL大表创建索引的经验

http://lists.mysql.com/mysql/212738

<一href="http://forums.mysql.com/read.php?24,356410,356889#msg-356889" rel="nofollow">http://forums.mysql.com/read.php?24,356410 ,356889#msg-356889

Index creation on large table is relatively slow process, and although I am not an expert, but I believe there is nothing much that u can do in this regard.

Time does not only depend on the size of table, but it also largely depends upon the column on which index is being created.
taking 3000 seconds is normal i guess, for table with 2 million rows, I once created composite index on a table with almost 3.5 million rows and it took more than 2 hours.....

Here are some links where people have shared about their experiences of creating index on large tables in MySQL

http://lists.mysql.com/mysql/212738

http://forums.mysql.com/read.php?24,356410,356889#msg-356889

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文