Difference between Key and Index

Mar 1, 2011 at 7:10 AM


What is the difference between key and index? Why not include everything you need for queries in a complex key so you don't need to have an index that has to be referenced by a name (read magic string)?



Mar 1, 2011 at 12:53 PM

The key is unique and helps Sterling internally organize the instances. The index provides flexibility around definining various in-memory values. The index might be named but you can always use an enumeration or constant to define it - I wouldn't change the implementation and force you to use "Index1" and "Index2" just to avoid a string identifier.

Mar 1, 2011 at 1:21 PM

I have a similar question, I have an object that needs an id for identification, but at the same time almost all of my queries involves a date property on the object. Is this a reason to put the Id and the DateTime as the key, or is it better to use index with the dates. Its probably a lot persisted objects of this type so im afraid it will use up to much memory if i have a a index and a key, 

Mar 4, 2011 at 1:37 AM

How many objects are we talking about? When in doubt, why not just load up the scenario and test yourself? There is no substitute for actual performance and testing. However, if you do the math, if the key is an integer (4 bytes) and you had 100,000 objects, that would still only take up 100,000 x 4 = 400,000 bytes = 400KB = less than 1/2 MB of memory.