简体   繁体   中英

How can I speed up INNODB queries comparable to MYISAM performance?

I have recently switched my database tables from MYISAM to INNODB and experience bad timeouts with queries, mostly inserts. One function I use previously took <2 seconds to insert, delete and update a large collection of records across ~30 MYISAM tables, but now that they are INNODB, the function causes a PHP timeout.

The timeout was set to 60 seconds. I have optimised my script enough that now, even though there are still many queries, they are combined together (multiple inserts, multiple deletes, etc) and the script now takes ~25 seconds, which is a substantial increase from what appeared to be at least 60 seconds.

This duration is still over 10x quicker when previously using MYISAM, is there any mistakes I could be making in the way I process these queries? Or are there any settings that could assist in the performance? Currently the MySQL is using the default settings of installation.

The queries are nothing special, DELETE ... WHERE ... simple logic, same with the INSERT and UPDATE queries.

Hard to say without knowing too much about your environment, but this might be more of a database tuning problem. InnoDB can be VERY slow on budget hardware where every write forces a true flush. (This affects writes, not reads.)

For instance, you may want to read up on options like:

innodb_flush_log_at_trx_commit=2
sync_binlog=0

By avoiding the flushes you may be able to speed up your application considerably, but at the cost of potential data loss if the server crashes.

If data loss is something you absolutely cannot live with, then the other option is to use better hardware.

Run explain for each query. That is, if the slow query is select foo from bar; , run explain select foo from bar; .

Examine the plan, and add indices as necessary. Re-run the explain, and make sure the indices are being used.

Innodb构建哈希索引,通过传递BTREE索引和使用更快的哈希来帮助加快索引查找速度

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM