我有一张叫'notifications‘的桌子
dateTime | message | sentStatus | sentDateTime | sensorID | userID我已经在这个表上为(dateTime, sensorID)创建了一个索引。
我在某处读到过,在MySQL中,索引是从左到右的。
我像这样查询数据
SELECT dateTime, message
WHERE sensorID = 'id'
AND sentStatus != 'sent'
ORDER BY dateTime desc;我的查询是否使用了索引?
如果我像这样改变列的顺序,是否会对性能产生影响?
userID | sensorID | dateTime | message | sentStatus | sentDateTime 发布于 2017-08-30 23:21:30
正确的索引应该是:
(sensorID, status, dateTime)前两个是where条件的一部分,最后一个用于排序。
检查MySQL索引
https://stackoverflow.com/questions/45964068
复制相似问题