SlideShare a Scribd company logo
1 of 33
Download to read offline
Sergei Petrunia
MariaDB devroom
FOSDEM 2021
JSON Support in MariaDB
News, non-news, and the bigger picture
FOSDEM 2021
MariaDB devroom
Sergei Petrunia
MariaDB developer
2
JSON Path
Non-news
3
JSON Path
●
A lot of JSON functions accept “JSON Path” expressions
– locate element(s) in JSON document
●
Path language in MariaDB wasn’t documented
– It’s more than “foo.bar.baz”
●
Caution: there are many different JSON Path definitions on the
web
– SQL uses SQL:2016, “SQL/JSON Path language”
4
SQL/JSON Path language
●
mode is lax (the default) or strict
●
$ is the context element (root by default)
●
followed by several steps.
path: [mode] $ [step]*
5
Object member selection step
●
In strict mode, the context must be an object, it must have a
member with the specified name.
●
lax mode “ignores” missing elements, “unwraps” 1-element arrays
.name
.*
{
"name": "MariaDB"
"version": "10.5"
}
$.name → "MariaDB"
$.* → "MariaDB" "10.5"
●
Select a member
●
Select all members
– produces a sequence of values
6
Array element selection step
●
Produces a sequence of elements
●
Strict mode: indexes must be within bounds
[N]
[*]
[
10, "abc", {"x":0}
]
$[0] → 10
$[last] → {"x":0}
●
Select array elements
– one
– range
– last element
– list of ^^
– all elements
[N to M]
[N1,N2,...]
[last]
$[*] →10 "abc" {"x":0}
7
Filters
●
Predicate can have
– AND/OR formulas (&&, ||)
– comparisons
– arithmetics
– some functions
– parameters passed from outside
[
{
"item":"Jeans",
"color":"blue"
},
{
"item":"Laptop",
"color":"black"
}
]
●
Filters elements in sequence
?(predicate)
$[*]?(@.color=="black").item
→ "Laptop"
8
MariaDB and MySQL
●
Support only lax mode
– Not fully compliant: MySQL BUG#102233, MDEV-24573.
●
Object member selection is supported
●
Array selection: [N] is supported
– MySQL also supports [last] and [N to M]
●
Filters are not supported
– expressions, arithmetics, functions, passing variables
9
Recursive search extension
●
Task: find “foo” anywhere in the JSON document
●
SQL/JSON Path doesn’t allow this
●
Extension: wildcard search step
●
Select all (direct and indirect) children:
step: **
$**.price
●
Example: find “price” anywhere:
●
PostgreSQL also supports this, the syntax is .**
10
Usage example: Optimizer trace
●
Optimizer Trace is JSON, log of query optimizer’s actions
– Deeply-nested
– “Recursive”, as SQL allows nesting of subqueries/CTEs/etc
select
JSON_DETAILED(JSON_EXTRACT(trace, '$**.rows_estimation'))
from
information_schema.optimizer_trace;
●
Filters would be helpful: $**.rows_estimation?(@table=="tbl1")
11
JSON Path summary
●
Language for pointing to node(s) in JSON document
– SQL:2016, “SQL/JSON Path language”
●
MariaDB and MySQL implement a subset
– lax mode only
– no support for filters (BAD)
– array index – only [N]
●
MySQL also allows [last] and [M to N]
●
MySQL and MariaDB have recursive-search extension (GOOD)
12
JSON Path in other databases
●
PostgreSQL seems have the most compliant implementation
– Supports filtering, strict/lax modes, etc.
●
Other databases support different and [very] restrictive subsets.
13
JSON_TABLE
News
14
JSON_TABLE
●
JSON_TABLE converts JSON input to a table
– It is a “table function”
– to be used in the FROM clause
●
Introduced in SQL:2016
●
Supported by Oracle DB, MySQL 8
●
Under development in MariaDB
– Trying to get it into 10.6
15
JSON_TABLE by example
●
Start with a JSON
document:
select *
from
JSON_TABLE(@json_doc,
'$[*]' columns(name varchar(32) path '$.name',
price int path '$.price')
) as T
●
Use JSON_TABLE to produce tabular output:
set @json_doc='
[
{"name": "Laptop", "price": 1200},
{"name": "Jeans", "price": 60}
]';
16
JSON_TABLE by example
●
Start with a JSON
document:
set @json_doc='
[
{"name": "Laptop", "price": 1200},
{"name": "Jeans", "price": 60}
]';
select *
from
JSON_TABLE(@json_doc,
'$[*]' columns(name varchar(32) path '$.name',
price int path '$.price')
) as T
●
Use JSON_TABLE to produce tabular output:
+--------+-------+
| name | price |
+--------+-------+
| Laptop | 1200 |
| Jeans | 60 |
+--------+-------+
17
JSON_TABLE syntax
select *
from
JSON_TABLE(@json_doc,
'$[*]' columns(name varchar(32) path '$.name',
price int path '$.price')
) as T
Source document
18
JSON_TABLE syntax
select *
from
JSON_TABLE(@json_doc,
'$[*]' columns(name varchar(32) path '$.name',
price int path '$.price')
) as T
Source document
Path to nodes
to examine
19
JSON_TABLE syntax
select *
from
JSON_TABLE(@json_doc,
'$[*]' columns(name varchar(32) path '$.name',
price int path '$.price')
) as T
Source document
Path to nodes
to examine
Column definitions
20
JSON_TABLE syntax
select *
from
JSON_TABLE(@json_doc,
'$[*]' columns(name varchar(32) path '$.name',
price int path '$.price')
) as T
Source document
Path to nodes
to examine
Column definitions
Column name Path where to get the value
from. The context item is the
node being examined
21
Nested paths
set @json_doc='
[
{"name": "Laptop", "colors": ["black", "white", "red"] },
{"name": "T-Shirt", "colors": ["yellow", "blue"] }
]';
select *
from
JSON_TABLE(@json_doc,
'$[*]'
columns(name varchar(32) path '$.name',
nested path '$.colors[*]'
columns (
color varchar(32) path '$'
)
)
) as T
22
Nested paths
set @json_doc='
[
{"name": "Laptop", "colors": ["black", "white", "red"] },
{"name": "T-Shirt", "colors": ["yellow", "blue"] }
]';
select *
from
JSON_TABLE(@json_doc,
'$[*]'
columns(name varchar(32) path '$.name',
nested path '$.colors[*]'
columns (
color varchar(32) path '$'
)
)
) as T
+---------+--------+
| name | color |
+---------+--------+
| Laptop | black |
| Laptop | white |
| Laptop | red |
| T-Shirt | yellow |
| T-Shirt | blue |
+---------+--------+
23
Multiple nested paths
●
NESTED PATH can be nested
●
Can have “sibling” NESTED PATHs
– The standard allows to specify how to unnest (“the PLAN clause”)
– The default way is “outer join” like:
{
"name": "T-Shirt",
"colors": ["yellow", "blue"],
"sizes": ["Small", "Medium", "Large"]
}
+---------+--------+--------+
| name | color | size |
+---------+--------+--------+
| T-Shirt | yellow | NULL |
| T-Shirt | blue | NULL |
| T-Shirt | NULL | Small |
| T-Shirt | NULL | Medium |
| T-Shirt | NULL | Large |
+---------+--------+--------+
– MySQL (and soon MariaDB) only support “outer join”-like unnesting
●
“no PLAN clause support”.
24
Error handling
columns(column_name type path '$path' [action on empty]
[action on error])
Handling missing values and/or conversion errors
action: NULL
default 'string'
error
● on empty is used when JSON element is missing
● on error is used on datatype conversion error or non-scalar JSON.
●
Both MariaDB and MySQL support this
25
JSON_TABLE and joins
26
JSON_TABLE and joins
[
{"name": "Laptop", "price": 1200},
{"name": "Jeans", "price": 60}
]
[
{"name": "T-Shirt", "price": 10},
{"name": "Headphones", "price": 100}
]
1
2
orders
27
JSON_TABLE and joins
select
orders.order_id,
order_items.name,
order_items.price
from
orders,
JSON_TABLE(orders.items_json,
'$[*]' columns(name varchar(32) path '$.name',
price int path '$.price')
) as order_items
+----------+------------+-------+
| order_id | name | price |
+----------+------------+-------+
| 1 | Laptop | 1200 |
| 1 | Jeans | 60 |
| 2 | T-Shirt | 10 |
| 2 | Headphones | 100 |
+----------+------------+-------+
[
{"name": "Laptop", "price": 1200},
{"name": "Jeans", "price": 60}
]
[
{"name": "T-Shirt", "price": 10},
{"name": "Headphones", "price": 100}
]
1
2
orders
28
JSON_TABLE and joins
●
JSON_TABLE’s argument can refer to other tables
●
LATERAL-like semantics: contents of JSON_TABLE(...) depends on
the parameter
●
Allows to do “normalization” for contents of columns with JSON data
29
JSON_TABLE Summary
●
A table function to convert JSON data to relational form
●
Introduced in SQL:2016
– The standard specifies a lot of features
●
MySQL 8 implements a subset
– PLAN clause is not supported
●
MariaDB: MDEV-17399, under development
– Will implement a subset very similar to MySQL
30
JSON_TABLE in other databases
●
Quoting Markus Winand, https://modern-sql.com/slides/ModernSQL-
2019-05-30.pdf:
●
PostgreSQL have JSON_TABLE under development, too.
31
The takeaways
●
SQL:2016 introduced JSON support
●
MySQL 8 has implemented a subset of it
– The subset is reasonably good
– There are some extensions
●
MariaDB is catching up
– including the extensions
32
The low-hanging fruits
●
JSON Path: [last], [N to M]
●
JSON Path: filtering support
●
Improved JSON_DETAILED function
– It’s a JSON pretty-printer
– Used in development with JSON
– It works, but is fairly dumb
●
All are great to start contributing
– Contact us if interested.
33
Thanks!
Q & A

