I could not get a straight answer on this. The columns in my database have good selectivity on colA, colB, colC. They are in single table. These columns also contain NULL values. I tried building NORMAL indexes. But the query executions are not fast. I guess because of the operator NOT, indexes are not being used.
Question: Please confirm whether the index will be used in the following scenarios. I know that colB <> 'b1' will not use index. Also, I am NOT asking what would happen if I were to force index usage. I can't because my product builds the query in backend to which I don't have any control.
- NOT (colA = 'a1')
- NOT (colA = 'a1' OR colA = 'a2')
- NOT (colA = 'a1' OR colA = 'a2' AND colC = 'c1')
NOT (colA = 'a1' OR colA = 'a2' OR colC = 'c1')
colB = 'b1' OR colB is not null
- colB = 'b1' OR colB is null
- colB <> 'b1' OR colB is not null
- colB <> 'b1' OR colB is null