NoSQL + SQL = MySQL. Nicolas De Rico Principal Solutions Architect

Similar documents
Modern Development With MySQL

MySQL JSON. Morgan Tocker MySQL Product Manager. Copyright 2015 Oracle and/or its affiliates. All rights reserved.

NoSQL and SQL: The Best of Both Worlds

Combining SQL and NoSQL with MySQL

Using the MySQL Document Store

3 / 120. MySQL 8.0. Frédéric Descamps - MySQL Community Manager - Oracle

MySQL Next An overview of the MySQL 8 Beta

Introduction to the MySQL Document Store Alfredo Kojima, Rui Quelhas, Mike Zinner MySQL Middleware and Clients Team October 22, 2018

MySQL Document Store. How to replace a NoSQL database by MySQL without effort but with a lot of gains?

MySQL as a Document Store. Ted Wennmark

MySQL 5.7: What s New in the Optimizer?

MySQL High available by design

State of the Dolphin Developing new Apps in MySQL 8

Part 1: IoT demo Part 2: MySQL, JSON and Flexible storage

NoSQL + SQL = MySQL Get the Best of Both Worlds

Practical JSON in MySQL 5.7 and Beyond

What's New in MySQL 5.7?

Safe Harbor Statement

MARIADB & JSON: FLEXIBLE DATA MODELING

MySQL 5.7 News. Abel Flórez Technical Account Manager Copyright 2016 Oracle and/or its affiliates. All rights reserved.

Safe Harbor Statement

Flexible Data Modeling in MariaDB

MySQL InnoDB Cluster. MySQL HA Made Easy! Miguel Araújo Senior Software Developer MySQL Middleware and Clients. FOSDEM 18 - February 04, 2018

Introduction to MySQL InnoDB Cluster

What Is New in Optmizer and Executor?

Upgrading to MySQL 8.0+: a More Automated Upgrade Experience. Dmitry Lenev, Software Developer Oracle/MySQL, November 2018

MySQL & NoSQL: The Best of Both Worlds

MySQL Cluster Web Scalability, % Availability. Andrew

How to Use JSON in MySQL Wrong

Develop Python Applications with MySQL Connector/Python DEV5957

MariaDB 10.3 vs MySQL 8.0. Tyler Duzan, Product Manager Percona

MySQL Group Replication. Bogdan Kecman MySQL Principal Technical Engineer

#MySQL #oow16. MySQL Server 8.0. Geir Høydalsvik

More SQL in MySQL 8.0

<Insert Picture Here> MySQL Cluster What are we working on

MySQL vs MariaDB. Where are we now?

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

MySQL InnoDB Cluster. New Feature in MySQL >= Sergej Kurakin

ALTER TABLE Improvements in MARIADB Server. Marko Mäkelä Lead Developer InnoDB MariaDB Corporation

Everything You Need to Know About MySQL Group Replication

Oral Questions and Answers (DBMS LAB) Questions & Answers- DBMS

<Insert Picture Here> Upcoming Changes in MySQL 5.7 Morgan Tocker, MySQL Community Manager

What is MariaDB 5.5? w: e: Daniel Bartholomew Oct 2012

MySQL Group Replication in a nutshell

MySQL Cluster An Introduction

Building Highly Available and Scalable Real- Time Services with MySQL Cluster

MySQL HA Solutions Selecting the best approach to protect access to your data

MySQL High Availability. Michael Messina Senior Managing Consultant, Rolta-AdvizeX /

MySQL 8.0 What s New in the Optimizer

MySQL 8.0: Atomic DDLs Implementation and Impact

Instant ALTER TABLE in MariaDB Marko Mäkelä Lead Developer InnoDB

MySQL High Availability

Creating and Working with JSON in Oracle Database

What s New in MySQL and MongoDB Ecosystem Year 2017

InnoDB: What s new in 8.0

Copyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12

What s New in MySQL 5.7 Geir Høydalsvik, Sr. Director, MySQL Engineering. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Chapter 8: Working With Databases & Tables

Deep Dive on MySQL Databases on Amazon RDS. Chayan Biswas Sr. Product Manager Amazon RDS

Oracle Database 18c and Autonomous Database

Continuous delivery of Java applications. Marek Kratky Principal Sales Consultant Oracle Cloud Platform. May, 2016

Mix n Match Async and Group Replication for Advanced Replication Setups. Pedro Gomes Software Engineer

Safe Harbor Statement

MongoDB w/ Some Node.JS Sprinkles

