Rasmus Vind
Well-known member
I am getting slow queries. Please take a look:
It looks very much like MySQL has to do a full scan of the table to find the results for this very common query. Is there something I can do aside from deleting people's contributions or can you somehow optimize this? I wouldn't have a problem with sending you (in private) all my XFMG tables to help you optimize your queries.
Code:
# Query_time: 3.333284 Lock_time: 0.000156 Rows_sent: 2000 Rows_examined: 534714
EXPLAIN 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, data.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 = 'visible', 1=1))
ORDER BY media.media_date DESC, media.media_id DESC
LIMIT 2000;
It looks very much like MySQL has to do a full scan of the table to find the results for this very common query. Is there something I can do aside from deleting people's contributions or can you somehow optimize this? I wouldn't have a problem with sending you (in private) all my XFMG tables to help you optimize your queries.