我正在使用 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;
临时表的索引信息(temp_inf_articles_details)如下:
show indexes from temp_inf_articles_details;
主表结果解释如下:
explain select * from inf_articles_details
临时表结果解释如下:
explain select * from temp_inf_articles_details
主表 (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
),
KEYidx_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
),
KEYidx_status
(tard_status
)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
作为数据更新任务的一部分,我们将这两个表连接到“ard_ean_code & tard_ean_code”,并使用临时表中的值更新 master 表中的现有行,并将新行从临时表插入到 master 中。但是这种数据更新花费太多时间将数据从临时表插入/更新到主表。
我需要做任何调整来提高性能吗?
谢谢。
最佳答案
MyISAM 支持并发插入:如果表在数据文件中间没有空闲 block ,您可以在其他线程从表中读取的同时向其中插入新行。
引用:Bulk Data for MyISAM Tables
希望对你有所帮助
关于mysql - 如何提高 MyISAM 中 INSERT/UPDATE 查询的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8741644/