Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Oracle Code Roma: NoSQL + SQL = MySQL

207 views

Published on

MySQL 8.0 Document Store is a new way for developers to use MySQL without SQL. CRUD operations, collections of JSON Documents, X Protocol....

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Oracle Code Roma: NoSQL + SQL = MySQL

  1. 1. 1 / 100
  2. 2. 2 / 1002 / 100
  3. 3.   Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purpose 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 up in making purchasing decisions. The development, release and timing of any features or functionality described for Oracle´s product remains at the sole discretion of Oracle. Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 3 / 100
  4. 4. about me - http://about.me/lefred Who am I ? Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 4 / 100
  5. 5. Frédéric Descamps @lefred MySQL Evangelist Hacking MySQL since 3.23 devops believer living in Belgium 🇧🇪 http://lefred.be   Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 5 / 100
  6. 6. MySQL a Document Store with all the benefits of a RDBMS Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 6 / 100
  7. 7. Why ? Developers don´t really like SQL   Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 7 / 100
  8. 8. Why ? SQL can be complicated and slows down the initial development Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 8 / 100
  9. 9. easy operations What do developers want ? Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 9 / 100
  10. 10. Use Objects / Documents Developers want just to use objects Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 10 / 100
  11. 11. Use Objects / Documents Developers want just to use objects that´s why they usually love what DBAs hate the most ORMs !). Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 11 / 100
  12. 12. Use Objects / Documents Developers want just to use objects that´s why they usually love what DBAs hate the most ORMs !). They want to deal with these objects easily (CRUD operations) and they don´t want to think about schema design (slows down the initial development process). Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 12 / 100
  13. 13. Use Objects / Documents Developers want just to use objects that´s why they usually love what DBAs hate the most ORMs !). They want to deal with these objects easily (CRUD operations) and they don´t want to think about schema design (slows down the initial development process). But they also want to keep their data safe and use transactions. Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 13 / 100
  14. 14. RDBMS & MySQL Relational Databases Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 14 / 100
  15. 15. Relational Databases Data Integrity Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 15 / 100
  16. 16. Relational Databases Data Integrity normalization Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 16 / 100
  17. 17. Relational Databases Data Integrity normalization constraints (foreign keys, ...) Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 17 / 100
  18. 18. Relational Databases Data Integrity normalization constraints (foreign keys, ...) Atomicity, Consistency, Isolation, Durability Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 18 / 100
  19. 19. Relational Databases Data Integrity normalization constraints (foreign keys, ...) Atomicity, Consistency, Isolation, Durability ACID compliant Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 19 / 100
  20. 20. Relational Databases Data Integrity normalization constraints (foreign keys, ...) Atomicity, Consistency, Isolation, Durability ACID compliant transactions Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 20 / 100
  21. 21. Relational Databases Data Integrity normalization constraints (foreign keys, ...) Atomicity, Consistency, Isolation, Durability ACID compliant transactions SQL Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 21 / 100
  22. 22. Relational Databases Data Integrity normalization constraints (foreign keys, ...) Atomicity, Consistency, Isolation, Durability ACID compliant transactions SQL powerfull query language Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 22 / 100
  23. 23. NoSQL & MySQL NoSQL Databases Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 23 / 100
  24. 24. NoSQL or Document Store Schemaless Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 24 / 100
  25. 25. NoSQL or Document Store Schemaless no schema design, no normalization, no foreign keys, no data types, ... Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 25 / 100
  26. 26. NoSQL or Document Store Schemaless no schema design, no normalization, no foreign keys, no data types, ... very quick initial development Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 26 / 100
  27. 27. NoSQL or Document Store Schemaless no schema design, no normalization, no foreign keys, no data types, ... very quick initial development Flexible data structure Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 27 / 100
  28. 28. NoSQL or Document Store Schemaless no schema design, no normalization, no foreign keys, no data types, ... very quick initial development Flexible data structure embedded arrays or objects Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 28 / 100
  29. 29. NoSQL or Document Store Schemaless no schema design, no normalization, no foreign keys, no data types, ... very quick initial development Flexible data structure embedded arrays or objects valid solution when natural data can´t be modelized optimaly into a relational model Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 29 / 100
  30. 30. NoSQL or Document Store Schemaless no schema design, no normalization, no foreign keys, no data types, ... very quick initial development Flexible data structure embedded arrays or objects valid solution when natural data can´t be modelized optimaly into a relational model objects persistance without the use of any ORM - mapping oobject-oriented Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 30 / 100
  31. 31. NoSQL or Document Store Schemaless no schema design, no normalization, no foreign keys, no data types, ... very quick initial development Flexible data structure embedded arrays or objects valid solution when natural data can´t be modelized optimaly into a relational model objects persistance without the use of any ORM - mapping oobject-oriented JSON Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 31 / 100
  32. 32. NoSQL or Document Store Schemaless no schema design, no normalization, no foreign keys, no data types, ... very quick initial development Flexible data structure embedded arrays or objects valid solution when natural data can´t be modelized optimaly into a relational model objects persistance without the use of any ORM - mapping oobject-oriented JSON close to frontend Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 32 / 100
  33. 33. NoSQL or Document Store Schemaless no schema design, no normalization, no foreign keys, no data types, ... very quick initial development Flexible data structure embedded arrays or objects valid solution when natural data can´t be modelized optimaly into a relational model objects persistance without the use of any ORM - mapping oobject-oriented JSON close to frontend native in JS Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 33 / 100
  34. 34. NoSQL or Document Store Schemaless no schema design, no normalization, no foreign keys, no data types, ... very quick initial development Flexible data structure embedded arrays or objects valid solution when natural data can´t be modelized optimaly into a relational model objects persistance without the use of any ORM - mapping oobject-oriented JSON close to frontend native in JS easy to learn Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 34 / 100
  35. 35. How DBAs see data Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 35 / 100
  36. 36. How DBAs see data How Developers see data { "GNP" : 249704, "Name" : "Belgium", "government" : { "GovernmentForm" : "Constitutional Monarchy, Federation", "HeadOfState" : "Philippe I" }, "_id" : "BEL", "IndepYear" : 1830, "demographics" : { "Population" : 10239000, "LifeExpectancy" : 77.8000030517578 }, "geography" : { "Region" : "Western Europe", "SurfaceArea" : 30518, "Continent" : "Europe" } } Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 36 / 100
  37. 37. What if there was a way to provide both SQL and NoSQL on one stable platform that has proven stability on well know technology with a large Community and a diverse ecosystem ? Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 37 / 100
  38. 38. DBMS or NoSQL ? Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 38 / 100
  39. 39. DBMS or NoSQL ? Why not both ? Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 39 / 100
  40. 40. The MySQL Document Store ! SQL is now optional ?! Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 40 / 100
  41. 41. SQL is now optional ?! Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 41 / 100
  42. 42. Developers: [x] schemaless [x] rapid prototying/simpler APIs [x] document model [x] transactions Operations: [x] performance management/visibility [x] robust replication, backup, restore [x] comprehensive tooling ecosystem [x] simpler application schema upgrades Business Owner: [x] don't lose my data == ACID trx [x] capture all my data = extensible/schemaless [x] product on schedule/time to market = rapid developement A solution for all Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 42 / 100
  43. 43. MySQL Document Store the Solution Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 43 / 100
  44. 44. Built on the MySQL JSON Data type and Proven MySQL Server Technology Provides a schema flexible JSON Document Store No SQL required No need to define all possible attributes, tables, etc. Uses new X DevAPI Can leverage generated column to extract JSON values into materialized columns that can be indexed for fast SQL searches. Document can be ~1GB It's a column in a row of a table It cannot exceed max_allowed_packet Allows use of modern programming styles No more embedded strings of SQL in your code Easy to read Also works with relational Tables Proven MySQL Technology Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 44 / 100
  45. 45. X Protocol Connectors Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 45 / 100
  46. 46. X DevAPI We provide connectors for C++, Java, .Net, Node.js, Python, PHP working with Communities to help them supporting it too New MySQL Shell Command Completion Python, JavaScrips & SQL modes Admin functions New Util object A new high-level session concept that can scale from single MySQL Server to a multiple server environment Non-blocking, asynchronous calls follow common language patterns Supports CRUD operations Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 46 / 100
  47. 47. PY JS SQL > MySQL 8.0 Upgrade Checker Auto Completion & Command History Output Formats (table, json, tabs) Prompt Themes Batch Execution 5.7 8.0 JS Document Store X dev API SQL CLI InnoDB Cluster importJSON JSJS Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 47 / 100
  48. 48. Migration from MongoDB to MySQL DS For this example, I will use the well known restaurants collection: Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 48 / 100
  49. 49. Migration from MongoDB to MySQL DS For this example, I will use the well known restaurants collection: Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 49 / 100
  50. 50. Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 50 / 100
  51. 51. Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 51 / 100
  52. 52. Let´s query Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 52 / 100
  53. 53. Let´s query That´s too much records to show it here... let´s limit it Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 53 / 100
  54. 54. Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 54 / 100
  55. 55. Some more examples Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 55 / 100
  56. 56. Some more examples Let´s add a selection criteria: Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 56 / 100
  57. 57. Using IN... Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 57 / 100
  58. 58. Syntax slightly different than MongoDB Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 58 / 100
  59. 59. Syntax slightly different than MongoDB > db.restaurants. nd({"cuisine": "French", "borough": { $not: /^Manhattan/} }, {"_id":0, "name": 1,"cuisine": 1, "borough": 1}).limit(2) { "borough" : "Queens", "cuisine" : "French", "name" : "La Baraka Restaurant" } { "borough" : "Queens", "cuisine" : "French", "name" : "Air France Lounge" } Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 59 / 100
  60. 60. And for developers ? Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 60 / 100
  61. 61. And for developers ? $session = mysql_xdevapigetSession("mysqlx://fred:MyP@ssw0rd%@localhost"); $schema = $session->getSchema("docstore"); $collection = $schema->getCollection("restaurants"); $results = $collection-> nd($search)->execute()->fetchAll(); ... foreach ($results as $doc) { echo "<tr><td><a href='?id=${doc[_id]}'>${doc[name]}</a></td>"; echo "<td>${doc[borough]}</td><td>${doc[cuisine]}</td></tr>"; } Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 61 / 100
  62. 62. And for developers ? $session = mysql_xdevapigetSession("mysqlx://fred:MyP@ssw0rd%@localhost"); $schema = $session->getSchema("docstore"); $collection = $schema->getCollection("restaurants"); $results = $collection-> nd($search)->execute()->fetchAll(); ... foreach ($results as $doc) { echo "<tr><td><a href='?id=${doc[_id]}'>${doc[name]}</a></td>"; echo "<td>${doc[borough]}</td><td>${doc[cuisine]}</td></tr>"; }   Easy, using only CRUD operations ! Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 62 / 100
  63. 63. CRUD operations Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 63 / 100
  64. 64. CRUD operations for collections Add a document Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 64 / 100
  65. 65. CRUD operations for collections Add a document collection.add({ name: 'fred', age: 42 }) .add({ name: 'dave', age: 23 }) .execute() collection.add([ { name: 'dimo', age: 50 }, { name: 'kenny', age: 25 } ]).execute() Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 65 / 100
  66. 66. CRUD operations for collections Modify a document Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 66 / 100
  67. 67. CRUD operations for collections Modify a document collection.modify('name = :name') .bind('name', 'fred') .set('age', 43) .sort('name ASC') .limit(1) .execute() collection.modify('name = :name') .bind('name', 'fred') .patch({ age: 43, active: false }) .sort('name DESC') .limit(1) .execute() Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 67 / 100
  68. 68. CRUD operations for collections Remove a document Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 68 / 100
  69. 69. CRUD operations for collections Remove a document collection.remove('name = :name') .bind('name', 'fred') .sort('age ASC') .limit(1) .execute() Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 69 / 100
  70. 70. MySQL Document Store Objects Summary Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 70 / 100
  71. 71. All you need to know is here: https://dev.mysql.com/doc/x-devapi-userguide/en/crud-operations-overview.html Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 71 / 100
  72. 72. we do care about your data MySQL Document Store is Full ACID Compliant Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 72 / 100
  73. 73. Document Store Full ACID ! It relies on the proven MySQL InnoDB´s strength & robustness: Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 73 / 100
  74. 74. Document Store Full ACID ! It relies on the proven MySQL InnoDB´s strength & robustness: innodb_ ush_log_at_trx_commit = 1 Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 74 / 100
  75. 75. Document Store Full ACID ! It relies on the proven MySQL InnoDB´s strength & robustness: innodb_ ush_log_at_trx_commit = 1 innodb_doublewrite = ON Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 75 / 100
  76. 76. Document Store Full ACID ! It relies on the proven MySQL InnoDB´s strength & robustness: innodb_ ush_log_at_trx_commit = 1 innodb_doublewrite = ON sync_binlog = 1 Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 76 / 100
  77. 77. Document Store Full ACID ! It relies on the proven MySQL InnoDB´s strength & robustness: innodb_ ush_log_at_trx_commit = 1 innodb_doublewrite = ON sync_binlog = 1 transaction_isolation = REPEATABLE-READ|READ- COMMITTED|... Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 77 / 100
  78. 78. Document Store Full ACID ! It relies on the proven MySQL InnoDB´s strength & robustness: innodb_ ush_log_at_trx_commit = 1 innodb_doublewrite = ON sync_binlog = 1 transaction_isolation = REPEATABLE-READ|READ- COMMITTED|... We do care about your data ! Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 78 / 100
  79. 79. MySQL DS Full ACID - Transactions support Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 79 / 100
  80. 80. MySQL DS Full ACID - Transactions support Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 80 / 100
  81. 81. OK we have Document Store, CRUD and ACID but what makes MySQL Document Store unique ? Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 81 / 100
  82. 82. Challenge: list the best restaurant of each type of food and show the top 10, with the best one first !   don't forget that all these restaurants are just JSON documents Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 82 / 100
  83. 83. NoSQL as SQL - aggregation Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 83 / 100
  84. 84. NoSQL as SQL - aggregation Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 84 / 100
  85. 85. NoSQL as SQL - aggregation Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 85 / 100
  86. 86. NoSQL or SQL You have the possibility to write clean and neat code: Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 86 / 100
  87. 87. NoSQL or SQL You have the possibility to write clean and neat code: $results = $collection-> nd('cuisine like "italian"')->execute()->fetchAll(); Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 87 / 100
  88. 88. NoSQL or SQL You have the possibility to write clean and neat code: $results = $collection-> nd('cuisine like "italian"')->execute()->fetchAll(); Or use SQL only when really needed: Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 88 / 100
  89. 89. NoSQL or SQL You have the possibility to write clean and neat code: $results = $collection-> nd('cuisine like "italian"')->execute()->fetchAll(); Or use SQL only when really needed: $results = $session->sql('WITH cte1 AS (SELECT doc->>"$.name" AS name, doc->>"$.cuisine" AS cuisine, (SELECT AVG(score) FROM JSON_TABLE(doc, "$.grades[*]" COLUMNS (score INT PATH "$.score")) AS r) AS avg_score FROM docstore.restaurants) SELECT *, RANK() OVER ( PARTITION BY cuisine ORDER BY avg_score) AS `rank` FROM cte1 ORDER BY `rank`, avg_score DESC LIMIT 10;')->execute(); Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 89 / 100
  90. 90. NoSQL or SQL You have the possibility to write clean and neat code: $results = $collection-> nd('cuisine like "italian"')->execute()->fetchAll(); Or use SQL only when really needed: $results = $session->sql('WITH cte1 AS (SELECT doc->>"$.name" AS name, doc->>"$.cuisine" AS cuisine, (SELECT AVG(score) FROM JSON_TABLE(doc, "$.grades[*]" COLUMNS (score INT PATH "$.score")) AS r) AS avg_score FROM docstore.restaurants) SELECT *, RANK() OVER ( PARTITION BY cuisine ORDER BY avg_score) AS `rank` FROM cte1 ORDER BY `rank`, avg_score DESC LIMIT 10;')->execute(); All in the same MySQL X Session ! Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 90 / 100
  91. 91. MySQL Shell is for DBAs and Developers     DEMO Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 91 / 100
  92. 92. what do I gain ? Conclusion Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 92 / 100
  93. 93. schemaless flexible data structure easy to start (CRUD) Conclusion This is the best of the two worlds in one product ! Data integrity ACID Compliant Transactions SQL Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 93 / 100
  94. 94. 94 / 100
  95. 95. Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 95 / 100
  96. 96. http://lefred.be/content/top-10-reasons-for- nosql-with-mysql/ Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 96 / 100
  97. 97. Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 97 / 100
  98. 98.   May 9th, 2019 Hotel NH Collection Roma Giustiniano Via Virgilio, 1 E/F/G, 0019 ROMA MySQL Day Roma You are invited to listen last news on MySQL 8.0, watch demos and be in contact with the MySQL Italian Team! http://bit.ly/MySQLDayRoma2019 Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 98 / 100
  99. 99. Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 99 / 100
  100. 100. Thank you ! Any Questions ? share your 💕 for MySQL on social media using @mysql #MySQL8isGreat #MySQL Copyright @ 2019 Oracle and/or its affiliates. All rights reserved. 100 / 100

×