gpt4 book ai didi

sql - 如果 where 条件为 !=?,则不使用数据库索引

转载 作者:太空狗 更新时间:2023-10-30 01:47:59 25 4
gpt4 key购买 nike

我在列上有一个索引,并且在查询时正确使用它

select * from Table where x = 'somestring'

但是当查询是这样的时候它似乎没有被使用

select * from Table where x != 'someotherstring'

这是正常现象还是我在查询中遗漏了其他内容?实际查询当然要大得多,所以它可能是由其他一些因素引起的。为什么在查询中不使用索引还有其他想法吗?

最佳答案

这是正常的。仅当您有“=”条件时才会使用索引。搜索 != 条件的索引无效。

同样,这个可能会用到索引(在Oracle中)

select * from Table where x like 'some%'

但这不会

select * from Table where x like '%thing%'

此外,select * from Table where x between 1 and 10 将使用索引

但不是从表中选择 *,其中 x 不在 1 到 10 之间

关于sql - 如果 where 条件为 !=?,则不使用数据库索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1759476/

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