我有一个特定的MySQL查询很慢,我无法弄清楚原因。
Route::resource('categories', 'CategoryController');
此查询的EXPLAIN如下:
SELECT
s.title,
p.minPrice,
s.booking, r.url
FROM shows s
INNER JOIN showResources r
ON r.showID = s.id
INNER JOIN performances p
ON p.showID = s.id
WHERE s.lastDate >= CURDATE()
AND r.type = 'rectangle-poster'
AND p.minPrice > 0
GROUP BY s.id
ORDER BY p.minPrice ASC
LIMIT 30
其他的,在同一台服务器上看似更为复杂的查询速度非常快 - 但这个通常需要大约4秒才能运行,而我却无法弄清楚原因。我甚至已经删除了表格并重新创建它们,以防它是一些奇怪的腐败,但没有运气。 MySQL专家可以告诉我这里我做错了吗?
答案 0 :(得分:0)
试试这个:
SELECT
s.id AS id,
s.title,
p.minPrice AS min_price,
s.booking,
r.url
FROM shows s
INNER JOIN showResources r
ON r.showID = s.id AND s.lastDate >= CURDATE() AND r.type = 'rectangle-poster'
INNER JOIN performances p
ON p.showID = s.id AND p.minPrice > 0
GROUP BY id
ORDER BY min_price ASC
LIMIT 30