mysql - Intersection tables or Common Super table -
i have design so. there tables each object class. each table contains rows (objects) needs associated multiple statuses.
statuses table
- id
- status
users
- id
- username
- ...
some other object class
id
...
what's best way link each object class table status table? tossing between 2 methods described in sql antipatterns:
intersection tables
users_has_statuses
- user_id
- status_id
- unique(user_id, status_id)
etc. require intersection table each object class. so, add more object classes (tables), need add intersection table, means that
ancestor tables
object_ancestor
- id
object_ancestor_statuses
- object_ancestor_id
- status_id
- unique(object_ancestor_id, status_id)
each object class have column foreign key linked id column in object_ancestor table.
in terms of performance , design elegance, way better?
my opinion intersection tables way better.
if have many tables entities statuses , use single table linking them statuses, add more , more data, performance increasingly degrade (because when dbms statuses of entity, have "go through" entries other types of entities).
problem ancestor way looking @ database structure, couldn't tell types of entities have statuses. if have people, dogs , rocks, each having entries in ancestor table, couldn't tell rocks don't have statuses, example.
Comments
Post a Comment