fukamachi / mito

An ORM for Common Lisp with migrations, relationships and PostgreSQL support
284 stars 31 forks source link

Eager Loading should be with a JOIN not two queries #129

Open daninus14 opened 1 year ago

daninus14 commented 1 year ago

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;