SlideShare a Scribd company logo
MySQLWithout
the SQL - Oh My!
Dave Stokes
@stoker
david.stokes@oracle.com
Elephantdolphin.blogger.com
opensourcedba.wordpress.com
Relational Databases
2
Relational Databases
● Data Integrity
○ Normalization
○ constraints (foreign keys, ...)
● Atomicity, Consistency, Isolation, Durability
○ ACID compliant
○ transactions
● SQL
○ powerful query language 3
NoSQL or Document Store
4
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 not be modelized optimally into a
relational model
○ Objects persistence without the use of any ORM - *mapping
object-oriented*
● JSON
● close to frontend
● native in JS
● easy to learn
5
How DBAs see data as opposed to 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"
}
}
6
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 ?
With the MySQL Document
Store SQL is now optional!
7
A Solution for all
Developers:
★ schemaless
★ rapid prototyping &
simpler APIs
★ document model
★ transactions
Operations:
★ performance
management/visibility
★ robust replication, backup,
restore
★ comprehensive tooling
ecosystem
★ simpler application schema
upgrades
8
Business Owner:
★ don't lose my data ==
ACID trx
★ capture all my data =
extensible/schemaless
★ product on schedule/time
to market = rapid
development
Built on the MySQL JSON Data type and Proven MySQL Server Technology 9
★ 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
★ 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
★ Connectors for
○ C++, Java, .Net, Node.js, Python, PHP
○ working with Communities to help them supporting it too
★ New MySQL Shell
○ Command Completion
○ Python, JavaScripts & 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
10
Starting using MySQL in few minutes 11
Shell info 12
For this example, I will use the well known restaurants collection:
We need to dump the data to a file and
we will use the MySQL Shell
with the Python interpreter to load the data.
Migration from MongoDB to MySQL Document Store
13
Dump and load using MySQL Shell & Python
This example is inspired by @datacharmer's work: https://www.slideshare.net/datacharmer/mysql-documentstore
$ mongo quiet eval 'DBQuery.shellBatchSize=30000;
db.restaurants.find().shellPrint()' 
| perl -pe 's/(?:ObjectId|ISODate)(("[^"]+"))/ $1/g' > all_recs.json
14
15
16
Let’s query
Too many records to show here … let’s limit it!
17
More Examples!
18
Let’s add a selection criteria
>
db
.r
es
ta
> db.restaurants.find({"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" } 19
Syntax is slightly
different than
MongoDB
20
CRUD Operations
21
Add a Document
22
Modify a Document
23
Remove a Document
24
Find a Document
25
MySQL Document Store Objects Summary
MySQL Document Store is Fully ACID Compliant 26
MySQL Document Store is Fully ACID Compliant 27
What about old SQL? The Hidden Part of the Iceberg 28
★ Native datatype (since 5.7.8)
★ JSON values are stored in MySQL tables using UTF8MB4
★ Conversion from "native" SQL types to JSON values
★ JSON manipulation functions (JSON_EXTRACT, JSON_KEYS,
JSON_SEARCH, JSON_TABLES, ...)
★ Generated/virtual columns
○ Indexing JSON data
○ Foreign Keys to JSON data
○ SQL Views to JSON data
JSON datatype is behind the scene
29
How Does It Work?? 30
What does a collection look like on the server ? 31
Every document has a unique identifier called the document ID,
which can be thought of as the equivalent
of a table´s primary key. The document ID value can be manually
assigned when adding a document.
If novalue is assigned, a document ID is generated and assigned
to the document automatically !
Use getDocumentId() or getDocumentIds() to get _ids(s)
_id
32
Mapping to SQL Examples
createCollection('mycollection')
CREATE TABLE `test`.`mycoll` (
doc JSON,
_id VARCHAR(32)
GENERATED ALWAYS AS (doc->>'$._id') STORED
PRIMARY KEY
) CHARSET utf8mb4;
mycollection.add({‘test’: 1234})
INSERT INTO `test`.`mycoll` (doc) VALUES (
JSON_OBJECT('_id','663807fe367ee6114e0e5458bdac28bf', 'test',1234));
33
More Mapping to SQL Examples
mycollection.find("test > 100")
SELECT doc
FROM `test`.`mycoll`
WHERE (JSON_EXTRACT(doc,'$.test') >100);
34
35
SQL and JSON Example
It's also possible to create indexes without using SQL syntax 36
SQL and JSON Example (2): validation 37
SQL and JSON Example (3): explain 38
SQL and JSON Example (3): explain 39
SQL and JSON Example (4): add index 40
SQL and JSON Example (4): add index 41
SQL and JSON Example (5): arrays 42
NoSQL as SQL 43
JSON_TABLE turns your
un-structured JSON data into a
temporary structured table!
NoSQL as SQL 44
This temporary structured table can
be treated like any other table --
LIMIT, WHERE, GROUP BY ...
45
More Sophisticated Analysis
Find the top 10 restaurants by grade for each cuisine 46
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 restaurants)
SELECT *, rank() OVER
(PARTITION BY cuisine ORDER BY avg_score) AS `rank`
FROM cte1
ORDER by `rank`, avg_score DESC limit 10;
This query uses a Common Table Expression (CTE) and a Windowing Function to rank the average
scores of each restaurant, by each cuisine
SQL and NoSQL 47
Show Results 48
JOINing tables 49
Conclusion: What Do I Gain?
50
This is the best of the two worlds in one product !
● Data integrity
● ACID Compliant
● Transactions
● SQL
● Schemaless
● flexible data structure
● easy to start (CRUD)
51
Thanks!
Contact info:
Dave Stokes
David.Stokes@Oracle.com
@Stoker
slideshare.net/davidmstokes
Elepantdolphin.blogger.com
opensourcedba.Wordpress.com
52

