<p></p>
<p dir="auto">Although I'm not sure if rails' <code class="notranslate">.includes</code> works correctly with composite keys.</p>
<pre class="notranslate"><code class="notranslate">irb(main):020> OldNode.where("changeset_id = 81").includes(:old_tags).explain
  OldNode Load (0.7ms)  SELECT "nodes".* FROM "nodes" WHERE (changeset_id = 81)
  OldNodeTag Load (0.6ms)  SELECT "node_tags".* FROM "node_tags" WHERE "node_tags"."node_id" IN ($1, $2, $3) AND "node_tags"."version" IN ($4, $5, $6)  [["node_id", 1314], ["node_id", 1312], ["node_id", 1313], ["version", 1], ["version", 3], ["version", 2]]
=> 
EXPLAIN SELECT "nodes".* FROM "nodes" WHERE (changeset_id = 81)
                                     QUERY PLAN
-------------------------------------------------------------------------------------
 Index Scan using nodes_changeset_id_idx on nodes  (cost=0.28..8.29 rows=1 width=53)
   Index Cond: (changeset_id = 81)
(2 rows)

EXPLAIN SELECT "node_tags".* FROM "node_tags" WHERE "node_tags"."node_id" IN ($1, $2, $3) AND "node_tags"."version" IN ($4, $5, $6) [["node_id", 1314], ["node_id", 1312], ["node_id", 1313], ["version", 1], ["version", 3], ["version", 2]]
                                  QUERY PLAN
------------------------------------------------------------------------------
 Bitmap Heap Scan on node_tags  (cost=12.86..19.98 rows=3 width=29)
   Recheck Cond: (node_id = ANY ('{1314,1312,1313}'::bigint[]))
   Filter: (version = ANY ('{1,3,2}'::bigint[]))
   ->  Bitmap Index Scan on node_tags_pkey  (cost=0.00..12.86 rows=3 width=0)
         Index Cond: (node_id = ANY ('{1314,1312,1313}'::bigint[]))
(5 rows)
</code></pre>
<p dir="auto">Conditions like <code class="notranslate">WHERE "node_tags"."node_id" IN ($1, $2, $3) AND "node_tags"."version" IN ($4, $5, $6)</code> select unnecessary tag versions.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4569#issuecomment-1986884796">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLP7Z5B3VJN62VSB3Q3YXMSRDAVCNFSM6AAAAABEOEGIQWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBWHA4DINZZGY">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLJYPPEU4ATH7MXGLT3YXMSRDA5CNFSM6AAAAABEOEGIQWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTWNV2LY.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/4569/c1986884796</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/4569#issuecomment-1986884796",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/4569#issuecomment-1986884796",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>