Quantcast
Viewing all articles
Browse latest Browse all 15889

NONculstered Index not fire when i use or clause

i have jobs table

jobid primary key

jobcode (nonclustered index)

jobname (nonclustered index)

so

when i run my script as following:-

---case (1)-- in this case query use nonculstered index

declare @x int;

set @x=1;

select * from Jobs
where
 @x=0 and ( jobcode='j' or jobname='j') 


--case (2)-- in this case query not  use nonculstered index and performance be slow

declare @x int;

set @x=1;

select * from Jobs
where
 (@x=0 and ( jobcode='j' or jobname='j') )

or

(@x=0 and  jobcode='j' )

so what can i do to make case (2) use nonclustered index?

case (1)

Image may be NSFW.
Clik here to view.

case (2)

Image may be NSFW.
Clik here to view.





Viewing all articles
Browse latest Browse all 15889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>