<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>syu-m-5151</author_name>
  <author_url>https://blog.hatena.ne.jp/syu-m-5151/</author_url>
  <blog_title>じゃあ、おうちで学べる </blog_title>
  <blog_url>https://syu-m-5151.hatenablog.com/</blog_url>
  <categories>
    <anon>DB</anon>
    <anon>Rust</anon>
  </categories>
  <description>はじめに ある日、APIのレスポンスが突然5秒を超えた。コードを見直してもバグはない。SQLも正しく書けている。途方に暮れながらログを確認すると、1リクエストで300回以上もクエリが発行されていた。原因は、ループ内で著者情報を1件ずつ取得していたこと。これがN+1クエリ問題だ。 本記事では、RustとPostgreSQLで関連データをまとめて取得し、クエリの発行回数を減らす5つの方法を扱う。JOIN、IN句とHashMap、配列・JSON集約、DataLoaderを、取得するデータの関係や結果の組み立て方で比べる。 N+1クエリ問題とは 問題のあるコード 本記事では、RustのSQLクライアン…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fsyu-m-5151.hatenablog.com%2Fentry%2F2025%2F12%2F26%2F171102&quot; title=&quot; Rustにしたのに遅い？─ N+1クエリ問題の発見と解決 - じゃあ、おうちで学べる &quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url>https://cdn-ak.f.st-hatena.com/images/fotolife/s/syu-m-5151/20251226/20251226170118.png</image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2025-12-26 17:11:02</published>
  <title> Rustにしたのに遅い？─ N+1クエリ問題の発見と解決</title>
  <type>rich</type>
  <url>https://syu-m-5151.hatenablog.com/entry/2025/12/26/171102</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
