<p dir="auto">While deleting duplicate relationships after a while the heap got exhausted.</p>
<p dir="auto">Action executed:<br>
call apoc.periodic.commit("match (a)-[r]-(b)<br>
with a,b, TAIL(collect(r)) as rr<br>
where length(rr)&gt;0<br>
foreach (r in rr | delete r)",{limit:10000});</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/1593474/23226052/3f790360-f902-11e6-904f-5a5bee0248ee.png"><img src="https://cloud.githubusercontent.com/assets/1593474/23226052/3f790360-f902-11e6-904f-5a5bee0248ee.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">Heap dump:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/1593474/23226078/521daa98-f902-11e6-9a68-71df0655d126.png"><img src="https://cloud.githubusercontent.com/assets/1593474/23226078/521daa98-f902-11e6-9a68-71df0655d126.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">JVM:<br>
-Dlog4j.configuration=file:conf/log4j.properties<br>
-Dneo4j.ext.udc.source=zip-powershell<br>
-Dorg.neo4j.cluster.logdirectory=data/log<br>
-Xms24g<br>
-Xmx24g<br>
-XX:+UseG1GC<br>
-XX:-OmitStackTraceInFastThrow<br>
-XX:+AlwaysPreTouch<br>
-XX:+UnlockExperimentalVMOptions<br>
-XX:+TrustFinalNonStaticFields<br>
-XX:+DisableExplicitGC<br>
-Djdk.tls.ephemeralDHKeySize=2048<br>
-Dunsupported.dbms.udc.source=zip<br>
-Xloggc:C:\Local.Work\neo4j-enterprise-3.1.1-SNAPSHOT/gc.log<br>
-XX:+PrintGCDetails<br>
-XX:+PrintGCDateStamps<br>
-XX:+PrintGCApplicationStoppedTime<br>
-XX:+PrintPromotionFailure<br>
-XX:+PrintTenuringDistribution<br>
-XX:GCLogFileSize=20m<br>
-XX:NumberOfGCLogFiles=5<br>
-Dfile.encoding=UTF-8</p>
<p dir="auto">Nodes<br>
MATCH (n) RETURN count(n)<br>
count(n)<br>
44594815</p>
<p dir="auto">Relationships<br>
$MATCH ()--&gt;() RETURN count(<em>);<br>
count(</em>)<br>
28557252</p>
<p dir="auto">I found a discrepancy when running two semantically equivalent queries against an empty database:</p>
<hr>
<p dir="auto">1:</p>
<div class="highlight highlight-source-cypher notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="CREATE ({x:0})&lt;-[y:A]-() CREATE ({x:endNode(y).x})
-
RETURN COUNT { ({x:0}) } AS n"><pre class="notranslate"><span class="pl-k">CREATE</span> (<span class="pl-s1"><span class="pl-k">{</span><span class="pl-smi">x</span><span class="pl-k">:</span><span class="pl-c1">0</span><span class="pl-k">}</span></span>)<span class="pl-c1">&lt;-</span><span class="pl-k">[</span><span class="pl-smi">y</span><span class="pl-en"><span class="pl-k">:</span><span class="pl-en">A</span></span><span class="pl-k">]</span><span class="pl-c1">-</span>() <span class="pl-k">CREATE</span> (<span class="pl-s1"><span class="pl-k">{</span><span class="pl-smi">x</span><span class="pl-k">:</span><span class="pl-smi">endNode</span>(<span class="pl-smi">y</span>).<span class="pl-smi">x</span><span class="pl-k">}</span></span>)
<span class="pl-k">-</span>
<span class="pl-k">RETURN</span> <span class="pl-smi">COUNT</span> <span class="pl-s1"><span class="pl-k">{</span> ({<span class="pl-smi">x</span><span class="pl-k">:</span><span class="pl-c1">0</span><span class="pl-k">}</span></span>) } <span class="pl-k">AS</span> <span class="pl-smi">n</span></pre></div>
<p dir="auto">Produces:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="╒═══╕
│&quot;n&quot;│
╞═══╡
│1  │
└───┘"><pre class="notranslate"><code class="notranslate">╒═══╕
│"n"│
╞═══╡
│1  │
└───┘
</code></pre></div>
<hr>
<p dir="auto">2:</p>
<div class="highlight highlight-source-cypher notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="CREATE ({x:0})&lt;-[y:A]-() CREATE (z) DELETE z CREATE ({x:endNode(y).x})
-
RETURN COUNT { ({x:0}) } AS n"><pre class="notranslate"><span class="pl-k">CREATE</span> (<span class="pl-s1"><span class="pl-k">{</span><span class="pl-smi">x</span><span class="pl-k">:</span><span class="pl-c1">0</span><span class="pl-k">}</span></span>)<span class="pl-c1">&lt;-</span><span class="pl-k">[</span><span class="pl-smi">y</span><span class="pl-en"><span class="pl-k">:</span><span class="pl-en">A</span></span><span class="pl-k">]</span><span class="pl-c1">-</span>() <span class="pl-k">CREATE</span> (<span class="pl-smi">z</span>) <span class="pl-k">DELETE</span> <span class="pl-smi">z</span> <span class="pl-k">CREATE</span> (<span class="pl-s1"><span class="pl-k">{</span><span class="pl-smi">x</span><span class="pl-k">:</span><span class="pl-smi">endNode</span>(<span class="pl-smi">y</span>).<span class="pl-smi">x</span><span class="pl-k">}</span></span>)
<span class="pl-k">-</span>
<span class="pl-k">RETURN</span> <span class="pl-smi">COUNT</span> <span class="pl-s1"><span class="pl-k">{</span> ({<span class="pl-smi">x</span><span class="pl-k">:</span><span class="pl-c1">0</span><span class="pl-k">}</span></span>) } <span class="pl-k">AS</span> <span class="pl-smi">n</span></pre></div>
<p dir="auto">Produces:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="╒═══╕
│&quot;n&quot;│
╞═══╡
│2  │
└───┘"><pre class="notranslate"><code class="notranslate">╒═══╕
│"n"│
╞═══╡
│2  │
└───┘
</code></pre></div>
<hr>
<p dir="auto">I believe the queries mentioned above are semantically equivalent and thus their result should be the same.<br>
The only difference between them is the <code class="notranslate">CREATE (z) DELETE z</code> part which shouldn't have any impact on the query, especially on properties that it doesn't reference.</p>
<p dir="auto">I encountered this issue when testing queries against the <strong>neo4j:5.6.0</strong> Docker container.</p>
<h3 dir="auto">Steps to reproduce</h3>
<ol dir="auto">
<li>
 <details>
 <summary>Run the Docker Container</summary>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="docker run \
    -p 7474:7474 -p 7687:7687 \
    --name neo4j-apoc \
    -e apoc.export.file.enabled=true \
    -e apoc.import.file.enabled=true \
    -e apoc.import.file.use_neo4j_config=true \
    -e NEO4J_PLUGINS=\[\&quot;apoc\&quot;\] \
    -e NEO4J_AUTH=none
    --rm \
    neo4j:5.6.0"><pre class="notranslate"><code class="notranslate">docker run \
    -p 7474:7474 -p 7687:7687 \
    --name neo4j-apoc \
    -e apoc.export.file.enabled=true \
    -e apoc.import.file.enabled=true \
    -e apoc.import.file.use_neo4j_config=true \
    -e NEO4J_PLUGINS=\[\"apoc\"\] \
    -e NEO4J_AUTH=none
    --rm \
    neo4j:5.6.0
</code></pre></div>
 </details>
</li>
<li>
<p dir="auto">Navigate to the browser interface on <a href="http://localhost:7474" rel="nofollow">localhost:7474</a></p>
</li>
<li>
<p dir="auto">Run the aforementioned queries and observe that their results differ.</p>
</li>
</ol>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">The queries should result in the same behavior</p>
<h3 dir="auto">Actual behavior</h3>
<p dir="auto">The first query returns <code class="notranslate">1</code>, whereas the second query returns <code class="notranslate">2</code>.</p>