Documente Academic
Documente Profesional
Documente Cultură
the
MySQL Document Store
Alfredo Kojima Sr. Dev. Manager
Mike Frank Product Management Director
Oracle
Copyright 2014 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Internal/Restricted/Highly Restricted
Todays Agenda
1
The X DevAPI
RelaNonal Databases
Data Integrity
NormalizaNon
Constraints (foreign keys etc)
SQL
Powerful, OpNmizable Query Language
Declare what you want and the DB will nd out the most ecient way to get it to
you
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
Plus
MySQL has been around since 1995
Ubiquitous
Pregy much a standard
Scalable
When there are issues, they are known and understood
Large body of knowledge, from small to BIG deployments
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
Document Databases
Schemaless
no schema design, normalizaNon, foreign keys, constraints, data types etc
faster iniNal development
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
Why not both?
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
The X DevAPI
10
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
11
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
12
The X DevAPI
13
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
14
Ex.:
SELECT JSON_OBJECT('cust_id', id, 'name', name, 'email', email) FROM customer;
CREATE VIEW customer_json AS
SELECT JSON_OBJECT('cust_id', id, 'name', name, 'email', email) as doc FROM
customer;
SELECT * FROM customer_json;
15
Virtually Schemaless
Unstructured data
No clear, xed structure for the data records can have dierent elds
Oven data that is not involved in business rules
Examples: "product_info", "properNes", "opNons" etc
Data does not map cleanly into a relaNonal model (arrays, hierarchical data
etc)
Prototyping
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
16
hgps://www.mediawiki.org/wiki/Manual:Database_layout
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
17
value
size
color
red
fabric
cogon
11
avour
strawberry
12
capacity
128GB
12
speed class
class 10
13
connecNvity
Wi-Fi
13
storage
64GB
13
screen size
8.9"
13
resoluNon
13
bagery life
12 hours
{
"product_id": 9,
"size" : "M",
"color": "red",
"fabric": "cogon"
},
{
"product_id": 11,
"avour": "strawberry"
},
{
"product_id": 12,
"capacity": "128GB",
"speed class": "class 10"
},
{
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
18
19
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
20
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
21
The X DevAPI
22
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
23
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
24
The X DevAPI
AbstracNon over SQL
Focused on 4 basic CRUD operaNons (Create, Read, Update, Delete)
Fluent, NaNve Language API
No knowledge of SQL needed
X Protocol
CRUD requests encoded at protocol level
Request details "visible" (vs "opaque" SQL strings)
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
25
Create a CollecNon
mydb.createCollection("products");
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
26
Add Document
products.add({"name":"bananas", "color":"yellow"}).execute();
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
27
Find Documents
products.find("color = 'yellow'").sort(["name"]).execute();
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
28
Modify Documents
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
29
Remove Documents
products.remove("product_id = 123").execute();
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
30
X DevAPI Sessions
X Session
Stateless
CRUD only, no SQL
Abstracts the connecNon
Node Session
Direct connecNon to a database node
Allows CRUD and SQL
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
31
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
32
Document
CollecNon.add()
CollecNon.nd()
CollecNon.modify()
CollecNon.remove()
Rela+onal
Table.insert()
Table.select()
Table.update()
Table.delete()
33
The X DevAPI
34
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
35
Std Protocol
X Protocol
X and Std
Protocols
X Protocol
33060
Std Protocol
3306
MySQL
Shell
Memcached
driver
Memcache
Protocol
MySQL
Plugins
Core
X Protocol Plugin
Memcached Plugin
36
!
// increment the page number and fetch it again!
newDoc.add("title", !
new JsonString().setValue("Effi Briest"));!
coll.modify("isbn = 12345").!
set("currentlyReadingPage", !
((JsonNumber)book.get("currentlyReadingPage")).getInteger() +
1).execute();!
newDoc.add("author", !
new JsonString().setValue("Theodor Fontane"));!
newDoc.add("currentlyReadingPage", !
new JsonNumber().setValue(String.valueOf(42)));!
book = docs.fetchOne();!
coll.add(newDoc).execute();!
DocResult docs = coll.find("title = 'Effi Briest' and
currentlyReadingPage > 10").execute();!
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
37
Result r = coll.Add(docs).Execute();
r = coll.Modify("_id = :ID").
if (testSchema.ExistsInDatabase())
session.DropSchema(schemaName);
session.CreateSchema(schemaName);
// remove a book
OrderBy("pages DESC").Execute().FetchAll();
};
Console.WriteLine(doc.ToString());
}
}
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
38
const collection =
session.getSchema('myschema').getCollection('questions');!
mysqlx.getSession({!
collection.find("answer == 42")!
host: 'localhost',!
.orderBy("foo DESC")!
dbUser: 'myuser',!
.limit(10)!
dbPassword: 'secret'!
}).then(session => {!
const collection =
session.getSchema('myschema').getCollection('mycollection');!
return Promise.all([!
collection.add({ foo: "bar", something: { nested:
[1,2,3,4] } }).execute();!
session.close();!
])!
}).catch(err => {!
console.log(err);!
});!
!
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
39
MySQL Shell
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
40
Copyright 2016 Oracle and/or its aliates. All rights reserved. | Oracle CondenNal Restricted
41
Resources
Topic
Link(s)
hgp://dev.mysql.com/doc/refman/5.7/en/document-database.html
MySQL Shell
hgp://dev.mysql.com/doc/refman/5.7/en/mysql-shell.html
hgp://dev.mysql.com/doc/refman/5.7/en/mysqlx-shell-tutorial-javascript.html
hgp://dev.mysql.com/doc/refman/5.7/en/mysqlx-shell-tutorial-python.html
X Dev API
hgp://dev.mysql.com/doc/x-devapi-userguide/en/
X Plugin
hgp://dev.mysql.com/doc/refman/5.7/en/x-plugin.html
MySQL JSON
hgp://mysqlserverteam.com/tag/json/
hgps://dev.mysql.com/doc/refman/5.7/en/json.html
hgps://dev.mysql.com/doc/refman/5.7/en/json-funcNons.html
Blogs
hgp://mysqlserverteam.com/category/docstore/
42
Thank You!
Alfredo Kojima
alfredo.kengi.kojima@oracle.com