B
B
BonBon Slick2019-08-23 10:30:01
Database
BonBon Slick, 2019-08-23 10:30:01

How effective is Single Table Inheritance?

Real example

class Authentication{
    $password;
    $email;
}

User extends Authentication{
   $name;
   $posts; // relation ID
}
Admin extends Authentication {
   $actions; 
}
Moderator extends Authentication{
   $name;
   $moderatedPosts;
}
Supportextends Authentication{
   $name;
   $helpedUsers; // relation ID
}

Table structure for table authentication_clients
name  // for everyone, even admin who do not have name
password
email
// relations
helpedUsers // referenced on this table
moderatedPosts // join referenced to external table
posts // join referenced to external table
actions // long json of serialized objects

Here's what comes out
1 - we have empty fields like a name for Admin 2 - there are also empty fields
for others helpedUsers
3 - a huge table with a bunch of fields, which is difficult to read
4 - the weight of the database is more than
5 - Faster fetching especially in pgsql
6 - Easier change the table and map to objects
7 - it is more difficult to scale, some data will obviously be duplicated, those that could be moved to a separate object with its own table as in Class Table Inheritance.
Questions arise when and why to use Single Table Inheritance?
At what volumes of data?
Let's say with 10,000,000 records with a UUID as an ID and another 100 fields of type ValueObject, how well would it work?
When, why, and which of the 3 inheritance design patterns in tables is preferable?
Who worked, please share your experience. Maybe I missed something else from the list. Unfortunately, there is no experience of working with all 3 templates on real, high-load projects, so it is difficult to correctly assess the effectiveness of one or another. Perhaps somewhere there is performance tests or their results.
The most flexible of Class, Concrete and Single table Inheritances, Class. But there are a lot of joins out there, because there is a table for each class. But the duplication of data is minimized.
I use Concrete or Class myself, never used Single.
Info from the book https://martinfowler.com/eaaCatalog/classTableInhe...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
developer007, 2019-08-29
@developer007

we have a million records with doctrine inheritance and everything flies
https://www.doctrine-project.org/projects/doctrine...
see how it is implemented there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question