I have an update script which update my database every night.
It's a small database ~10k items. 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. 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 :
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.
When I use MyISAM engine it's about 2 sec. 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.
Could you help me increase performances please ?
Edit the InnoDB settings in your MySQL configuration and restart the MySQL daemon. They all start with "innodb_" and will have explanations of their purpose.
I changed the innodb_buffer_pool_size and innodb_log_file_size.
Change the insert to use IGNORE, and try without the 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.