Is there a way to optimize this RedisGraph query?

875 views Asked by At

I have this query "Get Recommended/Similar Products" 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.

Ref: https://redis.com/blog/new-redisgraph-1-0-achieves-600x-faster-performance-graph-databases/

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.

Here is the RedisGraph query I used:

MATCH (:product {id: 123})<-[:purchased]-(:user)-[r:purchased]->(p:product)
WHERE NOT (:user {id: 321})-[:purchased]->(p)
WITH p, COUNT(r) as occurrence
WHERE occurrence > 9
RETURN p.id as product_id, occurrence
ORDER BY occurrence DESC
LIMIT 5

It had an execution time of 6177.225 ms.

While the ArangoDB query looks like this:

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 > 9
SORT occurrence DESC
LIMIT 5
RETURN {product_id, occurrence}

And it had an execution time of only 33.256 ms.

Is there a way to optimize my Redisgraph query any further to make it match/exceed ArangoDB's performance?

More information regarding the schemas of both databases:

RedisGraph

Collection Type Indices Count
user node id 2 M
product node id 177 K
purchased relation 400 K

ArangoDB

Collection Type Indices Count
users document _key 6.7 M
products document _key 135 K
purchases edge _from, _to 420 K
0

There are 0 answers