Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Graph Databases, a little connected tour (Codem...

Graph Databases, a little connected tour (Codemotion Rome)

Slides of my talk at Codemotion Rome 2014 http://rome.codemotionworld.com/2014/

More Decks by Francisco Fernández Castaño

Other Decks in Programming

Transcript

  1. The old town of Königsberg has seven bridges: Can you

    take a walk through town, visiting each part of the town and crossing each bridge only once?
  2. Depth MySQL time (s) Neo4j time (s) Results 2 0.016

    0.01 ~2500 3 30.267 0.168 ~110,000 4 1543.505 1.359 ~600,000 5 No Acaba 2.132 ~800,000 MySQL vs Neo4j * Neo4J in Action
  3. Person Id Person 1 Frank 2 John .. … 99

    Alice PersonFriend PersonID FriendID 1 2 2 1 .. … 99 2
  4. MATCH p = (startNode:Station {name: ‘Sol’}) -[rels:CONNECTED_TO*]-> (endNode:Station {name: ‘Retiro’})

    RETURN p AS shortestPath, reduce(weight=0, r in rels: weight + r.weight) as tWeight ORDER BY tWeight ASC LIMIT 1
  5. Movies social network Users rate movies People act in movies

    People direct movies Users follow other users
  6. Movies social network MATCH (fran:User {name: ‘Fran’}) -[or:Rate]-> (pf:Film {title:

    ‘Pulp Fiction’}), ! (pf)<-[:Rate]-(other_users)-[:Rate]->(other_films) ! RETURN distinct other_films.title;
  7. Movies social network Rate {stars} Rate {stars} User 1 Film

    PF Fran User 2 Rate {stars} Film Film Rate {stars} Rate {stars}
  8. Movies social network MATCH (fran:User {name: ‘Fran’}) -[or:Rate]-> (pf:Film {title:

    ‘Pulp Fiction’}), ! (pf)<-[:Rate]-(other_users)-[r:Rate]->(other_films) ! WHERE or.stars = r.stars ! RETURN distinct other_films.title;
  9. Movies social network MATCH (fran:User {name: ‘Fran’}) -[or:Rate]-> (pf:Film {title:

    ‘Pulp Fiction’}), ! (pf)<-[:Rate]-(other_users)-[r:Rate]->(other_films), ! (other_users)-[:FOLLOW]-(fran) ! WHERE or.stars = r.stars ! RETURN distinct other_films.title;
  10. Movies social network Rate {star} User 1 Film PF Fran

    Rate {stars} Film Follow Rate {star}
  11. Movies social network MATCH (fran:User {name: ‘Fran’}) -[or:Rate]-> (pf:Film {title:

    ‘Pulp Fiction’}), ! (pf)<-[:Rate]-(other_users)-[r:Rate]->(other_films), (film)->[:BELONGS_TO*3]->(genre)<-[:BELONGS_TO]-(other_films), ! (other_users)-[:FOLLOW]-(fran) ! WHERE or.stars = r.stars ! RETURN distinct other_films.title;
  12. Instead of just picking a relational database because everyone does,

    we need to understand the nature of the data we’re storing and how we want to manipulate it. Martin Fowler