<p>If it's possible to have <code>current_way_nodes.node_id</code> FK reference <code>current_nodes.node_id WHERE visible</code>, then yes. Last time I looked, I wasn't able to see how to do it without stuff like creating a unique index on a materialized view just for FK checking.</p>

<p>Additionally, we'd need a fairly big schema change (or more materialized views) to support doing this for relation members, as currently that table "references" three different tables.</p>

<p>For the materialized views + indexes approach, it's unclear to me how much extra space and time that would take up on the server. The docs seem to suggest a materialized view takes the same space as if it were a table, and I assume the same for any index on it (despite the fact that it's a strict subset of the PK). This could, it seems to me, be slower than just using row locking.</p>

<p>The "real fix" here is to stop storing deleted items in the <code>current_*</code> tables at all (and split relation members by type). But that breaks the implementation of the deleted items call, etc... See discussions <em>passim</em> about how this has been on the TODO list since approximately forever <img class="emoji" title=":wink:" alt=":wink:" src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f609.png" height="20" width="20" align="absmiddle"></p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br>Reply to this email directly or <a href="https://github.com/openstreetmap/openstreetmap-website/pull/992#issuecomment-111651328">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/ABWnLW91ZUcazwCWWem2FzR39oRQcHFlks5oS37-gaJpZM4FBkjZ.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
  <div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
    <link itemprop="url" href="https://github.com/openstreetmap/openstreetmap-website/pull/992#issuecomment-111651328"></link>
    <meta itemprop="name" content="View Pull Request"></meta>
  </div>
  <meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>