<p dir="auto">I'm using twitter relations as a test bed for neo4j and I ran into issues when making some complicated queries.</p>
<p dir="auto">This query runs in just a little over a second</p>
<div class="highlight highlight-source-cypher notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="MATCH (x:User)
WHERE x.screen_name IN ['apple', 'banana', 'coconut','durian','eggplant']
WITH x
MATCH (y:User)
WHERE y.screen_name IN ['apple', 'banana', 'coconut','durian','eggplant']
WITH x,y
MATCH (x)-[:FOLLOWS]-&gt;(t:User),(y)-[:FOLLOWS]-&gt;(t:User)
RETURN count(*) as c, t.screen_name, t.id
ORDER BY c DESC
LIMIT 1000"><pre class="notranslate"><span class="pl-k">MATCH</span> (<span class="pl-smi">x</span>:<span class="pl-smi">User</span>)
<span class="pl-k">WHERE</span> <span class="pl-smi">x</span>.<span class="pl-smi">screen_name</span> <span class="pl-k">IN</span> [<span class="pl-s">'apple'</span>, <span class="pl-s">'banana'</span>, <span class="pl-s">'coconut'</span>,<span class="pl-s">'durian'</span>,<span class="pl-s">'eggplant'</span>]
<span class="pl-k">WITH</span> <span class="pl-smi">x</span>
<span class="pl-k">MATCH</span> (<span class="pl-smi">y</span>:<span class="pl-smi">User</span>)
<span class="pl-k">WHERE</span> <span class="pl-smi">y</span>.<span class="pl-smi">screen_name</span> <span class="pl-k">IN</span> [<span class="pl-s">'apple'</span>, <span class="pl-s">'banana'</span>, <span class="pl-s">'coconut'</span>,<span class="pl-s">'durian'</span>,<span class="pl-s">'eggplant'</span>]
<span class="pl-k">WITH</span> <span class="pl-smi">x</span>,<span class="pl-smi">y</span>
<span class="pl-k">MATCH</span> (<span class="pl-smi">x</span>)<span class="pl-c1">-</span><span class="pl-k">[</span><span class="pl-en"><span class="pl-k">:</span><span class="pl-en">FOLLOWS</span></span><span class="pl-k">]</span><span class="pl-c1">-&gt;</span>(<span class="pl-smi">t</span>:<span class="pl-smi">User</span>),(<span class="pl-smi">y</span>)<span class="pl-c1">-</span><span class="pl-k">[</span><span class="pl-en"><span class="pl-k">:</span><span class="pl-en">FOLLOWS</span></span><span class="pl-k">]</span><span class="pl-c1">-&gt;</span>(<span class="pl-smi">t</span>:<span class="pl-smi">User</span>)
<span class="pl-k">RETURN</span> <span class="pl-c1">count</span>(<span class="pl-k">*</span>) <span class="pl-k">as</span> <span class="pl-smi">c</span>, <span class="pl-smi">t</span>.<span class="pl-smi">screen_name</span>, <span class="pl-smi">t</span>.<span class="pl-smi">id</span>
<span class="pl-k">ORDER BY</span> <span class="pl-smi">c</span> <span class="pl-k">DESC</span>
<span class="pl-k">LIMIT</span> <span class="pl-c1">1000</span></pre></div>
<p dir="auto"><a href="http://pastebin.com/ZF0kSRec" rel="nofollow">See the profile here</a></p>
<p dir="auto">But this query does not appear to ever return even though the individuals in groups <code class="notranslate">x</code> and <code class="notranslate">y</code> are identical. The only difference is that I'm referring to them by <code class="notranslate">id</code>:</p>
<div class="highlight highlight-source-cypher notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="MATCH (x:User)
WHERE x.screen_name IN ['apple', 'banana', 'coconut'] OR x.id IN [12345,98765]
WITH x
MATCH (y:User)
WHERE y.screen_name IN ['apple', 'banana', 'coconut'] OR y.id IN [12345,98765]
WITH x,y
MATCH (x)-[:FOLLOWS]-&gt;(t:User),(y)-[:FOLLOWS]-&gt;(t:User)
RETURN count(*) as c, t.screen_name, t.id
ORDER BY c DESC
LIMIT 1000"><pre class="notranslate"><span class="pl-k">MATCH</span> (<span class="pl-smi">x</span>:<span class="pl-smi">User</span>)
<span class="pl-k">WHERE</span> <span class="pl-smi">x</span>.<span class="pl-smi">screen_name</span> <span class="pl-k">IN</span> [<span class="pl-s">'apple'</span>, <span class="pl-s">'banana'</span>, <span class="pl-s">'coconut'</span>] <span class="pl-k">OR</span> <span class="pl-smi">x</span>.<span class="pl-smi">id</span> <span class="pl-k">IN</span> [<span class="pl-c1">12345</span>,<span class="pl-c1">98765</span>]
<span class="pl-k">WITH</span> <span class="pl-smi">x</span>
<span class="pl-k">MATCH</span> (<span class="pl-smi">y</span>:<span class="pl-smi">User</span>)
<span class="pl-k">WHERE</span> <span class="pl-smi">y</span>.<span class="pl-smi">screen_name</span> <span class="pl-k">IN</span> [<span class="pl-s">'apple'</span>, <span class="pl-s">'banana'</span>, <span class="pl-s">'coconut'</span>] <span class="pl-k">OR</span> <span class="pl-smi">y</span>.<span class="pl-smi">id</span> <span class="pl-k">IN</span> [<span class="pl-c1">12345</span>,<span class="pl-c1">98765</span>]
<span class="pl-k">WITH</span> <span class="pl-smi">x</span>,<span class="pl-smi">y</span>
<span class="pl-k">MATCH</span> (<span class="pl-smi">x</span>)<span class="pl-c1">-</span><span class="pl-k">[</span><span class="pl-en"><span class="pl-k">:</span><span class="pl-en">FOLLOWS</span></span><span class="pl-k">]</span><span class="pl-c1">-&gt;</span>(<span class="pl-smi">t</span>:<span class="pl-smi">User</span>),(<span class="pl-smi">y</span>)<span class="pl-c1">-</span><span class="pl-k">[</span><span class="pl-en"><span class="pl-k">:</span><span class="pl-en">FOLLOWS</span></span><span class="pl-k">]</span><span class="pl-c1">-&gt;</span>(<span class="pl-smi">t</span>:<span class="pl-smi">User</span>)
<span class="pl-k">RETURN</span> <span class="pl-c1">count</span>(<span class="pl-k">*</span>) <span class="pl-k">as</span> <span class="pl-smi">c</span>, <span class="pl-smi">t</span>.<span class="pl-smi">screen_name</span>, <span class="pl-smi">t</span>.<span class="pl-smi">id</span>
<span class="pl-k">ORDER BY</span> <span class="pl-smi">c</span> <span class="pl-k">DESC</span>
<span class="pl-k">LIMIT</span> <span class="pl-c1">1000</span></pre></div>
<p dir="auto"><a href="http://pastebin.com/AhYi6KTk" rel="nofollow">See the profile here</a></p>
<p dir="auto">I would presume that both of these queries would quickly gather the indicated individuals in the first two clauses and then run the third clause with equal speed because x and y is just a group of ids at that point. I thought that <code class="notranslate">WITH</code> was a barrier beyond which the query planner could not look! So I don't understand what I'm seeing here.</p>
<p dir="auto">Facts:</p>
<ul dir="auto">
<li>neo4j-community-2.1.3,</li>
<li>using a mac</li>
<li>286,039 nodes; every node in the graph is <code class="notranslate">User</code>  (a twitter user)</li>
<li>381,255 relationships; all relationship is <code class="notranslate">-[:FOLLOWS]-&gt;</code></li>
<li>Indices and constraints</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Indexes
  ON :User(screen_name) ONLINE (for uniqueness constraint) 
  ON :User(id)          ONLINE (for uniqueness constraint) 
