<p></p>
<p><b>@tomhughes</b> commented on this pull request.</p>

<p dir="auto">I suspect you could do this using <code class="notranslate">in_batches_of</code> and <code class="notranslate">with</code> to construct CTEs inside the loop but it might be more hassle than it's worth.</p><hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6347#discussion_r2296110433">lib/tasks/backfill_changeset_stats.rake</a>:</p>
<pre style='color:#555'>> +      # Find changeset ids to be updated
+      ids_sql = <<~SQL.squish
+        SELECT id
+        FROM changesets
+        WHERE id BETWEEN #{start_id} AND #{end_id}
+          AND (
+            COALESCE(num_created_nodes, 0) +
+            COALESCE(num_modified_nodes, 0) +
+            COALESCE(num_deleted_nodes, 0) +
+            COALESCE(num_created_ways, 0) +
+            COALESCE(num_modified_ways, 0) +
+            COALESCE(num_deleted_ways, 0) +
+            COALESCE(num_created_relations, 0) +
+            COALESCE(num_modified_relations, 0) +
+            COALESCE(num_deleted_relations, 0)
+          ) IS DISTINCT FROM num_changes
</pre>
<p dir="auto">None of those columns are nullable so we don't really need the <code class="notranslate">COALESECE</code> calls and we can use normal comparison rather than <code class="notranslate">IS DISTINCT FROM</code>?</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/6347#pullrequestreview-3148231670">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLLYEWYKAUZQFCTOPN33PB5OJAVCNFSM6AAAAACEUBV34SVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTCNBYGIZTCNRXGA">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLPSO7766A56L3NWGWD3PB5OJA5CNFSM6AAAAACEUBV34SWGG33NNVSW45C7OR4XAZNRKB2WY3CSMVYXKZLTORJGK5TJMV32UY3PNVWWK3TUL5UWJTV3UYZ7M.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/6347/review/3148231670</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/6347#pullrequestreview-3148231670",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/6347#pullrequestreview-3148231670",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>