More Related Content

What's hot

Postgres rules
Postgres rulesPostgres rules
Postgres rulesgisborne
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineJason Terpko
 
Using JSON with MariaDB and MySQL
Using JSON with MariaDB and MySQLUsing JSON with MariaDB and MySQL
Using JSON with MariaDB and MySQLAnders Karlsson
 
Using spark data frame for sql
Using spark data frame for sqlUsing spark data frame for sql
Using spark data frame for sqlDaeMyung Kang
 
The Ring programming language version 1.8 book - Part 50 of 202
The Ring programming language version 1.8 book - Part 50 of 202The Ring programming language version 1.8 book - Part 50 of 202
The Ring programming language version 1.8 book - Part 50 of 202Mahmoud Samir Fayed
 
BGOUG15: JSON support in MySQL 5.7
BGOUG15: JSON support in MySQL 5.7BGOUG15: JSON support in MySQL 5.7
BGOUG15: JSON support in MySQL 5.7Georgi Kodinov
 
Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)MongoDB
 
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...Kangaroot
 
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
 
The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31Mahmoud Samir Fayed
 
Aggregation Framework in MongoDB Overview Part-1
Aggregation Framework in MongoDB Overview Part-1Aggregation Framework in MongoDB Overview Part-1
Aggregation Framework in MongoDB Overview Part-1Anuj Jain
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation Amit Ghosh
 
