[英]InnoDB Small update very slow, performance issue
I have an update script which update my database every night. 我有一个更新脚本,它每晚都会更新我的数据库。
It's a small database ~10k items. 这是一个约有1万个项目的小型数据库。 The update is fast for each table but one.
对于每个表,更新速度很快,但只有一个。 It's very slow on a join table.
在连接表上这非常慢。
The join table is a link between Item table and Type table as following : 联接表是项目表和类型表之间的链接,如下所示:
Item.Code <-> JoinTable.RefCode (VARCHAR 30), JoinTable.IdType(int 11) <-> Type.id
The engine is InnoDB. 引擎是InnoDB。 There are two foreign keys on the referenced tables and a unique key on the two columns.
在引用的表上有两个外键,在两列上有一个唯一键。 Also, indexes on each column in order to allow foreign keys.
同样,在每列上建立索引以允许外键。
I'm using the following SQL query to update the table : 我正在使用以下SQL查询来更新表:
INSERT INTO JoinTable (id, RefCode, IdType)
VALUES ( NULL, "AAA", 9584 )
ON DUPLICATE KEY UPDATE
id = LAST_INSERTED_ID(id),
refCode = values(refCode),
refType = values(refType)
So, the main problem it runs for about 30 MINUTES for 15k referenced id's. 因此,它的主要问题是15k引用ID的运行时间约为30分钟。
When I use MyISAM engine it's about 2 sec. 当我使用MyISAM引擎时,大约需要2秒钟。 but there is no more foreign keys.
但没有其他外键。
I understand that MyISAM delete foreign keys and it's faster but I think 30 min for a so small database is far from normal. 我了解MyISAM删除外键,而且速度更快,但是我认为对于如此小的数据库,30分钟的时间是不正常的。
Could you help me increase performances please ? 你能帮我提高表演吗?
Edit the InnoDB settings in your MySQL configuration and restart the MySQL daemon. 在MySQL配置中编辑InnoDB设置,然后重新启动MySQL守护程序。 They all start with "innodb_" and will have explanations of their purpose.
它们都以“ innodb_”开头,并将对其目的进行解释。
I changed the innodb_buffer_pool_size and innodb_log_file_size. 我更改了innodb_buffer_pool_size和innodb_log_file_size。
Change the insert to use IGNORE, and try without the VALUES() 更改插入以使用IGNORE,然后尝试不使用VALUES()
INSERT IGNORE INTO JoinTable (id, RefCode, IdType)
VALUES ( NULL, "AAA", 9584 )
ON DUPLICATE KEY UPDATE
id = LAST_INSERTED_ID(id),
refCode = refCode,
refType = refType
It could also be that your innodb buffer size is to small. 也可能是您的innodb缓冲区大小太小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.