SlideShare a Scribd company logo
1 of 25
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
JSON Support
in MySQL 5.7
Georgi “Joro” Kodinov
Team lead, MySQL server general team
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Agenda
2
 The new JSON data type
 Inlined JSON path expressions
 The new JSON functions
 Indexing JSON data
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
CREATE TABLE employees (data JSON);
INSERT INTO employees VALUES
('{"id": 1, "name": "Jane"}'),
('{"id": 2, "name": "Joe"}');
SELECT * FROM employees;
+-------------------------------------+
| data |
+-------------------------------------+
| {"id": 1, "name": "Jane"} |
| {"id": 2, "name": "Joe"} |
+-------------------------------------+
• Validation on INSERT
• No reparsing on SELECT
• Dictionary of fields
• Fields are sorted
• Can compare JSON/SQL
• Can convert JSON/SQL
• Supports all native JSON
datatypes
• Also supports date, time,
timestamp etc.
3
The New JSON Datatype
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
JSON vs TEXT columns
Pros Cons
JSON
• Validate once
• Fast access
• Can update in-place
• Slower to insert
• Unreadable as is
• Sets certain limitations on JSON
TEXT
• Fast to insert
• Human readable
• Requires manual validation
• Requires manual parsing
• Harder to update
4
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Beware: SQL vs JSON comparisons !
5
SQL JSON
create table t1 (data json); create table t2 (
id integer,
data varchar(20));
insert into t1 values
('{ "id": 1, "data": "1" }'),
('{ "id": 2, "data": "3" }');
insert into t2 values
(1, '1'),
(2, '3');
select count(*) from t1 where
data->'$.id' = data->'$.data';
select count(*) from t2 where
id = data;
0 rows ! 1 row !
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Agenda
6
 The new JSON data type
 Inlined JSON path expressions
 The new JSON functions
 Indexing JSON data
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Inlined JSON Path Expressions
• <field>->'<JSON path expression>'
e.g. data->'$.some.key[3].from.doc'
• Syntax sugar over JSON_EXTRACT function
• SELECT * FROM employees WHERE data->'$.id'= 2;
• ALTER … ADD COLUMN id INT AS (data->'$.id') …
• CREATE VIEW .. AS SELECT data->'$.id', data->'$.name' FROM …
• UPDATE employees SET data->'$.name'=‘John' WHERE …
Not
yet!
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Limitations of Inlined JSON Path Expressions
Inlined JSON path JSON_EXTRACT()
Data source Field Any JSON value
Path expression SQL Constant SQL Expression
# of expressions One Multiple
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Supported JSON Paths
[[[database.]table.]column]$<path spec>
Expression Example
[ [ [database.] table.] field]$ db.phonebook.data$
$ Current document’s root
$.identifier $.user.address.street
[array] $.user.addresses[2].street
.* and [*] $.user.addresses[*].street
** $.user**.phone
Not yet!
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Agenda
10
 The new JSON data type
 Inlined JSON path expressions
 The new JSON functions
 Indexing JSON data
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
New functions to handle JSON data
Example Result
SELECT JSON_VALID('{ "a":1 }'); 1
SELECT JSON_TYPE('[ 1, 2, 3 ]'); ARRAY
SELECT JSON_KEYS('{ "a":1, "b": 2 }'); ["a", "b"]
SELECT JSON_LENGTH('[ 1, 2, 3 ]'); 3
SELECT JSON_DEPTH('{ "a":{ "c": 1 }, "b": 2 }'); 3
11
Information
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
New functions to handle JSON data
Example Result
SELECT JSON_REMOVE('{ "a":1, "b": 2 }', '$.a'); {"b": 2}
SELECT JSON_ARRAY_APPEND('[1,[2,3],4]', '$[1]', 5); [1, [2, 3, 5], 4]
SELECT JSON_SET('{ "a":1 }', '$.c', 3); {"a": 1, “c": 3}
SELECT JSON_INSERT('{ "a":1 }', '$.b', 4); {"a": 1, "b": 4}
SELECT JSON_REPLACE('{ "a":1, "b": 2 }', '$.b', 3); {"a": 1, "b": 3}
SELECT JSON_MERGE('{ "a": 1 }', '{"b":2}'); {"a": 1, "b": 2}
SELECT JSON_UNQUOTE('"abc"'); abc
12
Modification
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
New functions to handle JSON data
Example Result
SELECT JSON_ARRAY(1, '2', null, true); [1, "2", null, true]
SELECT JSON_OBJECT(1, 2, '3', true); {"1": 2, "3": true}
SELECT JSON_QUOTE('"null"'); ""null""
13
Create JSON objects
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
New functions to handle JSON data
Example Result
SELECT JSON_CONTAINS_PATH(
'{ "a":{ "c": 1 }, "b": 2 }', 'one', '$.a.c');
1
SELECT JSON_CONTAINS( '{"a": 1, "b": "2" }', '1', '$.a'); 1
SELECT JSON_EXTRACT('{"a": 1, "n": { "b": 2}}', '$.n'); {"b": 2}
SELECT JSON_SEARCH( '{"a": "1", "b": "2" }', 'one', 2); "$.b"
14
Search in JSON data
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
New functions to handle JSON data
15
Further reading: http://dev.mysql.com/doc/refman/5.7/en/
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Agenda
16
 The new JSON data type
 Inlined JSON path expressions
 The new JSON functions
 Indexing JSON data
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Indexing JSON Data
• Use Functional Indexes
– Both STORED and VIRTUAL types are supported
• Examples:
– CREATE TABLE t1 (
data JSON,
id INTEGER AS (JSON_EXTRACT(data,"$.id")) STORED,
PRIMARY KEY(id));
– CREATE TABLE t2 (
data JSON,
id INTEGER AS (JSON_EXTRACT(data,"$.id")) VIRTUAL,
KEY(id));
17
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Indexing JSON: STORED vs VIRTUAL columns
Pros Cons
STORED
• Can be primary key too
• All index types supported
• Looks like a normal field
• Slow ALTER TABLE
• Takes space on disk
VIRTUAL
• Instant ALTER TABLE
• Faster INSERT
• Looks like a normal field
• Secondary key only
• BTREE index only
18
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
How do you tell if an JSON index is used ?
> EXPLAIN SELECT data FROM t1 WHERE JSON_EXTRACT(data,"$.series")
BETWEEN 3 AND 5;
+----+----------------+--------+---------------+--------+…+------------------------------+
| id | select_type | table | partitions | type | | Extra |
+----+----------------+--------+---------------+--------+…+------------------------------+
| 1 | SIMPLE | t1 | NULL | range | | Using index condition |
+----+----------------+--------+---------------+--------+…+------------------------------+
19
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Or this way ….
20
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Or maybe this way ?
21
ALTER TABLE features ADD feature_type VARCHAR(30) AS (feature->"$.type") VIRTUAL;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
ALTER TABLE features ADD INDEX (feature_type);
Query OK, 0 rows affected (0.73 sec)
Records: 0 Duplicates: 0 Warnings: 0
SELECT DISTINCT feature_type FROM features;
+-------------------+
| feature_type |
+-------------------+
| "Feature" |
+-------------------+
1 row in set (0.06 sec)
From table scan on 206K documents to index scan on 206K materialized values
Down from 1.25s !
Meta data change only (FAST).
Does not need to touch table.
Online CREATE INDEX !
No rows were
modified.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Roadmap
• Online alter for virtual columns
• Advanced JSON functions
• In-place update of JSON/BLOB
• Full text and GIS index on virtual columns
• Improved performance through condition pushdown
22
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Questions ?
@gkodinov, georgi.kodinov@oracle.com if you forget !
23
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Safe Harbor Statement
The preceding 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.
24
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 25

More Related Content

What's hot

Diving into MySQL 5.7: advanced features
Diving into MySQL 5.7: advanced featuresDiving into MySQL 5.7: advanced features
Diving into MySQL 5.7: advanced featuresGabriela Ferrara
 
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...DataStax
 
The Ring programming language version 1.7 book - Part 31 of 196
The Ring programming language version 1.7 book - Part 31 of 196The Ring programming language version 1.7 book - Part 31 of 196
The Ring programming language version 1.7 book - Part 31 of 196Mahmoud Samir Fayed
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Scott Leberknight
 
Next Top Data Model by Ian Plosker
Next Top Data Model by Ian PloskerNext Top Data Model by Ian Plosker
Next Top Data Model by Ian PloskerSyncConf
 
The Ring programming language version 1.10 book - Part 36 of 212
The Ring programming language version 1.10 book - Part 36 of 212The Ring programming language version 1.10 book - Part 36 of 212
The Ring programming language version 1.10 book - Part 36 of 212Mahmoud Samir Fayed
 
Validating JSON -- Percona Live 2021 presentation
Validating JSON -- Percona Live 2021 presentationValidating JSON -- Percona Live 2021 presentation
Validating JSON -- Percona Live 2021 presentationDave Stokes
 
Discover the Power of the NoSQL + SQL with MySQL
Discover the Power of the NoSQL + SQL with MySQLDiscover the Power of the NoSQL + SQL with MySQL
Discover the Power of the NoSQL + SQL with MySQLDave Stokes
 
The Ring programming language version 1.5.1 book - Part 26 of 180
The Ring programming language version 1.5.1 book - Part 26 of 180The Ring programming language version 1.5.1 book - Part 26 of 180
The Ring programming language version 1.5.1 book - Part 26 of 180Mahmoud Samir Fayed
 
Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my! Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my! Dave Stokes
 
Data Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database AnalyticsData Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database AnalyticsDave Stokes
 
SunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLSunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLGabriela Ferrara
 
Json within a relational database
Json within a relational databaseJson within a relational database
Json within a relational databaseDave Stokes
 
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...Dave Stokes
 
Scaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersScaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersJonathan Levin
 

What's hot (20)

Cassandra 3.0
Cassandra 3.0Cassandra 3.0
Cassandra 3.0
 
Diving into MySQL 5.7: advanced features
Diving into MySQL 5.7: advanced featuresDiving into MySQL 5.7: advanced features
Diving into MySQL 5.7: advanced features
 
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
 
Cassandra 2.2 & 3.0
Cassandra 2.2 & 3.0Cassandra 2.2 & 3.0
Cassandra 2.2 & 3.0
 
ROracle
ROracle ROracle
ROracle
 
The Ring programming language version 1.7 book - Part 31 of 196
The Ring programming language version 1.7 book - Part 31 of 196The Ring programming language version 1.7 book - Part 31 of 196
The Ring programming language version 1.7 book - Part 31 of 196
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0
 
Next Top Data Model by Ian Plosker
Next Top Data Model by Ian PloskerNext Top Data Model by Ian Plosker
Next Top Data Model by Ian Plosker
 
The Ring programming language version 1.10 book - Part 36 of 212
The Ring programming language version 1.10 book - Part 36 of 212The Ring programming language version 1.10 book - Part 36 of 212
The Ring programming language version 1.10 book - Part 36 of 212
 
Validating JSON -- Percona Live 2021 presentation
Validating JSON -- Percona Live 2021 presentationValidating JSON -- Percona Live 2021 presentation
Validating JSON -- Percona Live 2021 presentation
 
Discover the Power of the NoSQL + SQL with MySQL
Discover the Power of the NoSQL + SQL with MySQLDiscover the Power of the NoSQL + SQL with MySQL
Discover the Power of the NoSQL + SQL with MySQL
 
The Ring programming language version 1.5.1 book - Part 26 of 180
The Ring programming language version 1.5.1 book - Part 26 of 180The Ring programming language version 1.5.1 book - Part 26 of 180
The Ring programming language version 1.5.1 book - Part 26 of 180
 
Polyglot Persistence
Polyglot PersistencePolyglot Persistence
Polyglot Persistence
 
Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my! Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my!
 
Data Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database AnalyticsData Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database Analytics
 
My sql1
My sql1My sql1
My sql1
 
SunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLSunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQL
 
Json within a relational database
Json within a relational databaseJson within a relational database
Json within a relational database
 
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
 
Scaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersScaling MySQL Strategies for Developers
Scaling MySQL Strategies for Developers
 

Viewers also liked

Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...
Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...
Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...Frederic Descamps
 
MariaDB - Fast, Easy & Strong - Get Started Tutorial
MariaDB - Fast, Easy & Strong - Get Started TutorialMariaDB - Fast, Easy & Strong - Get Started Tutorial
MariaDB - Fast, Easy & Strong - Get Started Tutorialphamhphuc
 
MySQL Day Paris 2016 - MySQL Enterprise Edition
MySQL Day Paris 2016 - MySQL Enterprise EditionMySQL Day Paris 2016 - MySQL Enterprise Edition
MySQL Day Paris 2016 - MySQL Enterprise EditionOlivier DASINI
 
ProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQLProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQLRené Cannaò
 
Proxysql use case scenarios fosdem17
Proxysql use case scenarios    fosdem17Proxysql use case scenarios    fosdem17
Proxysql use case scenarios fosdem17Alkin Tezuysal
 
MySQL Cloud Service Deep Dive
MySQL Cloud Service Deep DiveMySQL Cloud Service Deep Dive
MySQL Cloud Service Deep DiveMorgan Tocker
 
MySQL High Availability -- InnoDB Clusters
MySQL High Availability -- InnoDB ClustersMySQL High Availability -- InnoDB Clusters
MySQL High Availability -- InnoDB ClustersMatt Lord
 
What you wanted to know about MySQL, but could not find using inernal instrum...
What you wanted to know about MySQL, but could not find using inernal instrum...What you wanted to know about MySQL, but could not find using inernal instrum...
What you wanted to know about MySQL, but could not find using inernal instrum...Sveta Smirnova
 
MySQL Day Paris 2016 - Introducing Oracle MySQL Cloud Service
MySQL Day Paris 2016 - Introducing Oracle MySQL Cloud ServiceMySQL Day Paris 2016 - Introducing Oracle MySQL Cloud Service
MySQL Day Paris 2016 - Introducing Oracle MySQL Cloud ServiceOlivier DASINI
 

Viewers also liked (9)

Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...
Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...
Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...
 
MariaDB - Fast, Easy & Strong - Get Started Tutorial
MariaDB - Fast, Easy & Strong - Get Started TutorialMariaDB - Fast, Easy & Strong - Get Started Tutorial
MariaDB - Fast, Easy & Strong - Get Started Tutorial
 
MySQL Day Paris 2016 - MySQL Enterprise Edition
MySQL Day Paris 2016 - MySQL Enterprise EditionMySQL Day Paris 2016 - MySQL Enterprise Edition
MySQL Day Paris 2016 - MySQL Enterprise Edition
 
ProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQLProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQL
 
Proxysql use case scenarios fosdem17
Proxysql use case scenarios    fosdem17Proxysql use case scenarios    fosdem17
Proxysql use case scenarios fosdem17
 
MySQL Cloud Service Deep Dive
MySQL Cloud Service Deep DiveMySQL Cloud Service Deep Dive
MySQL Cloud Service Deep Dive
 
MySQL High Availability -- InnoDB Clusters
MySQL High Availability -- InnoDB ClustersMySQL High Availability -- InnoDB Clusters
MySQL High Availability -- InnoDB Clusters
 
What you wanted to know about MySQL, but could not find using inernal instrum...
What you wanted to know about MySQL, but could not find using inernal instrum...What you wanted to know about MySQL, but could not find using inernal instrum...
What you wanted to know about MySQL, but could not find using inernal instrum...
 
MySQL Day Paris 2016 - Introducing Oracle MySQL Cloud Service
MySQL Day Paris 2016 - Introducing Oracle MySQL Cloud ServiceMySQL Day Paris 2016 - Introducing Oracle MySQL Cloud Service
MySQL Day Paris 2016 - Introducing Oracle MySQL Cloud Service
 

Similar to BGOUG15: JSON support in MySQL 5.7

Optimizer percona live_ams2015
Optimizer percona live_ams2015Optimizer percona live_ams2015
Optimizer percona live_ams2015Manyi Lu
 
MySQL 5.7 NF – JSON Datatype 활용
MySQL 5.7 NF – JSON Datatype 활용MySQL 5.7 NF – JSON Datatype 활용
MySQL 5.7 NF – JSON Datatype 활용I Goo Lee
 
Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.Mydbops
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015Dave Stokes
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015Dave Stokes
 
NoSQL для PostgreSQL: Jsquery — язык запросов
NoSQL для PostgreSQL: Jsquery — язык запросовNoSQL для PostgreSQL: Jsquery — язык запросов
NoSQL для PostgreSQL: Jsquery — язык запросовCodeFest
 
The rise of json in rdbms land jab17
The rise of json in rdbms land jab17The rise of json in rdbms land jab17
The rise of json in rdbms land jab17alikonweb
 
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...Ontico
 
Json improvements in my sql 8.0
Json improvements in my sql 8.0  Json improvements in my sql 8.0
Json improvements in my sql 8.0 Mysql User Camp
 
[OSC 2020 Online/Nagoya] MySQLドキュメントストア
[OSC 2020 Online/Nagoya] MySQLドキュメントストア[OSC 2020 Online/Nagoya] MySQLドキュメントストア
[OSC 2020 Online/Nagoya] MySQLドキュメントストアRyusuke Kajiyama
 
Starting with JSON Path Expressions in Oracle 12.1.0.2
Starting with JSON Path Expressions in Oracle 12.1.0.2Starting with JSON Path Expressions in Oracle 12.1.0.2
Starting with JSON Path Expressions in Oracle 12.1.0.2Marco Gralike
 
JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0Mydbops
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQLJussi Pohjolainen
 
PostgreSQL 9.4 JSON Types and Operators
PostgreSQL 9.4 JSON Types and OperatorsPostgreSQL 9.4 JSON Types and Operators
PostgreSQL 9.4 JSON Types and OperatorsNicholas Kiraly
 
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_103 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1mlraviol
 
Power JSON with PostgreSQL
Power JSON with PostgreSQLPower JSON with PostgreSQL
Power JSON with PostgreSQLEDB
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateKiev ALT.NET
 

Similar to BGOUG15: JSON support in MySQL 5.7 (20)

MySQL Rises with JSON Support
MySQL Rises with JSON SupportMySQL Rises with JSON Support
MySQL Rises with JSON Support
 
Optimizer percona live_ams2015
Optimizer percona live_ams2015Optimizer percona live_ams2015
Optimizer percona live_ams2015
 
MySQL 5.7 NF – JSON Datatype 활용
MySQL 5.7 NF – JSON Datatype 활용MySQL 5.7 NF – JSON Datatype 활용
MySQL 5.7 NF – JSON Datatype 활용
 
MySQL 5.7 + JSON
MySQL 5.7 + JSONMySQL 5.7 + JSON
MySQL 5.7 + JSON
 
Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
 
NoSQL для PostgreSQL: Jsquery — язык запросов
NoSQL для PostgreSQL: Jsquery — язык запросовNoSQL для PostgreSQL: Jsquery — язык запросов
NoSQL для PostgreSQL: Jsquery — язык запросов
 
The rise of json in rdbms land jab17
The rise of json in rdbms land jab17The rise of json in rdbms land jab17
The rise of json in rdbms land jab17
 
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
 
Json improvements in my sql 8.0
Json improvements in my sql 8.0  Json improvements in my sql 8.0
Json improvements in my sql 8.0
 
[OSC 2020 Online/Nagoya] MySQLドキュメントストア
[OSC 2020 Online/Nagoya] MySQLドキュメントストア[OSC 2020 Online/Nagoya] MySQLドキュメントストア
[OSC 2020 Online/Nagoya] MySQLドキュメントストア
 
Starting with JSON Path Expressions in Oracle 12.1.0.2
Starting with JSON Path Expressions in Oracle 12.1.0.2Starting with JSON Path Expressions in Oracle 12.1.0.2
Starting with JSON Path Expressions in Oracle 12.1.0.2
 
JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
 
PostgreSQL 9.4 JSON Types and Operators
PostgreSQL 9.4 JSON Types and OperatorsPostgreSQL 9.4 JSON Types and Operators
PostgreSQL 9.4 JSON Types and Operators
 
How to Use JSON in MySQL Wrong
How to Use JSON in MySQL WrongHow to Use JSON in MySQL Wrong
How to Use JSON in MySQL Wrong
 
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_103 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
 
Power JSON with PostgreSQL
Power JSON with PostgreSQLPower JSON with PostgreSQL
Power JSON with PostgreSQL
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
 

Recently uploaded

WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfryanfarris8
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Eraconfluent
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2WSO2
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2
 

Recently uploaded (20)

WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration Tooling
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 

BGOUG15: JSON support in MySQL 5.7

  • 1. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | JSON Support in MySQL 5.7 Georgi “Joro” Kodinov Team lead, MySQL server general team
  • 2. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Agenda 2  The new JSON data type  Inlined JSON path expressions  The new JSON functions  Indexing JSON data
  • 3. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. CREATE TABLE employees (data JSON); INSERT INTO employees VALUES ('{"id": 1, "name": "Jane"}'), ('{"id": 2, "name": "Joe"}'); SELECT * FROM employees; +-------------------------------------+ | data | +-------------------------------------+ | {"id": 1, "name": "Jane"} | | {"id": 2, "name": "Joe"} | +-------------------------------------+ • Validation on INSERT • No reparsing on SELECT • Dictionary of fields • Fields are sorted • Can compare JSON/SQL • Can convert JSON/SQL • Supports all native JSON datatypes • Also supports date, time, timestamp etc. 3 The New JSON Datatype
  • 4. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. JSON vs TEXT columns Pros Cons JSON • Validate once • Fast access • Can update in-place • Slower to insert • Unreadable as is • Sets certain limitations on JSON TEXT • Fast to insert • Human readable • Requires manual validation • Requires manual parsing • Harder to update 4
  • 5. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Beware: SQL vs JSON comparisons ! 5 SQL JSON create table t1 (data json); create table t2 ( id integer, data varchar(20)); insert into t1 values ('{ "id": 1, "data": "1" }'), ('{ "id": 2, "data": "3" }'); insert into t2 values (1, '1'), (2, '3'); select count(*) from t1 where data->'$.id' = data->'$.data'; select count(*) from t2 where id = data; 0 rows ! 1 row !
  • 6. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Agenda 6  The new JSON data type  Inlined JSON path expressions  The new JSON functions  Indexing JSON data
  • 7. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Inlined JSON Path Expressions • <field>->'<JSON path expression>' e.g. data->'$.some.key[3].from.doc' • Syntax sugar over JSON_EXTRACT function • SELECT * FROM employees WHERE data->'$.id'= 2; • ALTER … ADD COLUMN id INT AS (data->'$.id') … • CREATE VIEW .. AS SELECT data->'$.id', data->'$.name' FROM … • UPDATE employees SET data->'$.name'=‘John' WHERE … Not yet!
  • 8. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Limitations of Inlined JSON Path Expressions Inlined JSON path JSON_EXTRACT() Data source Field Any JSON value Path expression SQL Constant SQL Expression # of expressions One Multiple
  • 9. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Supported JSON Paths [[[database.]table.]column]$<path spec> Expression Example [ [ [database.] table.] field]$ db.phonebook.data$ $ Current document’s root $.identifier $.user.address.street [array] $.user.addresses[2].street .* and [*] $.user.addresses[*].street ** $.user**.phone Not yet!
  • 10. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Agenda 10  The new JSON data type  Inlined JSON path expressions  The new JSON functions  Indexing JSON data
  • 11. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. New functions to handle JSON data Example Result SELECT JSON_VALID('{ "a":1 }'); 1 SELECT JSON_TYPE('[ 1, 2, 3 ]'); ARRAY SELECT JSON_KEYS('{ "a":1, "b": 2 }'); ["a", "b"] SELECT JSON_LENGTH('[ 1, 2, 3 ]'); 3 SELECT JSON_DEPTH('{ "a":{ "c": 1 }, "b": 2 }'); 3 11 Information
  • 12. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. New functions to handle JSON data Example Result SELECT JSON_REMOVE('{ "a":1, "b": 2 }', '$.a'); {"b": 2} SELECT JSON_ARRAY_APPEND('[1,[2,3],4]', '$[1]', 5); [1, [2, 3, 5], 4] SELECT JSON_SET('{ "a":1 }', '$.c', 3); {"a": 1, “c": 3} SELECT JSON_INSERT('{ "a":1 }', '$.b', 4); {"a": 1, "b": 4} SELECT JSON_REPLACE('{ "a":1, "b": 2 }', '$.b', 3); {"a": 1, "b": 3} SELECT JSON_MERGE('{ "a": 1 }', '{"b":2}'); {"a": 1, "b": 2} SELECT JSON_UNQUOTE('"abc"'); abc 12 Modification
  • 13. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. New functions to handle JSON data Example Result SELECT JSON_ARRAY(1, '2', null, true); [1, "2", null, true] SELECT JSON_OBJECT(1, 2, '3', true); {"1": 2, "3": true} SELECT JSON_QUOTE('"null"'); ""null"" 13 Create JSON objects
  • 14. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. New functions to handle JSON data Example Result SELECT JSON_CONTAINS_PATH( '{ "a":{ "c": 1 }, "b": 2 }', 'one', '$.a.c'); 1 SELECT JSON_CONTAINS( '{"a": 1, "b": "2" }', '1', '$.a'); 1 SELECT JSON_EXTRACT('{"a": 1, "n": { "b": 2}}', '$.n'); {"b": 2} SELECT JSON_SEARCH( '{"a": "1", "b": "2" }', 'one', 2); "$.b" 14 Search in JSON data
  • 15. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. New functions to handle JSON data 15 Further reading: http://dev.mysql.com/doc/refman/5.7/en/
  • 16. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Agenda 16  The new JSON data type  Inlined JSON path expressions  The new JSON functions  Indexing JSON data
  • 17. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Indexing JSON Data • Use Functional Indexes – Both STORED and VIRTUAL types are supported • Examples: – CREATE TABLE t1 ( data JSON, id INTEGER AS (JSON_EXTRACT(data,"$.id")) STORED, PRIMARY KEY(id)); – CREATE TABLE t2 ( data JSON, id INTEGER AS (JSON_EXTRACT(data,"$.id")) VIRTUAL, KEY(id)); 17
  • 18. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Indexing JSON: STORED vs VIRTUAL columns Pros Cons STORED • Can be primary key too • All index types supported • Looks like a normal field • Slow ALTER TABLE • Takes space on disk VIRTUAL • Instant ALTER TABLE • Faster INSERT • Looks like a normal field • Secondary key only • BTREE index only 18
  • 19. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. How do you tell if an JSON index is used ? > EXPLAIN SELECT data FROM t1 WHERE JSON_EXTRACT(data,"$.series") BETWEEN 3 AND 5; +----+----------------+--------+---------------+--------+…+------------------------------+ | id | select_type | table | partitions | type | | Extra | +----+----------------+--------+---------------+--------+…+------------------------------+ | 1 | SIMPLE | t1 | NULL | range | | Using index condition | +----+----------------+--------+---------------+--------+…+------------------------------+ 19
  • 20. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Or this way …. 20
  • 21. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Or maybe this way ? 21 ALTER TABLE features ADD feature_type VARCHAR(30) AS (feature->"$.type") VIRTUAL; Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0 ALTER TABLE features ADD INDEX (feature_type); Query OK, 0 rows affected (0.73 sec) Records: 0 Duplicates: 0 Warnings: 0 SELECT DISTINCT feature_type FROM features; +-------------------+ | feature_type | +-------------------+ | "Feature" | +-------------------+ 1 row in set (0.06 sec) From table scan on 206K documents to index scan on 206K materialized values Down from 1.25s ! Meta data change only (FAST). Does not need to touch table. Online CREATE INDEX ! No rows were modified.
  • 22. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Roadmap • Online alter for virtual columns • Advanced JSON functions • In-place update of JSON/BLOB • Full text and GIS index on virtual columns • Improved performance through condition pushdown 22
  • 23. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Questions ? @gkodinov, georgi.kodinov@oracle.com if you forget ! 23
  • 24. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Safe Harbor Statement The preceding 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. 24
  • 25. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 25

Editor's Notes

  1. Create an index on type field, first create a virtual column by extracting the type field, and then create an index on this virtual column. Run the same query as before. Execution time goes 1.25 sec down to 0.06 sec. Still has to examine full index, but now it is just an index of the values all extracted. It is much smaller.