Roy Tang

Programmer, engineer, scientist, critic, gamer, dreamer, and kid-at-heart.

Blog Notes Photos Links Archives About

Someone on quora asked:

How many searches does it take on average to find a row when not indexed in MySQL database?

When there is no index in use, you are essentially performing a sequential search (iterating through each row and testing it to see if it matches your criteria), which means the search performs at O(n). If you limit your results to the first hit (using TOP 1 as pointed out by Scott Berry), the average number of checks is n/2 where n is the total size of the sample set. If there is no limit, the average number of checks is n (since you check all rows)

Posted by under notes at #answers
Also on: quora / 0