in mysql 8.0.23
case 1
select *
from boards b
where b.id = 11
select *
from comments c
where c.board_id = 11
case 2
select b.*
, c.comments
from boards b
left outer join lateral (
select json_arrayagg(json_object(
'id', c.id,
'title', c.title,
...
)) as comments
from comments c
where c.board_id = b.id
) c on true
where b.id = 11
Which one is more performant?
I'm not curious about anti-patterns or anything like that.
Is it better to reduce the connection cost and fetch it all at once?
Or is it better to have no json conversion cost
Case 2 was faster in my tests, but it only confirmed the response speed of the query. I want to know what mysql server can process more queries in same time.