More Related Content

What's hot (20)

PDF
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
Liwei Chou
 
PDF
Memory management
Kuban Dzhakipov
 
PDF
Back to Basics 2017: Mí primera aplicación MongoDB
MongoDB
 
ODP
2011 Mongo FR - Indexing in MongoDB
antoinegirbal
 
PPTX
Back to Basics, webinar 2: La tua prima applicazione MongoDB
MongoDB
 
PPTX
MongoDB Shell Tips & Tricks
MongoDB
 
PPTX
Back to Basics Webinar 5: Introduction to the Aggregation Framework
MongoDB
 
PPTX
Tag based sharding presentation
Juan Antonio Roy Couto
 
KEY
Introduction to MongoDB
Alex Bilbie
 
PDF
Сергей Матвеенко: MongoEngine: NoORM for NoSQL
it-people
 
PPTX
MongoDB: Comparing WiredTiger In-Memory Engine to Redis
Jason Terpko
 
PDF
Mongo db
Toki Kanno
 
PDF
Hive jdbc
Bennie Schut
 
PPTX
Beyond the Basics 2: Aggregation Framework
MongoDB
 
PDF
MongoDB
Rawin Windygallery
 
PDF
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
tdc-globalcode
 
PDF
Palestra Java + NoSQL = Iniciativa JNoSQL no TDC Florianópolis
Marcelo Souza Vieira
 
PDF
Python Files
Vikram Nandini
 
PDF
Latinoware
kchodorow
 
PDF
Hands On Spring Data
Eric Bottard
 
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
Liwei Chou
 
Memory management
Kuban Dzhakipov
 
Back to Basics 2017: Mí primera aplicación MongoDB
MongoDB
 
2011 Mongo FR - Indexing in MongoDB
antoinegirbal
 
Back to Basics, webinar 2: La tua prima applicazione MongoDB
MongoDB
 
MongoDB Shell Tips & Tricks
MongoDB
 
Back to Basics Webinar 5: Introduction to the Aggregation Framework
MongoDB
 
Tag based sharding presentation
Juan Antonio Roy Couto
 
Introduction to MongoDB
Alex Bilbie
 
Сергей Матвеенко: MongoEngine: NoORM for NoSQL
it-people
 
MongoDB: Comparing WiredTiger In-Memory Engine to Redis
Jason Terpko
 