Indexing and Performance Tuning
Indexing and Performance TuningIndexing and Performance Tuning
Indexing and Performance TuningMongoDB
 
SICP_2.5 일반화된 연산시스템
SICP_2.5 일반화된 연산시스템SICP_2.5 일반화된 연산시스템
SICP_2.5 일반화된 연산시스템HyeonSeok Choi
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Platonov Sergey
 
CR17 - Designing a database like an archaeologist
CR17 - Designing a database like an archaeologistCR17 - Designing a database like an archaeologist
CR17 - Designing a database like an archaeologistyoavrubin
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Rebecca Grenier
 
NoSQL для PostgreSQL: Jsquery — язык запросов
NoSQL для PostgreSQL: Jsquery — язык запросовNoSQL для PostgreSQL: Jsquery — язык запросов
NoSQL для PostgreSQL: Jsquery — язык запросовCodeFest
 

What's hot (20)

Postgres rules
Postgres rulesPostgres rules
Postgres rules
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
 
Using JSON with MariaDB and MySQL
Using JSON with MariaDB and MySQLUsing JSON with MariaDB and MySQL
Using JSON with MariaDB and MySQL
 
Using spark data frame for sql
Using spark data frame for sqlUsing spark data frame for sql
Using spark data frame for sql
 
The Ring programming language version 1.8 book - Part 50 of 202
The Ring programming language version 1.8 book - Part 50 of 202The Ring programming language version 1.8 book - Part 50 of 202
The Ring programming language version 1.8 book - Part 50 of 202
 
