In the project I'm working on, we have an activity table, and each action can be associated with one of about 20 different "activity information" tables ...
eg. If the operation was of type โworkโ, then it would have a corresponding record of activity_details_work, if it had a type of โsick leaveโ, then it would have a corresponding record of activity_details_sickleave, etc.
We are currently loading actions, and then for each type of activity we have a separate request to get information about the activity from the corresponding table. It clearly does not scale if you have thousands of actions.
So, my initial thought was to have one query that retrieves the actions and combines the details in one go, for example.
SELECT * FROM activity LEFT JOIN activity_details_1_work ON ... LEFT JOIN activity_details_2_sickleave ON ... LEFT JOIN activity_details_3_travelwork ON ... ...etc... LEFT JOIN activity_details_20_yearleave ON ...
But this will lead to the fact that each record will have 100 fields, most of which are empty, and this seems unpleasant.
Lazy-loading of parts is not really an option, since parts are almost always requested in the main logic, at least for the main types.
Is there a super-smart way to do this that I don't think about?
Thank you in advance
source share