Here are some of my thoughts on whether or not to use the inheritance features of PG. Tentatively we've been saying "yes, let's do it". The motivation for using them is that conceptually acs_objects are a good fit. However the implementation of inheritance in PG is incomplete ...
Pros and cons
Pro
- Conceptually slick.
- More readable datamodel.
- Gets rid of endless joins, exchanging them for (in essence) magic unions performed inside the RDBMS engine itself, so is likely more efficient. Maybe *much* more efficient.
- Not entirely there. Indices aren't inherited. Most constraints
aren't inherited, including referential integrity constraints.
(this last wouldn't matter if ACS 4 were written in a 100% object oriented style, because inheritance would replace foreign keys in all cases - but that's not how the ACS 4's written. It is a hybrid and this helps expose the incompleteness of the existing PG inheritance mechanism).
- Getting rid of lots of joins to parents also means rewriting
almost
every query in the system.
Only the most trivial of queries on acs_object-derived tables will work without change. This increases the load on people porting individual modules - it is this factor that really makes me think we should air this particular issue in public. I'm hoping people other than you and I do most of the module-level porting, and they should have a say in a fundamental decision that affects how much query mangling is needed.
This also magnifies the maintenance issue, though if it is true that aD is truly going to stop 4x development other than minor bug fixes then this is a minor point.
Ben points out that ACS4 makes very heavy use of views, and that much of the necessary changes might well be isolated and therefore not much of a burden at all. We need to start reading modules...
- Referential integrity checks on a foreign key pointing to an object table only check that table. This leads to potential RI errors if someone leaves them in by accident without thoroughly understanding the code using the table. Routine testing might not uncover these.
- Because of the incompleteness of the inheritance system, the PG group decided *not* to adopt the SQL92 syntax for inheritance in PG 7.1, but rather to keep the old syntax. Improving the inheritance mechanism for PG 7.2 is something of a priority, apparently - I hope so. It would be really cool if it were complete.
Con
Because of #1, if we do use the inheritance mechanism we might want to use a preprocessor on our datamodels to automatically define the necessary primary key, indices, etc when deriving one table from another. This would remove the primary source of worry i.e. folks forgetting to define the proper indices on child tables. A forgotten index could lead to test installations running fine, while real installations would get slower and slower as tables filled.
Any volunteers who might want to look into this? Any other hacks come to mind?
Request notifications