sql server - Execution plan shows index seek for 'is null' query on non-clustered index -


as know index on column null values not in 'is null' queries null matches everything. expecting see index scan or full table scan in execution plan.

however when @ actual execution plan of query see it's doing index seek.

how possible? or red-herring?

enter image description here

as understand question, worried why query optimizer chosses index seek when rows has null in data should have index scan or full table scan because end reading rows no nullable column. how possible? or red-herring?

first , @ defination of nonclusterd index seek on tooltip "

scan perticular range of rows on nonclustered index

"

seek not seek through b-tree structure sometime seekrange can there 2 type of seek in sql server

(1) singleton lookups : when go through b-tree direct root leaf exact matching row, , happen in unique index euality predicate.

(2) seek plus range scans : when go through b-tree root leaf performs range scan through leaf in 1 direction until qulify matching rows.

so in case seek plus range scans rows in index qulify data.

so why did not full table scan?

because using predicate "someio null"
someid had non-unique nonclustered index , index page size smaller table/custered index`s page size better read less pages more.

so why did not full index scan why choses index seek?

for i'll' demostrate execution plan both seek , scan same query

enter image description here

enter image description here

as might know sql server create multiple physical plan of logical expressed query, , chooses query plan has lowest overall cost. can see in above image query plan index seek has lowest overall cost index scan ( one of reason of lower cost in above plan estimated row size) . , on real world can compare both.

page read , scan count same both on system testtable

scan count 1, logical reads 3179,

warm chache results:

base line 5 execution without paralllism

  iterator      max time   min time    avg time  index seek     122 ms.    112 ms.     116 ms  index scan     149 ms     139 ms      145 ms 

on system seek winning well.

now completetly diffrent question index of worthy or not.

after op comment . sql server index null values?

yes does...


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -