Assume I have a table Business and I create an index on column 'country' As per my understanding, the DB will break up table into (sort of) chunks where one or more chunk is dedicated on a per country basis. Like so:
chunk1 = records for country US
chunk2 = records for country US
chunk3 = records for country IN
chunk4 = records for country NZ....
If I now create a separate index on column 'businessType' then how will the database structure look like?
Will the DB create 2 separate copies of the data, one indexed by country and one indexed by businessType?
OR
Will the DB create chunks so that for each chunk contains data on a per-country and per-businessType basis? Like so
chunk1 = records for country = US & businessType = IT
chunk2 = records for co开发者_如何学Cuntry = US & businessType = Finance
chunk3 = records for country = US & businessType = Finance
chunk4 = records for country = US & businessType = Finance
chunk5 = records for country = IN & businessType = IT
chunk6 = records for country = IN & businessType = IT
chunk7 = records for country = IN & businessType = Agriculture ......
Assume I have a table Business and I create an index on column 'country' As per my understanding, the DB will break up table into (sort of) chunks where one or more chunk is dedicated on a per country basis
Nope. Your understanding is wrong.
The table will not be broken up, it will have the records in a big chunk, at first in roughly insertion order.
The index is what is organized in chunks, if you will (even though it is usually more like a tree structure).
The index stores the indexed column value and a pointer the location of the record in the table itself.
If I now create a separate index on column 'businessType' then how will the database structure look like?
The table storage structure will not change at all. You will just have some additional indexes.
Will the DB create 2 separate copies of the data, one indexed by country and one indexed by businessType?
If you create a separate index on the column 'businessType', then you will have a tree structure organized by only 'businessType'. This is completely independent of the other index you created earlier.
Will the DB create chunks so that for each chunk contains data on a per-country and per-businessType basis?
If you create a composite index on (country, businessType), then you will indeed get an index that is "chunked" by both columns: The first level of the tree will dispatch on country, the second one (for a given country) on businessType.
精彩评论