51

MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

  • Upload
    others

  • View
    18

  • Download
    0

Embed Size (px)

Citation preview

Page 1: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL
Page 2: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

MySQL5.7+JSON

MorganTockerMySQLProductManager

Page 3: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

SafeHarborStatement

Thefollowingisintendedtooutlineourgeneralproductdirection.Itisintendedforinformationpurposesonly,andmaynotbeincorporatedintoanycontract.Itisnotacommitmenttodeliveranymaterial,code,orfunctionality,andshouldnotberelieduponinmakingpurchasingdecisions.Thedevelopment,release,andtimingofanyfeaturesorfunctionalitydescribedforOracle’sproductsremainsatthesolediscretionofOracle.

3

Page 4: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|4

Today’sAgenda

Introduction

CoreNewJSONFeatures

ToJSONor!JSON?

1

2

3

Page 5: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

MySQL5.7-TheTeam• 2xEngineeringStaff• 3xQAStaff• 2xSupportStaff

5

Jan2010 2015

Page 6: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

Labs DMRsRCsGA

ReleaseProcess

6

Youarehere

Page 7: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

MySQL5.7isGA!

7

EnhancedInnoDB:fasteronline&bulkloadoperations

ReplicationImprovements(incl.multi-source,multi-threadedslaves...)

NewOptimizerCostModel:greaterusercontrol&betterqueryperformance

PerformanceSchemaImprovements

MySQLSYSSchema

Performance&Scalability Manageability

3XFasterthanMySQL5.6

ImprovedSecurity:saferinitialization,setup&management

NativeJSONSupport

Page 8: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.| 8

THECOMPLETELISTOFFEATURES.COM

Page 9: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.| 9

THECOMPLETELISTOFFEATURES.COM

Page 10: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.| 10

THECOMPLETELISTOFFEATURES.COM

Page 11: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.| 11

THECOMPLETELISTOFFEATURES.COM

Page 12: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

MySQLEnterpriseEdition

NEW!MySQLEnterpriseFirewallBlockSQLInjecionAjacksIntrusionDetecion

MySQLEnterpriseEncrypionPublic/PrivateKeyCryptographyAsymmetricEncrypionDigitalSignatures,DataValidaion

MySQLEnterpriseAuthenicaionExternalAuthenicaionModules

MicrosonAD,LinuxPAMsMySQLEnterpriseAudit

UserAcivityAudiing,RegulatoryCompliance

12

MySQLEnterpriseMonitorChangesinDatabaseConfiguraions,UsersPermissions,DatabaseSchema,Passwords

MySQLEnterpriseBackupSecuringBackups,AES256encrypion

MySQLEnterpriseSupport

Moreinforma+onavailableat:h2p://www.mysql.com/products/enterprise/

Page 13: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|13

Today’sAgenda

Introduction

CoreNewJSONFeatures

ToJSONor!JSON?

1

2

3

2

1

Page 14: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

CoreNewJSONfeaturesinMySQL5.71. NativeJSONdatatype2. JSONFunctions3. GeneratedColumns

14

Page 15: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

TheJSONType

15

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)

Page 16: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

JSONTypeTechSpecs• utf8mb4characterset• Optimizedforreadintensiveworkload• Parseandvalidationoninsertonly• Fastaccesstoarraycellsbyindex

16

Page 17: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

JSONTypeTechSpecs(cont.)• SupportsallnativeJSONtypes• Numbers,strings,bool• Objects,arrays

• Extended• Date,time,datetime,timestamp• Other

17

Page 18: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

AdvantagesoverTEXT/VARCHAR1. ProvidesDocumentValidation:

2. EfficientBinaryFormat Allowsquickeraccesstoobjectmembersandarrayelements

18

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'.

Page 19: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

JSONFunctions

19

SET @document = '[10, 20, [30, 40]]';

SELECT JSON_EXTRACT(@document, '$[1]'); +---------------------------------+ | JSON_EXTRACT(@document, '$[1]') | +---------------------------------+ | 20 | +---------------------------------+ 1 row in set (0.01 sec)

Page 20: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

• AcceptsaJSONPath,whichissimilartoaselector:

• JSON_EXTRACTalsosupportsashorthand:column_name->"$.type"

JSON_EXTRACT

20

$("#type") JSON_EXTRACT (column_name,"$.type")

Page 21: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

UsingRealLifeData• ViaSFOpenData• 206KJSONobjects representingsubdivision parcels.

• Importedfromhttps://github.com/zemirco/sf-city-lots-json+smalltweaks

21

CREATE TABLE features (id INT NOT NULL auto_increment primary key,feature JSON NOT NULL );

Page 22: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.| 22

{ "type":"Feature", "geometry":{ "type":"Polygon", "coordinates":[ [ [-122.42200352825247,37.80848009696725,0], [-122.42207601332528,37.808835019815085,0], [-122.42110217434865,37.808803534992904,0], [-122.42106256906727,37.80860105681814,0], [-122.42200352825247,37.80848009696725,0] ] ] }, "properties":{ "TO_ST":"0", "BLKLOT":"0001001", "STREET":"UNKNOWN", "FROM_ST":"0", "LOT_NUM":"001", "ST_TYPE":null, "ODD_EVEN":"E", "BLOCK_NUM":"0001", "MAPBLKLOT":"0001001" } }

