MySQL-我如何知道要使用哪些索引?

MySQL-我如何知道要使用哪些索引?,mysql,indexing,Mysql,Indexing,我正在尝试向以下查询添加索引 SELECT * FROM Messages t WHERE perspective_user=? and timestamp BETWEEN ? AND ? AND timestamp_added = (select max(timestamp_added) from Messages t2 where t2.author = t.author AND t2.body = t.body AND t2.timestamp = t.timestamp AND

我正在尝试向以下查询添加索引

SELECT * FROM Messages t WHERE perspective_user=? and timestamp BETWEEN ? AND ? AND 
timestamp_added = 
(select max(timestamp_added) from Messages t2 
where 
t2.author = t.author AND
t2.body = t.body AND
t2.timestamp = t.timestamp AND
t2.timestamp_added <= ?
) AND convo_id IN(SELECT convo_id FROM Conversations WHERE perspective_user=? AND identity=? AND timestamp_added=?);
我的第一个想法是三个索引:一个是关于perspective_user、timestamp、timestamp_added和conva_id的索引,另一个是关于author、body、timestamp和timestamp_added的索引,最后一个是关于perspective_user、identity和timestamp_added的索引。然而,这不起作用,而且,据我所知,执行起来需要同样的时间

如何向该查询添加索引,更一般地说,如何知道将来如何正确添加索引?

要使用的索引

索引取决于您的查询需求。 大多数使用的索引都来自where子句。 索引最好使用的一件事是主键。 避免为表创建太多索引,因为这可能会使数据对查询的速度变慢。
有关详细信息,请参阅此部分。

使用解释选择分别执行查询。。。要了解它的性能,您可以将索引添加到表中,而不是查询中。这个问题不是问题的一部分吗?我已经回答了这里的索引问题。