More Related Content
Similar to MySQL JSON Functions (20)
More from Sveta Smirnova (20)
MySQL JSON Functions
- 2. MySQL JSON Functions
Sveta Smirnova
Principal Technical Support Engineer
2Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Insert Picture Here
- 3. Program Agenda
Introduction: NoSQL involvement on MySQL
Overview of the functions
Function descriptions
Where to get
The future
3Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 4. NoSQL history
4
3.5
3
2.5
2
1.5
Main historic points of
NoSQL
1
0.5
WebSphere
MongoDB
Virtuoso
Redis
DynamoDB
MemcacheDB
Tarantool
Hbase
CouchDB
BigTable
db40 memcached
NoSQL
NoSQL Insert Chart Here term
database
0
1997
1998
2000
2003
2004
2008
Databases
4Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
2009
2010
2012
2013
- 5. NoSQL in MySQL world
Hadoop Applier
mysqlv8udfs
JSON UDFs
InnoDB with memcached
Memcache API for
MySQL Cluster
6
5
4
3
Main points for NoSQL
features in MySQL
HandlerSocket NoSQL Connector
Insert Chart Here
for JavaScript
1 Memcached bugs
EXPLAIN in JSON
at mysql.com
0
2
2009
5Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
2010
2011
2012
2013
- 6. JSON functions in MySQL
A little bit before this year
0.2
0.18
0.16
0.14
0.12
0.1
0.08
0.06
0.04
0.02
0
Version 0.2
Version 0.1
Never published
Insert Chart Here
2012
2013
6Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 7. JSON functions overview
What are they doing?
Functions
Manipulate JSON text
●
Validate
●
Search
●
Modify
UDF functions
●
Easy to install
●
Independent from MySQL server version
Work on all MySQL supported platforms
Binaries for Linux, Mac OSX 7 and Windows
7Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 10. Dependencies
Regex library
UNIX
●
Usually already exists
Windows
●
Provided with sources
●
Compiled statically
You don't need to install additional libraries to run the UDF!
10Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 11. How to compile?
UNIX
You need:
●
cmake
●
Regex library (usually already exists)
●
Working compiler
To build:
●
cmake . DMYSQL_DIR=/home/sveta/src/mysql5.5
●
make
11Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 12. How to compile?
Windows
You need: PCRE static libraries, Visual Studio and cmake (cmake.org)
To build PCRE:
●
Download sources from http://www.pcre.org/ Recommended version is 8.33 or cd pcre8.33
●
Unpack archive and run:
●
"C:Program Files (x86)CMake 2.8bincmake.exe" G "Visual Studio
11 Win64"
●
●
devenv PCRE.sln /build Release
To build JSON UDFs copy pcre.h, pcreposix.h, Release/pcre.lib,
Release/pcreposix.lib into JSON UDFs source directory, then run:
●
"C:Program Files (x86)CMake 2.8bincmake.exe" G "Visual Studio
11 Win64" . DMYSQL_DIR="C:/MySQL/mysql5.5"
●
devenv my_json_udf.sln /build Release
12Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 13. Disadvantages of UDFs
They are slow
●
Can not use certain server features, available for internal functions
●
Full-text
●
Indexes
●
Built-in optimization
13Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 14. Why UDFs?
Flexibility
●
You can install as many functions as you want: single, few or all of them
Compatible with any server version
●
You don't need to upgrade to not stable version only to try these functions
Easy to add
Easy to change
Easy to remove
Feature requests are easy to implement
●
Report bugs!
●
Raise your opinion!
14Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 16. json_valid(doc)
Checks if doc is valid JSON document.
Returns 1 if document is valid, 0 if document is invalid.
Strict format as described at http://json.org
16Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 19. json_contains_key(doc, keypart1, keypart2, ...)
Checks if documents contains specified key.
Returns 1 if key exists, 0 if not exists or NULL if parsing failed.
Warning! This version does not check whole document for validity.
19Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 20. json_contains_key(doc, keypart1, keypart2, ...)
SET optimizer_trace=1;
mysql> select user from mysql.user;
++
...
mysql> select json_contains_key(trace, 'steps', '0',
'join_optimization', 'steps', '0', 'condition_processing') as contains
from information_schema.optimizer_trace;
++
| contains |
++
| 0 |
++
1 row in set (0.01 sec)
20Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 21. json_contains_key(doc, keypart1, keypart2, ...)
mysql> select user from mysql.user where user='Sveta';
++
...
mysql> select json_contains_key(trace, 'steps', '0',
'join_optimization', 'steps', '0', 'condition_processing') as
contains from information_schema.optimizer_trace;
++
| contains |
++
| 1 |
++
1 row in set (0.01 sec)
21Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 22. json_extract(doc, keypart1, keypart2, ...)
Extracts value of the specified key.
Returns value of the key specified, NULL if the key does not exist or if
parsing failed.
Warning! This version does not check whole document for validity.
22Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 23. json_extract(doc, keypart1, keypart2, ...)
SET optimizer_trace=1;
mysql> select user from mysql.user;
++
...
mysql> select json_extract(trace, 'steps', '0', 'join_optimization',
'steps', '0', 'condition_processing') as value from
information_schema.optimizer_trace;
++
| value |
++
| NULL |
++
1 row in set (0.01 sec)
23Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 25. json_extract(doc, keypart1, keypart2, ...)
mysql> select user from mysql.user where user='Sveta';
++
...
mysql> select json_extract(trace, 'steps', '0', 'join_optimization',
'steps', '0', 'condition_processing') as value from
information_schema.optimizer_traceG
*************************** 1. row ***************************
value: {
"condition": "WHERE",
"original_condition": "(`mysql`.`user`.`User` =
'sveta')",
"steps": [
....
25Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 26. json_append(doc, keypart1, keypart2, ...,
new_element)
Inserts new element into JSON document.
Returns document with appended element, original document if no
place to insert or NULL if parsing failed.
Warning! This version does not check whole document for validity.
26Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 27. json_append(doc, keypart1, keypart2, ...,
new_element)
mysql> select json_append('{"MySQL connect": ["conference", 2013]}', 'MySQL
connect', '2', '”San Francisco”') as 'MySQL connect';
++
| MySQL connect |
++
| {"MySQL connect": ["conference", 2013, “San Francisco”]} |
++
1 row in set (0.00 sec)
27Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 28. json_append(doc, keypart1, keypart2, ...,
new_element)
mysql> select json_append('{"MySQL connect":
["conference", 2013]}', 'MySQL connect', '1', '”San
Francisco”') as 'MySQL connect';
++
| MySQL connect |
++
| {"MySQL connect": ["conference", 2013]} |
++
1 row in set (0.00 sec)
28Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 29. json_replace(doc, keypart1, keypart2, ...,
new_value)
Updates value of the specified key.
Returns document with replaced key or original document if no such an
element found, NULL if parsing failed.
Warning! This version does not check whole document for validity.
29Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 30. json_replace(doc, keypart1, keypart2, ...,
new_value)
mysql> select json_replace('{"MySQL connect":
["conference", 2013]}', 'MySQL connect', '0', '"User
conference"') as 'MySQL connect';
++
| MySQL connect |
++
| {"MySQL connect": ["User conference", 2013]} |
++
1 row in set (0.00 sec)
30Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 31. json_replace(doc, keypart1, keypart2, ...,
new_value)
mysql> select json_replace('{"MySQL connect":
["conference", 2013]}', 'MySQL connect', '2', '"User
conference"') as 'MySQL connect';
++
| MySQL connect |
++
| {"MySQL connect": ["conference", 2013]} |
++
1 row in set (0.00 sec)
31Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 32. json_set(doc, keypart1, keypart2, ..., new_value)
Performs kind of INSERT ... ON DUPLICATE KEY UPDATE operation.
Returns document with updated or inserted element or NULL if parsing
failed.
Warning! This version does not check whole document for validity.
32Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 33. json_set(doc, keypart1, keypart2, ..., new_value)
mysql> select json_set('{"MySQL connect":
["conference", 2013]}', 'MySQL connect', '0', '"User
conference"') as 'MySQL connect';
++
| MySQL connect |
++
| {"MySQL connect": ["User conference", 2013]} |
++
1 row in set (0.00 sec)
33Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 34. json_set(doc, keypart1, keypart2, ..., new_value)
mysql> select json_set('{"MySQL connect": ["conference", 2013]}', 'MySQL
connect', '2', '"San Francisco"') as 'MySQL connect';
++
| MySQL connect |
++
| {"MySQL connect": ["conference", 2013, "San Francisco"]} |
++
1 row in set (0.00 sec)
34Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 35. json_remove(doc, keypart1, keypart2, ...)
Removes element specified by the key.
Returns document without the element, original document if no element
found or NULL if parsing failed.
Warning! This version does not check whole document for validity.
35Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 36. json_remove(doc, keypart1, keypart2, ...)
mysql> select json_remove('{"MySQL connect":
["conference", 2013]}', 'MySQL connect', '1') as
'MySQL connect';
++
| MySQL connect |
++
| {"MySQL connect": ["conference"]} |
++
1 row in set (0.00 sec)
36Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 37. json_remove(doc, keypart1, keypart2, ...)
mysql> select json_remove('{"MySQL connect":
["conference", 2013]}', 'MySQL connect', '2') as
'MySQL connect';
++
| MySQL connect |
++
| {"MySQL connect": ["conference", 2013]} |
++
1 row in set (0.00 sec)
37Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 38. json_search(doc, value)
Searches for specified value in the document.
Returns key path of the element which contains the value in reverse
order or NULL if not found or parsing failed.
Warning! This version does not check whole document for validity.
38Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 41. json_merge(doc1, doc2, ...)
Merges 2 or more documents into one.
Returns first document with following documents appended.
Warning! This version does not check whole document for validity.
If one of following documents does not contain an opening curly
bracket first documents merged are returned and warning is generated.
NULL if first document does not contain an opening curly bracket.
41Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 43. json_merge(doc1, doc2, ...)
mysql> select json_merge('{"MySQL connect": ["conference", 2012]}', '{"MySQL
connect": ["conference", 2013]}', '1') as 'MySQL connect';
++
| MySQL connect |
++
| {"MySQL connect": ["conference", 2012], "MySQL connect": ["conference", 2013]} |
++
1 row in set (0.00 sec)
43Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 44. json_test_parser(doc)
Returns text representation of parse tree of the JSON document,
partial parse tree or empty string if document is invalid.
This function is supposed to use for tests only and should not be used
in production.
44Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 47. Where to get
Insert Picture Here
47Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 48. Source code and binaries
MySQL Labs
●
Source code
●
Binaries
●
x86 and x86_64
●
●
Mac OSX 10.7
●
●
Generic Linux
Windows 7
http://labs.mysql.com/
48Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 49. More information
Manuals and articles
●
README file
●
My blog: https://blogs.oracle.com/svetasmirnova/
Announces
●
My twitter: https://twitter.com/#!/svetsmirnova
49Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 51. Depends from you
Send bugs
Send feature requests
More you send – more ideas we implement
Now you can affect decisions
51Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 52. Where to report bugs and feature requests
MySQL Community bugs database
●
https://bugs.mysql.com/
●
No special category for now
●
General category
●
“MySQL Server: User-defined functions (UDF)”
Internal Oracle bugs database
●
Ask MySQL Support engineer to open a bug report for you
●
Category “UDFJSON”
52Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 53. More NoSQL
Sessions at MySQL Connect
MySQL and Hadoop: Big Data Integration—Unlocking New Insights [CON2053,
Sunday, 11:30 AM]
MySQL User-Defined Functions....in JavaScript! [CON1738, passed]
Oracle NoSQL Database: When Is It the Right Tool for the Job? [CON13034,
Saturday, 4:00 PM]
MySQL As a NoSQL Store with the InnoDB/memcached Plug-in [CON3457,
Sunday, 1:00 PM]
MySQL’s EXPLAIN Command New Features [HOL9734, passed]
Big Data with MySQL and Hadoop [CON2342, Sunday, 5:30 PM]
53Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
- 58. 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.
58Copyright © 2013, Oracle and/or its affiliates. All rights reserved.