Drupal 7 Sql Schema Api Datetime

Percona Server for MySQL 8.0 Walkthrough

MySQL for Developers. Duration: 5 Days

RethinkDB. Niharika Vithala, Deepan Sekar, Aidan Pace, and Chang Xu

Javaentwicklung in der Oracle Cloud

Module 9: Managing Schema Objects

Survey of the Azure Data Landscape. Ike Ellis

MySQL for Developers. Duration: 5 Days

Jargons, Concepts, Scope and Systems. Key Value Stores, Document Stores, Extensible Record Stores. Overview of different scalable relational systems

replic8 The Eighth Generation of MySQL Replication Sven Sandberg MySQL Replication Core Team Lead

Open source, high performance database. July 2012

Analyzing a social network using Big Data Spatial and Graph Property Graph

Welcome to Virtual Developer Day MySQL!

Microsoft vision for a new era

Oracle APEX 18.1 New Features

Document Object Storage with MongoDB

whoami MySQL MongoDB 100% open source PostgreSQL To champion unbiased open source database solutions

How Well Do Relational Database Engines Support

Jailbreaking MySQL Replication Featuring Tungsten Replicator. Robert Hodges, CEO, Continuent

Consolidate and Prepare for Cloud Efficiencies Oracle Database 12c Oracle Multitenant Option

Paul Bird June 2018 Db2 = JSON + SQL

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved.

MySQL High Availability Solutions. Alex Poritskiy Percona

High Availability Using MySQL Group Replication

PostgreSQL. JSON Roadmap. Oleg Bartunov Postgres Professional. March 17, 2017, Moscow

Oracle GoldenGate and Oracle Streams: The Future of Oracle Replication and Data Integration

OKC MySQL Users Group

Oracle MySQL Free vs. commercial

Brad Dayley. Sams Teach Yourself. NoSQL with MongoDB. SAMS 800 East 96th Street, Indianapolis, Indiana, USA

Do-It-Yourself 1. Oracle Big Data Appliance 2X Faster than

Mysql Insert Manual Timestamp Into Datetime Field

Kim Greene - Introduction

The Hazards of Multi-writing in a Dual-Master Setup

Compare Two Identical Tables Data In Different Oracle Databases

From the Beginning: Your First Node.js Web Service

Optional SQL Feature Summary

Transcription:

NoSQL + SQL = MySQL Nicolas De Rico Principal Solutions Architect nicolas.de.rico@oracle.com

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.

What If I Told You?? NoSQL + SQL?? is possible?

MySQL 8.0 The MySQL Document Store

MySQL 8.0 MySQL 5.0 MySQL 5.1 MySQL 5.5 MySQL 5.6 MySQL 5.7 MySQL 8.0 MySQL AB Sun Microsystems Improved Windows OS Performance Schema Semi-sync repl Robust replication Stricter SQL Stronger security Native JSON Cost-based optimizer Group Replication Document Store Data dictionary OLAP NDB Cluster 6.2, 6.3, 7.0, 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.6

MySQL Open Source ( Because It Makes Sense) GPLv2 Slightly modified for FOSS and OpenSSL No extraneously restrictive licensing MySQL source code available on Github MySQL Receives many contributions from community and partners Development collaboration with some leading MySQL users Open Core business model Additional tools and extensions available in Enterprise Edition Server and client are GPL open source This also helps to keep the ecosystem open source

New! Alter Table - Instant Add Column Contribution from Tencent Only a metadata change No copying of data Smaller final data size Forward compatibility with old data file ALTER TABLE ADD COLUMN col, ALGORITHM = INSTANT; Supports DYNAMIC/COMPACT/REDUNDANT row formats Tencent Contribution

MySQL Document Store NoSQL JSON Cluster MySQL Document Store

Native JSON Data Type CREATE TABLE employees (data JSON); INSERT INTO employees VALUES ('{"id": 1, "name": "Jane"}'); INSERT INTO employees VALUES ('{"id": 2, "name": "Joe"}'); SELECT * FROM employees; +---------------------------+ data +---------------------------+ {"id": 1, "name": "Jane"} {"id": 2, "name": "Joe"} +---------------------------+ 2 rows in set (0,00 sec)

JSON Data Type Specifications utf8mb4 default character set Optimized for read intensive workload Parse and validation on insert only Dictionary: Sorted objects' keys Fast access to array cells by index Full type range supported: Standard: numbers, string, bool, objects, arrays Extended: date, time, timestamp, datetime, others JSON Objects and Arrays, including embedded within each other

