大型 MySQL 表更新速度慢

发布于 2024-09-17 01:19:27 字数 869 浏览 3 评论 0原文

嗨,这是我的表结构

CREATE TABLE IF NOT EXISTS `sms_report` (
 `R_id` int(11) NOT NULL auto_increment,
 `R_uid` int(11) NOT NULL,
 `R_smppid` varchar(100) collate utf8_unicode_ci NOT NULL,
 `R_from` varchar(10) collate utf8_unicode_ci NOT NULL,
 `R_status` longtext collate utf8_unicode_ci NOT NULL,
 `R_message` text collate utf8_unicode_ci NOT NULL,
 `R_numbers` longtext collate utf8_unicode_ci NOT NULL,
 `R_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
 `R_timedate` varchar(40) collate utf8_unicode_ci NOT NULL,
 `R_show` int(11) NOT NULL default '1',
 `oldformat` tinyint(1) NOT NULL default '0',
 PRIMARY KEY  (`R_id`)

)ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCRMENT=1947722 ;

我有大约 200 万行,所以当我在这里对 R_status 进行更新时,似乎花费了太长的时间(R_status 是 1、2、16 或 24)。 请建议如何优化。

Hi this is my table structure

CREATE TABLE IF NOT EXISTS `sms_report` (
 `R_id` int(11) NOT NULL auto_increment,
 `R_uid` int(11) NOT NULL,
 `R_smppid` varchar(100) collate utf8_unicode_ci NOT NULL,
 `R_from` varchar(10) collate utf8_unicode_ci NOT NULL,
 `R_status` longtext collate utf8_unicode_ci NOT NULL,
 `R_message` text collate utf8_unicode_ci NOT NULL,
 `R_numbers` longtext collate utf8_unicode_ci NOT NULL,
 `R_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
 `R_timedate` varchar(40) collate utf8_unicode_ci NOT NULL,
 `R_show` int(11) NOT NULL default '1',
 `oldformat` tinyint(1) NOT NULL default '0',
 PRIMARY KEY  (`R_id`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1947722 ;

I have approx 2 million rows so when I do an update on R_status here, it seem to take too long(R_status is either 1,2,16 or 24).
Please suggest on how to optimise.

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

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

发布评论

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

评论(2

猫九 2024-09-24 01:19:27

如果 R_status 始终为整数,则将其设为整数。
另外,我会尝试将此表转换为固定行宽格​​式(无 varchars/texts)

另外,在 R_smppid 上创建索引,否则它会在每次更新时进行全表扫描。

If R_status is always integer, make it integer.
Also, I would try to convert this table into fixed-row-width format (no varchars/texts)

Also, make index on R_smppid, without that it would do full table scan on each update.

甜宝宝 2024-09-24 01:19:27

正如 @BarsMonster 建议的那样,将 R_status 转换为整数(如果值仅为 1,2,16,24,则为 TINYINT),并创建一个 < R_smppid 上的代码>INDEX。另外,如果R_smppid是固定宽度,请将字段类型更改为char(40)或任何内容的长度,或者如果它可以转换为整数,那就是甚至更好。

As @BarsMonster suggestd, convert R_status into an integer (TINYINT if values are only 1,2,16,24), and create an INDEX on R_smppid. Also, if R_smppid is fixed width, change field type to char(40) or whatever the length of the content is, or if it can be converted into an integer, that's even better.

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