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.

Queries with related nodes

Hi all,
let's assume that we have orders, assigned orderlines.
and the query
(o:Order)-[ol:ORDERLINE]->(p:Product) return o,ol,p;

this would return for each orderline all attributes about o.
actually neo4j returns result arrays with each line having o,ol,p as keys. Well, with with respect to the transferred number of bytes this is far from beeing optimal. o properties are repeated count(ol) times for each o.
a) is it worth to care about the amount of douplicated data transferred over the wire? I guess when you have a large number of orderlines, this would certainly be the case. Imagine Orders with 50 Attributes with 20 bytes each 1000 Orderlines =1MB of Data where you would only need to transfer 1000Bytes.

b) is there a way to optimize
i am thinking of union all for header info and orderline infos.

similar questions arise when you want to query for data in a single query that has to be related to existing data and the result contains header data as well as resulting arrays/collections. The header Data would be repeated.

One reason to have one single query is about the fact that multiple queries probably introduce latency issues. And I guess they would not take adavantage of neo4js queryplanning / optimizations capabilities.

regards
Thomas

1 ACCEPTED SOLUTION

asperlinga
Graph Buddy

I'm 56 old, I think as an old man.
If You have a number or row for every ORDERLINE you can use CASE struct for compose a string with the order head and the ORDERLINE.
I presume you have number of order, number of orderline and product code and description.

Then you can use cypher
MATCH (o:Order)-[ol:ORDERLINE]->(p:Product)
return
CASE WHEN ol.Number=1 THEN "Order "+o.Number+" "+ol.Number+" "+p.Code+" "+p.Description ELSE ol.Number+" "+p.Code+" "+p.Description END
as order_detail
order by o.Number,ol.Number

ciao

Alessio

View solution in original post

2 REPLIES 2

asperlinga
Graph Buddy

I'm 56 old, I think as an old man.
If You have a number or row for every ORDERLINE you can use CASE struct for compose a string with the order head and the ORDERLINE.
I presume you have number of order, number of orderline and product code and description.

Then you can use cypher
MATCH (o:Order)-[ol:ORDERLINE]->(p:Product)
return
CASE WHEN ol.Number=1 THEN "Order "+o.Number+" "+ol.Number+" "+p.Code+" "+p.Description ELSE ol.Number+" "+p.Code+" "+p.Description END
as order_detail
order by o.Number,ol.Number

ciao

Alessio

Hi Alessio,
i am 51 Years old, and I realy like your approach very much.

regards
Thomas