BGOUG15: JSON support in MySQL 5.7
BGOUG15: JSON support in MySQL 5.7BGOUG15: JSON support in MySQL 5.7
BGOUG15: JSON support in MySQL 5.7
 
Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)
 
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
 
MySQL 5.7 NF – JSON Datatype 활용
MySQL 5.7 NF – JSON Datatype 활용MySQL 5.7 NF – JSON Datatype 활용
MySQL 5.7 NF – JSON Datatype 활용
 
The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31
 
Data import-cheatsheet
Data import-cheatsheetData import-cheatsheet
Data import-cheatsheet
 
Php forum2015 tomas_final
Php forum2015 tomas_finalPhp forum2015 tomas_final
Php forum2015 tomas_final
 
Aggregation Framework in MongoDB Overview Part-1
Aggregation Framework in MongoDB Overview Part-1Aggregation Framework in MongoDB Overview Part-1
Aggregation Framework in MongoDB Overview Part-1
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation
 
Indexing and Performance Tuning
Indexing and Performance TuningIndexing and Performance Tuning
Indexing and Performance Tuning
 
SICP_2.5 일반화된 연산시스템
SICP_2.5 일반화된 연산시스템SICP_2.5 일반화된 연산시스템
SICP_2.5 일반화된 연산시스템
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”
 
CR17 - Designing a database like an archaeologist
CR17 - Designing a database like an archaeologistCR17 - Designing a database like an archaeologist
CR17 - Designing a database like an archaeologist
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access
 
NoSQL для PostgreSQL: Jsquery — язык запросов
NoSQL для PostgreSQL: Jsquery — язык запросовNoSQL для PostgreSQL: Jsquery — язык запросов
NoSQL для PostgreSQL: Jsquery — язык запросов
 

Similar to JSON Support in MariaDB: News, non-news and the bigger picture

Postgre(No)SQL - A JSON journey
Postgre(No)SQL - A JSON journeyPostgre(No)SQL - A JSON journey
Postgre(No)SQL - A JSON journeyNicola Moretto
 
Oracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory DatabaseOracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory DatabaseMarco Gralike
 
Postgres vs Mongo / Олег Бартунов (Postgres Professional)
Postgres vs Mongo / Олег Бартунов (Postgres Professional)Postgres vs Mongo / Олег Бартунов (Postgres Professional)
Postgres vs Mongo / Олег Бартунов (Postgres Professional)Ontico
 
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 Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...Ryan B Harvey, CSDP, CSM
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - GuilinJackson Tian
 
UKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the DatabaseUKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the DatabaseMarco Gralike
 
Greenplum 6 Changes
Greenplum 6 ChangesGreenplum 6 Changes
Greenplum 6 ChangesVMware Tanzu
 
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
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation FrameworkCaserta
 
Webscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Webscale PostgreSQL - JSONB and Horizontal Scaling StrategiesWebscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Webscale PostgreSQL - JSONB and Horizontal Scaling StrategiesJonathan Katz
 
XML introduction and Uses of XML in JSBSim
XML introduction and Uses of XML in JSBSimXML introduction and Uses of XML in JSBSim
XML introduction and Uses of XML in JSBSimWai Nwe Tun
 
MongoDB Advanced Topics
MongoDB Advanced TopicsMongoDB Advanced Topics
MongoDB Advanced TopicsCésar Rodas
 
JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)Faysal Shaarani (MBA)
 
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
 
MongoDB a document store that won't let you down.
MongoDB a document store that won't let you down.MongoDB a document store that won't let you down.
MongoDB a document store that won't let you down.Nurul Ferdous
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database JonesJohn David Duncan
 

Similar to JSON Support in MariaDB: News, non-news and the bigger picture (20)

Oh, that ubiquitous JSON !
Oh, that ubiquitous JSON !Oh, that ubiquitous JSON !
Oh, that ubiquitous JSON !
 
Postgre(No)SQL - A JSON journey
Postgre(No)SQL - A JSON journeyPostgre(No)SQL - A JSON journey
Postgre(No)SQL - A JSON journey
 
Oracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory DatabaseOracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory Database
 
Postgres vs Mongo / Олег Бартунов (Postgres Professional)
Postgres vs Mongo / Олег Бартунов (Postgres Professional)Postgres vs Mongo / Олег Бартунов (Postgres Professional)
Postgres vs Mongo / Олег Бартунов (Postgres Professional)
 
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 Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - Guilin
 
UKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the DatabaseUKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the Database
 
Greenplum 6 Changes
Greenplum 6 ChangesGreenplum 6 Changes
Greenplum 6 Changes
 
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
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 
Drupal7 dbtng
Drupal7  dbtngDrupal7  dbtng
Drupal7 dbtng
 
Webscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Webscale PostgreSQL - JSONB and Horizontal Scaling StrategiesWebscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Webscale PostgreSQL - JSONB and Horizontal Scaling Strategies
 
XML introduction and Uses of XML in JSBSim
XML introduction and Uses of XML in JSBSimXML introduction and Uses of XML in JSBSim
XML introduction and Uses of XML in JSBSim
 
MongoDB Advanced Topics
MongoDB Advanced TopicsMongoDB Advanced Topics
MongoDB Advanced Topics
 
JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)
 
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
 
MongoDB a document store that won't let you down.
MongoDB a document store that won't let you down.MongoDB a document store that won't let you down.
MongoDB a document store that won't let you down.
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 

More from Sergey Petrunya

New optimizer features in MariaDB releases before 10.12
New optimizer features in MariaDB releases before 10.12New optimizer features in MariaDB releases before 10.12
New optimizer features in MariaDB releases before 10.12Sergey Petrunya
 
MariaDB's join optimizer: how it works and current fixes
MariaDB's join optimizer: how it works and current fixesMariaDB's join optimizer: how it works and current fixes
MariaDB's join optimizer: how it works and current fixesSergey Petrunya
 
Improved histograms in MariaDB 10.8
Improved histograms in MariaDB 10.8Improved histograms in MariaDB 10.8
Improved histograms in MariaDB 10.8Sergey Petrunya
 
Optimizer Trace Walkthrough
Optimizer Trace WalkthroughOptimizer Trace Walkthrough
Optimizer Trace WalkthroughSergey Petrunya
 
Optimizer features in recent releases of other databases
Optimizer features in recent releases of other databasesOptimizer features in recent releases of other databases
Optimizer features in recent releases of other databasesSergey Petrunya
 
MariaDB 10.4 - что нового
MariaDB 10.4 - что новогоMariaDB 10.4 - что нового
MariaDB 10.4 - что новогоSergey Petrunya
 
Query Optimizer in MariaDB 10.4
Query Optimizer in MariaDB 10.4Query Optimizer in MariaDB 10.4
Query Optimizer in MariaDB 10.4Sergey Petrunya
 
Lessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmarkLessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmarkSergey Petrunya
 
MyRocks in MariaDB | M18
MyRocks in MariaDB | M18MyRocks in MariaDB | M18
MyRocks in MariaDB | M18Sergey Petrunya
 
New Query Optimizer features in MariaDB 10.3
New Query Optimizer features in MariaDB 10.3New Query Optimizer features in MariaDB 10.3
New Query Optimizer features in MariaDB 10.3Sergey Petrunya
 
Histograms in MariaDB, MySQL and PostgreSQL
Histograms in MariaDB, MySQL and PostgreSQLHistograms in MariaDB, MySQL and PostgreSQL
Histograms in MariaDB, MySQL and PostgreSQLSergey Petrunya
 
Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2Sergey Petrunya
 
MyRocks in MariaDB: why and how
MyRocks in MariaDB: why and howMyRocks in MariaDB: why and how
MyRocks in MariaDB: why and howSergey Petrunya
 
Эволюция репликации в MySQL и MariaDB
Эволюция репликации в MySQL и MariaDBЭволюция репликации в MySQL и MariaDB
Эволюция репликации в MySQL и MariaDBSergey Petrunya
 
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)Sergey Petrunya
 
MariaDB 10.1 - что нового.
MariaDB 10.1 - что нового.MariaDB 10.1 - что нового.
MariaDB 10.1 - что нового.Sergey Petrunya
 
Window functions in MariaDB 10.2
Window functions in MariaDB 10.2Window functions in MariaDB 10.2
Window functions in MariaDB 10.2Sergey Petrunya
 
MyRocks: табличный движок для MySQL на основе RocksDB
MyRocks: табличный движок для MySQL на основе RocksDBMyRocks: табличный движок для MySQL на основе RocksDB
MyRocks: табличный движок для MySQL на основе RocksDBSergey Petrunya
 

