In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `team_football_1001_postmeta` ADD INDEX `team_1001_idx_meta_key_post_id` (`meta_key`,`post_id`);
ALTER TABLE `team_football_1001_posts` ADD INDEX `team_1001_idx_post_type_post_statu_id` (`post_type`,`post_status`,`ID`);
SELECT
SQL_CALC_FOUND_ROWS team_football_1001_posts.ID
FROM
team_football_1001_posts
INNER JOIN
team_football_1001_postmeta
ON (
team_football_1001_posts.ID = team_football_1001_postmeta.post_id
)
LEFT JOIN
team_football_1001_postmeta AS mt1
ON (
team_football_1001_posts.ID = mt1.post_id
)
LEFT JOIN
team_football_1001_postmeta AS mt2
ON (
team_football_1001_posts.ID = mt2.post_id
)
LEFT JOIN
team_football_1001_postmeta AS mt3
ON (
team_football_1001_posts.ID = mt3.post_id
AND mt3.meta_key = '_team_winner_id'
)
WHERE
1 = 1
AND (
team_football_1001_postmeta.meta_key = '_date_start'
AND (
(
(
mt1.meta_key = '_date_start'
AND mt1.meta_value > '2017-07-07 06:48:49'
)
OR (
(
mt2.meta_key = '_date_start'
AND mt2.meta_value < '2017-07-07 06:48:49'
)
AND mt3.post_id IS NULL
)
)
)
)
AND team_football_1001_posts.post_type = 'matches'
AND (
(
team_football_1001_posts.post_status = 'publish'
)
)
GROUP BY
team_football_1001_posts.ID
ORDER BY
team_football_1001_postmeta.meta_value DESC LIMIT 0,
3