Upgrade to Pro — share decks privately, control downloads, hide ads and more …

N+1問題が起きる原因について調べてみた 

smallmonkeykey
January 19, 2024
20

 N+1問題が起きる原因について調べてみた 

学習中の者です。
1月11日のOmotesando.rbで、初めてのLTをしました。

smallmonkeykey

January 19, 2024
Tweet

Transcript

  1. article.user.name の場合のSQL Article Load (0.5ms) SELECT "articles".* FROM "articles"    1回

    User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]] User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]] User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 3], ["LIMIT", 1]] N回(ここでは3回)