Mongo db
Toki Kanno
 
Hive jdbc
Bennie Schut
 
Beyond the Basics 2: Aggregation Framework
MongoDB
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
tdc-globalcode
 
Palestra Java + NoSQL = Iniciativa JNoSQL no TDC Florianópolis
Marcelo Souza Vieira
 
Python Files
Vikram Nandini
 
Latinoware
kchodorow
 
Hands On Spring Data
Eric Bottard
 

Similar to MySQL Without The SQL -- Oh My! PHP Detroit July 2018 (20)

PDF
MySQL without the SQL -- Cascadia PHP
Dave Stokes
 
PDF
MySQL Document Store -- SCaLE 17x Presentation
Dave Stokes
 
PDF
Open Source World June '21 -- JSON Within a Relational Database
Dave Stokes
 
PDF
Json within a relational database
Dave Stokes
 
PDF
MySQL Without the SQL -- Oh My!
Data Con LA
 
PDF
Datacon LA - MySQL without the SQL - Oh my!
Dave Stokes
 
PPTX
Discover The Power of NoSQL + MySQL with MySQL
Dave Stokes
 
PPTX
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
Dave Stokes
 
PDF
MySQL Document Store - when SQL & NoSQL live together... in peace!
Frederic Descamps
 
PPTX
MySQL Without the SQL -- Oh My! Longhorn PHP Conference
Dave Stokes
 
ODP
MySQL Without the MySQL -- Oh My!
Dave Stokes
 
PPTX
Making MySQL Agile-ish
Dave Stokes
 
PDF
Oracle Code Event - MySQL JSON Document Store
Mark Swarbrick
 
PDF
MySQL NoSQL JSON JS Python "Document Store" demo
Keith Hollman
 
PDF
Python and MySQL 8.0 Document Store
Frederic Descamps
 
PPTX
A Step by Step Introduction to the MySQL Document Store
Dave Stokes
 
PDF
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
Dave Stokes
 
PDF
MySQL 5.7 Tutorial Dutch PHP Conference 2015
Dave Stokes
 
PPTX
No sql for sql professionals
Ric Centre
 
PDF
MySQL as a Document Store
Dave Stokes
 
MySQL without the SQL -- Cascadia PHP
Dave Stokes
 
MySQL Document Store -- SCaLE 17x Presentation
Dave Stokes
 
Open Source World June '21 -- JSON Within a Relational Database
Dave Stokes
 
Json within a relational database
Dave Stokes
 
MySQL Without the SQL -- Oh My!
Data Con LA
 
Datacon LA - MySQL without the SQL - Oh my!
Dave Stokes
 
Discover The Power of NoSQL + MySQL with MySQL
Dave Stokes
 
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
Dave Stokes
 
MySQL Document Store - when SQL & NoSQL live together... in peace!
Frederic Descamps
 
MySQL Without the SQL -- Oh My! Longhorn PHP Conference
Dave Stokes
 
MySQL Without the MySQL -- Oh My!
Dave Stokes
 
Making MySQL Agile-ish
Dave Stokes
 
Oracle Code Event - MySQL JSON Document Store
Mark Swarbrick
 
MySQL NoSQL JSON JS Python "Document Store" demo
Keith Hollman
 
Python and MySQL 8.0 Document Store
Frederic Descamps
 
A Step by Step Introduction to the MySQL Document Store
Dave Stokes
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
Dave Stokes
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
Dave Stokes
 
No sql for sql professionals
Ric Centre
 
MySQL as a Document Store
Dave Stokes
 
Ad

More from Dave Stokes (20)

PDF
Database basics for new-ish developers -- All Things Open October 18th 2021
Dave Stokes
 
PDF
Php & my sql - how do pdo, mysq-li, and x devapi do what they do
Dave Stokes
 
PDF
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
Dave Stokes
 
PDF
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
Dave Stokes
 
PDF
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
Dave Stokes
 
PDF
Dutch PHP Conference 2021 - MySQL Indexes and Histograms
Dave Stokes
 
PPTX
Validating JSON -- Percona Live 2021 presentation
Dave Stokes
 
