Number of pages required for an index
I'm trying to work out how many pages would be required If I was to index carID on the following table.
employeeID | name | carID
1 | John | null
2 | Jack | 52
3 | Rob | 开发者_如何学编程 42
and so on...
If each page was able to hold, say, 100 record pointers and the table had 3000 rows. Then I know if there were no null values then there would be: (3000/ 100) = 30 pages of leaf nodes. So 31 pages total to index carID.
However, I'm unsure what happens if there are null values. Surely you don't need to index them? If there were only 1000 cars in the car table lets say (so 2000 null values were present). Would the index of carID require (1000/100) = 10 pages?
Thanks
NULL
values do not get indexed.
As far as exactly how many pages are needed, it depends on the specific database you're using and probably database settings.
Indexes are represented using B-tree structures rather than linear sorted lists so calculating the size of the index is probably not doable with with a simple formula.
Update: Please also note that it is not a rule that NULL values are not indexed. It is dependent on the database engine, as explained here: http://en.wikipedia.org/wiki/Null_(SQL)#Effect_on_index_operation
精彩评论