mito icon indicating copy to clipboard operation
mito copied to clipboard

Eager Loading should be with a JOIN not two queries

Open daninus14 opened this issue 1 year ago • 0 comments

In the docs for eager-loading https://github.com/fukamachi/mito#eager-loading I noticed that the queries are:

;-> ;; SELECT * FROM `tweet` WHERE (`status` LIKE ?) ("%Japan%") [3 row] | MITO.DB:RETRIEVE-BY-SQL
;-> ;; SELECT * FROM `user` WHERE (`id` IN (?, ?, ?)) (1, 3, 12) [3 row] | MITO.DB:RETRIEVE-BY-SQL

But really this is inefficient since it's causing two queries, it should really be handled as a LEFT JOIN to be one query instead of two and it should be:

SELECT * FROM `tweet` WHERE (`status` LIKE ?) ("%Japan%") LEFT JOIN `user` ON `user`.ID = `tweet`.ID;

daninus14 avatar Aug 23 '23 14:08 daninus14