PDF
Midwest PHP Presentation - New MSQL Features
Dave Stokes
 
PDF
Data Love Conference - Window Functions for Database Analytics
Dave Stokes
 
PPTX
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Dave Stokes
 
PPTX
Confoo 2021 -- MySQL New Features
Dave Stokes
 
PPTX
Confoo 2021 - MySQL Indexes & Histograms
Dave Stokes
 
PDF
MySQL Replication Update - DEbconf 2020 presentation
Dave Stokes
 
PDF
MySQL 8.0 Operational Changes
Dave Stokes
 
PPTX
cPanel now supports MySQL 8.0 - My Top Seven Features
Dave Stokes
 
PDF
Confoo 202 - MySQL Group Replication and ReplicaSet
Dave Stokes
 
PPTX
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
Dave Stokes
 
PDF
MySQL New Features -- Sunshine PHP 2020 Presentation
Dave Stokes
 
PPTX
MySQL 8.0 from December London Open Source Database Meetup
Dave Stokes
 
PPTX
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
Dave Stokes
 
Database basics for new-ish developers -- All Things Open October 18th 2021
Dave Stokes
 
Php & my sql - how do pdo, mysq-li, and x devapi do what they do
Dave Stokes
 
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
Dave Stokes
 
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
Dave Stokes
 
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
Dave Stokes
 
Dutch PHP Conference 2021 - MySQL Indexes and Histograms
Dave Stokes
 
Validating JSON -- Percona Live 2021 presentation
Dave Stokes
 
Midwest PHP Presentation - New MSQL Features
Dave Stokes
 
Data Love Conference - Window Functions for Database Analytics
Dave Stokes
 
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Dave Stokes
 
Confoo 2021 -- MySQL New Features
Dave Stokes
 
Confoo 2021 - MySQL Indexes & Histograms
Dave Stokes
 
MySQL Replication Update - DEbconf 2020 presentation
Dave Stokes
 
MySQL 8.0 Operational Changes
Dave Stokes
 
cPanel now supports MySQL 8.0 - My Top Seven Features
Dave Stokes
 
Confoo 202 - MySQL Group Replication and ReplicaSet
Dave Stokes
 
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
Dave Stokes
 
MySQL New Features -- Sunshine PHP 2020 Presentation
Dave Stokes
 
MySQL 8.0 from December London Open Source Database Meetup
Dave Stokes
 
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
Dave Stokes
 
Ad

Recently uploaded (20)

PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 

