Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

el3's avatar
Level 1

How to optimize performance on a big db select/request?

I have a list of players, around 40 elements, every of these elements has additional data from other tables, exactly looks structure so:

- Player
    -> position -> relation to another table with positions
    -> tshirt_icon -> last element of a additional table with this player id...
    -> Last 5 teams -> additional table with all teams, relations is team_id and player_id
        -> Team 5 - position
        -> Team 4 - position
        -> Team 3 - position
        -> Team 2 - position
        -> Team 1 - position
    -> Color
    -> Years
    -> Last 5 games -> additional table with all players of a game, relations is game_id and player_id
        -> Game 5 -> state
        -> Game 4 -> state
        -> Game 3 -> state
        -> Game 2 -> state
        -> Game 1 -> state
    -> VIP player -> bool
    -> Played games -> all played games of actuall season
    -> Disqualified games -> count
    -> inactive -> bool
    -> only_freetime -> bool

I know it is not ideal to list directly all element in one list but it is required...

By loading is the page to slow, in the debugbar I see for a short time arround 700 queries, after page is loaded then I see normaly max. 10 queries, memory usage 2mb and request duration 155ms. I use never raw sql queries, there are only laravel relations and scopes... by elements which has 5 additional items there is also only 5 requested from database...

Is there any way to make a little faster the loading without to use cache because the data will be permanently edited...?

0 likes
1 reply

Please or to participate in this conversation.