gpt4 book ai didi

mysql - 当where条件由 'AND'和 'OR'组合组成时,mysql应该创建什么索引?

转载 作者:行者123 更新时间:2023-11-29 21:46:19 25 4
gpt4 key购买 nike

我的mysql查询如下,我需要创建索引来提高结果获取。

   SELECT * FROM  tbl_name 
WHERE seasonid = 1 AND status = 'N'
AND month = 10 AND (team_a = 'India' OR team_b = 'India');

提前致谢

最佳答案

(a = 1 OR a = 3) 转换为 a IN (1,3),有时是可以优化的。但是,你没有这种情况。因此,OR 两侧的表达式对于索引来说是无用的。

INDEX(seasonid,status,month)

具有任意顺序的 3 个字段是该查询的“最佳”索引。

另请参阅我的 index cookbook .

关于mysql - 当where条件由 'AND'和 'OR'组合组成时,mysql应该创建什么索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34082557/

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