Rasmus Vind
Well-known member
I just looked in my slow_query_log and found this repeated in the 1000s.
This is the explain:
I am guessing that we are missing some index.
I am willing to run a query or two on your recommendation.
SQL:
# Time: 2018-04-05T18:55:39.819781Z
# User@Host: root[root] @ [192.168.208.179] Id: 1028754
# Query_time: 3.948271 Lock_time: 0.000123 Rows_sent: 2000 Rows_examined: 565049
SET timestamp=1522954539;
SELECT media.*
,
album.*, albumviewperm.*,
category.*,
user.*, user_profile.*, IF(user.username IS NULL, media.username, user.username) AS username,
attachment.attachment_id, attachment.data_id, attachment.attach_date,data.filename, data.file_size, data.file_hash, data.file_path, data.width, data.height, data.thumbnail_width, d
ata.thumbnail_height
FROM xengallery_media AS media
LEFT JOIN xengallery_album AS album ON
(album.album_id = media.album_id)
LEFT JOIN xengallery_album_permission as albumviewperm ON
(album.album_id = albumviewperm.album_id AND albumviewperm.permission = 'view')
LEFT JOIN xengallery_category AS category ON
(category.category_id = media.category_id)
LEFT JOIN xf_user AS user ON
(user.user_id = media.user_id)
LEFT JOIN xf_user_profile AS user_profile ON
(user_profile.user_id = media.user_id)
LEFT JOIN xf_attachment AS attachment ON
(attachment.content_type = 'xengallery_media' AND attachment.attachment_id = media.attachment_id)
LEFT JOIN xf_attachment_data AS data ON
(data.data_id = attachment.data_id)
WHERE (
media.media_privacy = 'public'
OR IF(media.category_id > 0, media.category_id IN (1), NULL)) AND (media.media_state IN ('visible')) AND (IF(media.album_id > 0, album.album_state = 'vi
sible', 1=1))
ORDER BY media.media_date DESC, media.media_id DESC
LIMIT 2000;
This is the explain:
Code:
+----+-------------+---------------+------------+--------+------------------------------+---------+---------+------------------------------+-------+----------+----------------------------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+---------------+------------+--------+------------------------------+---------+---------+------------------------------+-------+----------+----------------------------------------------------+
| 1 | SIMPLE | media | NULL | ALL | NULL | NULL | NULL | NULL | 77432 | 33.33 | Using where; Using temporary; Using filesort |
| 1 | SIMPLE | album | NULL | eq_ref | PRIMARY | PRIMARY | 4 | xenforo.media.album_id | 1 | 100.00 | Using where |
| 1 | SIMPLE | albumviewperm | NULL | eq_ref | PRIMARY | PRIMARY | 5 | xenforo.album.album_id,const | 1 | 100.00 | NULL |
| 1 | SIMPLE | category | NULL | ALL | PRIMARY | NULL | NULL | NULL | 1 | 100.00 | Using where; Using join buffer (Block Nested Loop) |
| 1 | SIMPLE | user | NULL | eq_ref | PRIMARY | PRIMARY | 4 | xenforo.media.user_id | 1 | 100.00 | NULL |
| 1 | SIMPLE | user_profile | NULL | eq_ref | PRIMARY | PRIMARY | 4 | xenforo.media.user_id | 1 | 100.00 | NULL |
| 1 | SIMPLE | attachment | NULL | eq_ref | PRIMARY,content_type_id_date | PRIMARY | 4 | xenforo.media.attachment_id | 1 | 100.00 | Using where |
| 1 | SIMPLE | data | NULL | eq_ref | PRIMARY | PRIMARY | 4 | xenforo.attachment.data_id | 1 | 100.00 | NULL |
+----+-------------+---------------+------------+--------+------------------------------+---------+---------+------------------------------+-------+----------+----------------------------------------------------+
8 rows in set, 1 warning (0.01 sec)
I am guessing that we are missing some index.
I am willing to run a query or two on your recommendation.
Last edited: