2

I apologize for the naive question as I am relatively new to graph databases and currently working with Neptune OpenCypher for my use case. I am experiencing different outcomes for two similar queries and would like to understand the reasons behind it.

My dataset consists of hundreds of millions of nodes. Here are the details of the queries:

Query 1: Timeout Error

MATCH p=(n:Person)-[:RELATIONSHIP*..5]->(m:Person {condition: True})
WHERE 
ID(n) = <id_Value>
AND size([node IN nodes(p) WHERE node.event_date > n.event_date]) = 0
RETURN p
LIMIT 1

Query 2: Successful Response

MATCH p=(n:Person)-[:RELATIONSHIP*..5]->(m:Person {condition: True})
WHERE 
ID(n) = <id_Value>
AND size([node IN nodes(p) WHERE node.event_date > n.event_date]) = 0
WITH p
ORDER BY n.event_date ASC
LIMIT 1
RETURN p

I'm curious about the reasons behind the timeout error in Query 1 and the successful response in Query 2. Both queries have a similar structure, but Query 1 times out while Query 2 executes successfully. Can someone explain why this might be happening?

I ran both queries mentioned earlier, and Query 1 resulted in a timeout while Query 2 executed successfully. However, I'm encountering unexpected results with Query 2, and I want to ensure that I'm not misunderstanding or misusing it.

topgun007
  • 21
  • 2
  • Just to rule out a few basic possible differences, I assume in each case the `id_Value` was the same? – Kelvin Lawrence Jul 05 '23 at 22:09
  • To further help investigate these queries it will be very helpful to see their explain plans. Are you able to open an AWS support case so that those can be shared more easily? – Kelvin Lawrence Jul 05 '23 at 23:15
  • Hi Kelvin, Yes ID values were same – topgun007 Jul 05 '23 at 23:21
  • Thanks - it's possible that the two queries are generating subtly different execution plans due to the presence of the ORDER BY in the second query, and that could explain the differences. It will take looking at the debug versions of the explain plans to know for sure. – Kelvin Lawrence Jul 06 '23 at 18:32

0 Answers0