More from Sergey Petrunya (20)

New optimizer features in MariaDB releases before 10.12
New optimizer features in MariaDB releases before 10.12New optimizer features in MariaDB releases before 10.12
New optimizer features in MariaDB releases before 10.12
 
MariaDB's join optimizer: how it works and current fixes
MariaDB's join optimizer: how it works and current fixesMariaDB's join optimizer: how it works and current fixes
MariaDB's join optimizer: how it works and current fixes
 
Improved histograms in MariaDB 10.8
Improved histograms in MariaDB 10.8Improved histograms in MariaDB 10.8
Improved histograms in MariaDB 10.8
 
Optimizer Trace Walkthrough
Optimizer Trace WalkthroughOptimizer Trace Walkthrough
Optimizer Trace Walkthrough
 
Optimizer features in recent releases of other databases
Optimizer features in recent releases of other databasesOptimizer features in recent releases of other databases
Optimizer features in recent releases of other databases
 
MariaDB 10.4 - что нового
MariaDB 10.4 - что новогоMariaDB 10.4 - что нового
MariaDB 10.4 - что нового
 
Query Optimizer in MariaDB 10.4
Query Optimizer in MariaDB 10.4Query Optimizer in MariaDB 10.4
Query Optimizer in MariaDB 10.4
 
Lessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmarkLessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmark
 
MyRocks in MariaDB | M18
MyRocks in MariaDB | M18MyRocks in MariaDB | M18
MyRocks in MariaDB | M18
 
New Query Optimizer features in MariaDB 10.3
New Query Optimizer features in MariaDB 10.3New Query Optimizer features in MariaDB 10.3
New Query Optimizer features in MariaDB 10.3
 
MyRocks in MariaDB
MyRocks in MariaDBMyRocks in MariaDB
MyRocks in MariaDB
 
Histograms in MariaDB, MySQL and PostgreSQL
Histograms in MariaDB, MySQL and PostgreSQLHistograms in MariaDB, MySQL and PostgreSQL
Histograms in MariaDB, MySQL and PostgreSQL
 
Say Hello to MyRocks
Say Hello to MyRocksSay Hello to MyRocks
Say Hello to MyRocks
 
Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2
 
MyRocks in MariaDB: why and how
MyRocks in MariaDB: why and howMyRocks in MariaDB: why and how
MyRocks in MariaDB: why and how
 
Эволюция репликации в MySQL и MariaDB
Эволюция репликации в MySQL и MariaDBЭволюция репликации в MySQL и MariaDB
Эволюция репликации в MySQL и MariaDB
 
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
 
MariaDB 10.1 - что нового.
MariaDB 10.1 - что нового.MariaDB 10.1 - что нового.
MariaDB 10.1 - что нового.
 
Window functions in MariaDB 10.2
Window functions in MariaDB 10.2Window functions in MariaDB 10.2
Window functions in MariaDB 10.2
 
MyRocks: табличный движок для MySQL на основе RocksDB
MyRocks: табличный движок для MySQL на основе RocksDBMyRocks: табличный движок для MySQL на основе RocksDB
MyRocks: табличный движок для MySQL на основе RocksDB
 

Recently uploaded

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 

Recently uploaded (20)

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 

