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

Graph databases

Graph databases

What are graph databases and what are they good for?

Alberto Perdomo

September 08, 2012
Tweet

More Decks by Alberto Perdomo

Other Decks in Technology

Transcript

  1. Graph databases • Focus on relations • Powerful queries based

    on deep relations • Enhance your queries, like full-text search engines • A new way to discover and interpret your data
  2. People you might know (SQL) Source: http://techportal.inviqa.com/2009/09/07/graphs-in-the-database-sql-meets-social-networks/ SELECT a AS

    you, b AS mightknow, shared_connection, CASE WHEN (n1.feat1 = n2.feat1 AND n1.feat1 = n3.feat1) THEN 'feat1 in common' WHEN (n1.feat2 = n2.feat2 AND n1.feat2 = n3.feat2) THEN 'feat2 in common' ELSE 'nothing in common' END AS reason FROM ( WITH RECURSIVE transitive_closure(a, b, distance, path_string) AS ( SELECT a, b, 1 AS distance, a || '.' || b || '.' AS path_string, b AS direct_connection FROM edges2 WHERE a = 1 -- set the starting node UNION ALL SELECT tc.a, e.b, tc.distance + 1, tc.path_string || e.b || '.' AS path_string, tc.direct_connection FROM edges2 AS e JOIN transitive_closure AS tc ON e.a = tc.b WHERE tc.path_string NOT LIKE '%' || e.b || '.%' AND tc.distance < 2 ) SELECT a, b, direct_connection AS shared_connection FROM transitive_closure WHERE distance = 2 ) AS youmightknow LEFT JOIN nodes AS n1 ON youmightknow.a = n1.id LEFT JOIN nodes AS n2 ON youmightknow.b = n2.id LEFT JOIN nodes AS n3 ON youmightknow.shared_connection = n3.id WHERE (n1.feat1 = n2.feat1 AND n1.feat1 = n3.feat1) OR (n1.feat2 = n2.feat2 AND n1.feat2 = n3.feat2);
  3. People you might know (gremlin) start = g.v(0) knows =

    start.out("knows").toList() + [start] start.out("knows").in("knows").filter { knows.indexOf(it) == -1 }
  4. • […] built this query in both MySQL and Neo4j

    with a database of 1,000,000 users and the results are striking. Execution Time is in seconds, for 1,000 users Friends of friends (performance) Source: http://www.neotechnology.com/2012/06/how-much-faster-is-a-graph-database-really/ Depth MySQL Neo4j Neo4j vs MySQL 2 0.016 secs 0.010 sec 60% faster 3 30 secs 0.168 sec 180x faster 4 25 minutes 1.359 sec 1,135x faster 5 Not finished in 1 hour 2.132 sec MySQL down
  5. Enter GrapheneDB • Graph database in the cloud • Based

    on Neo4j • Robust and mature • Transactional • REST API • Powerful tools to manage & visualize your data • Focus on documentation