Page 1
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 1www.orientechnologies.com
Luca Garulli – Founder and CEO@Orient Technologies LtdAuthor of OrientDB
www.twitter.com/lgarulli
Why Relationships
are coolbut the “JOIN”
sucks
BigData & GraphsIn Rome
Page 2
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 2
1979First Relational DBMS available as product
2009NoSQL movement
Page 3
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 3
1979First Relational DBMS available as product
2009NoSQL movement
Hey, 30 years in the IT field is so huge!
Page 4
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 4
Before 2009 teams of developersalways fought to select:
Operative SystemProgramming Language
Middleware (App-Servers)
What about the Database?
Page 5
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 5
One of the main resistances ofRDBMS users to pass to a NoSQL product
are related to thecomplexity of the model:
Ok, NoSQL products are super forBigData and BigScale
but...
Page 6
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 6
...what about the model?
Page 7
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 7
What is the NoSQL answer about managing complex domains?
Key-Value stores ?Column-Based ?
Document database ?Graph database !
No Relationshipssupport
Page 8
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 8
Why most of NoSQL
productsdon’t supportRelationship
Between entities?
Page 9
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 9
To understand why,let’s see how
Relational DBMSmanaged them
Page 10
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 10
Domain: the super minimal “Selling App”
Customer Address
Order Stock
Registry system
Order system
Page 11
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 11
Stock
Registry system
Domain: the super minimal “Selling App”
Order
Order system
Customer Address
How doesRelational DBMS
manage relationships?
Page 12
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 12
Relational World: 1-1 Relationships
JOIN Customer.Address -> Address.Id
CustomerId Name Address
10 Luca 34
11 Jill 44
34 John 54
56 Mark 66
88 Steve 68
AddressId Location
34 Rome
44 London
54 Moscow
66 New Mexico
68 Palo Alto
Foreign key
Primary keyPrimary key
Page 13
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 13
Relational World: 1-N Relationships
Inverse JOIN Address.Customer -> Customer.Id
CustomerId Name
10 Luca
11 Jill
34 John
56 Mark
88 Steve
AddressId Customer Location
24 10 Rome
33 10 London
44 34 Moscow
66 56 Cologne
68 88 Palo Alto
Page 14
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 14
Relational World: N-M Relationships
Additional table with 2 JOINs(1) CustomerAddress.Id -> Customer.Id and(2) CustomerAddress.Address -> Address.Id
CustomerId Name
10 Luca
11 Jill
34 John
56 Mark
88 Steve
AddressId Location
24 Rome
33 London
44 Moscow
66 Cologne
68 Palo Alto
CustomerAddressId Address
10 24
10 33
34 44
Page 15
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 15
What’s wrong with theRelational Model?
Page 16
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 16
These are all JOINs executedeverytime you traverse a
relationship
The JOIN is the evil!Customer
Id Name
10 Luca
11 Jill
34 John
56 Mark
88 Steve
AddressId Location
24 Rome
33 London
44 Moscow
66 Cologne
68 Palo Alto
These are all JOINs executedeverytime you traverse a
relationship
These are all JOINs executedeverytime you traverse a
relationship
These are all JOINs executedeverytime you traverse a
relationship!
CustomerAddressId Address
10 24
10 33
34 24
Page 17
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 17
A JOIN means searching for a key inanother table
The first rule to improve performanceis indexing all the keys
Index speeds up searches, but slows downinsert, updates and deletes
Page 18
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 18
So in the best case a JOIN is a lookupinto an index
This is done per single join!
If you traverse hundreds of relationshipsyou’re executing hundreds of JOINs
Page 19
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 19
Index Lookupis it really that fast?
Page 20
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 20
Index Lookup: how does it works?A-Z
A-L M-Z
Think to an Address Book
where we have to find the Luca’s phone
number
Page 21
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 21
Index Lookup: how does it works?A-Z
A-L M-Z
A-L
A-D E-L
M-Z
M-R S-Z
Index algorithms are all similar and based on
balanced trees
Page 22
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 22
Index Lookup: how does it works?A-Z
A-L M-Z
A-L
A-D E-L
M-Z
M-R S-Z
A-D
A-B C-D
E-L
E-G H-L
Page 23
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 23
Index Lookup: how does it works?A-Z
A-L M-Z
A-L
A-D E-L
M-Z
M-R S-Z
A-D
A-B C-D
E-L
E-G H-L
E-G
E-F G
H-L
H-J K-L
Page 24
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 24
Index Lookup: how does it works?A-Z
A-L M-Z
A-L
A-D E-L
M-Z
M-R S-Z
A-D
A-B C-D
E-L
E-G H-L
E-G
E-F G
H-L
H-J K-L
Luca
Found! This lookup took 5 steps and grows up with the index
size!
Page 25
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 25
Can you imaginehow many steps a
Lookup operation does into anIndex with Millions or Billions
of records?
Page 26
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 26
And this JOIN is executedforeach involved table,
multiplied foreach scanned records
!
Page 27
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 27
Querying more tables can easilyproduce millions of JOINs/Lookups!
Here the rule: more entries= more lookup steps = slower JOIN
Page 28
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 28
Oh! This is whyperformance of my database
drops down whenit becomes bigger,
and bigger,and bigger!
Page 29
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 29
What aboutDocument Databases
like MongoDB?
Page 30
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 30
How MongoDB manages relationships:
{ “_id” : “292846512”, “type” : “Order”, “number” : 1223, “customer” : “123456789”}
Page 31
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 31
MongoDB uses the same approach:
it stores the _id of the connecteddocuments. At run-time it lookups upfor the _id by using an index.
Page 32
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 32
Is there a better way tomanage relationships?
Page 33
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 33
“A graph database is anystorage system
that providesindex-free adjacency”
- Marko Rodriguez (author of TinkerPop Blueprints)
Page 34
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 34
How does GraphDB manageindex-free relationships?
Page 35
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 35
Every developer knowsthe Relational Model,but who knows the
Graph one?
Page 36
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 36
Back to school:Graph Theory crash course
Page 37
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 37
Basic Graph
Luca NoSQLDay
Likes
Page 38
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 38
Property Graph Model*
Lucaname: Luca
surname: Garullicompany: Orient Tech
NoSQLDay
date: Nov 15° 2013
Likes
since: 2013
Vertices and Edges can have propertiesVertices and Edges can have propertiesVertices and Edges can have properties
Vertices are directed
* https://github.com/tinkerpop/blueprints/wiki/Property-Graph-Model
Page 39
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 39
Property Graph Model
Luca NoSQLDay
Likessince: 2013
Speakstitle: «Switching...»
abstract: «This talk presents...»An Edge connects 2
vertices: use multiple edges to represents 1-N and N-M
relationships
Page 40
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 40
Property Graph Model
Likes
Daniel
Luca
Organizes
FriendOfNoSQL
Day
Udine
located
Studies
Page 41
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 41
Compliments, this is your diploma in«Graph Theory»
Page 42
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 42
The Graph theoryis so simple to be so
powerful
Page 43
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 43
Let’s go backto the Graph Stuff
How does OrientDBmanage relationships?
Page 44
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 44
Luca(vertex)
OrientDB: traverse a relationship
label : ‘Customer’name : ‘Luca’
RID = #13:35 RID = #13:100
label = ‘Address’name = ‘Rome’
The Record ID (RID)is the physical position
Rome(vertex)
The Record ID (RID)is the physical position
Page 45
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 45
Lives
OrientDB: traverse a relationship
out : [#14:54]label : ‘Customer’name : ‘Luca’
out: [#13:35]in: [#13:100]Label : ‘Lives’
RID = #13:35 RID = #13:100
in: [#14:54]label = ‘Address’name = ‘Rome’
The Edge’s RID is saved inside both vertices, as
«out» and «in»
The Edge’s RID is saved inside both vertices, as
«out» and «in»
RID = #14:54
Luca(vertex)
Rome(vertex)
Page 46
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 46
LucaLives
OrientDB: traverse -> outgoing
out : [#14:54]label : ‘Customer’name : ‘Luca’
out: [#13:35]in: [#13:100]Label : ‘Lives’
RID = #13:35RID = #14:54
RID = #13:100
in: [#14:54]label = ‘Address’name = ‘Rome’
Rome
Page 47
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 47
LucaLives
OrientDB: traverse <- incoming
out : [#14:54]label : ‘Customer’name : ‘Luca’
out: [#13:35]in: [#13:100]Label : ‘Lives’
RID = #13:35RID = #14:54
RID = #13:100
in: [#14:54]label = ‘Address’name = ‘Rome’
Rome
Page 48
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 48
GraphDB handles relationships as aphysical LINK to the record
assigned when the edge is created
on the other side
RDBMS computes therelationship every time you query a database
Is not that crazy?!
Page 49
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 49
This means jumping from aO(log N) algorithm to a near O(1)
traversing cost is not more affectedby database size!
This is huge in the BigData age
Page 50
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 50
an Open Source (Apache licensed)document-graph NoSQL dbms
Page 51
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 51
OrientDB in the Blueprints micro-benchmark,on common hw, with a hot cache,
traverses 29,6 Millionsof records in less than 5 seconds
about 6 Millions of nodes traversed per sec!
*unless you live in the Google’s server farm
Do not try this at home with a RDBMS*!
Page 52
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 52
Create the graph in SQL$luca> cd bin$luca> ./console.shOrientDB console v.1.6.1 (www.orientdb.org) Type 'help' to display all the commands supported.
orientdb> create vertex Customer set name = ‘Luca’Created vertex #13:35 in 0.03 secs
orientdb> create vertex Address set name = ‘Rome’Created vertex #13:100 in 0.02 secs
orientdb> create edge Lives from #13:35 to #13:100Created edge #14:54 in 0.02 secs
Page 53
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 53
Create the graph in JavaGraph graph = new OrientGraph("local:/tmp/db/graph”);
Vertex luca = graph.addVertex( “class:Customer” );luca.setProperty( “name", “Luca” );
Vertex rome = graph.addVertex ( “class:Address” );rome.setProperty( “name", “Rome” );
Edge edge = luca.addEdge( “Lives”, rome );
graph.shutdown();
Page 54
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 54
Query the graph in SQL
orientdb> select in(‘Lives’) from Address where name = ‘Rome’---+------+---------|--------------------+--------------------+--------+ #| RID |@class |label |out_Lives |in |---+------+---------+--------------------+--------------------+--------+ 0| 13:35|Customer |Luca |[#14:54] | |---+------+---------+--------------------+--------------------+--------+1 item(s) found. Query executed in 0.007 sec(s).
Incoming vertices
Page 55
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 55
More on query powerorientdb> select sum( out(‘Order’).total ) from Customer where name = ‘Luca’
orientdb> traverse both(‘Friend’) from Customer while $depth <= 7
orientdb> select from ( traverse both(‘Friend’) from Customer while $depth <= 7 ) where @class=‘Customer’ and city.name = ‘Udine’
Page 56
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 56
Query vs traversalOnce you’ve a well connected database
in the form of a Super Graph you cancross records instead of query them!
All you need is a few“Root Vertices”where to start traversing
Page 57
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 57
Query vs traversalCustomers
Luca Mark Jill
Order2332
Order8834
WhiteSoap
StocksSpecialCustomers
This is aroot
vertex
Page 58
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 58
Root Vertices can be enriched byMeta Graphs
to decorate Graphs withadditional informationand make easier/faster
the retrieval
Page 59
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 59
Temporal based Meta Graph
Order2333
Order2334
Calendar
Hour9/4/2013
10:00
Hour9/4/2013
09:00
Order2332
Day9/4/2013
MonthApril 2013
Year2013
Page 60
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 60
Location based Meta Graph
Order2333
Order2334
Location
CityRome
CityFiumicino
Order2332
StateRM
RegionLazio
CountryItaly
Page 61
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 61
Mix & Merge graphs
Order2333
Order2334
Location
CityRome
CityFiumicino
Order2332
StateRM
RegionLazio
CountryItaly
Calendar
Hour9/4/2013
10:00
Hour9/4/2013
09:00
Day9/4/2013
MonthApril 2013
Year2013
Page 62
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 62
Order2333
Order2334
Location
CityRome
CityFiumicino
Order2332
StateRM
RegionLazio
CountryItaly
Calendar
Hour9/4/2013
10:00
Hour9/4/2013
09:00
Day9/4/2013
MonthApril 2013
Year2013
Get all the orderssold in “Fiumicino” cityon 9/4/2013 at 10:00
Page 63
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 63
Start from Calendar, look for Hour 10:00
Order2333
Order2334
Location
CityRome
CityFiumicino
Order2332
StateRM
RegionLazio
CountryItaly
Calendar
Hour9/4/2013
10:00
Hour9/4/2013
09:00
Day9/4/2013
MonthApril 2013
Year2013
Page 64
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 64
Start from Calendar, look for Hour 10:00
Order2333
Order2334
Location
CityRome
CityFiumicino
Order2332
StateRM
RegionLazio
CountryItaly
Calendar
Hour9/4/2013
10:00
Hour9/4/2013
09:00
Day9/4/2013
MonthApril 2013
Year2013
Found 2 Orders, filter by incoming
edges<
Found 2 Orders, now filter by
incoming edges
Page 65
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 65
Order2333
Location
CityFiumicino
Order2332
StateRM
RegionLazio
CountryItaly
Calendar
Hour9/4/2013
10:00
Hour9/4/2013
09:00
Day9/4/2013
MonthApril 2013
Year2013
Order2334
Only “Order 2333” has incoming
connections with “Fiumicino”
CityRome
Start from Calendar, look for Hour 10:00
Page 66
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 66
Order2333
Location
CityFiumicino
Order2332
StateRM
RegionLazio
CountryItaly
Calendar
Hour9/4/2013
10:00
Hour9/4/2013
09:00
Day9/4/2013
MonthApril 2013
Year2013
Order2334
CityRome
Or start from Location, look for Fiumicino
Page 67
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 67
Order2333
Order2332
Calendar
Hour9/4/2013
10:00
Hour9/4/2013
09:00
Day9/4/2013
MonthApril 2013
Year2013
Order2334
Start from Location, look for Fiumicino
Location
CityRome
CityFiumicino
StateRM
RegionLazio
CountryItaly
Page 68
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 68
Luca
Recommendation system
Jill
Enrico
Friend
Friend
Page 69
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 69
Da Carlone
Luca
Recommendation system
Jill
Enrico
LaMediterranea
Meridionale
Friend
Friend
Eats
Eats
EatsEats
EaitalyEa
ts
Page 70
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 70
Recommendation system
Da Carlone
LucaJill
Enrico
LaMediterranea
Meridionale
Friend
Friend
Eats
Eats
EatsEats
Eaitaly
select both(‘Friend’) from Person where name = ‘Luca’
Page 71
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 71
Recommendation system
Da Carlone
LucaJill
Enrico
LaMediterranea
Meridionale
Friend
Friend
Eats
Eats
EatsEats
Eaitaly
select both(‘Friend’).out(‘Eats’) from Person where name = ‘Luca’
Page 72
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 72
Recommendation system
Da Carlone
LucaJill
Enrico
LaMediterranea
Meridionale
Friend
Friend
Eats
Eats
EatsEats
Eaitaly
select both(‘Friend’).out(‘Eats’) from Person where name = ‘Luca’
Page 73
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 73
This is your database
Page 74
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 74
Get last customer bought ‘Barolo’select last(out(‘Order’).in(‘Customer)) from Stock where name = ‘Barolo’
#34:22
Page 75
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 75
Get his’s country
select out(‘City’) from #34:22Udine, Italy
#55:12
Page 76
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 76
Get orders from that country
select in(‘Customer’) from #55:12
Page 77
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 77
Let’s move like aSpider
on the web
Page 78
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 78
OrientDB = {flexibility of Document databases+ complexity of the Graph model
+ Object Oriented concepts+ super fast Index
+ powerful SQL dialect+ multi-master replication and sharding}
Page 79
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 79
Ø configdownload, unzip, run!
cut & paste the db
Page 80
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 80
150,000records per second
(flat records, no index, on commodity hw)
Page 81
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 81
Schema-lessschema is not mandatory, relaxed model,collect heterogeneous documents all together
Page 82
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 82
Schema-fullschema with constraints on fields and validation rules
Customer.age > 17Customer.address not null
Customer.surname is mandatoryCustomer.email matches '\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b'
Page 83
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 83
Schema-mixedschema with mandatory and optional fields + constraints
the best of schema-less and schema-full modes
Page 84
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 84
ACID Transactionsdb.begin();try{ // your code ... db.commit();
} catch( Exception e ) { db.rollback();}
Page 85
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 85
SQLselect * from employee where name like '%Jay%' and status=0
Page 86
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 86
Why reinventyet another language when
the 100% of developers alreadyknow SQL?
OrientDB begins from SQLbut improves it with new
operators for graph manipulation
Page 87
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 87
For the most of the querieseveryday a programmer needs
SQL is simpler,more readable and
compact thenScripting (Map/Reduce)
Page 88
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 88
SQL & relationshipsselect from Account where address.city.country.name = 'Italy'
select from Account where addresses contains (city.country.name = 'Italy')
Page 89
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 89
SQL & trees/graphsselect out('friend’) from V where name = 'Luca' and surname = 'Garulli'
select out[@class='knows’] from V where name = 'Jay' and surname = 'Miner'
traverse friends from #13:55 where $depth < 7
Page 90
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 90
SQL sub queriesselect from ( traverse friends from Profile where $depth < 7 ) where home.city.name = ‘Cologne’
Page 91
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 91
SQL & stringsselect from Profile where name.toUpperCase() = 'LUCA'
select from City where country.name.substring(1,3).toUpperCase() = 'TAL'
select from Agenda where phones contains ( number.indexOf( '+39' ) > -1 )
select from Agenda where email matches '\bA-Z0-9._%[email protected] ?+\.A-Z?{2,4}\b'
Page 92
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 92
SQL & schema-lessselect from Profile where any() like '%Jay%'
select from Stock where all() is not null
Page 93
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 93
SQL & collectionsselect from Tree where children contains ( married = true )
select from Tree where children containsAll ( married = true )
select from User where roles containsKey 'shutdown'
select from Graph where edges.size() > 0
Page 94
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 94
Native JSONODocument = new ODocument().fromJSON( " { '@rid' = '26:10', '@class' = 'Developer', 'name' : 'Luca', 'surname' : 'Garulli', 'out' : [ #10:33, #10:232 ] }“ );
Page 95
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 95
Always FreeOpen Source Apache 2 license
free for any purposes,even commercials
Page 96
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 96
Some clients
Kondoot
Scenari
Page 97
(c) Luca Garulli Licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License Page 97www.orientechnologies.com
Thanks!Luca Garulli – Founder and CEO
www.twitter.com/lgarulli