gpt4 book ai didi

mysql - 索引列的顺序对性能的影响

转载 作者:行者123 更新时间:2023-11-29 06:55:07 26 4
gpt4 key购买 nike

我有一个名为“通知”的表

dateTime | message | sentStatus | sentDateTime | sensorID | userID

我已在此表上为(日期时间,传感器ID)创建了索引。

我读过某处,在 MySQL 中,索引是从左到右工作的。

我正在这样查询数据

SELECT dateTime, message 
WHERE sensorID = 'id'
AND sentStatus != 'sent'
ORDER BY dateTime desc;

我的查询是否使用了索引?

如果我像这样更改列的顺序,会对性能产生影响吗?

userID | sensorID | dateTime | message | sentStatus | sentDateTime 

最佳答案

正确的索引应该是:

(sensorID, status, dateTime)

前两个because是where条件的一部分,最后一个用于排序。

检查MySQL索引TIPS

关于mysql - 索引列的顺序对性能的影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45964068/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com