I don’t understand why the following queries show up in slow query log with query time from 12 to 20 seconds.
UPDATE `wp_postmeta` SET `meta_value` = '35' WHERE `post_id` = 1267 AND `meta_key` = 'views'
UPDATE `wp_postmeta` SET `meta_value` = '32' WHERE `post_id` = 874 AND `meta_key` = 'views'
UPDATE `wp_postmeta` SET `meta_value` = '122' WHERE `post_id` = 18557 AND `meta_key` = 'views'
UPDATE `wp_postmeta` SET `meta_value` = '3078' WHERE `post_id` = 21741 AND `meta_key` = 'views'
UPDATE `wp_postmeta` SET `meta_value` = '2657' WHERE `post_id` = 878 AND `meta_key` = 'views'
They look pretty normal to me and executing 1 of them in phpMyAdmin for testing only takes 0.0056s.
The size of the wp_postmeta
table here is 77,996.
I wonder why the above queries are so slow and if there is anything I can do to improve them?
Better index to use than what @Sandeep suggested is:
This index will capture all the
WHERE
clauses and enable the database engine to quickly go to the right row.Create an index on column “post_id”. It will solve your problem.
When data is huge, indexes play a significant role in query optimization.