Page 23: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

JSONSearch

23

# Basic FindSELECT * 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)

Page 24: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

JSONSearch

24

# Find where not existsSELECT * FROM features WHERE feature->"$.properties.STREET" IS NULLLIMIT 1\G Empty set (0.39 sec)

Page 25: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

NaivePerformanceComparison

25

# as JSON typeSELECT DISTINCT feature->"$.type" as json_extractFROM features; +--------------+ | json_extract | +--------------+ | "Feature" | +--------------+ 1 row in set (1.25 sec)

Unindexedtraversalof206Kdocuments

# as TEXT type SELECT DISTINCT feature->"$.type" as json_extractFROM features; +--------------+ | json_extract | +--------------+ | "Feature" | +--------------+ 1 row in set (12.85 sec)

Explanation:BinaryformatofJSONtypeisveryefficientatsearching.StoringasTEXTperformsover10xworseattraversal.

UsingshortcutforJSON_EXTRACT.

Page 26: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

IntroducingGeneratedColumns

26

id my_integer my_integer_plus_one

1 10 11

2 20 21

3 30 31

4 40 41

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.

Columnautomaticallymaintainedbasedonyourspecification.

Read-onlyofcourse

Page 27: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

GeneratedColumnsSupportIndexes!

27

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)

Fromtablescanon206Kdocumentstoindexscanon206Kmaterializedvalues

Downfrom1.25secto0.06sec

Createsindexonly.Doesnotmodifytablerows.

Metadatachangeonly(FAST).Doesnotneedtotouchtable.

Page 28: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

GeneratedColumns(cont.)• Usedfor“functionalindex”• AvailableaseitherVIRTUAL(default)orSTORED:

• Bothtypesofcomputedcolumnspermitforindexestobeadded.

28

ALTER TABLE features ADD feature_type varchar(30) AS (feature->"$.type") STORED; Query OK, 206560 rows affected (4.70 sec) Records: 206560 Duplicates: 0 Warnings: 0

Page 29: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

IndexingOptionsAvailable

29

STORED VIRTUALPrimaryandSecondary

BTREE,Fulltext,GIS

Mixedwithfields

Requirestablerebuild

NotOnline

SecondaryOnly

BTREEOnly

Mixedwithfields

Notablerebuild

INSTANTAlter

FasterInsert

BottomLine:UnlessyouneedaPRIMARYKEY,FULLTEXTorGISindexVIRTUALisprobablybetter.

Page 30: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

UnquoteJSONString

SELECT DISTINCT JSON_UNQUOTE(feature->"$.type") as feature_type FROM features; +-----------------+ | feature_type | +-----------------+ | Feature | +-----------------+ 1 row in set (1.22 sec)

30

Page 31: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

JSONPathSearch• Providesanovicewaytoknowthepath.Toretrievevia:[[database.]table.]column->"$<pathspec>"

31

SELECT JSON_SEARCH(feature, 'one', 'MARKET') AS extract_path FROM features WHERE id = 121254; +-----------------------+ | extract_path | +-----------------------+ | "$.properties.STREET" | +-----------------------+ 1 row in set (0.00 sec)

SELECTfeature->"$.properties.STREET" AS property_streetFROM featuresWHERE id = 121254; +-----------------+ | property_street | +-----------------+ | "MARKET" | +-----------------+1 row in set (0.00 sec)

Page 32: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

JSONArrayCreation

32

