MySQL Day Paris 2016 - MySQL as a Document Store

553 views

Published on

MySQL Day Paris 2016 - MySQL as a Document Store
✔ Built on Proven SQL/InnoDB/Replication
✔ Schema-less/Relational/Hybrid
✔ ACID/Transactions
✔ CRUD/JSON/Documents
✔ Modern Dev API
✔ Modern/Efficient Protocol
✔ SQL Queries/Analytics over JSON Documents
✔ Transparent and Easy HA/Scaling/Sharding

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
553
On SlideShare
0
From Embeds
0
Number of Embeds
454
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

MySQL Day Paris 2016 - MySQL as a Document Store

  1. 1. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | MySQL as a Document Store Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Olivier Dasini MySQL Principal Solutions Architect EMEA olivier.dasini@oracle.com @freshdaz
  2. 2. 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. 2
  3. 3. 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… 3
  4. 4. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Today’s Challenges (cont.) • Relational databases ask for schema up front – Potentially saving you time in the future – Less variations; less code to handle edge cases – Added cost with each schema change • NoSQL databases do not ask for schema – Saving you time up front – But potentially adding operational costs over time – No cost per schema change 4
  5. 5. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Today’s Challenges (cont.) • The Most popular NoSQL database uses similar data structures to relational databases (B+TREE) – Data structure influences key performance characteristics not data model – No inherent scalability advantages – Yet behind on key functionality • Standing up multiple technologies adds complexity for operations teams 5
  6. 6. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Why can you not… • Have both schema-less and schema in the same technology stack? • One that checks all the boxes of all stakeholders: 6 Developers: [ x ] Schemaless [ x ] Rapid Prototyping/Simpler APIs [ x ] Document Model Operations: [ x ] Performance Management/Visibility [ x ] Robust Replication, Backup, Restore [ x ] Comprehensive Tooling Ecosystem Business Owner: [ x ] Don’t lose my data = ACID transactions [ x ] Capture all my data = Extensible/Schemaless [ x ] Products On Schedule/Time to Market = Rapid Development
  7. 7. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | We <3 Schemaless • MySQL as a Document Store • All the existing features of MySQL – Replication – InnoDB – Performance Schema • With the addition of schemaless – Documents using JSON – Easy to program CRUD APIs 7
  8. 8. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | MySQL – a One Stop Shop • Expensive to manage many data stores • Better few databases – more flexibility – More developers • Can harness both NoSQL and SQL savvy – More DBAs • No shortage of highly experienced MySQL DBAs – Less training – don’t need to learn many products – Cross data store exchange – easier to move from from docs to tables etc. – One connector/driver needed for apps Combining Relational and Document Stores 8
  9. 9. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | • One Extensible database – Do more with the MySQL database – Many can manage (with deep skills) – Stable – Cost-effective – Easy to move data between like database types – Fewer Drivers – Few Tools – SQL works, CRUD works – Operational and Analytical Together • Many different databases – Requires larger skill repertoire, more complex development … • Harder to find deep skills – Many Drivers – Many Tools – More effort to share and exchange data – It’s a lot more work – Operational and Analytical Separate One Database Many Models VS Many Databases Many Models 9
  10. 10. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | NEW! MySQL as a Document Store • Native JSON Documents in MySQL 5.7 – JSON data type – Schema-less Document Storage – Indexes on JSON documents (w/ Generated Columns) • X Protocol (MySQL 5.7.12+) – Implemented by X Plugin to Extend MySQL Server as a Document Store • X Dev API – SQL and NoSQL CRUD Operations – Implemented in Connectors : Node.js, Java, .Net, Python, C/C++ – Supports Combined Document and Relational • MySQL Shell – JavaScript (js), Python (py), SQL (sql) modes
  11. 11. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | MySQL 5.7, Connectors, Drivers, and Protocols 11 MySQLMySQL Plugins X Protocol Plugin Memcached Plugin Core MySQL Connectors and Drivers X ProtocolStd Protocol Memcached driver X Protocol 33060 Std Protocol 3306 SQL API CRUD and SQL APIs Memcached Protocol X and Std Protocols MySQL Shell
  12. 12. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | MySQL X Protocol • Asynchronous API support – Supporting Parallelism and Batching – Pipelining (streaming) - Send multiple requests, Reduce Round Trips – Push Notifications - Beyond the Request/Response model • Middleware Friendly – Routing, Sharding, Read Write Splitting • Uses open standards: TLS, SASL, Protobuf etc – Proven, community friendly • Supports both CRUD and SQL operations 12 http://mysqlserverteam.com/mysql-5-7-12-part-2-improving-the-mysql-protocol/
  13. 13. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | MySQL Shell – Key Features • Multi-Language - JavaScript, Python, and SQL languages • Supports both Document and Relational Models • Interactive and Batch processing modes • Three results formats – Traditional Table, JSON, Tab Separated, • Exposes Full Development API – Sessions – Schemas – Collections – Tables Integrated Development and Administration Shell 13 – CRUD on Tables and Collections – SQL execution – Result Processing – Parameter Binding
  14. 14. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | MySQL Shell – Key Features (cont.) • Stored Sessions – for 1 to Many servers • Supports Multiple Connections per Session • Support all 3 New Session types – Xsession – CRUD only session (Connected Server is “Abstacted”) – Node – SQL and CRUD (Connected Server is “Fixed”) – Standard MySQL session – SQL (Connected Server is “Fixed”) • Optional Session Logging – – Set Logging Level, Verify state, Review history Global Sessions 14
  15. 15. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 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/C++ – MySQL Connector/Net | MySQL Connector/Python 15 http://dev.mysql.com/doc/x-devapi-userguide/en/
  16. 16. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Operation Document Relational Create Collection.add() Table.insert() Read Collection.find() Table.select() Update Collection.modify() Table.update() Delete Collection.remove() Table.delete() 16 • Use SQL, CRUD APIs – Document (NoSQL) and Relational (SQL), or “All of the Above” – All of this is in addition to the Classic APIs MySQL Connectors include X DevAPI
  17. 17. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | MySQL Documents and Collections • Collections are containers for documents – These documents share a purpose – Possibly share one or more indexes – Each collection has a unique name – Exists within a single schema • Within a Collection you can – Add(), Find(), Modify(), and Remove() - JSON documents • Collections can be – Create(), List(), Drop() 21
  18. 18. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Collection Search – find(), bind(), fields() • Supports many operators to specify searches – ||, &&, XOR, IS, NOT, BETWEEN, IN, LIKE, !=, <>, >, >=, <, <=, &, |, <<, >>, +, -, *, /, ~, %. • Searching – db.CountryInfo.find("GNP > 500000 and demographics.Population < 100000000") – db.CountryInfo.find("GNP*1000000/demographics.Population > 30000") • Binding - bind() – db.CountryInfo.find("Name = :country").bind("country", "Italy") • Project Results – fields() – returns specific fields – db.CountryInfo.find("Name = :country").bind("country", "Italy") 22
  19. 19. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Installation needs 1) MySQL 5.17.12 or later 2) Install X plugin mysql> INSTALL PLUGIN mysqlx SONAME “mysqlx.so”; 3) Install mysqlsh 24 https://dev.mysql.com/doc/refman/5.7/en/document-store-setting-up.html
  20. 20. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | CRUD Operations NoSQL/Document Javascript Java C#NodeJS
  21. 21. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | CRUD Operations SQL/Relational 26 Javascript Java C#NodeJS
  22. 22. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 27 Let's play with MySQL Shell...
  23. 23. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 28 $ mysqlsh ­­uri root@localhost/doc Creating an X Session to root@localhost:33060/doc Enter password:  Default schema `doc` accessible through db. … Currently in JavaScript mode. Use sql to switch to SQL mode and execute queries. mysql­js> session <XSession:root@localhost:33060/doc> mysql­js> db <Schema:doc> mysql­js> db.getCollections() { } mysql­js> db.createCollection("posts"); <Collection:posts> mysql­js> db.getCollections() {     "posts": <Collection:posts> } mysql­js> db.posts.add({"title":"MySQL rocks", "text":"My first post!"}) Query OK, 1 item affected (0.02 sec)
  24. 24. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 29 mysql­js> db.posts.add({"title":"Polyglot database", "text":"With MySQL we can handle SQL and NoSQL data"}) Query OK, 1 item affected (0.02 sec) mysql­js> db.posts.find(); [     {         "_id": "72bfbd1958a7e6119733dc53609b8b8d",         "text": "My first post!",         "title": "MySQL rocks"     },     {         "_id": "b2c4380859a7e6119733dc53609b8b8d",         "text": "With MySQL we can handle SQL and NoSQL data",         "title": "Polyglot database"     } ] 2 documents in set (0.01 sec) mysql­js> db.posts.find("title = 'Polyglot database'"); [     {         "_id": "b2c4380859a7e6119733dc53609b8b8d",         "text": "With MySQL we can handle SQL and NoSQL data",         "title": "Polyglot database"     } ] 1 document in set (0.00 sec)
  25. 25. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 30 An SQL view gives...
  26. 26. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 31 ­­ switch to a node session to be able to use sql commands mysql­js> connect_node root@localhost/doc Creating a Node Session to root@localhost:33060/doc mysql­js> sql Switching to SQL mode... Commands end with ; mysql­sql> SHOW TABLES; +­­­­­­­­­­­­­­­+ | Tables_in_doc | +­­­­­­­­­­­­­­­+ | posts         | +­­­­­­­­­­­­­­­+ mysql­sql> SHOW CREATE TABLE posts; … CREATE TABLE posts (   doc json DEFAULT NULL,   _id varchar(32) GENERATED ALWAYS AS (json_unquote(json_extract(`doc`,'$._id'))) STORED NOT NULL,   PRIMARY KEY (_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4  mysql­sql> SELECT doc FROM posts; +­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ | doc             | +­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ | {"_id": "72bfbd1958a7e6119733dc53609b8b8d", "text": "My first post!", "title": "MySQL rocks"}            | | {"_id": "b2c4380859a7e6119733dc53609b8b8d", "text": "With MySQL we can handle SQL and NoSQL data",  "title": "Polyglot database"} | +­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
  27. 27. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | MySQL Document Store ✔ Built on Proven SQL/InnoDB/Replication ✔ Schema-less/Relational/Hybrid ✔ ACID/Transactions ✔ CRUD/JSON/Documents ✔ Modern Dev API ✔ Modern/Efficient Protocol ✔ SQL Queries/Analytics over JSON Documents ✔ Transparent and Easy HA/Scaling/Sharding 35
  28. 28. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Resources Topic Link(s) MySQL as a Document Store http://dev.mysql.com/doc/refman/5.7/en/document-store.html http://mysqlserverteam.com/category/docstore/ 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 https://dev.mysql.com/doc/refman/5.7/en/json.html https://dev.mysql.com/doc/refman/5.7/en/json-functions.html http://mysqlserverteam.com/tag/json/ 36
  29. 29. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | Thank you!

×