The MySQL 5.7.7 JSON Lab release introduces a native JSON datatype. See Knut Anders Hatlen’s blog post for more details on this new datatype. In this release we also introduced a number of functions for creating and querying JSON documents. In this post we’ll explore the following new functions related to manipulating JSON documents:
jsn_array()
jsn_object()
jsn_insert()
jsn_remove()
jsn_set()
jsn_replace()
jsn_append()
jsn_merge()
jsn_extract()
Dag Wanvik’s follow up blog post will explore the functions related to querying and searching of JSON documents. More information on all of the new JSON functions can be found in the high level spec attached to WL#7909.
Creating JSON Data
Let’s start out by creating some simple JSON data. Suppose that we were using the JSON datatype to store large numbers of temperature readings coming from smart thermostats. We might find the following tables useful:
1
2
3
4
5
6
|
mysql> create table thermostat_model -> (model_id varchar(50) primary key, capabilities json); Query OK, 0 rows affected (0.21 sec) mysql> create table thermostat_reading( reading json ); Query OK, 0 rows affected (0.22 sec) |
Imagine that the ‘capabilities’ document is just an array of tags. Let’s create one of these arrays by using the new JSN_ARRAY()
function. This function evaluates a variable length list of expressions and inserts them into a JSON array, one after the other:
1
2
3
4
5
6
7
|
mysql> select jsn_array( 'programmable','fan', 'ac', 'furnace' ) json_array; +------------------------------------------+ | json_array | +------------------------------------------+ | ["programmable", "fan", "ac", "furnace"] | +------------------------------------------+ 1 row in set (0.04 sec) |
That’s easy. Alternatively, we could just insert valid JSON text into a JSON column. MySQL will then parse the text and convert it into the native JSON binary storage format:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
mysql> insert into thermostat_model values -> ( 'xyzzy', '[ "programmable","fan", "ac", "furnace" ]' ), -> ( 'abc123', '[ "fan", "furnace" ]' ); Query OK, 2 rows affected (0.05 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> select * from thermostat_model; +----------+------------------------------------------+ | model_id | capabilities | +----------+------------------------------------------+ | abc123 | ["fan", "furnace"] | | xyzzy | ["programmable", "fan", "ac", "furnace"] | +----------+------------------------------------------+ 2 rows in set (0.00 sec) |
In addition to JSN_ARRAY()
, there’s also a JSN_OBJECT()
constructor function. As you might guess, JSN_OBJECT()
builds JSON objects from a variable length list of key/value pairs. Here’s an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
mysql> select jsn_object -> ( -> 'device_id', 3001, -> 'unixtime', 1428440461, -> 'setting', 64.0, -> 'current_temp', 62.05 -> ) json_object; +-------------------------------------------------------------------------------------+ | json_object | +-------------------------------------------------------------------------------------+ | {"setting": 64.0, "unixtime": 1428440461, "device_id": 3001, "current_temp": 62.05} | +-------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) |
Again, we can alternatively just put valid JSON text into our table of thermostat readings:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
mysql> insert into thermostat_reading values -> ( '{ "device_id": 3001, "unixtime": 1428462061, "setting": 69.0, "current_temp": 62.05 }' ), -> ( '{ "device_id": 3001, "unixtime": 1428483661, "setting": 64.0, "current_temp": 70.25 }' ), -> ( '{ "device_id": 3002, "unixtime": 1428462061, "setting": 68.0, "current_temp": 61.05 }' ), -> ( '{ "device_id": 3002, "unixtime": 1428483661, "setting": 62.0, "current_temp": 71.25 }' ); Query OK, 4 rows affected (0.05 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql> select * from thermostat_reading; +-----------------------------------------------------------------------------------+ | reading | +-----------------------------------------------------------------------------------+ | {"setting": 69, "unixtime": 1428462061, "device_id": 3001, "current_temp": 62.05} | | {"setting": 64, "unixtime": 1428483661, "device_id": 3001, "current_temp": 70.25} | | {"setting": 68, "unixtime": 1428462061, "device_id": 3002, "current_temp": 61.05} | | {"setting": 62, "unixtime": 1428483661, "device_id": 3002, "current_temp": 71.25} | +-----------------------------------------------------------------------------------+ 4 rows in set (0.00 sec) |
Schema Evolution: Adding Data
Of course, in the real world, data changes over time, in-step with the applications which use it. Suppose that we, the thermostat maker, realize that we can’t tell whether our thermostats are actually on and therefore doing their jobs. Let’s say that we remotely upgrade all of our thermostats so that they start reporting their on/off state. Eventually, our table of thermostat readings will contain old records which don’t report on/off state as well as new records which do:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
mysql> insert into thermostat_reading values -> ( '{"on": true, "setting": 69, "unixtime": 1428548461, "device_id": 3001, "current_temp": 62.05}' ), -> ( '{"on": false, "setting": 64, "unixtime": 1428570061, "device_id": 3001, "current_temp": 75.25}' ), -> ( '{"on": true, "setting": 68, "unixtime": 1428548461, "device_id": 3002, "current_temp": 61.05}' ), -> ( '{"on": false, "setting": 62, "unixtime": 1428570061, "device_id": 3002, "current_temp": 76.25}' ); Query OK, 4 rows affected (0.03 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql> select * from thermostat_reading; +------------------------------------------------------------------------------------------------+ | reading | +------------------------------------------------------------------------------------------------+ | {"setting": 69, "unixtime": 1428462061, "device_id": 3001, "current_temp": 62.05} | | {"setting": 64, "unixtime": 1428483661, "device_id": 3001, "current_temp": 70.25} | | {"setting": 68, "unixtime": 1428462061, "device_id": 3002, "current_temp": 61.05} | | {"setting": 62, "unixtime": 1428483661, "device_id": 3002, "current_temp": 71.25} | | {"on": true, "setting": 69, "unixtime": 1428548461, "device_id": 3001, "current_temp": 62.05} | | {"on": false, "setting": 64, "unixtime": 1428570061, "device_id": 3001, "current_temp": 75.25} | | {"on": true, "setting": 68, "unixtime": 1428548461, "device_id": 3002, "current_temp": 61.05} | | {"on": false, "setting": 62, "unixtime": 1428570061, "device_id": 3002, "current_temp": 76.25} | +------------------------------------------------------------------------------------------------+ 8 rows in set (0.00 sec) |
We now want to fix the old data so that it also contains the on/off state. For our purposes here, it’s ok that the old records say that the on/off state is NULL (meaning “unknown”). We can use the new JSN_INSERT()
function to do this. JSN_INSERT()
adds missing data to JSON documents. However, it won’t override data that’s already there. JSN_INSERT()
takes 3 arguments: the document to be modified, a path expression (see below) locating the part of the document to change, and a value to be inserted at the indicated location:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
mysql> update thermostat_reading set reading = jsn_insert( reading, '$.on', cast( 'null' as json ) ); Query OK, 4 rows affected (0.05 sec) Rows matched: 8 Changed: 4 Warnings: 0 mysql> select * from thermostat_reading; +------------------------------------------------------------------------------------------------+ | reading | +------------------------------------------------------------------------------------------------+ | {"on": null, "setting": 69, "unixtime": 1428462061, "device_id": 3001, "current_temp": 62.05} | | {"on": null, "setting": 64, "unixtime": 1428483661, "device_id": 3001, "current_temp": 70.25} | | {"on": null, "setting": 68, "unixtime": 1428462061, "device_id": 3002, "current_temp": 61.05} | | {"on": null, "setting": 62, "unixtime": 1428483661, "device_id": 3002, "current_temp": 71.25} | | {"on": true, "setting": 69, "unixtime": 1428548461, "device_id": 3001, "current_temp": 62.05} | | {"on": false, "setting": 64, "unixtime": 1428570061, "device_id": 3001, "current_temp": 75.25} | | {"on": true, "setting": 68, "unixtime": 1428548461, "device_id": 3002, "current_temp": 61.05} | | {"on": false, "setting": 62, "unixtime": 1428570061, "device_id": 3002, "current_temp": 76.25} | +------------------------------------------------------------------------------------------------+ 8 rows in set (0.00 sec) |
Note that the old rows say that they don’t know what the on/off state was (NULL value). Also note that the new rows weren’t touched.
Looking more closely at the UPDATE statement, you might wonder:
- What’s that strange ‘
$.on
‘ argument? - Why do I need to
CAST
my NULL to JSON?
First, let’s talk about the ‘$.on
‘ argument. That’s a path expression. It’s the address of a value inside a JSON document. A path expression starts with a $, which indicates the root of the path. For all of the new JSON functions, the root is always indicated by $ and it always means “the selected document”. After the $ come an arbitrarily long sequence of member names and array indexes, which drill down to values nested (possibly deeply) inside the document. Member names are indicated by . and then the name of a key. Array indexes are just numbers enclosed in square brackets. For example, the path expression
$.fred.children[3] means “The 3rd child of fred inside the selected document”. Don’t worry too much about this right now though. The path expressions in this blog are all very simple. For example, in our UPDATE
statement above,
$.on means “The ‘on’ member of the selected document”.
All right, now what about that CAST
? Without the CAST
, the NULL argument would cause the whole JSN_INSERT()
expression to evaluate to NULL. And that would clobber the old rows. Furthermore,
CAST(NULL AS JSON) would have the same effect. The problem is that there is a difference between a JSON null literal and a SQL NULL. The way that you create a JSON null literal is to CAST
some valid JSON text which contains just the null literal.
Don’t worry if this seems tricky right now. As you play around with the new JSON functions, you will quickly learn how to handle JSON null literals. For the rest of this blog post, we won’t have to bother with SQL NULLs.
Schema Evolution: Removing Data
Any time that you add data, you need to have the option to remove it later on. Suppose that we, the thermostat maker, decide that it was a bad idea to add that on/off state. We’ll need to remotely upgrade all of our thermostats again. We’ll tell them to stop reporting on/off state. Afterward, we’ll want to scrub the on/off cruft from our old thermostat readings. For this purpose, we use the new JSN_REMOVE()
function. JSN_REMOVE()
takes a document argument along with a path expression locating the data to be removed. Here’s how we remove all of those on/off indicators:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
mysql> update thermostat_reading set reading = jsn_remove( reading, '$.on' ); Query OK, 8 rows affected (0.03 sec) Rows matched: 8 Changed: 8 Warnings: 0 mysql> select * from thermostat_reading; +-----------------------------------------------------------------------------------+ | reading | +-----------------------------------------------------------------------------------+ | {"setting": 69, "unixtime": 1428462061, "device_id": 3001, "current_temp": 62.05} | | {"setting": 64, "unixtime": 1428483661, "device_id": 3001, "current_temp": 70.25} | | {"setting": 68, "unixtime": 1428462061, "device_id": 3002, "current_temp": 61.05} | | {"setting": 62, "unixtime": 1428483661, "device_id": 3002, "current_temp": 71.25} | | {"setting": 69, "unixtime": 1428548461, "device_id": 3001, "current_temp": 62.05} | | {"setting": 64, "unixtime": 1428570061, "device_id": 3001, "current_temp": 75.25} | | {"setting": 68, "unixtime": 1428548461, "device_id": 3002, "current_temp": 61.05} | | {"setting": 62, "unixtime": 1428570061, "device_id": 3002, "current_temp": 76.25} | +-----------------------------------------------------------------------------------+ 8 rows in set (0.00 sec) |
Schema Evolution: Updating Data
Suppose that we, the thermostat maker, upgrade our thermostats so that they contain a new piece of data, the “spread” or difference between the thermostat setting and the actual room temperature. Newer thermostat readings will contain this new data but older readings won’t:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
mysql> insert into thermostat_reading values -> ( '{"spread": 3.95, "setting": 69, "unixtime": 1428634861, "device_id": 3001, "current_temp": 65.05}' ), -> ( '{"spread": -12.25, "setting": 64, "unixtime": 1428656461, "device_id": 3001, "current_temp": 76.25}' ), -> ( '{"spread": 1.95, "setting": 68, "unixtime": 1428634861, "device_id": 3002, "current_temp": 66.05}' ), -> ( '{"spread": -15.25, "setting": 62, "unixtime": 1428656461, "device_id": 3002, "current_temp": 77.25}' ); Query OK, 4 rows affected (0.03 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql> select * from thermostat_reading; +-----------------------------------------------------------------------------------------------------+ | reading | +-----------------------------------------------------------------------------------------------------+ | {"setting": 69, "unixtime": 1428462061, "device_id": 3001, "current_temp": 62.05} | | {"setting": 64, "unixtime": 1428483661, "device_id": 3001, "current_temp": 70.25} | | {"setting": 68, "unixtime": 1428462061, "device_id": 3002, "current_temp": 61.05} | | {"setting": 62, "unixtime": 1428483661, "device_id": 3002, "current_temp": 71.25} | | {"setting": 69, "unixtime": 1428548461, "device_id": 3001, "current_temp": 62.05} | | {"setting": 64, "unixtime": 1428570061, "device_id": 3001, "current_temp": 75.25} | | {"setting": 68, "unixtime": 1428548461, "device_id": 3002, "current_temp": 61.05} | | {"setting": 62, "unixtime": 1428570061, "device_id": 3002, "current_temp": 76.25} | | {"spread": 3.95, "setting": 69, "unixtime": 1428634861, "device_id": 3001, "current_temp": 65.05} | | {"spread": -12.25, "setting": 64, "unixtime": 1428656461, "device_id": 3001, "current_temp": 76.25} | | {"spread": 1.95, "setting": 68, "unixtime": 1428634861, "device_id": 3002, "current_temp": 66.05} | | {"spread": -15.25, "setting": 62, "unixtime": 1428656461, "device_id": 3002, "current_temp": 77.25} | +-----------------------------------------------------------------------------------------------------+ 12 rows in set (0.00 sec) |
We can use the JSN_SET()
function to update the old records. JSN_SET()
behaves much like JSN_INSERT()
except that it also overrides existing values:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
mysql> update thermostat_reading set reading = jsn_set -> ( -> reading, -> '$.spread', -> cast( jsn_extract( reading, '$.current_temp' ) as decimal(5,2) ) - cast( jsn_extract( reading, '$.setting' ) as decimal(5,2) ) -> ); Query OK, 12 rows affected (0.04 sec) Rows matched: 12 Changed: 12 Warnings: 0 mysql> select * from thermostat_reading; +----------------------------------------------------------------------------------------------------+ | reading | +----------------------------------------------------------------------------------------------------+ | {"spread": -6.95, "setting": 69, "unixtime": 1428462061, "device_id": 3001, "current_temp": 62.05} | | {"spread": 6.25, "setting": 64, "unixtime": 1428483661, "device_id": 3001, "current_temp": 70.25} | | {"spread": -6.95, "setting": 68, "unixtime": 1428462061, "device_id": 3002, "current_temp": 61.05} | | {"spread": 9.25, "setting": 62, "unixtime": 1428483661, "device_id": 3002, "current_temp": 71.25} | | {"spread": -6.95, "setting": 69, "unixtime": 1428548461, "device_id": 3001, "current_temp": 62.05} | | {"spread": 11.25, "setting": 64, "unixtime": 1428570061, "device_id": 3001, "current_temp": 75.25} | | {"spread": -6.95, "setting": 68, "unixtime": 1428548461, "device_id": 3002, "current_temp": 61.05} | | {"spread": 14.25, "setting": 62, "unixtime": 1428570061, "device_id": 3002, "current_temp": 76.25} | | {"spread": -3.95, "setting": 69, "unixtime": 1428634861, "device_id": 3001, "current_temp": 65.05} | | {"spread": 12.25, "setting": 64, "unixtime": 1428656461, "device_id": 3001, "current_temp": 76.25} | | {"spread": -1.95, "setting": 68, "unixtime": 1428634861, "device_id": 3002, "current_temp": 66.05} | | {"spread": 15.25, "setting": 62, "unixtime": 1428656461, "device_id": 3002, "current_temp": 77.25} | +----------------------------------------------------------------------------------------------------+ 12 rows in set (0.00 sec) |
Note that “spread” values are added to records which didn’t have them. And we updated the existing “spread” values. Oops! We didn’t mean to do that! We got the computation backward. We meant to compute “spread” the opposite way, the way that the thermostats compute it, viz., by subtracting the actual temperature from the thermostat setting. Not a problem. We’ll fix that in a moment. But before we do, you might be wondering about that other function which we just introduced, JSN_EXTRACT()
. JSN_EXTRACT()
returns a value nested inside of a JSON document. JSN_EXTRACT()
locates the value by its path address.
OK, now let’s fix our thermostat readings. For this task, we use another update function, JSN_REPLACE()
. JSN_REPLACE()
behaves the opposite way that JSN_INSERT()
does: JSN_REPLACE()
won’t touch records with missing data. JSN_REPLACE()
only updates records where the data is present:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
mysql> update thermostat_reading set reading = jsn_replace -> ( -> reading, -> '$.spread', -> cast( jsn_extract( reading, '$.setting' ) as decimal(5,2) ) - cast( jsn_extract( reading, '$.current_temp' ) as decimal(5,2) ) -> ); Query OK, 12 rows affected (0.04 sec) Rows matched: 12 Changed: 12 Warnings: 0 mysql> select * from thermostat_reading; +-----------------------------------------------------------------------------------------------------+ | reading | +-----------------------------------------------------------------------------------------------------+ | {"spread": 6.95, "setting": 69, "unixtime": 1428462061, "device_id": 3001, "current_temp": 62.05} | | {"spread": -6.25, "setting": 64, "unixtime": 1428483661, "device_id": 3001, "current_temp": 70.25} | | {"spread": 6.95, "setting": 68, "unixtime": 1428462061, "device_id": 3002, "current_temp": 61.05} | | {"spread": -9.25, "setting": 62, "unixtime": 1428483661, "device_id": 3002, "current_temp": 71.25} | | {"spread": 6.95, "setting": 69, "unixtime": 1428548461, "device_id": 3001, "current_temp": 62.05} | | {"spread": -11.25, "setting": 64, "unixtime": 1428570061, "device_id": 3001, "current_temp": 75.25} | | {"spread": 6.95, "setting": 68, "unixtime": 1428548461, "device_id": 3002, "current_temp": 61.05} | | {"spread": -14.25, "setting": 62, "unixtime": 1428570061, "device_id": 3002, "current_temp": 76.25} | | {"spread": 3.95, "setting": 69, "unixtime": 1428634861, "device_id": 3001, "current_temp": 65.05} | | {"spread": -12.25, "setting": 64, "unixtime": 1428656461, "device_id": 3001, "current_temp": 76.25} | | {"spread": 1.95, "setting": 68, "unixtime": 1428634861, "device_id": 3002, "current_temp": 66.05} | | {"spread": -15.25, "setting": 62, "unixtime": 1428656461, "device_id": 3002, "current_temp": 77.25} | +-----------------------------------------------------------------------------------------------------+ 12 rows in set (0.00 sec) |
Schema Evolution: Appending Data
Now suppose that we need to append new data to old data, rather than completely clobbering the old data. Suppose that we, the thermostat maker, have upgraded our thermostats. We’ve added a variable speed fan control to one of the models. After the upgrade, we need to record the new capability in our thermostat metadata. We can use JSN_APPEND()
to do this. JSN_APPEND()
adds a value to the end of an array:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
mysql> update thermostat_model -> set capabilities = jsn_append( capabilities, '$', 'smart_fan' ) -> where model_id = 'xyzzy'; Query OK, 1 row affected (0.04 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from thermostat_model; +----------+-------------------------------------------------------+ | model_id | capabilities | +----------+-------------------------------------------------------+ | abc123 | ["fan", "furnace"] | | xyzzy | ["programmable", "fan", "ac", "furnace", "smart_fan"] | +----------+-------------------------------------------------------+ 2 rows in set (0.00 sec) |
Now suppose that we further upgrade one of our thermostat models with a package of several security features. Let’s use the new JSN_MERGE()
function to correspondingly update our metadata. JSN_MERGE()
is a very powerful function. It can merge two arrays together, and that’s what we’re going to do. (It can also merge two objects together, member by member, level by level.) JSN_MERGE()
takes a variable length list of JSON documents and it merges them into one composite document:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
mysql> update thermostat_model -> set capabilities = jsn_merge( capabilities, jsn_array( 'https', 'password_protected', 'intrusion_detection' ) ) -> where model_id = 'xyzzy'; Query OK, 1 row affected (0.04 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from thermostat_model; +----------+-------------------------------------------------------------------------------------------------------------+ | model_id | capabilities | +----------+-------------------------------------------------------------------------------------------------------------+ | abc123 | ["fan", "furnace"] | | xyzzy | ["programmable", "fan", "ac", "furnace", "smart_fan", "https", "password_protected", "intrusion_detection"] | +----------+-------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec) |
Schema Evolution: Indexing JSON Data
We started out dumping our thermostat readings onto a heap. Over time, we will want to query these readings. So we’ll want a useful index. Let’s add a virtual column to the thermostat reading table and then index that column. This will allow us to quickly look up thermostat readings based on the thermostat’s unique id:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
mysql> alter table thermostat_reading -> add column device_id int generated always as ( jsn_extract( reading, '$.device_id' ) ) virtual; Query OK, 0 rows affected (0.08 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> create index tr_di on thermostat_reading( device_id ); Query OK, 12 rows affected (0.57 sec) Records: 12 Duplicates: 0 Warnings: 0 mysql> select * from thermostat_reading where device_id = 3001; +-----------------------------------------------------------------------------------------------------+-----------+ | reading | device_id | +-----------------------------------------------------------------------------------------------------+-----------+ | {"spread": 6.95, "setting": 69, "unixtime": 1428462061, "device_id": 3001, "current_temp": 62.05} | 3001 | | {"spread": -6.25, "setting": 64, "unixtime": 1428483661, "device_id": 3001, "current_temp": 70.25} | 3001 | | {"spread": 6.95, "setting": 69, "unixtime": 1428548461, "device_id": 3001, "current_temp": 62.05} | 3001 | | {"spread": -11.25, "setting": 64, "unixtime": 1428570061, "device_id": 3001, "current_temp": 75.25} | 3001 | | {"spread": 3.95, "setting": 69, "unixtime": 1428634861, "device_id": 3001, "current_temp": 65.05} | 3001 | | {"spread": -12.25, "setting": 64, "unixtime": 1428656461, "device_id": 3001, "current_temp": 76.25} | 3001 | +-----------------------------------------------------------------------------------------------------+-----------+ 6 rows in set (0.00 sec) mysql> explain format=JSON select * from thermostat_reading where device_id = 3001\G *************************** 1. row *************************** EXPLAIN: { "query_block": { "select_id": 1, "cost_info": { "query_cost": "1.44" }, "table": { "table_name": "thermostat_reading", "access_type": "ref", "possible_keys": [ "tr_di" ], "key": "tr_di", "used_key_parts": [ "device_id" ], "key_length": "5", "ref": [ "const" ], "rows_examined_per_scan": 1, "rows_produced_per_join": 1, "filtered": "100.00", "cost_info": { "read_cost": "1.20", "eval_cost": "0.24", "prefix_cost": "1.44", "data_read_per_join": "28" }, "used_columns": [ "reading", "device_id" ] } } } 1 row in set, 1 warning (0.00 sec) |
Please see Jimmy Yang’s blog post for further details on the new “functional index” work that has also been added in the MySQL 5.7.7 JSON Lab release.
Now you’re ready to create and manipulate JSON data! You’re encouraged to go on and read Dag Wanvik’s follow up blog post on this topic. His blog post describes the new query and search related JSON functions introduced by the MySQL 5.7.7 JSON Lab release, namely:
jsn_search()
jsn_contains()
jsn_contains_path()
jsn_valid()
jsn_type()
jsn_keys()
jsn_length()
jsn_depth()
jsn_unquote()
jsn_quote()
Please let us know what you think of these new JSON features! We’d love to hear your feedback on what else you’d like to see related to our wider JSON support. If you encounter any problems with these new features, please let us know here in the comments, open a bug report at bugs.mysql.com, or open a support ticket.
Thank you for using MySQL!