Top Banner
A Game of Hierarchies SQL Server 2017 Graph DB
33

A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Jul 04, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

A Game of Hierarchies

SQL Server 2017 Graph DB

Page 3: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Demo Samples

Points-of-Interest (POI)Grouped by region, continent & worlds

With routes between

Recipe („A Feast of Ice and Fire“)Ingredients & meals

Family-TreeFemale & male ancestores

AGameOfHierarchies.wordpress.com

Page 4: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Episodes

Modelling hierarchies

What is a graph?

How can I use it?

How can I use it with SQL Server 2017?

Page 5: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Episodes

Modelling hierarchies

What is a graph?

How can I use it?

How can I use it with SQL Server 2017?

Page 6: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Episode “Modelling”

Several columns in one table (denormalized)

Several tables (normalized)

Self-joining table

Materialized path

HierarchyID

SQL GraphDB

Page 7: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Episodes

Modelling hierarchies

What is a graph?

How can I use it?

How can I use it with SQL Server 2017?

Page 8: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Graph

Eg. POI, Route

Nodes (POI) are connected via Edges (Route)

AdvantageNo redundancy

Unlimited in the amount of levels

All kind of graphs (not only hierarchies), eg. many-to-many

DisadvantageJoins needed

Complex queries (Loops, recursive CTE) vs. CQL

Page 9: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Graph

Node NodeEdge

Page 10: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Graph

Robis father ofEddard

Page 11: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Graph

WinterfellCastle

CerwynRoute

(Miles)

White Harbor

Moat Cailin

Page 12: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

(UN-)Directed Graph

Undirected Directed

Rob

Eddard Catlyn

Winter-fell

Castle Cerwyn

White Harbor

Moat Cailin

Page 13: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

(A-)Cyclic Graph

Cyclic Acyclic

Rob

Eddard Catlyn

Winter-fell

Castle Cerwyn

White Harbor

Moat Cailin

Page 14: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

(Un-)Connected Graph

Unconnected Connected

Rob

Eddard Catlyn

Winter-fell

Castle Cerwyn

White Harbor

Moat Cailin

Page 15: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

(Un-)Weighted Graph

Weighted Unweighted

Rob

Eddard Catlyn

Winter-fell

Castle Cerwyn

White Harbor

Moat Cailin

5

7

Page 16: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Properties

NodesAdjectiveEg. Birthdate

EdgesMeasureEg. Amount, Cost, Miles, …

Page 17: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Episodes

Modelling hierarchies

What is a graph?

How can I use it?

How can I use it with SQL Server 2017?

Page 18: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Use cases for graphs

Social networksNode: PeopleEdge: Interactions

Recommendation enginesNodes: Users & productsEdge: Purchases, browsing, rating, …

GeospatialRoute optimization

Internet of ThingsNetwork & connections of “Things”

Page Rank

Page 19: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Episodes

Modelling hierarchies

What is a graph?

How can I use it?

How can I use it with SQL Server 2017?

Page 20: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

What is SQL Server Graph DB

Integrated in SQL Engine, Tooling & Eco-SystemGraphs can be combined with “normal” tablesColumnStore, Machine Learning, HA, …SSMS (“Graph Tables”), Backup & Restore, …Dynamic Data Masking, Row Level Security, …Will be available for SQL on Linux as well

One Graph per database

Graph := collection of nodes & edges

Define & create graphsVia nodes-tables & edge-tables

Query Language ExtensionMATCH

Page 21: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Nodes

Entities, vertices

Similar to a row (RDBMS) or document (DocumentDB)

Typically a nounsEg. Eddard, King’s Landing, Ale

Must contain at least one column

Page 22: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Nodes

CREATE TABLE <MyNode>(

) AS NODE;

graph_id, $node_id

Page 23: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Edges

Graphs, relationshipsConnect nodes

Similar to relationship (RDBMS)Can model many-to-many relationships

Might have attributes

Typically an verbEg. is father of, connects, part of, likes

Can connect nodes multiple times

Page 24: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Edges

CREATE TABLE <MyEdge>(

) AS EDGE;

graph_id, from_obj_id, from_id, to_obj_id, to_id, $edge_id, $from_id, $to_id

Page 25: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Limitations and Known Issues

Pre ANSI-92 syntax for joins

Complex traverses not supported via MATCHUse loops or recursive CTEs for transitive closure, shortest path or page rank

Not allowed as Node or EdgeLocal or global temporary, Table types and table variables , system-versioned temporal tables, memory optimized tables, stretching, external table (Polybase)

No UPDATE for $from_id & $to_idInsert the new edge pointing to new nodes and delete the previous one

Cross database queries are not supported

Page 26: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Semantic Query

Pattern matching

Multi-hop queriesInternally represented as JOINs

Cypher Query Language (CQL)Created by Neo Technology for Neo4j, open source since 2015

Declarative query language

MATCH-extension to SELECT/WHERE

GremlinAPI for CosmosDB

Page 27: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Cypher Query Language (CQL)

Father Childis father of

Father-(IsFatherOf)->Child

Page 28: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Cypher Query Language

Page 29: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

What John SnoWknows

nothing (Source: Ygritte)

Page 30: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Resources

Using GROUP BY with ROLLUP, CUBE, and GROUPING SETShttps://technet.microsoft.com/en-us/library/bb522495(v=sql.105).aspx

Itzik Ben-Gan (2015), T-SQL Querying, Microsoft Presshttps://www.microsoftpressstore.com/store/t-sql-querying-9780735685048

Steve Stedman (2015), Advanced CTEhttp://stevestedman.com/2015/06/24-hours-of-pass-advanced-cte-presenation/

Graph DB Architecturehttps://docs.microsoft.com/en-us/sql/relational-databases/graphs/sql-graph-architecture

Graph data processing with SQL Server 2017 and Azure SQL DB https://www.youtube.com/watch?v=SdKwDhe5J4M

Page 32: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

Just like Jimi Hendrix …

We love to get feedback

Please complete the session feedback forms

Page 33: A Game of Hierarchies - Microsoft...A Game of Hierarchies SQL Server 2017 Graph DB Introduction Markus Ehrenmüller-Jensen Business Intelligence Architect SQL Server 2005 –2017 BI

SQLBits - It's all about the community...

Please visit Community Corner, we are trying this year to get more people to learn about the SQL Community, equally if you would be happy to visit the community corner we’d really appreciate it.