Unidirectional inheritance (with Ebean + Play! Framework)

I use the concept of single table inheritance due to OOP considerations, of course.
for example, PostLike and TopicLike inherit from the Like class.
I see two problems with this methodology:

  • instead of two tables (PostLike and TopicLike) I get "one big table" from the ones I like.
  • This table has an extra column called dtype that allows you to identify the record (i.e. type of type). in the long run, this could be a huge loss of disk space. is not it?

I am not a database expert, and because of this I wanted to get your idea about this database project and whether these two problems are important.

+4
source share
1 answer

If you have only one table instead of two, reading will be faster because you will avoid "join". But you will use more space because you will have an extra dtype column and some empty columns.

Take an example. Here is the model (without JPA annotations):

 public abstract class Like { public Long id; public String foo; } public class PostLike extends Like { public String post; } public class TopicLike extends Like { public String topic; } 

You will get a Like table:

 ---------------------------------- |dtype | id | foo | topic | post | ---------------------------------- |post | 1 | a | NULL | p1 | |topic | 2 | b | t1 | NULL | ---------------------------------- 

And as you can see, for the PostLike element, you will have a NULL theme value.

But there is currently disk space if this is not a real problem.

The only drawback that I see when inheriting with a single table is the number of columns that can be huge if you have many properties, and it’s more difficult to add a new property / column to your model (if you need to apply DB Evolution).

And AFAIK, ebean only supports "unidirectional table inheritance."

+7
source

Source: https://habr.com/ru/post/1437035/


All Articles