Hi @bvytis,
I’m sorry for confusing, but the screenshot I posted was on my test website. Our real website has over 700,000 wp_posts
records and over 100,000 media files, and logs showed a slow query of 35.334482 seconds
by that query.
For reference, I tried to run the query on our website using the EXPLAIN statement as follows:
$ wp db query "EXPLAIN SELECT post_mime_type, COUNT( * ) AS num_posts FROM wp_posts WHERE post_type = 'attachment' AND post_status != 'trash' AND (post_mime_type LIKE 'image/%') GROUP BY post_mime_type"
+------+-------------+----------+-------+------------------+------------------+---------+------+--------+---------------------------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+----------+-------+------------------+------------------+---------+------+--------+---------------------------------------------------------------------+
| 1 | SIMPLE | wp_posts | range | type_status_date | type_status_date | 164 | NULL | 136235 | Using index condition; Using where; Using temporary; Using filesort |
+------+-------------+----------+-------+------------------+------------------+---------+------+--------+---------------------------------------------------------------------+
Since post_mime_type
doesn’t have an index, Using temporary; Using filesort
seems to occur. It could have an impact on performance in a larger website.
I feel like it’s a kind of problem to be ran this query on every request, even if the status isn’t activated in the general settings of this plugin. What do you think?
-
This reply was modified 2 years ago by
Ko Takagi.