If i have table with two column: id
and priority
.
- Id is primary key
- priority is number, unique and have indexing (Non-clustered).
So if i search by id or by priority. Which one is faster and why?
If i have table with two column: id
and priority
.
So if i search by id or by priority. Which one is faster and why?
THIS ANSWERS THE ORIGINAL VERSION OF THE QUESTION.
This has little to do with clustered versus non-clustered indexing. Presumably, the type of id
is a number (usually such columns are integers and hence four bytes). The type of username
is probably some sort of varchar()
.
When searching through a B-Tree index -- whether clustered or not -- fixed length keys have a slight advantage. Hence, I would expect id
to be slightly faster than username
.
Does this make a difference in real world applications? I really doubt it. In a large-ish table, the time for query processing is typically dominated by I/O time loading the index and/or pages. Not always. But micro-optimizations (nano-opimizations?) generally have much less impact than one would expect.