Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

[db tech showcase 2015 Sapporo HOKKAIDO] MySQL as document database!?

779 views

Published on

2015年9月11日のdb tech showcase 2015 Sapporo HOKKAIDOにて「MySQLはドキュメントデータベースの夢を見るか?」のセッションで利用した資料です。MySQLサーバのmemcached APIやJSONデータ型、HTTPプラグインの他、MySQL Clusterのハイブリッド型APIなどをご紹介しています。 #dbts2015 #dbts-sapporo-2015

Published in: Technology
  • Be the first to comment

[db tech showcase 2015 Sapporo HOKKAIDO] MySQL as document database!?

  1. 1. Copyright*©*201 ,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|* #mysql_jp* Ryusuke*Kajiyama*/* */*@RKajiyama* MySQL*Sales*ConsulIng*Senior*Manager,*Asia*Pacific*&*Japan* db*tech*showcase*Sapporo*HOKKAIDO* MySQL* *
  2. 2. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* SAFE*HARBOR*STATEMENT* 2*
  3. 3. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* The*world's*most*popular*open*source*database* * 3
  4. 4. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* 4 4.0* /GIS*(MyISAM)* UPDATE/DELETE* Oracle*MySQL* Sun* 3.23* MyISAM* InnoDB* * 5.1* * * * * * 5.6* memcached*API* UNDO * Global*TransacIon*ID* * ALTER*TABLE* * 5.5* InnoDB * * PERFORMANCE_SCHEMA* 1.0G3.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+* * * * * CJK /GIS*(InnoDB)* * * NoSQL * * *
  5. 5. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* •  * –  * –  * – SSD * – UNDO * –  * – JSON*EXPLAIN* – Memcached*API* •  – Global*TransacIon*ID* –  * –  * – Binlog* * –  * –  * * –  5 •  * –  ALTER*TABLE* –  * * –  * * –  * •  * •  SHA256* •  * MySQL*5.6
  6. 6. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* MySQL*5.6:*InnoDB RDBMS NoSQL •  Memcached*API * –  Memcached * – SQL •  NotOnlySQL * –  * –  JOIN FK SQL •  * – mysqld Memcached * –  InnoDB*API memcached* * InnoDB*Storage*Engine* MySQL*Server* Memcached*plugin* ApplicaSon* SQL** (MySQL*Client)* NoSQL** (Memcached* **Protocol)* mysqld*
  7. 7. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* InnoDB*memcached*Plugin •  The*mapping*is*done*through*specifying*corresponding*column*values*in* containers*table:* mysql> desc containers; +------------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------------+--------------+------+-----+---------+-------+ | name | varchar(50) | NO | PRI | NULL | | | db_schema | varchar(250) | NO | | NULL | | | db_table | varchar(250) | NO | | NULL | | | key_columns | varchar(250) | NO | | NULL | | | value_columns | varchar(250) | YES | | NULL | | | flags | varchar(250) | NO | | 0 | | | cas_column | varchar(250) | YES | | NULL | | | expire_time_column | varchar(250) | YES | | NULL | | | unique_idx_name_on_key | varchar(250) | NO | | NULL | | +------------------------+--------------+------+-----+---------+-------+ 9 rows in set (0.02 sec)
  8. 8. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* MySQL*Cluster*7.4*GA 8
  9. 9. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* 1,000 MySQL*Cluster 9 Paypal 1 20 203 30% MySQL MySQL Cluster AWS 5 1/3 MySQL “NoSQL SQL ” Daniel Austin, Chief Architect, PayPal hXp://wwwGjp.mysql.com/customers/view/?id=1223
  10. 10. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* :* * •  * •  * •  * •  * •  * •  * •  * •  * •  * •  *&* * •  4 MySQL*Cluster *Linux Windows* MySQL*User*Conference*Session:*hmp://bit.ly/ogeid3*
  11. 11. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* MySQL*Cluster:*SQL*and*NoSQL*Hybrid*APIs AcSveGAcSve*RDBMS &* NoSQL* 11 MySQL*Cluster*Data*Nodes* Apps Apps Apps Apps Apps Apps Apps Apps Apps Apps Apps JPA Cluster*JPA PHP Perl Python Ruby JDBC Cluster*J JS Memcached MySQL JNI Node.JS ndb_eng NDB*API*(C++)
  12. 12. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* MySQL*Cluster*7.4*–* NoSQL:*20 / & * FlexAsych*(C++*NDB*API) SQL:*250 / & * DBT2*BM 12 !"!!!! !50,000,000!! !100,000,000!! !150,000,000!! !200,000,000!! !250,000,000!! 2! 4! 6! 8! 10! 12! 14! 16! 18! 20! 22! 24! 26! 28! 30! 32! Reads&per&second& Data&Nodes& FlexAsync&Reads& !"!!!! !500,000!! !1,000,000!! !1,500,000!! !2,000,000!! !2,500,000!! !3,000,000!! 2! 4! 6! 8! 10! 12! 14! 16! SQL$Statements/sec$ Data$Nodes$ DBT2$SQL$Statements$per$Second$
  13. 13. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* MySQL*Labs 13
  14. 14. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* MySQL*Labs •  * –  * •  MySQL MySQL*Cluster * – MySQL*5.6*memcached*API* – MySQL*Cluster*7.2*memcached*API* – MySQL*5.6*Performance*Schema* – MySQL*5.6*Intrapschema*MulI*Thread*Slave* – MySQL*5.6*Online*Alter*Table* – MySQL*5.7*MulI*Source*ReplicaIon* – MySQL*5.7*New*OpImizer*Cost*Model 14
  15. 15. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* •  ” ” * •  * –  ( * –  “OpImisIc*State*Machine”* * •  * –  * –  / * –  * –  * •  * –  InnoDB* –  GTID * –  PERFORMANCE_SCHEMA* * * ApplicaIon* MySQL*Masters* ReplicaIon** Plugin* API* MySQL* Server* Group*Comms* (Corosync)* 15* labs.mysql.com*
  16. 16. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* MySQL*Binlog*Events Binlog*API •  C++ * •  * – 2 "transport"* – TCP*Transport*&*File*Transport* •  * –  * •  API* hmp://mysqlhighavailability.com/author/nehakumari/* 16
  17. 17. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* HTTP*Plugin*for*MySQL* •  MySQL HTTP(S) * •  UTF8 JSON * •  3 * – SQL* – CRUD*p*KeypValue* – JSON*p*Document* •  For*more*details;* hmp://www.slideshare.net/nixnutz/hmpppluginpforpmysqlp39598656* 17*
  18. 18. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* HTTP*Plugin*for*MySQL*–* SQL CRUD JSON* URL hXp[s]://server:port/sql/ hXp[s]://server:port/crud/ hXp[s]://server:port/doc/ SQL CRUD CRUD JSON * SQL Yes No No HTTP GET GET,*PUT.*DELETE GET,*PUT.*DELETE* Yes No Yes Yes Yes Yes UTFG8 UTFG8 UTFG8 Yes Yes Yes 18
  19. 19. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* HTTP*Plugin*for*MySQL The*SQL*endpoint*and*JSON* 19 shell> curl -X GET --user scott:tiger --url 'http://127.0.0.1:8080/sql/world/ SELECT+ID,Name+FROM+City+WHERE+Name=%27Tokyo%27' [ { "meta":[ {"type":,"catalog":"def","database":"world","table":"City","org_table":"ci ty","column":"ID","org_column":"ID","charset":63,"length":11,"flags": 16899,"decimals":0}, {"type": 254,"catalog":"def","database":"world","table":"City","org_table":"city","column ":"Name","org_column":"Name","charset":33,"length":105,"flags":1,"decimals":0} ], "data":[ ["1532","Tokyo"] ], "status":[{"server_status":34,"warning_count":0 } ]
  20. 20. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* HTTP*Plugin*for*MySQL*p*IniIal*version* •  HTTP*Basic*AuthenIcaIon*for*SSL*and*NonpSSL** •  No*query*cache*support** •  No*commercial*thread*pool*plugin*support** •  Not*all*MySQL*pluggable*auth*methods*supported** •  Unlimited:*all*SQL*statements** •  Unlimited:*everything*the*server*returns** 20* shell> curl --user basic_auth_user:basic_auth_passwd --url "http://.../sql/db/SELECT+col_float+FROM+sql_types"
  21. 21. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* HTTP*Plugin*for*MySQL GET*=*SELECT* 21 shell> curl ... --url "http://../crud/db/sql_types/1" { "id" : "1", "col_char" : "CHAR(127)" , "col_null" : null, "col_date" : "2014-12-23", "col_decimal" : "123.45", "col_float" : "0.9999", "col_bigint" : "9223372036854775807" } shell> curl ... --url 'http://../crud/db/simple/' { "errno" : 2000, "error" : "The request URL must include a primary key value” }
  22. 22. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* MySQL*5.7*Release*Candidate*2*Available!* 22* InnoDB :** * Online&Bulk*load* * * *(mulIpsource,*mulIpthreaded*slaves )* :* greater*user*control*&*bemer*query*performance* Performance*Schema * MySQL*SYS*Schema * *&* * * MySQL*5.6 2 * :** ,* & * NEW!*JSON Support*(now*in*labs)* RC2* And*many*more*new*features*and*enhancements...*hmp://mysqlserverteam.com/thepmysqlp5p7p7preleasepcandidatepispavailable/*!
  23. 23. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* MySQL*5.7*JSON 23
  24. 24. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* MySQL*5.7:*JSON* •  * •  JSON * –  * •  JSON * –  * – SQL * •  Generated*Columns( ) ** – InnoDB STORED VIRTUAL Generated*Columns * –  * •  hmp://mysqlserverteam.com/jsonplabspreleasepoverview/* 24* RC2*
  25. 25. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* MySQL*5.7:*JSON 25 mysql> CREATE TABLE employees (ename JSON); Query OK, 0 rows affected (0,01 sec) mysql> INSERT INTO employees VALUES ('{"id": 1, "name": "Jane"}'); Query OK, 1 row affected (0,00 sec) mysql> INSERT INTO employees VALUES ('{"id": 2, "name": "Joe"}'); Query OK, 1 row affected (0,00 sec) mysql> SELECT * FROM employees; +---------------------------+ | ename| +---------------------------+ | {"id": 1, "name": "Jane"} | | {"id": 2, "name": "Joe"} | +---------------------------+ 2 rows in set (0,00 sec) RC2*
  26. 26. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* MySQL*5.7:*JSON •  Document*ValidaIon* – on*insert*only** •  Efficient*Access* 26 mysql> 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'. mysql> SELECT JSON_EXTRACT(ename, '$.name') FROM employees; +-------------------------------+ | JSON_EXTRACT(ename, '$.name') | +-------------------------------+ | "Jane" | | "Joe" | +-------------------------------+ 2 rows in set (0,00 sec) RC2*
  27. 27. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* New*JSON*datatype:*Supported*Types •  JSON * –  Bool* –  * •  * –  (dateIme) (Imestamp)* – NULL*(5.7.9*)* –  27 RC2*
  28. 28. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* •  json_array() –  Build*a*JSON*array*from*list*of*expressions* •  json_object() –  Builds*JSON*objects*from*a*variable*length*list* of*key/value*pairs* •  json_insert() –  Adds*'missing'*data*to*JSON*documents* •  json_remove() –  Removes*amributes*from*exisIng*JSON* documents* •  json_set() –  Sets*amributes*within*JSON*documents* •  json_replace() –  Replaces*(but*doesn't*add)*amributes*within* JSON*documents* •  json_append() json_array_append()*(5.7.9+)* –  Adds*a*value*to*the*end*of*an*array* •  json_merge() –  Merges*two*arrays** •  json_extract() –  Returns*a*value*nested*inside*of*a*JSON* document* 28* JSON*FuncIons*for*CreaIng*&*ManipulaIng* *JSON*Documents* RC2*
  29. 29. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* •  json_search() –  Search*for*values*within*JSON*documents*and* return*their*locaIons* •  json_contains() –  Checks*for*a*specific*element*and*value* •  json_contains_path() –  Determine*if*a*specific*element*is*present*in*a* document*in*a*specific*posiIon* •  json_valid() –  Check*if*document*is*a*valid*JSON*document* •  json_type() –  Find*the*type*of*a*value*within*a*document* •  json_keys() –  Returns*arrays*of*the*key*names*for*the*JSON* documents* •  json_length() –  Number*of*elements*in*JSON*document* •  json_depth() –  Level*of*nesIng*in*JSON*document* •  json_unquote() –  Helps*move*from*JSON*to*other*MySQL*types* •  json_quote() –  Helps*move*from*other*MySQL*types*to*JSON* 29* Query*and*Search*JSON*FuncIons* RC2*
  30. 30. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* New*FuncIons*to*Handle*JSON*Data:*Path •  [[[database.]table.]column]$<path*spec> 30 •  Path*expr* –  [*[*[database.]*table.]*field]* –  $* –  .idenIfier* –  [array]* –  .**and*[*]* –  ** •  Example* – db.phonebook.data*(future* extension)** – document’s*root* – $.user.address.street* – $.user.addresses[2].street* – $.user.addresses[*].street* – $.user**.phone** RC2*
  31. 31. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* Generated*Columns*p* * •  Virtual*Generated*Column* –  * –  * •  Stored*Generated*Column* –  * –  * mysql> ALTER TABLE employees ADD iname VARCHAR(100) GENERATED ALWAYS AS(json_extract(ename, '$.name')) VIRTUAL; mysql> ALTER TABLE employees ADD INDEX(iname); hmp://mysqlserverteam.com/* 31* JSON * RC2*
  32. 32. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* •  * –  JOIN* –  * –  * •  * –  / * 33* ?*
  33. 33. Copyright*©*201 *Oracle*and/or*its*affiliates.*All*rights*reserved.**|* The*world's*most*popular*open*source*database* * 34

×