<p dir="auto">I need to create indexes in relationship to optimize my query. Cypher not support indexes in relationship ?<br>
And I cannot create the follow constraint in relationship SHARED_REACTION:<br>
CREATE CONSTRAINT ON ()-[sr:SHARED_REACTION]-() ASSERT EXISTS (sr.id)<br>
Neo4j returns:<br>
"Unable to create CONSTRAINT.."<br>
Neo.DatabaseError.Schema.ConstraintCreationFailed</p>
<p dir="auto">How can I create this constraint and to use indexes in relationship SHARED_REACTION ?</p>
<p dir="auto"><em>NOTE: This description has been updated, the original description is at the bottom</em></p>
<p dir="auto">While Neo4j primitives are <code class="notranslate">read committed</code>, Cypher composes these primitives together in ways that can lead to errors - notably cypher may read an entity that is subsequently deleted, and will then fail to perform some operation on it.</p>
<p dir="auto">While this could be construed as a cypher issue, it is really an issue of isolation levels - we need to implement <code class="notranslate">repeatable read</code> isolation in the kernel to allow cypher to expose a single cypher statement as a read committed operation.</p>
<h3 dir="auto">If you suspect an isolation issue</h3>
<p dir="auto">If you believe you are hitting a problem related to transaction isolation levels, please post a comment on this ticket with:</p>
<ul dir="auto">
<li>Any setup required</li>
<li>All cypher statements involved</li>
<li>What you expected the result to be</li>
<li>What the result actually is</li>
<li>Your Neo4j version, Java version and operating system</li>
</ul>
<h2 dir="auto">Workarounds</h2>
<h3 dir="auto">Lock the read set</h3>
<p dir="auto">Many (but not all) of the cases where this is an issue have a format like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;match some stuff&gt;
&lt;perform some mutation&gt;"><pre class="notranslate"><code class="notranslate">&lt;match some stuff&gt;
&lt;perform some mutation&gt;
</code></pre></div>
<p dir="auto">For this category of statements, we suffer the same problem as SQL solves with <code class="notranslate">SELECT ... FOR UPDATE</code>. Cypher does not yet support a construct like that, but it can be emulated using the following pattern:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;match some stuff&gt;
&lt;set a property, for instance __lock__&gt;
WITH &lt;stuff&gt;
&lt;perform some mutation&gt;"><pre class="notranslate"><code class="notranslate">&lt;match some stuff&gt;
&lt;set a property, for instance __lock__&gt;
WITH &lt;stuff&gt;
&lt;perform some mutation&gt;
</code></pre></div>
<p dir="auto">For example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="MATCH (n:Person)
SET n.__lock__ = 1
WITH n
SET n.description = &quot;Some description&quot;"><pre class="notranslate"><code class="notranslate">MATCH (n:Person)
SET n.__lock__ = 1
WITH n
SET n.description = "Some description"
</code></pre></div>
<h3 dir="auto">Retry transaction</h3>
<p dir="auto">Particularly for small read operations and small writes, given the transactional nature of Neo4j, you can rollback and retry any transaction where a statement fails due to this issue. A common pattern for this is to model your query as a unit of work that can be retried.</p>
<h2 dir="auto">Original message</h2>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/peterneubauer/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/peterneubauer">@peterneubauer</a>: 'See <a href="https://groups.google.com/group/neo4j/browse_thread/thread/9355edd2059d70e2/a51d06c894107327?lnk=gst&amp;q=Concurrent+reading+and+deleting+on+relationships+leads+to+NotFoundException.+How+to+ignore%3F#a51d06c894107327" rel="nofollow">https://groups.google.com/group/neo4j/browse_thread/thread/9355edd2059d70e2/a51d06c894107327?lnk=gst&amp;q=Concurrent+reading+and+deleting+on+relationships+leads+to+NotFoundException.+How+to+ignore%3F#a51d06c894107327</a> for background.</p>
<p dir="auto">Example code is at <a href="http://code.google.com/p/graph-query-benchmarks/source/browse/trunk/graph-query-benchmarks/src/test/nz/ac/massey/cs/graphbenchmarks/spikes/neo4j/NeoIssues.java" rel="nofollow">http://code.google.com/p/graph-query-benchmarks/source/browse/trunk/graph-query-benchmarks/src/test/nz/ac/massey/cs/graphbenchmarks/spikes/neo4j/NeoIssues.java</a>'</p>