SELECT JSON_ARRAY(id, feature->"$.properties.STREET", feature->'$.type") AS json_arrayFROM features ORDER BY RAND() LIMIT 3; +-------------------------------+ | json_array | +-------------------------------+ | [65298, "10TH", "Feature"] | | [122985, "08TH", "Feature"] | | [172884, "CURTIS", "Feature"] | +-------------------------------+ 3 rows in set (2.66 sec)

Page 33: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

JSONObjectCreation

33

SELECT JSON_OBJECT('id', id, 'street', feature->"$.properties.STREET", 'type', feature->"$.type" ) AS json_object FROM features ORDER BY RAND() LIMIT 3; +--------------------------------------------------------+ | json_object | +--------------------------------------------------------+ | {"id": 122976, "type": "Feature", "street": "RAUSCH"} | | {"id": 148698, "type": "Feature", "street": "WALLACE"} | | {"id": 45214, "type": "Feature", "street": "HAIGHT"} | +--------------------------------------------------------+ 3 rows in set (3.11 sec)

Page 34: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

JSON_REPLACE

34

SELECT JSON_REPLACE(feature, '$.type', JSON_ARRAY('feature', 'bug')) as json_object FROM features LIMIT 1; +--------------------------------------------------------+ | json_object | +--------------------------------------------------------+ | {"type": ["feature", "bug"], "geometry": {"type": ..}} | +--------------------------------------------------------+

Page 35: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

• 5.7supportsfunctionstoCREATE,SEARCH,MODIFYandRETURNJSONvalues:

JSONFunctions

35

JSON_ARRAY_APPEND()

JSON_ARRAY_INSERT()

JSON_ARRAY()

JSON_CONTAINS_PATH()

JSON_CONTAINS()

JSON_DEPTH()

JSON_EXTRACT()

JSON_INSERT()

JSON_KEYS()

JSON_LENGTH()

JSON_MERGE()

JSON_OBJECT()

JSON_QUOTE()

JSON_REMOVE()

JSON_REPLACE()

JSON_SEARCH()

JSON_SET()

JSON_TYPE()

JSON_UNQUOTE()

JSON_VALID()

https://dev.mysql.com/doc/refman/5.7/en/json-functions.html

Page 36: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

JSONComparator

36

SELECT CAST(1 AS JSON) = 1; +---------------------+ | CAST(1 AS JSON) = 1 | +---------------------+ | 1 | +---------------------+ 1 row in set (0.01 sec) SELECT CAST('{"num": 1.1}' AS JSON) = CAST('{"num": 1.1}' AS JSON); +-------------------------------------------------------------+ | CAST('{"num": 1.1}' AS JSON) = CAST('{"num": 1.1}' AS JSON) | +-------------------------------------------------------------+ | 1 | +-------------------------------------------------------------+ 1 row in set (0.00 sec)

JSONvalueof1equals1

JSONObjectsCompare

Page 37: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|37

Today’sAgenda

Introduction

CoreNewJSONFeatures

ToJSONor!JSON?

1

22

1

2

3

Page 38: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

JSONorColumn?• Uptoyou!• Advantagestobothapproaches

38

Page 39: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

StoringasaColumn• Easiertoapplyaschematoyourapplication• Schemamaymakeapplicationseasiertomaintainovertime,aschangeiscontrolled;• Donothavetoexpectasmanypermutations• Allowssomeconstraintsoverdata

39

Page 40: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

StoringasJSON• Moreflexiblewaytorepresentdatathatishardtomodelinschema;• ImagineyouareaSaaSapplicationservingmanycustomers• Stronguse-casetosupportcustom-fields• HistoricallythismayhaveusedEntity–attribute–valuemodel(EAV).Doesnotalwaysperformwell

40

Page 41: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

JSON(cont.)• Easierdenormalization;anoptimizationthatisimportantinsomespecificsituations• Nopainfulschemachanges*• Easierprototyping• Fewertypestoconsider• Noenforcedschema,startstoringvaluesimmediately

41

*MySQL5.6hasOnlineDDL.Thisisnotaslargeofanissueasitwashistorically.

Page 42: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

Schema+Schemaless

42

SSDshavecapacity_in_gb,CPUshaveacore_count.Theseattributesarenotconsistentacrossproducts.

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 );

Page 43: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

SSDs• Compressionisagreatfitrequirementformodernstorage• Allowsnegationofnewconstraint;lowercapacity

43

HardDrive SSD

Capacity High Low

IOPSAvailable Low High

SequentialIOPerformance Good VeryGood

RandomIOPerformance Bad VeryGood

Lifetime Good MaximumRead/WriteCycles

Page 44: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

JSONDocuments• Maycompresswell• Schemalessmeansthatthekeysarerepeatedineachofthedocuments

• Repetitionimprovescompressionperformance• MySQL5.7alsosupports32KBand64KBpages(improvedcompression)

44

Page 45: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

MySQL5.7PageCompression• InnoDBhashadcompressionsince5.1-plugin• MySQL5.7introducesanew,simplerversionofpagecompression• Itreliesonpunch-holesupport

45

Page 46: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

CompressionPerformance(16KPage)

46

SELECT name, ((file_size-allocated_size)*100)/file_size as compressed_pct from information_schema.INNODB_SYS_TABLESPACES WHERE name like 'test/features'; +---------------+----------------+ | name | compressed_pct | +---------------+----------------+ | test/features | 59.2634 | +---------------+----------------+ 1 row in set (0.01 sec)

Usingreal-lifedatasetfromearlier

Page 47: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

AdditionalFeatures• ViewsandtriggerscanbeusedmigratebetweenJSONandtoplevelcolumns• MySQL5.7supportsmultipletriggerspertableevent!

• 5.7alsosupportsserver-sidequeryrewrite

47

Page 48: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

RoadMap• In-placepartialupdateofJSON/BLOB(performance)• PartialstreamingofJSON/BLOB(replication)• FulltextandGISindexonvirtualcolumns• Currentlyworksfor"STORED"

• Multi-valueIndex

48

Page 49: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2015Oracleand/oritsaffiliates.Allrightsreserved.|

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

49

Page 50: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL

Copyright©2014Oracleand/oritsaffiliates.Allrightsreserved.|50

Page 51: MySQL 5.7 + JSON - FOSDEM · • No painful schema changes* • Easier prototyping • Fewer types to consider • No enforced schema, start storing values immediately 41 * MySQL