More Related Content
Similar to Power of SQL and NoSQL with MySQL5.7 (20)
More from Shinya Sugiyama (20)
Power of SQL and NoSQL with MySQL5.7
- 1. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Combining the Power of SQL and NoSQL
Databases with MySQL
Oracle Code 2017 in Tokyo
Shinya Sugiyama
Master Principal Sales Consultant
MySQL Global Business Unit
May 18, 2017
- 2. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Safe Harbor Statement
以下の事項は、弊社の一般的な製品の方向性に関する概要を説明するものです。
また、情報提供を唯一の目的とするものであり、いかなる契約にも組み込むことはでき
ません。以下の事項は、マテリアルやコード、機能を提供することをコミットメントするも
のではない為、購買決定を行う際の判断材料になさらないで下さい。
オラクル製品に関して記載されている機能の開発、リリースおよび時期については、
弊社の裁量により決定されます。
2
- 3. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Today’s Agenda
3
Introduction
Core New JSON Features
Use Cases
Document Store Enhancement feature
1
2
3
4
- 4. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 4
例) DB-Enginesによる調査結果
MySQL is the 2nd most popular database!
■ グローバルで多くの利用者
■ グローバルで多くの人材
■ 多種・多用な管理ツール
■ Oracle社が企業として対応
- バージョンリリース、パッチ
http://bugs.mysql.com/
- フルタイムの専任開発者
- 開発ロードマップ(ユーザベース)
- 組み込み利用時のIP対応
http://db-engines.com/en/
データベースソフトウェアの普及度や
人気を、インターネット上の求人情報
や職務経歴上での経験、および検索
エンジンやSNSでの情報量を元に、
毎月作成し公開。
- 5. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 5
Mile Stone of MySQL
4.0
全文検索/GIS (MyISAM)
複数テーブルUPDATE/DELETE
組み込みライブラリ型サーバ
OracleMySQL AB Sun
3.23
MyISAM
InnoDB
レプリケーション
5.1
プラグガブル・
ストレージエンジン・
アーキテクチャ
パーティショニング
タスクスケジューラ
5.6
memcached API
UNDO表領域
Global Transaction ID
マルチスレッドスレーブ(DB)
オンラインALTER TABLE
トランスポータブル表領域
5.5
InnoDBがデフォルトに
準同期型レプリケーション
PERFORMANCE_SCHEMA
1.0-3.22以前
ストレージエンジン (ISAM, HEAP)
マルチスレッド
Windows対応/64bit対応
日本語文字コード (SJIS/UJIS)
5.0
ストアドプロシージャ
ストアドファンクション
カーソル/トリガ/ビュー
XAトランザクション
INFORMATION_SCHEMA
4.1
Unicode対応
サブクエリ
CSV, ARCHIVE
ndbcluster
1995 2000 2005 2010 2015
5.7
2015年10月21日 - 5.7.9 GA
新コストモデル オプティマイザ
ロスレス レプリケーション
マルチソース レプリケーション
グループ レプリケーション
マルチスレッドスレーブ
全文検索CJK対応/GIS (InnoDB)
セキュリティ強化 (コンプライアンス対応)
NoSQLオプション (JSON)
General Tablespace
Performance: Benchmark
8.0
Character (UNICODE9.0)
Invisible Indexes
セキュリティROLE追加
Descending Index
Common Table Exp (CTE)
Windows Functions
- 6. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Application
MySQLは10億人以上のユーザーが使用するFacebookを支え
ています。Facebookでは、数万台のMySQLサーバーを使用し、
典型的なサーバーでは1~2TBのデータを保持。
1秒当たり1120万行の更新処理と2.5億行の参照処理
http://www.facebook.com/ User:16億5,000万人
※ 2015年12月のデイリーアクティブ利用者は10億4,000万人
※ 2015年12月31日時点での月間アクティブ利用者数は15億9,000万人
Facebook
Twitter
Application
典型的な日では、1日当たり5億ツイート(つまり、1秒当たり約
5,700ツイート)以上をMySQLで処理しています。2013年8月に
は、世界新記録となる143,199ツイート/秒を記録しました。
https://twitter.com/ User:3億2,000万人
- 7. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Application
YouTubeでは、毎月6億時間以上の動画が再生されてい
ます。そして、毎分100時間の動画がアップロードされて
います。あなたがYouTubeで動画を見る場合、そのデータ
はMySQLから取得されています。
https://www.youtube.com User:10 億人以上
YouTube
Booking.com Application
Booking.comは2003年からMySQLを使用しています。
MySQLはアジャイル開発モデルとBooling.comの60-70%
の年間成長率を支えています。毎日、70万部屋が
Booking.comを通して予約されています。
• 60 MB/秒 (イベントのデータ量)
• 20億イベント/日
• 15 TB のデータ量(イベント処理、検索、など)
• 150 TB のデータ量(アーカイブ用)
http://www.booking.com 施設:220カ国・810,000以上の宿泊施設
- 8. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
MySQL Powers the Cloud
MySQL導入事例:
https://www-jp.mysql.com/why-mysql/case-studies/
最新事例:
アンリツ株式会社様
株式会社 oricon ME様
参考:
株式会社スクウェア・エニックス様
ソニー株式会社様
- 9. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Today’s Agenda
9
Introduction
Core New JSON Features
Use Cases
Document Store Enhancement feature
1
2
3
2
1
4
- 10. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
MySQL 5.7 is GA – October 2015
InnoDBの機能拡張:
Online&Bulk load オペレーション高速化
レプリケーションの改善と拡張
(multi-source, multi-threaded slaves等)
新しいオプティマイザコストモデル:
greater user control & better query performance
JSONのSupport
(ドキュメント管理サポート)
セキュリティの向上:
より安全な初期化, セットアップ&管理
パフォーマンス & 拡張性 管理性
MySQL 5.6比3倍の速度
Performance Schema拡張
MySQL SYS Schema改善
10
- 11. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Core New JSON features in MySQL 5.7
1.JSONデータ型
2.JSONデータ参照処理
3.生成列とインデックス
4.JSON関数
5.JSON Comparator
11
- 12. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JSONデータ型: Create and Insert
12
CREATE TABLE employees (data JSON);
INSERT INTO employees VALUES ('{"id": 1, "name": "Jane"}');
INSERT INTO employees VALUES ('{"id": 2, "name": "Joe"}');
SELECT * FROM employees;
+---------------------------+
| data |
+---------------------------+
| {"id": 1, "name": "Jane"} |
| {"id": 2, "name": "Joe"} |
+---------------------------+
2 rows in set (0,00 sec)
JSONデータ型を指定して、テーブル内に列を作成
JSON配列は内カンマで区切られ、囲まれた値のリスト[と]の文字が含まれています。
JSONオブジェクトは、{と}文字以内カンマで区切られ、囲まれたキー/値のペアのセットが含まれています。
- 13. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
JSONデータ型:Specifications
ネイティブJSONデータ型 (バイナリ形式)
Insert時のJSON構文バリデーション機能
組み込みJSON関数 (保存、検索、更新、操作)
ドキュメントにインデックス設定し高速アクセス
SQLとの統合を容易にする、新しいインライン構文
utf8mb4の文字セットとutf8mb4_binの照合 「🐬」
サイズはmax_allowed_packetの値で制限 (Default:4MB)
外部サイト
/SNS
モバイル
デバイス
コマース
/ポータル
その他
(data JSON);
REST/JSON
mysql> select feature from NEW57.features where json_extract(feature,'$.properties.STREET') = 'MARKET'
limit 1¥G
************** 1. row **************
feature: {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[-122.39836263491878,
37.79189388899312, 0], [-122.39845248797837, 37.79233030084018, 0], [-122.39768507706792,
37.7924280850133, 0], [-122.39836263491878, 37.79189388899312, 0]]]}, "properties": {"TO_ST": "388",
"BLKLOT": "0265003", "STREET": "MARKET", "FROM_ST": "388", "LOT_NUM": "003", "ST_TYPE": "ST",
"ODD_EVEN": "E", "BLOCK_NUM": "0265", "MAPBLKLOT": "0265003"}}
13
- 14. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 14
JSONで表現する全てのデータ型をサポート
•数値, 文字列, bool(true,false)
•オブジェクト {“キー”: “値”}, 配列 [123456, “String”, …]
•null
拡張
•日付(date), 時刻, 日付(datetime), タイムスタンプ, その他
[CONFIRM]> show create table T_JSON_SUPPORT¥G
*************************** 1. row ***************************
Table: T_JSON_SUPPORT
Create Table: CREATE TABLE `T_JSON_SUPPORT` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`body` json DEFAULT NULL,
`type` varchar(20) GENERATED ALWAYS AS (json_type(`body`)) VIRTUAL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4
[CONFIRM]> select * from T_JSON_SUPPORT;
+----+---------------------------------------------+----------+
| id | body | type |
+----+---------------------------------------------+----------+
| 1 | 123456789 | INTEGER |
| 2 | NULL | NULL |
| 3 | true | BOOLEAN |
| 4 | "abcde" | STRING |
| 5 | {“id”: 5, “name”: “オブジェクト”} | OBJECT |
| 6 | [-122.42200352825247, 37.80848009696725, 0] | ARRAY |
| 7 | "2016-02-29" | DATE |
| 8 | "2016-02-29 00:00:00.000000" | DATETIME |
+----+---------------------------------------------+----------+
JSONデータ型: Specifications jQuery.type(123) →number
jQuery.type("123") → string
jQuery.type([1,2,3]) → array
- 15. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
TEXT/VARCHARと比較した場合の優位性
1. JSONドキュメントデータ形式の検証
2. 効率の良い、バイナリーフォーマットでストレージエンジンに格納し、
15
INSERT INTO employees VALUES ('some random text');
ERROR 3130 (22032): Invalid JSON text:
"Expect a value here." at position 0 in value (or column) 'some random text'.
出力時にテキスト変換している為、オブジェクトメンバと配列要素への
参照性能が向上
- 16. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
検証: 実生活のデータを用いた参照処理
• Via SF OpenData
• 206,560件のJSONデータ (Approx:230MB)
[検証用テーブル]
[検証用データ]
https://github.com/zemirco/sf-city-lots-json
http://mysqlserverteam.com/taking-the-new-mysql-5-7-json-features-for-a-test-drive/
16
CREATE TABLE features (
id INT NOT NULL auto_increment primary key,
feature JSON NOT NULL );
位置情報を含む、サンフランシスコの区, 市, 郡を表現した地域データ
- 17. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 17
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates":
[
[
[-122.42172266586077,37.805880378752626,0],
[-122.42180807535102,37.80586933951822,0],
[-122.42180534242786,37.80585577934527,0],
[-122.42195480811408,37.805836461229084,0],
[-122.42198623402446,37.80599239421059,0],
[-122.42175135840604,37.806022752521805,0],
[-122.42172266586077,37.805880378752626,0]
]
]
},
"properties": {
"TO_ST": "799",
"BLKLOT": "0025023",
"STREET": "BEACH",
"FROM_ST": "799",
"LOT_NUM": "023",
"ST_TYPE": "ST",
"ODD_EVEN": "O",
"BLOCK_NUM": "0025",
"MAPBLKLOT": "0025023"
}
}
ロケーション情報等
を含むJSONデータ
- 18. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JSON関数と参照処理
18
SET @document = '[10, 20, [30, 40]]';
SELECT JSON_EXTRACT(@document, '$[1]');
+---------------------------------+
| JSON_EXTRACT(@document, '$[1]') |
+---------------------------------+
| 20 |
+---------------------------------+
1 row in set (0.01 sec)
JSON_EXTRACTによる
基本的な参照処理
MySQLでJSONデータを参照する為の基本関数
- 19. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JSON_EXTRACTの省略演算子
• Accepts a JSON Path, which is similar to a selector:
• JSON_EXTRACTでは、2つの省略形をサポートしています:
column_name->"$.type" (extract)
column_name->>"$.type" (extract + unquote)
19
$("#type") JSON_EXTRACT
(column_name, "$.type")
- 20. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
SELECT DISTINCT
JSON_EXTRACT(feature,"$.type")
as feature_type FROM features;
+--------------+
| feature_type |
+--------------+
| "Feature" |
+--------------+
1 row in set (1.00 sec)
20
EX: JSON_EXTRACTの省略演算子
SELECT DISTINCT feature->"$.type" as
feature_type FROM features;
+--------------+
| feature_type |
+--------------+
| "Feature" |
+--------------+
1 row in set (0.99 sec)
SELECT DISTINCT
JSON_UNQUOTE(JSON_EXTRACT(feature,"$.type"))
as feature_type FROM features;
+--------------+
| feature_type |
+--------------+
| Feature |
+--------------+
1 row in set (1.06 sec)
SELECT DISTINCT feature->>"$.type" as
feature_type FROM features;
+--------------+
| feature_type |
+--------------+
| Feature |
+--------------+
1 row in set (1.02 sec)
- 21. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
特定データの参照処理
21
SELECT * FROM features WHERE feature->"$.properties.STREET" = 'MARKET' LIMIT 1¥G
************************* 1. row *************************
id: 12250
feature: {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[-
122.39836263491878, 37.79189388899312, 0],[-122.39845248797837, 37.79233030084018, 0],
[-122.39768507706792, 37.7924280850133, 0],[-122.39836263491878, 37.79189388899312, 0]]]},
"properties": {"TO_ST": "388", "BLKLOT": "0265003", "STREET": "MARKET", "FROM_ST": "388",
"LOT_NUM":"003","ST_TYPE": "ST","ODD_EVEN": "E","BLOCK_NUM":"0265","MAPBLKLOT":"0265003"}}
1 row in set (0.02 sec)
SELECT * FROM features WHERE feature->"$.properties.STREET" IS NULL LIMIT 1¥G
Empty set (0.39 sec)
特定データを含む
JSONドキュメントを
WHERE句で参照
- 22. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 22
# as JSON type
SELECT DISTINCT
feature->>"$.type" as json_extract
FROM features;
+--------------+
| json_extract |
+--------------+
| Feature |
+--------------+
1 row in set (1.25 sec)
# as TEXT type
SELECT DISTINCT
feature->>"$.type" as json_extract
FROM features;
+--------------+
| json_extract |
+--------------+
| Feature |
+--------------+
1 row in set (12.85 sec)
JSON_UNQUOTE + JSON_EXTRACT
の省略形(->>)で参照処理を実行
シンプルなパフォーマンス比較
インデックスの無い206,000件のドキュメントデータを使用した、
JSON とText型 によるデータ参照処理の比較
JSON形式のバイナリ形式は、非常に効率の良い検索を実装しています。
こちらの検証では、テキスト型でのトラバーサルと比較し、約10倍以上のパフォーマンスが出ています。
- 23. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
生成列(Generated Columns)とは?
23
CREATE TABLE t1 (
id INT NOT NULL PRIMARY KEY auto_increment,
my_integer INT,
my_integer_plus_one INT AS (my_integer+1));
UPDATE t1 SET my_integer_plus_one = 10 WHERE id = 1;
ERROR 3105 (HY000): The value specified for generated column
'my_integer_plus_one' in table 't1' is not allowed.
id my_integer my_integer_plus_one
1 10 11
2 20 21
3 30 31
4 40 41
自動的に計算された列と値
式から列を生成
動的に生成される列の為、
更新は出来ない
- 24. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
生成列へのインデックス作成!!
24
From table scan on 206K documents to index scan on 206K materialized values
ALTER TABLE features ADD feature_type VARCHAR(30) AS (feature->"$.type");
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)
メタデータの変更のみでテーブル変更は不要 (FAST)
インデックス作成のみで、テーブル行の変更は不要
JSONドキュメント検索: 1.25秒 → 0.06秒へ改善
- 25. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 25
ALTER TABLE T_ONLINE ALGORITHM=INPLACE, ADD feature_type varchar(30) AS (feature->"$.type") VIRTUAL;
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0
ALTER TABLE T_ONLINE ALGORITHM=INPLACE, ADD feature_type varchar(30) AS (feature->"$.type") STORED;
ERROR 1845 (0A000): ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY.
ALTER TABLE T_ONLINE ADD feature_type varchar(30) AS (feature->"$.type") STORED;
Query OK, 206560 rows affected (6.17 sec)
Records: 206560 Duplicates: 0 Warnings: 0
生成列に設定可能なインデックスオプション
VIRTUAL (Default)
STORED
メタデータの変更のみでオンライン処理可能
但し、データを呼び出す度にCPU処理が発生する
実データを含む為、作成時は参照のみが可能
データを含む為、高速だが追加でディスク容量が必用
- 26. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
生成列に設定可能なインデックスオプション
26
Generated Column (STORED)
挿入・更新時に演算、値を格納
データも含まれる為、参照が早い
PKにする事で、データの重複を防ぐ事も可能!!
Generated Column (VIRTUAL)
参照時に演算、値は格納しない
メタデータ変更のみ、INSERT/UPDATEが早い
Primary and Secondary
BTREE, Fulltext, GIS
Mixed with fields
Requires table rebuild
Not Online
Secondary Only
BTREE Only
Mixed with virtual column only
No table rebuild
INSTANT Alter
Faster Insert
Bottom Line: 主キー, FULLTEXTまたは仮想GISインデックスを必要とする場合を除き,デフォルトのVIRTUALで問題無い。
Advantage
Disadvantage
- 27. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 27
その他: JSON関数
• 情報取得
– JSON_VALID()
– JSON_TYPE()
– JSON_KEYS()
– JSON_LENGTH()
– JSON_DEPTH()
– JSON_CONTAINS()
– JSON_CONTAINS_PATH()
• データ編集
– JSON_REMOVE()
– JSON_SET()
– JSON_INSERT()
– JSON_REPLACE()
– JSON_ARRAY_INSERT()
– JSON_ARRAY_APPEND()
• データ作成
– JSON_MERGE()
– JSON_ARRAY()
– JSON_OBJECT()
• データ取得
– JSON_EXTRACT()
– JSON_SEARCH()
– -> /* JSON_EXTRACT() */
– ->> /* JSON_UNQUOTE(JSON_EXTRACT()) */
• ヘルパー
– JSON_QUOTE()
– JSON_UNQUOTE()
– JSON_VALID()
参照: https://dev.mysql.com/doc/refman/5.7/en/json-function-reference.html
New functions will be available in MySQL8.0!!
- 28. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
JSON関数でドキュメントの情報を取得
28
[NEW57]> SELECT JSON_VALID(body) from T_JSON_DOC where id = 5;
+------------------+
| JSON_VALID(body) |
+------------------+
| 1 |
+------------------+
[NEW57]> SELECT JSON_TYPE(body) from T_JSON_DOC where id = 5;
+-----------------+
| JSON_TYPE(body) |
+-----------------+
| OBJECT |
+-----------------+
[NEW57]> SELECT JSON_KEYS(body) from T_JSON_DOC where id = 5;
+---------------------------------------+
| JSON_KEYS(body) |
+---------------------------------------+
| ["id", "name", "price", "Conditions"] |
+---------------------------------------+
- 29. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 29
リレーショナルテーブルからJSONデータ生成
Relational In, Relational + Document Out
データがリレーショナルテーブルに格納されていても、フロントエンドは
JSONを使用する事が可能
JSONは多くの言語でネイティブデータ構造に直接マッピングされます
アプリケーションコードの使用が容易になるケースがある
JavaScript, Python, Ruby, その他
ブラウザのJavaScriptとのデータ連携が容易
Relational
REST/JSON DML
- 30. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
リレーショナルテーブルからJSONデータ生成
SELECT NAME,CountryCode from
world.City where CountryCode ='JPN' limit 1;
+-------+-------------+
| NAME | CountryCode |
+-------+-------------+
| Tokyo | JPN |
+-------+-------------+
30
SELECT JSON_OBJECT('CITY',NAME,'Country',CountryCode)
from world.City where CountryCode ='JPN' limit 1;
+------------------------------------------------+
| JSON_OBJECT('CITY',NAME,'Country',CountryCode) |
+------------------------------------------------+
| {"CITY": "Tokyo", "Country": "JPN"} |
+------------------------------------------------+
リレーショナルから
スキーマレスへの変換
[NEW57]> CREATE VIEW v_City_json AS
-> SELECT JSON_OBJECT('ID', ID, 'name', Name, 'CountryCode', CountryCode, 'District',
District,'Population',Population) as doc FROM City where CountryCode = 'JPN';
Query OK, 0 rows affected (0.01 sec)
[NEW57]> select * from v_City_json limit 1¥G
*************************** 1. row ***************************
doc: {"ID": 1532, "name": "Tokyo", "District": "Tokyo-to", "Population": 7980230, "CountryCode": "JPN"}
1 row in set (0.01 sec)
例) ビュー
JSON関数: JSON_OBJECT(), JSON_ARRAY()でJSONを組み立てる
更新と挿入は引き続きテーブルの列を介して行われます
- 31. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 31
値の(空を含む)リストを評価し、それらの値を含むJSON配列を返します。
リレーショナルテーブルからJSONデータ生成
JSON関数: JSON_OBJECT(), JSON_ARRAY()でJSONを組み立てる
SELECT NAME,CountryCode from
world.City where CountryCode ='JPN' limit 1;
+-------+-------------+
| NAME | CountryCode |
+-------+-------------+
| Tokyo | JPN |
+-------+-------------+
[NEW57]> SELECT JSON_ARRAY(NAME,CountryCode) from world.City
where CountryCode ='JPN' limit 1;
+------------------------------+
| JSON_ARRAY(NAME,CountryCode) |
+------------------------------+
| ["Tokyo", "JPN"] |
+------------------------------+
[NEW57]> select feature from features limit 10,1¥G
*************************** 1. row ***************************
feature: {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[-122.41629403378657, 37.807666226310545,
0], [-122.4162948864558, 37.80767056801045, 0], [-122.41636926744471, 37.80804964445761, 0], [-122.41590475297633,
37.80810646146374, 0], [-122.41582868876579, 37.8077282259018, 0], [-122.41598542756716, 37.80770884145562, 0], [-
122.41615558481081, 37.807683349374365, 0], [-122.41629403378657, 37.807666226310545, 0]]]}, "properties": {"TO_ST":
"229", "BLKLOT": "0012001", "STREET": "JEFFERSON", "FROM_ST": "211", "LOT_NUM": "001", "ST_TYPE": "ST", "ODD_EVEN": "O",
"BLOCK_NUM": "0012", "MAPBLKLOT": "0012001"}}
[NEW57]> SELECT JSON_ARRAY(id,feature->"$.properties.STREET",feature->"$.type") AS json_array FROM features ORDER BY id
LIMIT 10,1;
+------------------------------+
| json_array |
+------------------------------+
| [11, "JEFFERSON", "Feature"] |
+------------------------------+
リレーショナルから
スキーマレスへの変換
- 32. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 32
[CONFIRM]> select * from T_JSON_PLACE;
+----+-------------------------------------+----------+-----------+
| id | place | latitude | longitude |
+----+-------------------------------------+----------+-----------+
| 1 | 東京都港区北青山2-5-8 | 35.67125 | 139.71864 |
| 2 | 大阪府大阪市北区堂2-4-27 | 34.69584 | 135.49291 |
+----+-------------------------------------+----------+-----------+
[CONFIRM]> select JSON_OBJECT('ID',id,'住所',place,'緯度経度', JSON_ARRAY(latitude,longitude)) from T_JSON_PLACE;
+---------------------------------------------------------------------------------------------------+
| JSON_OBJECT('ID',id,'住所',place,'緯度経度', JSON_ARRAY(latitude,longitude)) |
+---------------------------------------------------------------------------------------------------+
| {"ID": 1, "住所": "東京都港区北青山2-5-8", "緯度経度": [35.67125, 139.71864]} |
| {"ID": 2, "住所": "大阪府大阪市北区堂2-4-27", "緯度経度": [34.69584, 135.49291]} |
+---------------------------------------------------------------------------------------------------+
リレーショナルテーブルからJSON抽出
JSON関数: JSON_OBJECT(), JSON_ARRAY()でJSONを組み立てる
JSON_ARRAYとJSON_OBJECTを組み合わせてJSONデータを使用する事も可能
オブジェクト {}は、順序が異なっても同じキーと値のペアを含んでいれば同値だが、
配列[]は順序が意味を持つ為、順序が異なると同値では無い。
ST_AsGeoJSONやST_GeomFromGeoJSON等のSpatial GeoJSON Functionsで空間を表すJSONを処理可能
- 33. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
JSON Path Search
JSON形式のドキュメント内の指定された値のパスを返します
To retrieve via: [[database.]table.]column->"$<path spec>"
33
SELECT JSON_SEARCH(feature,
'one', 'MARKET') AS
extract_path
FROM features
WHERE id = 121254;
+-----------------------+
| extract_path |
+-----------------------+
| "$.properties.STREET" |
+-----------------------+
SELECT
feature->"$.properties.STREET"
AS property_street
FROM features
WHERE id = 121254;
+-----------------+
| property_street |
+-----------------+
| "MARKET" |
+-----------------+
feature: {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[-122.39790233801507,
37.790726654724864, 0], [-122.39823963293078, 37.79099174693105, 0], [-122.39835208359005, 37.79090296883558, 0],
[-122.3986901921814, 37.79116869825866, 0], [-122.39823249443299, 37.7915300431353, 0], [-122.39756221186288,
37.79099545718336, 0], [-122.39790233801507, 37.790726654724864, 0]]]}, "properties": {"TO_ST": "425", "BLKLOT":
"3709016", "STREET": "MARKET", "FROM_ST": "425", "LOT_NUM": "016", "ST_TYPE": "ST", "ODD_EVEN": "O", "BLOCK_NUM":
"3709", "MAPBLKLOT": "3709014"}}
“$”はJSONドキュメント全体で,オブジェクトメンバーは“.”に続いてパスを表現
- 34. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
JSON_REMOVE()
34
JSONドキュメントからデータを削除し、結果を返します。
[NEW57]> select * from T_JSON_DOC;
+----+---------------------------------------------------------------------------------------------------+------------+
| id | body | price_only |
+----+---------------------------------------------------------------------------------------------------+------------+
| 1 | {"id": 1, "name": "自転車", "price": 10000, "Conditions": ["NEW", 2015, "Excellent"]} | 10000.00 |
| 2 | {“id”: 2, “name”: “テレビ”, “price”: 30000, “Conditions”: [“USED”, 2013, “故障”]} | 30000.00 |
| 3 | {"id": 3, "name": "冷蔵庫", "price": 17131, "Conditions": ["NEW", 2015]} | 17131.00 |
| 4 | {“id”: 4, “name”: “オートバイ”, “price”: 500000, “Conditions”: [“NEW”, 2015]} | 500000.00 |
| 5 | {"id": 5, "name": "自転車", "price": 25000, "Quantity": "[1,10]", "Conditions": ["NEW", 2015]} | 25000.00 |
+----+---------------------------------------------------------------------------------------------------+------------+
[NEW57]> select JSON_REMOVE(body,"$.Quantity") from T_JSON_DOC where id = 5;
+-----------------------------------------------------------------------------+
| JSON_REMOVE(body,"$.Quantity") |
+-----------------------------------------------------------------------------+
| {"id": 5, "name": "自転車", "price": 25000, "Conditions": ["NEW", 2015]} |
+-----------------------------------------------------------------------------+
[NEW57]> update T_JSON_DOC set body = JSON_REMOVE(body,"$.Quantity") where id = 5;
- 35. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
JSON_SET ()
35
JSONドキュメントにデータを挿入または更新し、結果を返します。
replaces existing values and adds nonexisting values.
[NEW57]> select * from T_JSON_DOC;
+----+------------------------------------------------------------------------------+------------+
| id | body | price_only |
+----+------------------------------------------------------------------------------+------------+
| 1 | {“id”: 1, “name”: “自転車”, “price”: 10000, “Conditions”: [“NEW”, 2015]} | 10000.00 |
| 2 | {"id": 2, "name": "テレビ", "price": 30000, "Conditions": ["USED",2013]} | 30000.00 |
| 3 | {"id": 3, "name": "冷蔵庫", "price": 11154, "Conditions": ["NEW", 2015]} | 11154.00 |
| 4 | {"id": 4, "name": "冷蔵庫", "price": 50000, "Conditions": ["NEW", 2015]} | 50000.00 |
| 5 | {"id": 5, "name": "自転車", "price": 25000, "Conditions": ["NEW", 2015]} | 25000.00 |
+----+------------------------------------------------------------------------------+------------+
[NEW57]> SELECT JSON_SET(body,'$.name',"オートバイ", '$.price',500000) from T_JSON_DOC where id = 4;
+------------------------------------------------------------------------------------+
| JSON_SET(body,'$.name',"オートバイ", '$.price',500000) |
+------------------------------------------------------------------------------------+
| {"id": 4, "name": "オートバイ", "price": 500000, "Conditions": ["NEW", 2015]} |
+------------------------------------------------------------------------------------+
[NEW57]> update T_JSON_DOC set body = JSON_SET(body,'$.name',"オートバイ", '$.price',500000) where id = 4;
- 36. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
JSON_INSERT ()
36
JSONドキュメントにデータを挿入し、結果を返します。
inserts values without replacing existing values.
[NEW57]> select * from T_JSON_DOC;
+----+------------------------------------------------------------------------------+------------+
| id | body | price_only |
+----+------------------------------------------------------------------------------+------------+
| 1 | {“id”: 1, “name”: “自転車”, “price”: 10000, “Conditions”: [“NEW”, 2015]} | 10000.00 |
| 2 | {"id": 2, "name": "テレビ", "price": 30000, "Conditions": ["USED",2013]} | 30000.00 |
| 3 | {"id": 3, "name": "冷蔵庫", "price": 11154, "Conditions": ["NEW", 2015]} | 11154.00 |
| 4 | {"id": 4, "name": "冷蔵庫", "price": 50000, "Conditions": ["NEW", 2015]} | 50000.00 |
| 5 | {"id": 5, "name": "自転車", "price": 25000, "Conditions": ["NEW", 2015]} | 25000.00 |
+----+------------------------------------------------------------------------------+------------+
[NEW57]> select JSON_INSERT(body,'$.Quantity','[1,10]') from NEW57.T_JSON_DOC where id = 5;
+---------------------------------------------------------------------------------------------------+
| JSON_INSERT(body,'$.Quantity','[1,10]') |
+---------------------------------------------------------------------------------------------------+
| {"id": 5, "name": "自転車", "price": 25000, "Quantity": "[1,10]", "Conditions": ["NEW", 2015]} |
+---------------------------------------------------------------------------------------------------+
[NEW57]> update NEW57.T_JSON_DOC set body = JSON_INSERT(body,'$.Quantity','[1,10]') where id = 5;
- 37. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
JSON_REPLACE ()
37
JSON文書の既存の値を置き換え、その結果を返します。
replaces only existing values.
[NEW57]> select * from T_JSON_DOC;
+----+------------------------------------------------------------------------------+------------+
| id | body | price_only |
+----+------------------------------------------------------------------------------+------------+
| 1 | {“id”: 1, “name”: “自転車”, “price”: 10000, “Conditions”: [“NEW”, 2015]} | 10000.00 |
| 2 | {“id”: 2, “name”: “テレビ”, “price”: 30000, “Conditions”: [“USED”,2013]} | 30000.00 |
| 3 | {"id": 3, "name": "冷蔵庫", "price": 11154, "Conditions": ["NEW", 2015]} | 11154.00 |
| 4 | {"id": 4, "name": "冷蔵庫", "price": 50000, "Conditions": ["NEW", 2015]} | 50000.00 |
| 5 | {"id": 5, "name": "自転車", "price": 25000, "Conditions": ["NEW", 2015]} | 25000.00 |
+----+------------------------------------------------------------------------------+------------+
[NEW57]> select JSON_REPLACE(body,"$.price",FLOOR(10000 + (RAND() * 9000))) from T_JSON_DOC where id = 3;
+-----------------------------------------------------------------------------+
| JSON_REPLACE(body,"$.price",FLOOR(10000 + (RAND() * 9000))) |
+-----------------------------------------------------------------------------+
| {"id": 3, "name": "冷蔵庫", "price": 18359, "Conditions": ["NEW", 2015]} |
+-----------------------------------------------------------------------------+
[NEW57]> update T_JSON_DOC set body = JSON_REPLACE(body,"$.price",FLOOR(10000 + (RAND() * 9000))) where id = 3;
- 38. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
JSON_ARRAY_INSERT ()
38
JSONドキュメントを更新し、ドキュメント内の配列に挿入し変更された結果を返します。
[NEW57]> select * from T_JSON_DOC;
+----+------------------------------------------------------------------------------+------------+
| id | body | price_only |
+----+------------------------------------------------------------------------------+------------+
| 1 | {“id”: 1, “name”: “自転車”, “price”: 10000, “Conditions”: [“NEW”, 2015]} | 10000.00 |
| 2 | {"id": 2, "name": "テレビ", "price": 30000, "Conditions": ["USED",2013]} | 30000.00 |
| 3 | {"id": 3, "name": "冷蔵庫", "price": 11154, "Conditions": ["NEW", 2015]} | 11154.00 |
| 4 | {"id": 4, "name": "冷蔵庫", "price": 50000, "Conditions": ["NEW", 2015]} | 50000.00 |
| 5 | {"id": 5, "name": "自転車", "price": 25000, "Conditions": ["NEW", 2015]} | 25000.00 |
+----+------------------------------------------------------------------------------+------------+
SELECT JSON_ARRAY_INSERT(body,'$.Conditions[2]','January') from T_JSON_DOC where id = 5;
+----------------------------------------------------------------------------------------+
| JSON_ARRAY_INSERT(body,'$.Conditions[2]','January') |
+----------------------------------------------------------------------------------------+
| {"id": 5, "name": "自転車", "price": 25000, "Conditions": ["NEW", 2015, "January"]} |
+----------------------------------------------------------------------------------------+
[NEW57]> update T_JSON_DOC set body = JSON_ARRAY_INSERT(body,'$.Conditions[2]','January') where id = 5;
- 39. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
JSON_ARRAY_APPEND ()
39
JSONドキュメント内の指定された配列の最後に値を追加し、結果を返します。
[NEW57]> select * from T_JSON_DOC;
+----+------------------------------------------------------------------------------+------------+
| id | body | price_only |
+----+------------------------------------------------------------------------------+------------+
| 1 | {“id”: 1, “name”: “自転車”, “price”: 10000, “Conditions”: [“NEW”, 2015]} | 10000.00 |
| 2 | {"id": 2, "name": "テレビ", "price": 30000, "Conditions": ["USED",2013]} | 30000.00 |
| 3 | {"id": 3, "name": "冷蔵庫", "price": 11154, "Conditions": ["NEW", 2015]} | 11154.00 |
| 4 | {"id": 4, "name": "冷蔵庫", "price": 50000, "Conditions": ["NEW", 2015]} | 50000.00 |
| 5 | {"id": 5, "name": "自転車", "price": 25000, "Conditions": ["NEW", 2015]} | 25000.00 |
+----+------------------------------------------------------------------------------+------------+
[NEW57]> select JSON_ARRAY_APPEND(body,'$.Conditions','故障') from NEW57.T_JSON_DOC where id = 2;
+----------------------------------------------------------------------------------------+
| JSON_ARRAY_APPEND(body,'$.Conditions','故障') |
+----------------------------------------------------------------------------------------+
| {"id": 2, "name": "テレビ", "price": 30000, "Conditions": ["USED", 2013, "故障"]} |
+----------------------------------------------------------------------------------------+
[NEW57]> update T_JSON_DOC set body = JSON_ARRAY_APPEND(body,'$.Conditions','故障') where id = 2;
- 40. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
JSON_MERGE ()
40
2つ以上のJSONドキュメントをマージし、マージした結果を返します。
[NEW57]> select * from T_JSON_DOC;
+----+------------------------------------------------------------------------------+------------+
| id | body | price_only |
+----+------------------------------------------------------------------------------+------------+
| 1 | {“id”: 1, “name”: “自転車”, “price”: 10000, “Conditions”: [“NEW”, 2015]} | 10000.00 |
| 2 | {"id": 2, "name": "テレビ", "price": 30000, "Conditions": ["USED",2013]} | 30000.00 |
| 3 | {"id": 3, "name": "冷蔵庫", "price": 11154, "Conditions": ["NEW", 2015]} | 11154.00 |
| 4 | {"id": 4, "name": "冷蔵庫", "price": 50000, "Conditions": ["NEW", 2015]} | 50000.00 |
| 5 | {"id": 5, "name": "自転車", "price": 25000, "Conditions": ["NEW", 2015]} | 25000.00 |
+----+------------------------------------------------------------------------------+------------+
[NEW57]> SELECT JSON_MERGE(body,'{"Conditions":"Excellent"}') from T_JSON_DOC where id = 1;
+------------------------------------------------------------------------------------------+
| JSON_MERGE(body,'{"Conditions":"Excellent"}') |
+------------------------------------------------------------------------------------------+
| {"id": 1, "name": "自転車", "price": 10000, "Conditions": ["NEW", 2015, "Excellent"]} |
+------------------------------------------------------------------------------------------+
[NEW57]> update T_JSON_DOC set body = JSON_MERGE(body,'{"Conditions":"Excellent"}') where id = 1;
- 41. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JSON Comparator
41
SELECT CAST(1 AS JSON) = 1;
+---------------------+
| CAST(1 AS JSON) = 1 |
+---------------------+
| 1 |
+---------------------+
1 row in set (0.01 sec)
SELECT CAST('{"a": 10, "num": 1.1}' AS JSON) = CAST('{"num": 1.1, "a":10}' AS JSON);
+------------------------------------------------------------------------------+
| CAST('{"a": 10, "num": 1.1}' AS JSON) = CAST('{"num": 1.1, "a":10}' AS JSON) |
+------------------------------------------------------------------------------+
| 1 |
+------------------------------------------------------------------------------+
1 row in set (0.00 sec)
JSON Objectsの比較
JSONの1は1と同等
- 42. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JSON Comparator (cont.)
42
JSONの値とMySQLの値をJOIN処理
CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, a INTEGER NOT NULL);
CREATE TABLE t2 (id INT NOT NULL PRIMARY KEY, doc JSON NOT NULL);
INSERT INTO t1 VALUES (1, 1), (2, 2);
INSERT INTO t2 VALUES (1, JSON_OBJECT('a', 1)), (2, JSON_OBJECT('a', 2));
SELECT t1.id, t1.a, t2.doc FROM t1 INNER JOIN t2 ON (t1.a=t2.doc->"$.a");
+----+---+----------+
| id | a | doc |
+----+---+----------+
| 1 | 1 | {"a": 1} |
| 2 | 2 | {"a": 2} |
+----+---+----------+
- 43. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Today’s Agenda
43
Introduction
Core New JSON Features
Use cases
Document Store Enhancement feature
1
22
1
2
3
224
- 44. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
リレーショナルそれともスキーマレス?
44
両方共にそれぞれのアプローチとメリット
mysql> SELECT * FROM pizza;
+------+------------------+-------+
| code | name | price |
+------+------------------+-------+
| CLA | Classic Pizza | 400 |
| MAR | Margherita Pizza | 500 |
+------+------------------+-------+
mysql> SELECT * FROM toppings;
+--------+------------+
| p_code | name |
+--------+------------+
| CLA | Pepperoni |
| CLA | Parmesan |
| MAR | Basil |
| MAR | Mozzarella |
+--------+------------+
{
"name":"Classic Pizza", "price":400,
"toppings":[
"Pepperoni", "Parmesan"
]
}
{
"name":"Margherita Pizza", "price":500,
"toppings":[
"Basil", "Mozzarella"
],
"options":[
{
"name":"Olive", "price":100
}
]
}
Schema Schema Less (JSONドキュメント)
属性値のペアのコレクション表, カラム, 行
- 45. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Schema: Columnへのデータ格納
45
• アプリケーションに対し、スキーマの適用が容易
• スキーマにより長期的に、アプリケーションの変更管理がコントロールしやすい
- 表, カラム, 行を使用して効率よくデータを管理
- データにいくつかの制約を設定可能 (データ型、外部キー制約等)
- データ重複を削減する事が可能 (正規化)
+--------------+-------------+---------------+
| id | type | street |
+--------------+-------------+---------------+
| 190838 | Feature | FARALLONES |
| 153676 | Feature | ELLSWORTH |
- 46. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Schema Less: JSONへのデータ格納
46
● スキーマ内でモデル化する事が困難であるデータを柔軟に表現。
- 例)多くのお客様へSaaSアプリケーション提供してる場合
- 強力なユースケースとしてカスタムフィールドをサポート
- 歴史的に エンティティ属性値モデル(EAV)が使われているが、
必ずしも十分に機能していない場合等
●容易な非正規化は, 特定の状況 において重要である最適化手法
●容易なプロトタイピング
1) 考慮すべき型 が少なくて済む 2) スキーマ強制不要,直ぐに値を格納可能
●労力を伴うスキーマ変更不要* (MySQL 5.6+ has Online DDL)
+-----------------------------------------------------------+
| json_object |
+-----------------------------------------------------------+
| {"id": 190838, "type": "Feature", "street": "FARALLONES"} |
| {"id": 153676, "type": "Feature", "street": "ELLSWORTH"} |
- 47. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Schema + Schemaless
47
CREATE TABLE pc_components (
id INT NOT NULL PRIMARY KEY,
description VARCHAR(60) NOT NULL,
vendor VARCHAR(30) NOT NULL,
serial_number VARCHAR(30) NOT NULL,
attributes JSON NOT NULL);
ColumnデータとJSONデータ連携
Relational Tables
Schema less JSON Collection
MySQL5.7
開発チーム:
[ x ] スキーマレス/スキーマ
[ x ] 迅速なプロトタイプ/シンプルAPI
[ x ] ドキュメントモデル
オペレーション:
[ x ] パフォーマンス管理/可視化
[ x ] 堅牢レプリケーション,バックアップ, リストア
[ x ] 包括的なツールによるエコシステム
ビジネス:
[ x ] データを確実に保護 = ACIDトランザクション
[ x ] 全てのデータをキャプチャー = 拡張性/スキーマレス
[ x ] スケージュール/製品化の時間 = 迅速なサービス開発
リレーショナル、スキーマレスデータを
同じ技術スタックで利用可能
- 48. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Resources
• http://mysqlserverteam.com/
• http://mysqlserverteam.com/tag/json/
• https://dev.mysql.com/doc/refman/5.7/en/mysql-nutshell.html
• http://dev.mysql.com/doc/relnotes/mysql/5.7/en/
• https://dev.mysql.com/doc/refman/5.7/en/json.html
• https://dev.mysql.com/doc/refman/5.7/en/json-functions.html
• http://www.thecompletelistoffeatures.com
今後も更に、関数を含む多くの機能追加を計画しています。
48
- 49. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Today’s Agenda
49
Introduction
Core New JSON Features
Use cases
Document Store Enhancement feature
1
22
1
2
4
223
- 50. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
コネクター, ドライバー, プロトコル拡張機能
MySQL
Plugins
X Protocol Plugin Memcached Plugin
Core
MySQL Connectors and Drivers
X ProtocolStd Protocol
Memcached
driver
X Protocol
33060
Std Protocol
3306
SQL API CRUD and SQL APIs
Memcache
Protocol
X and Std
Protocols
MySQL
Shell
50
+-------------+----------------+--------------------+
| PLUGIN_NAME | PLUGIN_VERSION | PLUGIN_DESCRIPTION |
+-------------+----------------+--------------------+
| mysqlx | 1.0 | X Plugin for MySQL |
+-------------+----------------+--------------------+
- 51. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
X DevAPI
• X Pluginを有効にする事で、X Protocol経由で通信可能
• ドキュメントとテーブルのコレクションに対してのCRUD処理
• NoSQLライクな構文でドキュメントに対しCRUD処理可能
• Fluent API
prod = sess.getSchema("prod")
res = prod.users.
find("$.name = 'Milk'").
fields(["name", "properties"])
X Plugin (MySQL) ⇔ X Protocol ⇔ X DevAPI (Driver)
51
MySQL Connector/node.js (1.0.x)
MySQL Connector/J (6.0.x)
MySQL Connector/Net (7.0.x)
MySQL Connector/python(2.2.x)
MySQL Shell (1.0.x)
参照: http://dev.mysql.com/downloads/connector/
- 52. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
MySQL Connectors include X Dev API
• Use SQL, CRUD APIs
スキーマレスドキュメントおよびリレーショナルテーブルに対応
- Classic APIsに加えて、これらの全てが追加されます
52
Operation Document Relational
Create Collection.add() Table.insert()
Read Collection.find() Table.select()
Update Collection.modify() Table.update()
Delete Collection.remove() Table.delete()
参照) http://dev.mysql.com/doc/x-devapi-userguide/en/crud-operations-overview.html
- 53. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 53
[root@misc01 nodejs]# cat sample_node_X_API.js
const mysqlx = require('mysqlx');
mysqlx.getSession({ host: 'localhost', port: 33060, dbUser: 'demo_user', dbPassword: 'password'
}).then(function (session) {
return session.createSchema("test_schema").then(function (schema) {
return schema.createCollection("myCollection");
}).then(function (collection) {
return Promise.all([
collection.add( {baz: { foo: "bar"}},{foo: { bar: "baz"}}).execute(),
collection.find("$.baz.foo == 'bar'").execute(function (row) {console.log("Row: %j", row);
}).then(function (res) {console.log("Collection find done!");}),
collection.remove("($.foo.bar) == 'baz'").execute().then(function () {
console.log("Document deleted");}), collection.drop() ]);
}).then(function () { return session.dropSchema("test_schema");
}).then(function () { return session.close(); });
}).catch(function (err) { console.log(err.stack); process.exit(); });
[root@misc01 nodejs]# node sample_node_X_API.js
Row: {"_id":"630f0d3b-f6fd-1d99-6d80-a8e90352","baz":{"foo":"bar"}}
Collection find done!
Document deleted Connector:mysql-connector-nodejs-1.0.5.tar.gz
- 54. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
• Elasticity
• Fault tolerance
• Automatic server fail-over
• Automatic reconfiguration
• Automatic conflict detection & resolution
Learn more at blogs.oracle.com/mysql
InnoDB Clusterによる高可用性のサポート
With MySQL Group Replication + MySQL Shell + MySQL Router
2017年4月 GA
- 56. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Appendix: MySQL Enterprise Edition
TCO削減、包括的なセキュリティ対策が必要な場合の拡張機能とサポート
- 57. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 57
MySQLのコミュニティ版と商用版
MySQL はデュアルライセンスソフトウェアです。ビジネスの変化や状況に応じて、
CommunityやCommercial Editionを使い分けて頂く事で,常に最適なソリューションを選択可能。
• MySQL Community Server
• MySQL Cluster
• MySQL GUI管理ツール
• MySQLコネクタ (JDBC, ODBC, etc.)
• ドキュメント
• フォーラム
Community Edition (GPL)
•Standard Edition
•Enterprise Edition
•MySQL Cluster Carrier Grade Edition
• 商用ライセンス (組み込み用)
• プロフェッショナルサービス
• トレーニング、コンサルティング、サポート
Commercial Edition
コミュニティ版ソフトウェアはGPLv2でソースコードも公開し提供
商用版は、付加価値として技術サポートや管理機能、拡張機能を有償で提供
参考:MySQL Downloads
- 58. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 58
MySQL Enterprise Edition のサービスカテゴリー
管理ツール拡張機能 サポート
• 拡張性
• 高可用性
• 統合認証
• 監査
• 暗号化
• ファイヤーウオール
• 透過的データ暗号化
• 監視
• バックアップ
• 開発
• 管理
• マイグレーション
• 技術サポート
• コンサルティングサポート
• オラクル製品との
動作保証
Enterprise Editionに含まれる、
コンサルティングサポートでは、
設計、パフォーマンスチューニング等も
無制限でサポート致します。
“ Support As Remote DBA ”
- 59. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 59
MySQL Enterprise Edition管理ツールと拡張機能概要
目的 MySQL Enterprise Edition 概要
TCO削減 MySQL Enterprise Monitor 複数サーバの一括管理、クエリ性能分析
TCO削減 Oracle Enterprise Manager for MySQL Oracle Enterprise ManagerからMySQLを統合管理可能
TCO削減と最適化 Oracle Premier Support 24x7, インシデント無制限、コンサルティングサポート
品質維持 MySQL Enterprise Scalability Thread Poolプラグインによる性能拡張性の向上
機会損失対策 MySQL Enterprise Backup 高速なオンラインバックアップ、ポイントインタイムリカバリ
セキュリティ
コンプライアンス
MySQL Enterprise Authentication LDAPやWindows Active Directoryとの統合認証と管理
セキュリティ
コンプライアンス
MySQL Enterprise TDE データベースオブジェクトの透過的暗号化
セキュリティ
コンプライアンス
MySQL Enterprise Audit ユーザ処理の監査、Oracle DBと同じツールで管理可能
セキュリティ
コンプライアンス
MySQL Enterprise Encryption 非対称暗号化(公開鍵暗号)の業界標準機能を提供
セキュリティ
コンプライアンス
MySQL Enterprise Firewall SQLインジェクション対策
- 60. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
MySQL & Oracle製品との動作保証
• Oracle Linux
• Oracle VM
• Oracle Solaris
• Oracle Clusterware
• Oracle Secure Backup
• Oracle Enterprise Manager
• Oracle Fusion Middleware
• Oracle GoldenGate
• Oracle Audit Vault & Database Firewall
• MyOracle Online Support
MySQL Integrates into your Oracle Environment
MySQLとOracle間での双方レプリケーション
Oracle GoldenGate
60
- 61. Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
お問合せ先
• [MySQL お問い合わせ窓口]
0120-065556
• 【受付時間】
平日 9:00-12:00/13:00-18:00
(祝日及び年末年始休業日を除きます)
MySQL-Sales_jp_grp@oracle.com
61