I have some questions about database design.
- Is there a name for this?
- Is this a good practice?
- Any performance considerations?
I have a general table structure used to store relationships.
I recently reworked some things to use this general structure instead of direct Fk columns, but now I'm not sure if this was really a better idea.
Original circuit:
+ ------------------ + + --------------------- + + ------ ---------------- +
| Book | | Note | | MetaParent |
| ------------------ | | --------------------- | | ---------------------- |
| Id | | Id | | Id |
| NoteId | | MetaParentId: (Null) | | MetaTableId |
| + ------- + + ---- + KeyValue |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
+ ------------------ + + --------------------- + + ------ ---------------- +
New scheme
+ ------------------ + + --------------------- + + ------ ---------------- +
| Book | | Note | | MetaParent |
| ------------------ | | --------------------- | | ---------------------- |
| Id | | Id | | Id |
| | | MetaParentId: (Null) | | MetaTableId |
| + + + ---- + KeyValue |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
+ ------------------ + + --------------------- + + ------ ---------------- +
So basically instead of the direct Fk relationship between Book and Note, we have an indirect relationship through the MetaParent table using the MetaTableId / KeyValue columns.
Currently, the MetaParent table contains about 500 thousand records, and everything works fine. But we restore indexes every night.
My fears are that the relationship between the book and the record is not obvious. You need to know what exists and use the MetaParent table.
Also performance, I'm not sure at what point we would encounter problems merging with MetaTableId / KeyValue, which run too slowly. It seems the more you add to this table, the slower the queries will be.
source share