Feb 1999
Mapping Object to Tables in DBOS
There are 3 standard ways of mapping objects to tables in a database.
- Method 1, Store all objects in a single table:
This method is usually used if the number of classes is low, or the inheritance graph is relatively deep. It involves mapping each object to a row, and defining an attribute of the table for each member field of the class. The attributes could be overloaded to save space, but that causes query complexity. This method allows for a single object to be loaded by querying a single table. It can be fast, if indexed well, but wasteful of space. This method is definitely not normalized.
- Method 2, For each class, store all fields in a single table.
This method is commonly used. It is probably the most efficient design, accounting for speed and space. Like method 1, an object can be loaded quickly and simply. The use of different tables causes problems when trying to gather all objects of a certain subtype; many tables have to be queried. The tables to search will have to be stored in the system somehow. Many to one joins can be quite complicated because the join attribute may exist in many tables. This method is not normalized.
- Method 3, For each class store only the non-inherited fields in a table.
This method results in a normalized table structure. Getting a complete list of a certain type of object only requires the search of single table because all values of an attribute are found in the one table. Many to One joins are simpler than method 2.. But this method may require a large number of queries just to get all the information for a single object.
It is method 3 that is used in the DBOS. The drawbacks of this method are overcome using the GUID.