title: Is there a way to optimize this RedisGraph query?
body: <p>I have this query &quot;Get Recommended/Similar Products&quot; on both RedisGraph and ArangoDB, and RedisGraph is showing significant slow execution time in comparison to ArangoDB. Although RedisGraph benchmarks show that it should have a better performance than other graph databases.</p>
  <p>Ref: <a href="https://redis.com/blog/new-redisgraph-1-0-achieves-600x-faster-performance-graph-databases/" rel="nofollow noreferrer">https://redis.com/blog/new-redisgraph-1-0-achieves-600x-faster-performance-graph-databases/</a></p>
  <p>The query fetches what other products users who have purchased this specific product (id: 123) have also purchased, while filtering out the current user's (id: 321) purchases, and also while ordering the result by the products that occurred the most.</p>
  <p>Here is the RedisGraph query I used:</p>
  <pre><code>MATCH (:product {id: 123})&lt;-[:purchased]-(:user)-[r:purchased]-&gt;(p:product)
  WHERE NOT (:user {id: 321})-[:purchased]-&gt;(p)
  WITH p, COUNT(r) as occurrence
  WHERE occurrence &gt; 9
  RETURN p.id as product_id, occurrence
  ORDER BY occurrence DESC
  LIMIT 5
  </code></pre>
  <p>It had an execution time of 6177.225 ms.</p>
  <p>While the ArangoDB query looks like this:</p>
  <pre><code>LET userPurchases = (FOR purchase IN OUTBOUND 'users/321' purchases RETURN purchase._id)
  FOR product,purchase IN 2..2 ANY 'products/123' purchases
  FILTER purchase._to NOT IN userPurchases
  COLLECT product_id = product._key WITH COUNT INTO occurrence
  FILTER occurrence &gt; 9
  SORT occurrence DESC
  LIMIT 5
  RETURN {product_id, occurrence}
  </code></pre>
  <p>And it had an execution time of only 33.256 ms.</p>
  <p><strong>Is there a way to optimize my Redisgraph query any further to make it match/exceed ArangoDB's performance?</strong></p>
  <p>More information regarding the schemas of both databases:</p>
  <p>RedisGraph</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Collection</th>
  <th>Type</th>
  <th>Indices</th>
  <th>Count</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>user</td>
  <td>node</td>
  <td>id</td>
  <td>2 M</td>
  </tr>
  <tr>
  <td>product</td>
  <td>node</td>
  <td>id</td>
  <td>177 K</td>
  </tr>
  <tr>
  <td>purchased</td>
  <td>relation</td>
  <td></td>
  <td>400 K</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>ArangoDB</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Collection</th>
  <th>Type</th>
  <th>Indices</th>
  <th>Count</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>users</td>
  <td>document</td>
  <td>_key</td>
  <td>6.7 M</td>
  </tr>
  <tr>
  <td>products</td>
  <td>document</td>
  <td>_key</td>
  <td>135 K</td>
  </tr>
  <tr>
  <td>purchases</td>
  <td>edge</td>
  <td>_from, _to</td>
  <td>420 K</td>
  </tr>
  </tbody>
  </table>
  </div>