Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run MATCH with multiple edges query faster #2129

Open
wgmayer0 opened this issue Nov 4, 2024 · 5 comments
Open

Run MATCH with multiple edges query faster #2129

wgmayer0 opened this issue Nov 4, 2024 · 5 comments
Labels
question Further information is requested

Comments

@wgmayer0
Copy link

wgmayer0 commented Nov 4, 2024

Is there a way to run this query faster? Maybe a technique I am overlooking? I see that I am running MATCH multiple times and not sure if that has anything to do with it

SELECT concat(a::text, ' / ', b::text, ' / ', c::text, ' / ', d::text, ' / ', e::text) AS concatenated_string
FROM cypher('hermech', $$ 
  MATCH (a:load_number)-[]-(b:origin) 
  MATCH (a)-[]-(c:pickup_time) 
  MATCH (a)-[]-(d:destination) 
  MATCH (a)-[]-(e:delivery_time) 
  MATCH (a)-[]-(d:destination) 
  MATCH (a)-[]-(e:delivery_time) 
  RETURN a.value, b.value, c.value, d.value, e.value
$$) AS (a agtype, b agtype, c agtype, d agtype, e agtype);

It seems to take about 4 seconds

@wgmayer0 wgmayer0 added the question Further information is requested label Nov 4, 2024
@wgmayer0 wgmayer0 changed the title Run this query faster Run MATCH with multiple edsges query faster Nov 4, 2024
@wgmayer0 wgmayer0 changed the title Run MATCH with multiple edsges query faster Run MATCH with multiple edges query faster Nov 4, 2024
@bravius
Copy link

bravius commented Nov 14, 2024

You have a couple of duplicate match clauses, this would be more concise:

MATCH (a:load_number)-[]-(b:origin),
      (a)-[]-(c:pickup_time),
      (a)-[]-(d:destination),
      (a)-[]-(e:delivery_time)
RETURN a.value, b.value, c.value, d.value, e.value

@wgmayer0
Copy link
Author

wgmayer0 commented Nov 14, 2024 via email

@uhayat
Copy link
Contributor

uhayat commented Nov 14, 2024

@MuhammadTahaNaveed do you think your PR (#2117) will improve the query performance in this specific case as well ?

@tronper123
Copy link

If your edges are all directed the same, you could add directed arrows,

MATCH (a:load_number)-[]->(b:origin),
      (a)-[]->(c:pickup_time),
      (a)-[]->(d:destination),
      (a)-[]->(e:delivery_time)
RETURN a.value, b.value, c.value, d.value, e.value

Also, if you use different labels for each connection type and specify the name, that will also improve the performance

MATCH (a:load_number)-[:orgin_label]-(b:origin),
      (a)-[:pickup_label]-(c:pickup_time),
      (a)-[:destination_label]-(d:destination),
      (a)-[:delivery_label]-(e:delivery_time)
RETURN a.value, b.value, c.value, d.value, e.value

@wgmayer0
Copy link
Author

wgmayer0 commented Nov 21, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants