像这样的查询需要设置哪些索引?谢谢

SELECT distinct event_dates.* FROM `event_dates`
INNER JOIN `events` ON `events`.id = `event_dates`.event_id
INNER JOIN `cores` ON `cores`.resource_id = `events`.id AND cores.resource_type = 'Event'
INNER JOIN `cores_kinds` ON `cores_kinds`.core_id = `cores`.id
INNER JOIN `kinds` ON `kinds`.id = `cores_kinds`.kind_id
WHERE (((super_kind_en IN ('party','cinema and theater'))
AND (day >= '2010-07-17' AND day <= '2010-08-16'))
AND (cores.searchable like '%p%'))
ORDER BY day, cores.vote desc LIMIT 0, 30

最佳答案

一般经验法则是在筛选结果集的列上建立索引。换句话说,where子句中包含的列和执行联接的列。
对于特定查询,您可能需要参考查询的解释计划。它将显示mysql如何执行查询,因此可以相应地设置索引:http://dev.mysql.com/doc/refman/5.0/en/explain.html

10-07 18:08