SlideShare a Scribd company logo
Submit Search
Upload
Login
Signup
JSON_TABLE -- The best of both worlds
Report
oysteing
Follow
Apr. 25, 2018
•
0 likes
•
526 views
1
of
11
JSON_TABLE -- The best of both worlds
Apr. 25, 2018
•
0 likes
•
526 views
Download Now
Download to read offline
Report
Data & Analytics
Lightning talk at Percona Live 2018
oysteing
Follow
Recommended
MongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
MongoDB
1.5K views
•
231 slides
How to Win Friends and Influence People (with Hadoop)
Sam Shah
441 views
•
41 slides
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
MongoDB
1.3K views
•
72 slides
PHP Database Programming Basics -- Northeast PHP
Dave Stokes
259 views
•
38 slides
ETL for Pros: Getting Data Into MongoDB
MongoDB
325 views
•
77 slides
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Alex Sharp
991 views
•
128 slides
More Related Content
Similar to JSON_TABLE -- The best of both worlds
More SQL in MySQL 8.0
Norvald Ryeng
991 views
•
28 slides
Data Representation - Day 2
blprnt
591 views
•
37 slides
JSON + Relational – How to Use Hybrid Data Models
DATAVERSITY
495 views
•
44 slides
Java 8 Examples
Scott Taylor
431 views
•
21 slides
Processing & Dataviz
blprnt
1.3K views
•
52 slides
Drupal Mobile
Ruben Teijeiro
1.3K views
•
30 slides
Similar to JSON_TABLE -- The best of both worlds
(14)
More SQL in MySQL 8.0
Norvald Ryeng
•
991 views
Data Representation - Day 2
blprnt
•
591 views
JSON + Relational – How to Use Hybrid Data Models
DATAVERSITY
•
495 views
Java 8 Examples
Scott Taylor
•
431 views
Processing & Dataviz
blprnt
•
1.3K views
Drupal Mobile
Ruben Teijeiro
•
1.3K views
JSON Support in Java EE 8
Dmitry Kornilov
•
1.6K views
jQuery Datatables With MongDb
sliimohara
•
3.3K views
Native json in the Cache' ObjectScript 2016.*
Timur Safin
•
473 views
Ext GWT 3.0 Data Widgets
Sencha
•
1.4K views
UKOUG Tech14 - Getting Started With JSON in the Database
Marco Gralike
•
1.3K views
Oracle Database - JSON and the In-Memory Database
Marco Gralike
•
2.5K views
Tapping the Data Deluge with R
Jeffrey Breen
•
24.7K views
JSON Support in Java EE 8
Dmitry Kornilov
•
33K views
More from oysteing
POLARDB: A database architecture for the cloud
oysteing
663 views
•
27 slides
The MySQL Query Optimizer Explained Through Optimizer Trace
oysteing
924 views
•
55 slides
POLARDB: A database architecture for the cloud
oysteing
549 views
•
18 slides
POLARDB for MySQL - Parallel Query
oysteing
780 views
•
30 slides
Histogram Support in MySQL 8.0
oysteing
834 views
•
36 slides
MySQL Optimizer: What’s New in 8.0
oysteing
282 views
•
67 slides
More from oysteing
(17)
POLARDB: A database architecture for the cloud
oysteing
•
663 views
The MySQL Query Optimizer Explained Through Optimizer Trace
oysteing
•
924 views
POLARDB: A database architecture for the cloud
oysteing
•
549 views
POLARDB for MySQL - Parallel Query
oysteing
•
780 views
Histogram Support in MySQL 8.0
oysteing
•
834 views
MySQL Optimizer: What’s New in 8.0
oysteing
•
282 views
How to Analyze and Tune MySQL Queries for Better Performance
oysteing
•
1.7K views
Common Table Expressions (CTE) & Window Functions in MySQL 8.0
oysteing
•
1.8K views
How to analyze and tune sql queries for better performance
oysteing
•
294 views
Using Optimizer Hints to Improve MySQL Query Performance
oysteing
•
5.5K views
MySQL 8.0: Common Table Expressions
oysteing
•
3.3K views
How to Analyze and Tune MySQL Queries for Better Performance
oysteing
•
1.7K views
MySQL 8.0: Common Table Expressions
oysteing
•
658 views
How to analyze and tune sql queries for better performance vts2016
oysteing
•
559 views
How to Analyze and Tune MySQL Queries for Better Performance
oysteing
•
1.9K views
How to analyze and tune sql queries for better performance percona15
oysteing
•
1.7K views
How to analyze and tune sql queries for better performance webinar
oysteing
•
4.3K views
Recently uploaded
Programming Portfolio Nahari Rasif
NahariRasif
23 views
•
5 slides
Interpreting the brief B2.pptx
Stephen266013
8 views
•
4 slides
Dunning - SIGMOD - Data Economy.pptx
Ted Dunning
13 views
•
21 slides
International Observe the Moon Night 2023
VICTOR MAESTRE RAMIREZ
16 views
•
1 slide
BLOCK CHAIN TECHNOLOGY.pptx
Priyanka749523
18 views
•
11 slides
Quantum Karnaugh map in NV-center Quantum Computer
ssuserb645ae
16 views
•
17 slides
Recently uploaded
(20)
Programming Portfolio Nahari Rasif
NahariRasif
•
23 views
Interpreting the brief B2.pptx
Stephen266013
•
8 views
Dunning - SIGMOD - Data Economy.pptx
Ted Dunning
•
13 views
International Observe the Moon Night 2023
VICTOR MAESTRE RAMIREZ
•
16 views
BLOCK CHAIN TECHNOLOGY.pptx
Priyanka749523
•
18 views
Quantum Karnaugh map in NV-center Quantum Computer
ssuserb645ae
•
16 views
criteria of a good research design.pdf
MuthuLakshmi124949
•
39 views
Prescriber's Guide: Stahl's Essential Psychopharmacology
DoloresLPerez
•
5 views
G20.pptx
vazid ali khan
•
24 views
Data processing.pdf
MuthuLakshmi124949
•
58 views
CASL compliance.pptx
papalipadhihari
•
19 views
Random Forests without the Randomness Sept_2023.pptx
KirkMonteverde1
•
7 views
Building and deploying LLM applications with Apache Airflow
Kaxil Naik
•
14 views
Your Analytics does not have to be dramatic to be useful
Andrew Patricio
•
31 views
research report.pdf
MuthuLakshmi124949
•
49 views
Data collection.pdf
MuthuLakshmi124949
•
48 views
Essential numpy before you start your Machine Learning journey in python.pdf
Smrati Kumar Katiyar
•
11 views
Wellbeing of Wales 2023
Statistics for Wales @ Welsh Government
•
62 views
Proposal Presentation
SolarBhai
•
18 views
Data Warehouse with Fabric on data lakehouse
Marco Pozzan
•
69 views
JSON_TABLE -- The best of both worlds
1.
Copyright © 2018,
Oracle and/or its affiliates. All rights reserved. | JSON_TABLE Øystein Grøvlen Optimizer Geek Oracle April 24, 2018 The Best of Both Worlds
2.
Copyright © 2018,
Oracle and/or its affiliates. All rights reserved. | JSON Data Type CREATE TABLE t1(json_col JSON); INSERT INTO t1 VALUES ( '{ "people": [ { "name":"John Smith", "address":"780 Mission St, San Francisco, CA 94103"}, { "name":"Sally Brown", "address":"75 37th Ave S, St Cloud, MN 94103"}, { "name":"John Johnson", "address":"1262 Roosevelt Trail, Raymond, ME 04071"} ] }' ); 2
3.
Copyright © 2018,
Oracle and/or its affiliates. All rights reserved. | JSON_TABLE SELECT people.* FROM t1, JSON_TABLE(json_col, '$.people[*]' COLUMNS ( name VARCHAR(40) PATH '$.name', address VARCHAR(100) PATH '$.address')) people; 3 Convert JSON documents to relational tables name address John Smith 780 Mission St, San Francisco, CA 94103 Sally Brown 75 37th Ave S, St Cloud, MN 9410 John Johnson 1262 Roosevelt Trail, Raymond, ME 04071
4.
Copyright © 2018,
Oracle and/or its affiliates. All rights reserved. | JSON_TABLE SELECT people.* FROM t1, JSON_TABLE(json_col, '$.people[*]' COLUMNS ( name VARCHAR(40) PATH '$.name', address VARCHAR(100) PATH '$.address')) people; WHERE people.name LIKE 'John%'; 4 Filter JSON data name address John Smith 780 Mission St, San Francisco, CA 94103 John Johnson 1262 Roosevelt Trail, Raymond, ME 04071
5.
Copyright © 2018,
Oracle and/or its affiliates. All rights reserved. | Construct a New JSON Document SELECT JSON_OBJECT("people", JSON_ARRAYAGG(JSON_OBJECT("name", name, "address", address))) json_doc FROM t1, JSON_TABLE(json_col, '$.people[*]' COLUMNS ( name VARCHAR(40) PATH '$.name', address VARCHAR(100) PATH '$.address')) people; WHERE people.name LIKE 'John%'; 5 json_doc {"people": [{"name": "John Smith", "address": "780 Mission St, San Francisco, CA 94103"}, {"name": "John Johnson", "address": "1262 Roosevelt Trail, Raymond, ME 04071"}]}
6.
Copyright © 2018,
Oracle and/or its affiliates. All rights reserved. | 6 JSON_TABLE id father married child_id child age 1 John 1 1 Eric 12 1 John 1 2 Beth 10 2 Paul 0 1 Sarah 9 2 Paul 0 2 Noah 3 2 Paul 0 3 Peter 1 [ { "father":"John", "mother":"Mary", "marriage_date":"2003-12-05", "children": [ { "name":"Eric", "age":12 }, { "name":"Beth", "age":10 } ] }, { "father":"Paul", "mother":"Laura", "children": [ { "name":"Sarah", "age":9}, { "name":"Noah", "age":3} , { "name":"Peter", "age":1} ] } ] Nested arrays
7.
Copyright © 2018,
Oracle and/or its affiliates. All rights reserved. | 7 JSON_TABLE – Nested Arrays id father married child_id child age 1 John 1 1 Eric 12 1 John 1 2 Beth 10 2 Paul 0 1 Sarah 9 2 Paul 0 2 Noah 3 2 Paul 0 3 Peter 1 JSON_TABLE (families, '$[*]' COLUMNS ( id FOR ORDINALITY, father VARCHAR(30) PATH '$.father', married INTEGER EXISTS PATH '$.marriage_date', NESTED PATH '$.children[*]' COLUMNS ( child_id FOR ORDINALITY, child VARCHAR(30) PATH '$.name', age INTEGER PATH '$.age') ) )
8.
Copyright © 2018,
Oracle and/or its affiliates. All rights reserved. | JSON_TABLE SELECT father, COUNT(*) "#children", AVG(age) "age average" FROM t, JSON_TABLE (families, '$[*]' COLUMNS ( id FOR ORDINALITY, father VARCHAR(30) PATH '$.father', NESTED PATH '$.children[*]' COLUMNS (age INTEGER PATH '$.age' ) ) ) AS fam GROUP BY id, father; 8 SQL aggregation on JSON data father #children age average John 2 11.0000 Paul 3 4.3333
9.
Copyright © 2018,
Oracle and/or its affiliates. All rights reserved. | Put Computed Data Back Into JSON Document SELECT JSON_ARRAYAGG(fam_obj) families FROM ( SELECT JSON_MERGE_PATCH(family, JSON_OBJECT("#children", COUNT(*), "avg_age" , AVG(age))) fam_obj FROM t, JSON_TABLE (families, '$[*]' COLUMNS ( id FOR ORDINALITY, family JSON PATH '$', NESTED PATH '$.children[*]' COLUMNS (age INTEGER PATH '$.age' ) ) ) fam GROUP BY id, family) fams; 9
10.
Copyright © 2018,
Oracle and/or its affiliates. All rights reserved. | Modify JSON Objects SELECT JSON_ARRAYAGG(JSON_MERGE_PATCH(JSON_OBJECT("id", id), family)) AS families FROM t, JSON_TABLE (families, '$[*]' COLUMNS ( id FOR ORDINALITY, family JSON PATH '$')) fam; 10 Put IDs in objects families [{"id": 1, "father": "John", "mother": "Mary", "children": [{"age": 12, "name": "Eric"}, {"age": 10, "name": "Beth"}], "marriage_date": "2003-12-05"}, {"id": 2, "father": "Paul", "mother": "Laura", "children": [{"age": 9, "name": "Sarah"}, {"age": 3, "name": "Noah"}, {"age": 1, "name": "Peter"}]}]
11.
Copyright © 2018,
Oracle and/or its affiliates. All rights reserved. | Want to Learn More About New and Upcoming SQL Features? • MySQL 8.0: What is New in Optimizer and Executor? – Manyi Lu – Tuesday 4:50PM-5:15PM; Room GS • Running JavaScript Stored-Programs Inside MySQL Server – Øystein Grøvlen, Vojin Jovanovic, Farhan Tauheed – Wednesday 11:00AM-11:50AM; Room GS 11 Presentations at Percona Live