JSON Functions JSON_ARRAY_APPEND() JSON_ARRAY_INSERT() JSON_ARRAY() JSON_CONTAINS_PATH() JSON_CONTAINS() JSON_DEPTH() JSON_EXTRACT() JSON_INSERT() JSON_KEYS() JSON_LENGTH() JSON_MERGE() JSON_OBJECT() JSON_QUOTE() JSON_REMOVE() JSON_REPLACE() JSON_SEARCH() JSON_SET() JSON_TYPE() JSON_UNQUOTE() JSON_VALID() MySQL 8.0: JSON_TABLE() JSON_PRETTY() JSON_STORAGE_SIZE() JSON_STORAGE_FREE() JSON_ARRAYAGG() JSON_OBJECTAGG()

Shortcut Syntax mysql> SELECT DISTINCT data-> $.zoning AS Zoning FROM lots; +--------------+ Zoning +--------------+ "Commercial" +--------------+ 1 row in set (1.22 sec) Special new syntax to access data inside JSON documents

Shortcut Syntax + Unquote mysql> SELECT DISTINCT data->> $.zoning AS Zoning FROM lots; +------------+ Zoning +------------+ Commercial +------------+ 1 row in set (1.22 sec) Special new syntax to access data inside JSON documents + UNQUOTE

Indexing JSON Documents With Generated Columns Available as either VIRTUAL (default) or STORED: ALTER TABLE features ADD feature_type varchar(30) AS (feature->>"$.type") VIRTUAL; Both types of computed columns permit for indexes to be added as functional indexes Use ALTER TABLE ADD INDEX(generated_column) Use virtual generated columns to index JSON fields!

MySQL InnoDB Cluster Group-based replication Group awareness Conflict detection Consensus 50% + 1 Multi-primary mode Single primary mode MySQL Router Automated failover Tooling for controlling cluster High Availability becomes a core first class feature of MySQL!

MySQL Has Native NoSQL X Protocol Classic MySQL Protocol JavaScript / Python X DevAPI MySQL Shell 33060 X Plugin 3306 MySQL Connection handling MySQL Connector/ODBC Existing Application MySQL C / Node.js X DevAPI Node.js Application MySQL Connector/Net X DevAPI Windows Application SQL Result Optimizer GraalVM Storage Javascript Python Ruby R... MySQL Server

Node.JS Example Native MySQL Programming var schema = session.getschema('myschema'); var collection = schema.getcollection('mycoll'); var query = "$.name == :name"; collection.find(query).bind('name','alfredo').execute(function (doc) { console.log(doc); }).catch(function (err) { console.log(err.message); console.log(err.stack); });

Tables or Collections? A collection is a table with 2+ columns: Primary key: `_id` JSON document: `doc` The document s `_id` field can be supplied or be automatically generated by server as UUID This field is also used to populate the primary key Can add extra columns and indexes to a collection SQL, NoSQL, tables, collections, all can be used simultaneously Operations compatible with replication

NoSQL + SQL Demo

NoSQL The demo uses MySQL Shell, which is part of the MySQL 8 distribution Create a collection in Javascript View what is a collection in MySQL? Insert JSON documents With and without _id Find JSON documents Update JSON documents Confirm the changes Use SQL commands on JSON documents

Creating A Collection Show the current database JS> db Change the current database JS> \use demo JS> db Create a new collection JS> var Collection=db.createCollection("architects") JS> Collection JS> \sql SQL> SHOW CREATE TABLE `architects`;

Accessing An Existing Collection Opening a collection JS> var Collection=db.getCollection("architects") JS> Collection

The help() Function General help JS> Collection.help() In-depth help JS> Collection.help("add")

Inserting Documents Into The Collection The missing _id field is automatically generated. JS> Collection.add({"name": "nicolas"}) JS> Collection.add({"name": "sastry"}) JS> Collection.add({"name": "dale"}) JS> Collection.add({"name": "michael"}) JS> Collection.add({"name": "kathy"}) JS> Collection.add({"name": "lee", "title": "manager"}) JS> Collection.add({"name": "benjamin"},{"name": "priscila"}) JS> \sql SQL> SELECT * FROM `demo`.` architects`;

Inserting Documents Into The Collection (cont d) The existing _id field is used. JS> Collection.add({"_id": "xoxoxoxo", "name": "tony"}) JS> \sql SQL> SELECT * FROM `demo`.` architects`;

