Why index search becomes more expensive than index scanning

I have a basic question about crawl / search index. Index scanning is effective for a large number of rows. That is, the cost of scanning the index is inversely proportional to the number of rows returned. This is less than the number of lines that are more expensive than the request, as it must crawl all pages, resulting in more I / O.

I was looking for the reason why searches are becoming more expensive than crawling, but I cannot understand why the search is becoming expensive.

What bothers me is index search. Why index search becomes expensive with lots of rows returned. Index search will always be faster and more efficient than crawling, as it directly relates to pages containing strings. Thus, even with a large number of rows, the returned index search should always be more efficient than the index. But this does not happen. I want to know exactly why at some point the search becomes expensive.

select id,name,col1,col2 from TableA -- Will result in index scan. Table has 10000 rows with clustered index on ID column. Query has covering index. select id,name,col1,col2 where ID between 1 and 10 from TableA -- Optimizer Will use index Seek. 

Now, why does the query below get expensive when forcing an index -

 select id,name,col1,col2 from TableA with (forceseek) 
+5
source share
1 answer

The reason that searching for a clustered index is more expensive than indexing is because the index search begins by reading tree B directly from the root nodes to the leaf nodes. This includes reading the index and pages inside the sheet nodes. Therefore, this leads to more I / O. Therefore, when selectivity is less than the optimizer, you choose index scanning instead of index search. It is better to search only when the returned records do not exceed 2 - 3%.

+2
source

Source: https://habr.com/ru/post/1244559/


All Articles