I have a mysql table containing 400,000 rows
whenever I run a PHP script to update one row, it takes about 3-4 seconds to do it.
How can I optimize the update query?
UPDATE `weakvocab` SET `times` = times+1, `wrong` = wrong+1, `mtime` = 1284369979 WHERE `owner` = 'owner_name' AND `vocID` = 'ID_number' AND `type` = 'type_name';
This query is about updating user data after answering a question, so I need a fast query to give user a better experience in loading the next question.
Thank you,
Are the columns in your WHERE condition indexed? Change the UPDATE to a SELECT to see how Mysql executes it:
EXPLAIN SELECT * FROM `weakvocab` WHERE `owner` = 'owner_name' AND `vocID` = 'ID_number' AND `type` = 'type_name';
and paste the result in here
您可以尝试在(owner_name, vocID, type)
上添加索引(owner_name, vocID, type)
以便可以更快地找到要更新的记录。
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.