Constraints
  ON (user:User) ASSERT user.screen_name IS UNIQUE
  ON (user:User) ASSERT user.id IS UNIQUE"><pre class="notranslate"><code class="notranslate">Indexes
  ON :User(screen_name) ONLINE (for uniqueness constraint) 
  ON :User(id)          ONLINE (for uniqueness constraint) 
Constraints
  ON (user:User) ASSERT user.screen_name IS UNIQUE
  ON (user:User) ASSERT user.id IS UNIQUE
</code></pre></div>
<ul dir="auto">
<li><a href="http://stackoverflow.com/questions/25235616/slow-neo4j-query-despite-indices/25248807" rel="nofollow">My question on StackOverflow</a></li>
</ul>
<p dir="auto">You guys might already be working on this, but this is a somewhat common use case that was easy with the old index syntax, and entirely too inefficient with the new indexes. Index hinting on this type of query returns an error, and the query without an index hint does a label scan for horrid performance.</p>
<p dir="auto">Query:<br>
match a:Crew using index a:Crew(name)<br>
where a.name="Neo" or a.name="Cypher"<br>
return a;<br>
Error: org.neo4j.cypher.IndexHintException: Can't use an index hint without an equality comparison on the correct node property label combo.<br>
Label: <code class="notranslate">Crew</code><br>
Property name: <code class="notranslate">name</code></p>