I have a set of data (assume they are objects) with unique immutable names, like this:
class Datum {
final string name
// other fields
}
Considering that:
- I don't need to support rename. (The names are immutable as I mentioned)
- The names are unique. Among the data I store, there are no two data with the same name.
- There may or may not (depending on how future plugins will be using the API) be a lot of API calls to search a datum by name.
Should When should I index my data with an addition numeric ID, or rather than just by the name?
- in databases?
- The ID would be an auto_increment primary key from the database engine
- The name is provided
- at a runtime memory storage (most likely hashtable, but also other data structures that may be applicable)?
- The ID is an increment value attached with each datum when a datum is loaded.
- The data may be inserted into or removed fro the storage anytime with no specific order, and may be re-inserted (after being removed), but the same datum only occurs in the storage once at the same time.
- Consider implementation in different languages. For example, in Java, a
HashMap<String, ?>
vsHashMap<Integer, ?>
may be used. In PHP, the difference is the key used in the array that stores the data.
Note: The two questions are independent from each other, i.e. yes for database only but no for runtime only may also be a reasonable answer.