mysql - 如何提高 MyISAM 中 INSERT/UPDATE 查询的性能

标签 mysql myisam

我正在使用 MySQL 数据库,它有两个 MyISAM 表 1. 主表 (inf_article_details) 有 10+ 百万条记录和 2. 临时 (temp_inf_article_details) 表有大约 50,000 多条记录。这些表结构相同,它们只有一列(BIGINT 作为数据类型)作为主键。数据定期从不同的数据源提供程序填充到临时表中,我有一个计划的作业将数据从临时表推送到主表中。

仅供引用,主表在 KEY 上被划分为 20 个分区

主表索引信息(inf_articles_details)如下:

show indexes from inf_articles_details; enter image description here

临时表的索引信息(temp_inf_articles_details)如下:

show indexes from temp_inf_articles_details; enter image description here

主表结果解释如下:

explain select * from inf_articles_details enter image description here

临时表结果解释如下:

explain select * from temp_inf_articles_details enter image description here

主表 (inf_articles_details) 结构(总共有大约 70 多列)

CREATE TABLE inf_articles_details (
ard_ean_code bigint(20) unsigned NOT NULL,
ard_provider_reference bigint(20) unsigned DEFAULT NULL,
ard_reference varchar(20) NOT NULL,
ard_modified_date datetime DEFAULT NULL,
PRIMARY KEY (ard_ean_code),
KEY idx_ard_modified_date (ard_modified_date)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 /*!50100 PARTITION BY KEY () PARTITIONS 20 */

临时表 (temp_inf_articles_details) 结构是(大约有 70 多列)

CREATE TABLE temp_inf_articles_details (
tard_ean_code bigint(20) unsigned NOT NULL,
tard_provider_reference bigint(20) unsigned DEFAULT NULL,
tard_status tinyint(3) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (tard_ean_code),
KEY idx_status (tard_status)
) ENGINE=MyISAM DEFAULT CHARSET=utf8

作为数据更新任务的一部分,我们将这两个表连接到“ard_ean_code & tard_ean_code”,并使用临时表中的值更新 master 表中的现有行,并将新行从临时表插入到 master 中。但是这种数据更新花费太多时间将数据从临时表插入/更新到主表。

我需要做任何调整来提高性能吗?

谢谢。

最佳答案

MyISAM 支持并发插入:如果表在数据文件中间没有空闲 block ,您可以在其他线程从表中读取的同时向其中插入新行。

引用:Bulk Data for MyISAM Tables

Concurent Inserts

希望对你有所帮助

关于mysql - 如何提高 MyISAM 中 INSERT/UPDATE 查询的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8741644/

相关文章:

php - Laravel Homestead 连接远程数据库 SSH

php - 获取 SQL 语法错误

mysql - 大型 MySQL 数据库中的重复项

mysql - 选择列值较上一行发生变化的行、用户变量、innodb

django - 强制django使用MYISAM存储引擎创建表

mysql - 在一对多关系中维护一致的数据

python - cc1 : error: unrecognized command line option "-Wno-null-conversion" within installing python-mysql on mac 10. 7.5

mysql - 数据透视表sql

mysql - WHERE IN崩溃的MySQL

mysql - 非常大的表中的 MyISAM 与 InnoDB