如果where条件为!= ?,则不使用数据库索引。 [英] Database Index not used if the where criteria is !=?

查看:124
本文介绍了如果where条件为!= ?,则不使用数据库索引。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在列上有一个索引,并且在查询为

I have a index on a column and it is correctly used when the query is

select * from Table where x = 'somestring'

但是当查询类似

select * from Table where x != 'someotherstring'

这是正常现象还是在查询中丢失了其他内容?当然,实际的查询要大得多,因此它可能是由其他因素引起的。为什么不在查询中使用索引呢?

Is this normal or am I missing something else in the query? The actual query is of course much larger and so it could be caused by some other factor. Any other ideas why an index would not be used in a query?

推荐答案

这是正常现象。仅当您具有 =条件时才使用索引。搜索!=条件的索引无效。

This is normal. Index will only be used if you have a '=' condition. Searching index for != condition is not effective.

类似地,这可能使用索引(在Oracle中)

Similarly, this may use the index (in Oracle)

select * from Table where x like 'some%'

,但这不是

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

此外,
从表中选择*其中1到10之间的x 将使用索引

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

这篇关于如果where条件为!= ?,则不使用数据库索引。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