Top Banner
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | MySQL as a Document Store Mario Beck MySQL Sales Consulting Manager EMEA [email protected]
47

MySQL Document Store

Feb 22, 2017

Download

Technology

Mario Beck
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: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

MySQL as a Document Store Mario Beck MySQL Sales Consulting Manager EMEA [email protected]

Page 2: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Safe Harbor Statement

The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

Page 3: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Program Agenda

MySQL Document Store

MySQL Future

1

2

3

Page 4: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Program Agenda

MySQL Document Store

MySQL Future

1

2

4

Page 5: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Today’s Challenges

• Developers want to move faster

• Time to market has a premium value

• Rapid prototyping, iterate fast…

5

Page 6: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

InnoDB Storage Engine

mysqld process

Advantages of SQL and NoSQL

NoSQL

Simple access patterns

Compromise on consistency for performance

Ad-hoc data format

Simple operation

SQL

Complex queries with joins

ACID transactions

Well defined schemas

Rich set of tools

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 6

Page 7: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Our Objective: Leverage the Infrastructure

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 7

Clients and Applications

InnoDB Storage Engine

mysqld process

Firewall

Audit

Encryption

Authentication

Online Backup

Monitoring

Integration

Support

3rd Party Tools 3rd Party Tools

3rd Party Tools 3rd Party Tools

3rd Party Tools

NoSQL

Simple access patterns

Compromise on consistency for performance

Ad-hoc data format

Simple operation

SQL

Complex queries with joins

ACID transactions

Well defined schemas

Rich set of tools

Page 8: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

NEW! MySQL Document Store

• Native JSON Documents in MySQL 5.7

– Schema-less Document Storage

• X Protocol (MySQL 5.7.12 DMR)

– Implemented by X Plugin to Extend MySQL Server as a Document Store

• X Dev API – SQL and Document CRUD Operations

– Implemented in Connector/Node.js, Connector/J, Connector/Net

• MySQL Shell

– Javascript, Python, SQL modes

Page 9: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Indexing JSON data

• Use Functional Indexes,

• STORED and VIRTUAL types are supported

9

CREATE TABLE employees (data JSON); ALTER TABLE employees ADD COLUMN name VARCHAR(30) AS (JSON_UNQUOTE(data->”$.name”)) VIRTUAL, ADD INDEX name_idx (name); SELECT data FROM employees WHERE name = ”Simone”; SELECT data FROM employees WHERE JSON_UNQUOTE(data->”$.name”) = ”Simone”;

• Column – generated from the expression – extracts attribute

• Index on virtual column

• Optimizer uses index automatically

Page 10: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Architecture

10

MySQL

Plugins

X Protocol Plugin Memcached Plugin Core

X Protocol Std Protocol

X Protocol 33060

Std Protocol 3306

SQL API CRUD API

X and Std Protocols

MySQL Shell

Page 11: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

New! MySQL X DevAPI

• Modern: fluent API, method chaining

• Stateless sessions enable transparent scaling to multi-server environments

• SQL support

• CRUD for Collections of Documents and Tables

– Documents as simple basic domain objects

– Search expressions match SQL SELECT expressions

• Implemented in MySQL Shell & MySQL Connectors – NEW! MySQL Connector/node.js

– MySQL Connector/J

– MySQL Connector/Net

Page 12: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

New! MySQL Shell

• Integrated Development and Administration Shell

• Exposes New X DevAPI

• Multi-Language scripting

– JavaScript, Python, and SQL

• Configurable results formats

– Traditional Table, JSON, Tab Separated

12

Page 13: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 13

tomas@localhost $ mysqlsh --uri root@localhost/test Creating an X Session to root@localhost:33060/test Enter password: Default schema `test` accessible through db. …

Currently in JavaScript mode. Use \sql to switch to SQL mode and execute queries. mysql-js> db.createCollection("posts"); <Collection:posts> mysql-js> db.posts.add({"title":"Hello World", "text":"First post!"}) Query OK, 1 item affected (0.03 sec) mysql-js> db.posts.find("title = 'Hello World'").sort(["title"]); [ { "_id": "8202bda28206e611140b3229389b6526", "text": "First post!", "title": "Hello World" } ] 1 document in set (0.01 sec)