MySQL Without The SQL -- Oh My! PHP Detroit July 2018

  • 1. MySQLWithout the SQL - Oh My! Dave Stokes @stoker [email protected] Elephantdolphin.blogger.com opensourcedba.wordpress.com
  • 3. Relational Databases ● Data Integrity ○ Normalization ○ constraints (foreign keys, ...) ● Atomicity, Consistency, Isolation, Durability ○ ACID compliant ○ transactions ● SQL ○ powerful query language 3
  • 5. 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 not be modelized optimally into a relational model ○ Objects persistence without the use of any ORM - *mapping object-oriented* ● JSON ● close to frontend ● native in JS ● easy to learn 5
  • 6. How DBAs see data as opposed to 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" } } 6
  • 7. 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 ? With the MySQL Document Store SQL is now optional! 7
  • 8. A Solution for all Developers: ★ schemaless ★ rapid prototyping & simpler APIs ★ document model ★ transactions Operations: ★ performance management/visibility ★ robust replication, backup, restore ★ comprehensive tooling ecosystem ★ simpler application schema upgrades 8 Business Owner: ★ don't lose my data == ACID trx ★ capture all my data = extensible/schemaless ★ product on schedule/time to market = rapid development
  • 9. Built on the MySQL JSON Data type and Proven MySQL Server Technology 9 ★ 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 ★ 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
  • 10. ★ Connectors for ○ C++, Java, .Net, Node.js, Python, PHP ○ working with Communities to help them supporting it too ★ New MySQL Shell ○ Command Completion ○ Python, JavaScripts & 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 10
  • 11. Starting using MySQL in few minutes 11
  • 13. For this example, I will use the well known restaurants collection: We need to dump the data to a file and we will use the MySQL Shell with the Python interpreter to load the data. Migration from MongoDB to MySQL Document Store 13
  • 14. Dump and load using MySQL Shell & Python This example is inspired by @datacharmer's work: https://www.slideshare.net/datacharmer/mysql-documentstore $ mongo quiet eval 'DBQuery.shellBatchSize=30000; db.restaurants.find().shellPrint()' | perl -pe 's/(?:ObjectId|ISODate)(("[^"]+"))/ $1/g' > all_recs.json 14
  • 15. 15
  • 16. 16 Let’s query Too many records to show here … let’s limit it!
  • 18. 18 Let’s add a selection criteria
  • 19. > db .r es ta > db.restaurants.find({"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" } 19 Syntax is slightly different than MongoDB
  • 25. 25 MySQL Document Store Objects Summary
  • 26. MySQL Document Store is Fully ACID Compliant 26
  • 27. MySQL Document Store is Fully ACID Compliant 27
  • 28. What about old SQL? The Hidden Part of the Iceberg 28
  • 29. ★ Native datatype (since 5.7.8) ★ JSON values are stored in MySQL tables using UTF8MB4 ★ Conversion from "native" SQL types to JSON values ★ JSON manipulation functions (JSON_EXTRACT, JSON_KEYS, JSON_SEARCH, JSON_TABLES, ...) ★ Generated/virtual columns ○ Indexing JSON data ○ Foreign Keys to JSON data ○ SQL Views to JSON data JSON datatype is behind the scene 29
  • 30. How Does It Work?? 30
  • 31. What does a collection look like on the server ? 31
  • 32. Every document has a unique identifier called the document ID, which can be thought of as the equivalent of a table´s primary key. The document ID value can be manually assigned when adding a document. If novalue is assigned, a document ID is generated and assigned to the document automatically ! Use getDocumentId() or getDocumentIds() to get _ids(s) _id 32
  • 33. Mapping to SQL Examples createCollection('mycollection') CREATE TABLE `test`.`mycoll` ( doc JSON, _id VARCHAR(32) GENERATED ALWAYS AS (doc->>'$._id') STORED PRIMARY KEY ) CHARSET utf8mb4; mycollection.add({‘test’: 1234}) INSERT INTO `test`.`mycoll` (doc) VALUES ( JSON_OBJECT('_id','663807fe367ee6114e0e5458bdac28bf', 'test',1234)); 33
  • 34. More Mapping to SQL Examples mycollection.find("test > 100") SELECT doc FROM `test`.`mycoll` WHERE (JSON_EXTRACT(doc,'$.test') >100); 34
  • 35. 35 SQL and JSON Example
  • 36. It's also possible to create indexes without using SQL syntax 36
  • 37. SQL and JSON Example (2): validation 37
  • 38. SQL and JSON Example (3): explain 38
  • 39. SQL and JSON Example (3): explain 39
  • 40. SQL and JSON Example (4): add index 40
  • 41. SQL and JSON Example (4): add index 41
  • 42. SQL and JSON Example (5): arrays 42
  • 43. NoSQL as SQL 43 JSON_TABLE turns your un-structured JSON data into a temporary structured table!
  • 44. NoSQL as SQL 44 This temporary structured table can be treated like any other table -- LIMIT, WHERE, GROUP BY ...
  • 46. Find the top 10 restaurants by grade for each cuisine 46 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 restaurants) SELECT *, rank() OVER (PARTITION BY cuisine ORDER BY avg_score) AS `rank` FROM cte1 ORDER by `rank`, avg_score DESC limit 10; This query uses a Common Table Expression (CTE) and a Windowing Function to rank the average scores of each restaurant, by each cuisine
  • 50. Conclusion: What Do I Gain? 50
  • 51. This is the best of the two worlds in one product ! ● Data integrity ● ACID Compliant ● Transactions ● SQL ● Schemaless ● flexible data structure ● easy to start (CRUD) 51