Retrieving Documents All documents JS> Collection.find() With a condition JS> Collection.find("name='Nicolas'") With a bound variable JS> var Value = "nicolas" JS> Collection.find("name=:nm").bind("nm",Value).execute() A single document JS> var Document=Collection.getOne("xoxoxoxo") JS> Document

Modifying A Document Add a field JS> Collection.modify("_id='xoxoxoxo'").set("weight",150).execute() Transform the field into an object JS> Collection.modify("_id='xoxoxoxo'").set("dimmensions",{weight:150}).execute() JS> Collection.modify("_id='xoxoxoxo'").unset("weight").execute() The document already retrieved doesn t change JS> Document

Deleting A Document The remove() function JS> Collection.help("remove") JS> Collection.remove("_id='xoxoxoxo'")

Creating An Index NoSQL JS> Collection.createIndex("nosql_index",{"fields":[{"field":"$.name","type":"TEXT(20)"}],"type":"INDEX"}) JS> \sql SQL> SHOW CREATE TABLE `architects`; SQL SQL> ALTER TABLE `architects` ADD COLUMN `name` TEXT GENERATED ALWAYS AS (JSON_UNQUOTE(JSON_EXTRACT(`doc`,_utf8mb4'$.name ))) VIRTUAL; SQL> ALTER TABLE `architects` ADD INDEX `sql_index`(`name`(20));

Verifying Index Is Used The explain command SQL> EXPLAIN SELECT * FROM `architects`; SQL> EXPLAIN SELECT * FROM `architects` WHERE `doc`->>'$.name' = 'nicolas ;

Bulk Importing Documents Create collection (optional) JS> var Restaurants = db.createcollection("restaurants") Import documents JS> utils.help("importjson") JS> util.importjson("restaurants",{collection : "restaurants", convertbsonoid : true}) Search for documents JS> Restaurants.find() JS> Restaurants.find("name='Europa Cafe'") JS> Restaurants.find("name='Europa Cafe' and address.street = 'Lexington Avenue'")

Mixing SQL And JSON

Exercise We are going to use the "restaurants" collection in SQL to find great restaurants near Times Square in New York City. The collection has geographical locations that we can index to limit the search of the scope to 0.5 miles around Times Square. We can also index the cuisine types for each restaurant so that we can choose based on our mood. The restaurants collection is a standard example collection from MongoDB (thanks Mongo!).

Adding Indexes To The Collection Create a Spatial index (can also be done in NoSQL) SQL> ALTER TABLE `demo`.`restaurants` ADD COLUMN `location` GEOMETRY GENERATED ALWAYS AS (POINT(`doc`->>'$.address.coord[0]',`doc`->>'$.address.coord[1]')) STORED NOT NULL SRID 0; SQL> ALTER TABLE `demo`.`restaurants` ADD SPATIAL INDEX(`location`); Create a full-text search index SQL> ALTER TABLE `demo`.`restaurants` ADD COLUMN `Cuisine` TEXT GENERATED ALWAYS AS (`doc`->>'$.cuisine') STORED; SQL> ALTER TABLE `demo`.`restaurants` ADD FULLTEXT INDEX(`Cuisine`);

Best Italian And Chinese Restaurants Near Times Square WITH `CTE` AS (SELECT `doc`->>'$.name' AS `Restaurant`, `Cuisine`, (SELECT AVG(`Grades`.`Score`) AS `Score` FROM JSON_TABLE(`doc`,'$.grades[*]' COLUMNS (`Score` INT PATH '$.score')) AS `Grades`) AS `Average`, ST_Distance_Sphere(`location`,@TimesSq) AS `Distance` FROM `demo`.`restaurants` WHERE ST_Contains(ST_MakeEnvelope(POINT(ST_X(@TimesSq) + @Dist,ST_Y(@TimesSq) + @Dist), POINT(ST_X(@TimesSq) - @Dist,ST_Y(@TimesSq) - @Dist)), `location`) AND MATCH(`Cuisine`) AGAINST('Italian Chinese' IN BOOLEAN MODE) ORDER BY `Distance`)...

Best Italian And Chinese Restaurants Near Times Square SELECT `Restaurant`, `Cuisine`, RANK() OVER (PARTITION BY `Cuisine` ORDER BY `Average`) AS `Rank`, `Distance` FROM `CTE` ORDER BY `Rank`, `Average` DESC LIMIT 10;

Thank You!