Page 14: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 14

Under the Hood

Page 15: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 15

Collections are tables

Tables with: - JSON column - Generated Column

Create a Collection

Page 16: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Under The Hood II

16

• X-Plugin translates CRUD -> SQL

• No code changes in core parts of MYSQL

Create Document (CRUD)

Look inside general-log

Page 17: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Under The Hood III

17

Read Document (CRUD)

Look inside general-log

Page 18: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

CRUD Operations – NoSQL/Document and SQL/Relational

Operation Document Relational

Create Collection.add() Table.insert()

Read Collection.find() Table.select()

Update Collection.modify() Table.update()

Delete Collection.remove() Table.delete()

18

Page 19: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

CRUD Operations NoSQL/Document Javascript Java

C# NodeJS

Page 20: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

CRUD Operations in php NoSQL/Document

/* open a new connection */ $session = mysql_xdevapi\getSession("localhost","root", "secretpwd"); /* CREATE a new collection and document*/ $schema = $session->getSchema("products"); $collection = $schema->createCollection("best_products"); $product = array('name' => 'superdent', ' quantity' => 42); $collection->add($product)->execute(); /* READ documents */ $largestock = $collection->find()->sort(“quantity desc")->limit(3)->execute();

Page 21: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

CRUD Operations in php NoSQL/Document

/* UPDATE a document*/ $collection->modify("name like 'SuperDent'")->set(“quantity", 15)->execute(); $collection->modify("name like :pr_name")->bind(["pr_name" => $productName])-> set(“quantity", 15)->execute(); $collection->modify(“quantity < 10")->set("comment", "order more")->execute(); /* DELETE documents */ $collection->remove("name like 'Super%'")->execute();

Page 22: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

CRUD Operations SQL/Relational

22

Javascript Java

C# NodeJS

Page 23: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Program Agenda

MySQL Document Store

MySQL Future

1

2

23

Page 24: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Vision

24

Page 25: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

“Be the most popular open source database for scale-out”

25

Page 26: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

“Be the most popular open source database for scale-out”

26

Page 27: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

3 MySQL will focus on three things.

27

Page 28: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 28

Scale-Out

Ease-of-Use

Out-of-Box Solution

MySQL

Page 29: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 29

Ease-of-Use

• Download, Install, HA & Scale-Out in 15 minutes

• Single Interface for Everything MySQL

• Easy to Setup, Scale-Out, Manage & Monitor

• Excellent Quality

MySQL

Page 30: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 30

Out-of-Box Solution

• Integrated Solution vs. Individual Components

• Designed & Developed Together

• Tested & Delivered Together

• Managed & Monitored Together

MySQL

Page 31: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 31

Scale-Out

• Maintain World-Class Performance

• Rock Solid, Server-Side HA With Auto-Failover

• Read Scale-Out With Replication

• Write Scale-Out With Sharding

MySQL

Page 32: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

4 Rollout will happen in four steps.

32

Page 33: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 33

Read Scale-Out

Async Replication + Auto Failover

Write Scale-Out

Sharding

S1

S2

S3

S4

MySQL Vision – 4 Steps

Timeline

MySQL Document Store

Relational & Document Model

MySQL HA

Out-Of-Box HA

Page 34: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Introducing …

34

Page 35: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 35

Scale-Out High Performance

Ease-of-Use Built-in HA

Out-of-Box Solution Everything Integrated

MySQL InnoDB

cluster

Page 36: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 36

A single product: MySQL • All components created together

• Tested together

• Packaged together

Flexible and Modern • C++ 11

• Protocol Buffers

• Developer friendly

MySQL InnoDB Cluster – Goals

Easy to use • A single client: MySQL Shell

• Easy packaging

• Homogenous servers

Scale-out • Sharded clusters

• Federated system of N replica sets

• Each replica set manages a shard

Page 37: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

MySQL

InnoDB cluster

MySQL InnoDB Cluster – Architecture - S2

M

M M

MySQL Connector

Application

MySQL Router

MySQL Connector

Application

MySQL Router

MySQL Shell

HA

Group Replication

Page 38: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

S1 S2 S3 S4 S…

M

M M

MySQL Connector

Application

MySQL Router

MySQL Connector

Application

MySQL Router

MySQL Shell

HA

MySQL InnoDB Cluster – Architecture - S3 MySQL

InnoDB cluster

Read-Only Slaves

Page 39: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

S1 S2 S3 S4 S…

M

M M

MySQL Connector

Application

MySQL Router

MySQL Connector

Application

MySQL Router

MySQL Shell

HA

Rep

licaS

et (

Shar

d 1

)

S1 S2 S3 S4 S…

M

M M

MySQL Connector

Application

MySQL Router

HA

Rep

licaS

et (

Shar

d 2

)

S1 S2 S3 S4

M

M M

HA

Rep

licaS

et (

Shar

d 3

)

MySQL Connector

Application

MySQL Router

MySQL InnoDB Cluster – Architecture - S4 MySQL

InnoDB cluster

Page 40: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

MySQL Shell – Deploy MySQL Instances

shell> mysqlsh

mysql-js> dba.deployLocalInstance(3306)

mysql-js> dba.deployInstance(‘hanode2:3306’)

mysql-js> dba.deployInstance(‘hanode3:3306’)

40

Page 41: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

MySQL Shell – Create an InnoDB Cluster

mysql-js> \connect root@hanode1:3306

mysql-js> cluster = dba.createCluster(‘NewAppCluster')

mysql-js> cluster.addInstance('root@hanode2:3306')

mysql-js> cluster.addInstance('root@hanode3:3306')

41

Page 42: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

MySQL Shell – Add a MySQL Router

shell> mysqlrouter --bootstrap hanode1:3306

shell> mysqlrouter &

shell> mysqlsh --uri root@localhost:6446

42

Page 43: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

InnoDB Storage Engine

mysqld process

Advantages of SQL and NoSQL

NoSQL

Simple access patterns

Compromise on consistency for performance

Ad-hoc data format

Simple operation

SQL

Complex queries with joins

ACID transactions

Well defined schemas

Rich set of tools

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 43

Page 44: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Our Objective: Leverage the Infrastructure

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 44

Clients and Applications

InnoDB Storage Engine

mysqld process

Firewall

Audit

Encryption

Authentication

Online Backup

Monitoring

Integration

Support

3rd Party Tools 3rd Party Tools

3rd Party Tools 3rd Party Tools

3rd Party Tools

NoSQL

Simple access patterns

Compromise on consistency for performance

Ad-hoc data format

Simple operation

SQL

Complex queries with joins

ACID transactions

Well defined schemas

Rich set of tools

Page 45: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Our Objective: Empower Application Developers

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 45

Clients and Applications

InnoDB Storage Engine

mysqld process

Firewall

Audit

Encryption

Authentication

Online Backup

Monitoring

Integration

Support

3rd Party Tools 3rd Party Tools

3rd Party Tools 3rd Party Tools

3rd Party Tools

NoSQL

Simple access patterns

Compromise on consistency for performance

Ad-hoc data format

Simple operation

SQL

Complex queries with joins

ACID transactions

Well defined schemas

Rich set of tools

Page 46: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Resources

Topic Link(s)

MySQL as a Document Database http://dev.mysql.com/doc/refman/5.7/en/document-database.html

MySQL Shell http://dev.mysql.com/doc/refman/5.7/en/mysql-shell.html http://dev.mysql.com/doc/refman/5.7/en/mysqlx-shell-tutorial-javascript.html http://dev.mysql.com/doc/refman/5.7/en/mysqlx-shell-tutorial-python.html

X Dev API http://dev.mysql.com/doc/x-devapi-userguide/en/

X Plugin http://dev.mysql.com/doc/refman/5.7/en/x-plugin.html

MySQL JSON http://mysqlserverteam.com/tag/json/ https://dev.mysql.com/doc/refman/5.7/en/json.html https://dev.mysql.com/doc/refman/5.7/en/json-functions.html

46

Page 47: MySQL Document Store

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Thank you!