cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to explicitly specify join orders for query planning?

Hi, I am new to neo4j and have some questions

I am evaluating the query performance under different join orders (query is written in Cypher)
According to Neo4j manual, I can input several hints such as index, scan, and join hints.
https://neo4j.com/docs/cypher-manual/current/query-tuning/using/#query-using-join-hint

Index hints are used to specify the starting nodes for joins.
Join hints are used to specify the joining nodes for joins.

However, there seems to be no way to force certain join orders.
For example, say a query Q is given as follow:

v1 -- v2 -- v3
........ |
....... v4 -- v5

How can I evaluate the query performance for different join orders such as:
(1) (v1, v2, v3, v4, v5)
(2) (v1, v2, v4, v5, v3)
(3) (v2, v3, v4, v5, v1)
...

Currently, using the index and join hints, I can only make certain join orders (Not all of possible orders)
Is there any way to achieve it?
(In Oracle DB, it is achieved by using ORDERED)

Thanks for your attention,

2 REPLIES 2

There is no direct way to do that. It is also usually not a good idea to force the planner onto expensive paths.

you could split your patterns into smaller MATCH patterns, reorder them in your query and then add a WITH * WHERE 1+1=2 (or some expression that can not be easily removed) to disable reordering/with removal.

For research purposes I think there should be a switch that does it. With enough experience, one can beat the cost model, whose score doesn't always point towards lower exec time...