JSON Support in MariaDB: News, non-news and the bigger picture

  • 1. Sergei Petrunia MariaDB devroom FOSDEM 2021 JSON Support in MariaDB News, non-news, and the bigger picture FOSDEM 2021 MariaDB devroom Sergei Petrunia MariaDB developer
  • 3. 3 JSON Path ● A lot of JSON functions accept “JSON Path” expressions – locate element(s) in JSON document ● Path language in MariaDB wasn’t documented – It’s more than “foo.bar.baz” ● Caution: there are many different JSON Path definitions on the web – SQL uses SQL:2016, “SQL/JSON Path language”
  • 4. 4 SQL/JSON Path language ● mode is lax (the default) or strict ● $ is the context element (root by default) ● followed by several steps. path: [mode] $ [step]*
  • 5. 5 Object member selection step ● In strict mode, the context must be an object, it must have a member with the specified name. ● lax mode “ignores” missing elements, “unwraps” 1-element arrays .name .* { "name": "MariaDB" "version": "10.5" } $.name → "MariaDB" $.* → "MariaDB" "10.5" ● Select a member ● Select all members – produces a sequence of values
  • 6. 6 Array element selection step ● Produces a sequence of elements ● Strict mode: indexes must be within bounds [N] [*] [ 10, "abc", {"x":0} ] $[0] → 10 $[last] → {"x":0} ● Select array elements – one – range – last element – list of ^^ – all elements [N to M] [N1,N2,...] [last] $[*] →10 "abc" {"x":0}
  • 7. 7 Filters ● Predicate can have – AND/OR formulas (&&, ||) – comparisons – arithmetics – some functions – parameters passed from outside [ { "item":"Jeans", "color":"blue" }, { "item":"Laptop", "color":"black" } ] ● Filters elements in sequence ?(predicate) $[*]?(@.color=="black").item → "Laptop"
  • 8. 8 MariaDB and MySQL ● Support only lax mode – Not fully compliant: MySQL BUG#102233, MDEV-24573. ● Object member selection is supported ● Array selection: [N] is supported – MySQL also supports [last] and [N to M] ● Filters are not supported – expressions, arithmetics, functions, passing variables
  • 9. 9 Recursive search extension ● Task: find “foo” anywhere in the JSON document ● SQL/JSON Path doesn’t allow this ● Extension: wildcard search step ● Select all (direct and indirect) children: step: ** $**.price ● Example: find “price” anywhere: ● PostgreSQL also supports this, the syntax is .**
  • 10. 10 Usage example: Optimizer trace ● Optimizer Trace is JSON, log of query optimizer’s actions – Deeply-nested – “Recursive”, as SQL allows nesting of subqueries/CTEs/etc select JSON_DETAILED(JSON_EXTRACT(trace, '$**.rows_estimation')) from information_schema.optimizer_trace; ● Filters would be helpful: $**.rows_estimation?(@table=="tbl1")
  • 11. 11 JSON Path summary ● Language for pointing to node(s) in JSON document – SQL:2016, “SQL/JSON Path language” ● MariaDB and MySQL implement a subset – lax mode only – no support for filters (BAD) – array index – only [N] ● MySQL also allows [last] and [M to N] ● MySQL and MariaDB have recursive-search extension (GOOD)
  • 12. 12 JSON Path in other databases ● PostgreSQL seems have the most compliant implementation – Supports filtering, strict/lax modes, etc. ● Other databases support different and [very] restrictive subsets.
  • 14. 14 JSON_TABLE ● JSON_TABLE converts JSON input to a table – It is a “table function” – to be used in the FROM clause ● Introduced in SQL:2016 ● Supported by Oracle DB, MySQL 8 ● Under development in MariaDB – Trying to get it into 10.6
  • 15. 15 JSON_TABLE by example ● Start with a JSON document: select * from JSON_TABLE(@json_doc, '$[*]' columns(name varchar(32) path '$.name', price int path '$.price') ) as T ● Use JSON_TABLE to produce tabular output: set @json_doc=' [ {"name": "Laptop", "price": 1200}, {"name": "Jeans", "price": 60} ]';
  • 16. 16 JSON_TABLE by example ● Start with a JSON document: set @json_doc=' [ {"name": "Laptop", "price": 1200}, {"name": "Jeans", "price": 60} ]'; select * from JSON_TABLE(@json_doc, '$[*]' columns(name varchar(32) path '$.name', price int path '$.price') ) as T ● Use JSON_TABLE to produce tabular output: +--------+-------+ | name | price | +--------+-------+ | Laptop | 1200 | | Jeans | 60 | +--------+-------+
  • 17. 17 JSON_TABLE syntax select * from JSON_TABLE(@json_doc, '$[*]' columns(name varchar(32) path '$.name', price int path '$.price') ) as T Source document
  • 18. 18 JSON_TABLE syntax select * from JSON_TABLE(@json_doc, '$[*]' columns(name varchar(32) path '$.name', price int path '$.price') ) as T Source document Path to nodes to examine
  • 19. 19 JSON_TABLE syntax select * from JSON_TABLE(@json_doc, '$[*]' columns(name varchar(32) path '$.name', price int path '$.price') ) as T Source document Path to nodes to examine Column definitions
  • 20. 20 JSON_TABLE syntax select * from JSON_TABLE(@json_doc, '$[*]' columns(name varchar(32) path '$.name', price int path '$.price') ) as T Source document Path to nodes to examine Column definitions Column name Path where to get the value from. The context item is the node being examined
  • 21. 21 Nested paths set @json_doc=' [ {"name": "Laptop", "colors": ["black", "white", "red"] }, {"name": "T-Shirt", "colors": ["yellow", "blue"] } ]'; select * from JSON_TABLE(@json_doc, '$[*]' columns(name varchar(32) path '$.name', nested path '$.colors[*]' columns ( color varchar(32) path '$' ) ) ) as T
  • 22. 22 Nested paths set @json_doc=' [ {"name": "Laptop", "colors": ["black", "white", "red"] }, {"name": "T-Shirt", "colors": ["yellow", "blue"] } ]'; select * from JSON_TABLE(@json_doc, '$[*]' columns(name varchar(32) path '$.name', nested path '$.colors[*]' columns ( color varchar(32) path '$' ) ) ) as T +---------+--------+ | name | color | +---------+--------+ | Laptop | black | | Laptop | white | | Laptop | red | | T-Shirt | yellow | | T-Shirt | blue | +---------+--------+
  • 23. 23 Multiple nested paths ● NESTED PATH can be nested ● Can have “sibling” NESTED PATHs – The standard allows to specify how to unnest (“the PLAN clause”) – The default way is “outer join” like: { "name": "T-Shirt", "colors": ["yellow", "blue"], "sizes": ["Small", "Medium", "Large"] } +---------+--------+--------+ | name | color | size | +---------+--------+--------+ | T-Shirt | yellow | NULL | | T-Shirt | blue | NULL | | T-Shirt | NULL | Small | | T-Shirt | NULL | Medium | | T-Shirt | NULL | Large | +---------+--------+--------+ – MySQL (and soon MariaDB) only support “outer join”-like unnesting ● “no PLAN clause support”.
  • 24. 24 Error handling columns(column_name type path '$path' [action on empty] [action on error]) Handling missing values and/or conversion errors action: NULL default 'string' error ● on empty is used when JSON element is missing ● on error is used on datatype conversion error or non-scalar JSON. ● Both MariaDB and MySQL support this
  • 26. 26 JSON_TABLE and joins [ {"name": "Laptop", "price": 1200}, {"name": "Jeans", "price": 60} ] [ {"name": "T-Shirt", "price": 10}, {"name": "Headphones", "price": 100} ] 1 2 orders
  • 27. 27 JSON_TABLE and joins select orders.order_id, order_items.name, order_items.price from orders, JSON_TABLE(orders.items_json, '$[*]' columns(name varchar(32) path '$.name', price int path '$.price') ) as order_items +----------+------------+-------+ | order_id | name | price | +----------+------------+-------+ | 1 | Laptop | 1200 | | 1 | Jeans | 60 | | 2 | T-Shirt | 10 | | 2 | Headphones | 100 | +----------+------------+-------+ [ {"name": "Laptop", "price": 1200}, {"name": "Jeans", "price": 60} ] [ {"name": "T-Shirt", "price": 10}, {"name": "Headphones", "price": 100} ] 1 2 orders
  • 28. 28 JSON_TABLE and joins ● JSON_TABLE’s argument can refer to other tables ● LATERAL-like semantics: contents of JSON_TABLE(...) depends on the parameter ● Allows to do “normalization” for contents of columns with JSON data
  • 29. 29 JSON_TABLE Summary ● A table function to convert JSON data to relational form ● Introduced in SQL:2016 – The standard specifies a lot of features ● MySQL 8 implements a subset – PLAN clause is not supported ● MariaDB: MDEV-17399, under development – Will implement a subset very similar to MySQL
  • 30. 30 JSON_TABLE in other databases ● Quoting Markus Winand, https://modern-sql.com/slides/ModernSQL- 2019-05-30.pdf: ● PostgreSQL have JSON_TABLE under development, too.
  • 31. 31 The takeaways ● SQL:2016 introduced JSON support ● MySQL 8 has implemented a subset of it – The subset is reasonably good – There are some extensions ● MariaDB is catching up – including the extensions
  • 32. 32 The low-hanging fruits ● JSON Path: [last], [N to M] ● JSON Path: filtering support ● Improved JSON_DETAILED function – It’s a JSON pretty-printer – Used in development with JSON – It works, but is fairly dumb ● All are great to start contributing – Contact us if interested.