SlideShare a Scribd company logo
1 of 49
Download to read offline
Diving into MySQL 5.7
Advanced features
Gabriela Ferrara


@gabidavila
gabriela.io
@gabidavila
But first...
gabi
Developer Advocate @ Google
@gabidavila
MySQL 5.7 Adoption
@gabidavila
5.7
@gabidavila
What to expect?
● Online DDL modes
● JSON Data type
● Generated Columns
● sql_mode
● `sys` schema
@gabidavila
Online DDL
changes
On InnoDB
● INPLACE
● COPY
@gabidavila
@gabidavila
New Online DDL Changes on 5.7 | InnoDB Only
In-place | ALGORITHM=INPLACE
● Rename Index
● Add a Virtual Column
● VARCHAR from 1 to 255
@gabidavila
More info 🔗
@gabidavila
New Online DDL Changes on 5.7 | InnoDB Only
Table-copy | ALGORITHM=COPY
● VARCHAR from 255 to 65535
● Drop Stored Column
@gabidavila
More info 🔗
JSON
@gabidavila
Table `laps`
Column Type
id INT(10)
athlete VARCHAR(255)
distance (m) INT(10)
time (s) INT(10)
summary JSON
@gabidavila
SELECT * FROM `laps` LIMIT 1;
************************** 1. row ***************************

id: 1

athlete: Martha

distance: 3200

time: 1800

summary: {"weight": 55, "nickname": "M", "professional": true}

1 row in set (0.04 sec)
@gabidavila
@gabidavila
Display athlete, nickname and professional status
@gabidavila
+---------+----------+--------------+
| athlete | nickname | professional |
+---------+----------+--------------+
| Martha | "M" | true |
| Marcus | "Flash" | false |
| Martha | "M" | true |
| James | NULL | NULL |
| Marcus | "Flash" | false |
+---------+----------+--------------+
5 rows in set (0.04 sec)
SELECT
athlete,
JSON_EXTRACT(summary, '$.nickname') AS nickname,
JSON_EXTRACT(summary, '$.professional') AS professional
FROM laps;
@gabidavila
JSON_EXTRACT shortcut
@gabidavila
SELECT
athlete,
summary->'$.nickname' AS nickname,
summary->'$.professional' AS professional
FROM laps;
+---------+----------+--------------+
| athlete | nickname | professional |
+---------+----------+--------------+
| Martha | "M" | true |
| Marcus | "Flash" | false |
| Martha | "M" | true |
| James | NULL | NULL |
| Marcus | "Flash" | false |
+---------+----------+--------------+
5 rows in set (0.04 sec)
@gabidavila
JSON_UNQUOTE + JSON_EXTRACT shortcut
@gabidavila
SELECT
athlete,
summary->>'$.nickname' AS nickname,
summary->>'$.professional' AS professional
FROM laps;
+---------+----------+--------------+

| athlete | nickname | professional |

+---------+----------+--------------+

| Martha | M | true |

| Marcus | Flash | false |

| Martha | M | true |

| James | NULL | NULL |

| Marcus | Flash | false |

+---------+----------+--------------+

5 rows in set (0.04 sec)
@gabidavila
JSON_UNQUOTE + JSON_EXTRACT vs. ->>
@gabidavila
SELECT
athlete,
summary->>'$.nickname' AS nickname,
summary->>'$.professional' AS professional
FROM laps;
😎
SELECT
athlete,
JSON_UNQUOTE(JSON_EXTRACT(summary, '$.nickname')) AS nickname,
JSON_UNQUOTE(JSON_EXTRACT(summary, '$.professional')) AS professional
FROM laps;
😕
@gabidavila
JSON Path
● Access key:
● `$` refers to the document itself
● Keys can contain spaces
● JSON_EXTRACT() and -> are the same
● JSON_UNQUOTE(JSON_EXTRACT()) and ->> are the same
Generated
Columns
@gabidavila
@gabidavila
Types
Virtual
● No disk space
● In-place change operation
● Value generated on demand and
on every BEFORE triggers
Stored
● Uses disk space
● Copy operation
● Updated on every INSERT and
UPDATE
@gabidavila
@gabidavila
Virtual & Stored similarities
● They only know the table domain
● They have a type
● Allows expressions to be used such as:
○ Operators (product * quantity)
○ Built-in functions (YEAR(dob))
○ Literals ("expression", 1)
● Can be indexed
@gabidavila
Virtual & Stored limitations
● Subqueries ARE NOT allowed
● Custom functions ARE NOT supported
● Column rename is not possible
● Non deterministic functions are not supported (i.e. NOW())
@gabidavila
Example
@gabidavila
Modified table `laps`
Column Type
id INT(10)
athlete VARCHAR(255)
distance (m) INT(10)
time (s) INT(10)
summary JSON
speed (m/s) DOUBLE
Should it be VIRTUAL or STORED?
@gabidavila
Virtual
Adding the `speed` field to the
`laps` table
Dropping the `speed` field to the
`laps` table
Gist 🔗
ALTER TABLE `laps`
ADD COLUMN speed DOUBLE
GENERATED ALWAYS
AS (`distance` / `time`);
ALTER TABLE `laps`
DROP COLUMN speed;
@gabidavila
Virtual
Adding the `speed` field to the
`laps` table
Dropping the `speed` field to the
`laps` table
Gist 🔗
ALTER TABLE `laps`
ADD COLUMN speed DOUBLE
GENERATED ALWAYS
AS (`distance` / `time`);
-- completed in 82ms
ALTER TABLE `laps`
DROP COLUMN speed;
-- completed in 103ms
@gabidavila
Stored
Adding the `speed` field to the
`laps` table
Dropping the `speed` field to the
`laps` table
Gist 🔗
ALTER TABLE `laps`
ADD COLUMN speed DOUBLE
GENERATED ALWAYS
AS (`distance` / `time`) STORED;
-- 548 rows affected in 778ms
ALTER TABLE `laps`
DROP COLUMN speed;
-- completed in 3s 142ms
Generated
Columns & JSON
Indexing
DEMO!
sql_mode
@gabidavila
@gabidavila
SQL Modes | SELECT @@GLOBAL.sql_mode; | MySQL 5.6
On MySQL 5.6:
+--------------------------------------------+
| @@GLOBAL.sql_mode |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+
1 row in set (0.00 sec)
@gabidavila
@gabidavila
SQL Modes | SELECT @@GLOBAL.sql_mode; | MySQL 5.7
On MySQL 5.7:
+-----------------------------------------------------------------------+
| @@GLOBAL.sql_mode |
+-----------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE, |

| ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+-----------------------------------------------------------------------+
1 row in set (0.00 sec)
@gabidavila
@gabidavila
SQL Modes | Comparison
On MySQL 5.6:
! STRICT_TRANS_TABLES
! NO_ENGINE_SUBSTITUTION
On MySQL 5.7:
! STRICT_TRANS_TABLES
! NO_ENGINE_SUBSTITUTION
! NO_ZERO_IN_DATE*
! NO_ZERO_DATE*
! ERROR_FOR_DIVISION_BY_ZERO*
! ONLY_FULL_GROUP_BY
@gabidavila
@gabidavila
Example
@gabidavila
@gabidavila
Table `laps`
Column Type
id INT(10)
athlete VARCHAR(255)
distance (m) INT(10)
time (s) INT(10)
summary JSON
speed (m/s) DOUBLE
Gist 🔗
@gabidavila
@gabidavila
SELECT * FROM `laps`;
+----+---------+----------+------+

| id | athlete | distance | time |

+----+---------+----------+------+

| 1 | Martha | 3200 | 1800 |

| 2 | Marcus | 10000 | 2100 |

| 3 | Martha | 200 | 50 |

| 4 | James | 1600 | 480 |

| 5 | Marcus | 1600 | 240 |

+----+---------+----------+------+

5 rows in set (0.04 sec)
@gabidavila
@gabidavila
mysql> SELECT * FROM `laps` GROUP BY athlete;
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and
contains nonaggregated column 'olympics.laps.id' which is not functionally
dependent on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by
SELECT * FROM `laps` GROUP BY athlete;
SELECT `id`, `athlete`, `distance`, `time`, `summary`
FROM `laps`
GROUP BY athlete;
@gabidavila
mysql> SELECT * FROM `laps` GROUP BY athlete;
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and
contains nonaggregated column 'olympics.laps.id' which is not functionally
dependent on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by
SELECT * FROM `laps` GROUP BY athlete;
SELECT `id`, `athlete`, `distance`, `time`, `summary`
FROM `laps`
GROUP BY athlete;
@gabidavila
Why?
"Reject queries for which the select list, HAVING condition, or ORDER BY list
refer to nonaggregated columns that are neither named in the GROUP BY
clause nor are functionally dependent on (uniquely determined by) GROUP BY
columns."
@gabidavila
@gabidavila
Translation
This happens because the query is grouping by athlete and MySQL is
magically trying to “discover” which field should it bring as a result to the other
columns since there are more than one possible value per row.


This mode is known as ONLY_FULL_GROUP_BY.
More info 🔗
@gabidavila
@gabidavila
@gabidavila
Group By
● Columns should either be on the GROUP BY clause OR be using an
aggregator on the SELECT clause.
● Aggregators:
● ANY_VALUE()
● MIN()
● MAX()
● SUM()
● COUNT()
@gabidavila@gabidavila
`sys` schema
@gabidavila
MySQL `sys` schema
● Needs to be installed on 5.6
● Installed by default on 5.7
● MySQL Workbench 6.3 ships with a client for it
● If enabled, in production should be used for critical analytical cases
@gabidavila
@gabidavila
What can I do with it?
*High Cost SQL statements select * from sys.`x$statement_analysis`
Top 5% slower queries
select * from
sys.`x$statements_with_runtimes_in_95th_percentile`
Use temporary tables select * from sys.`statements_with_temp_tables`
Unused Indexes select * from sys.`schema_unused_indexes`
Full table scans
select * from
sys.`schema_tables_with_full_table_scans`
*x$ is actually a view duplicated from a table with a more user friendly format
@gabidavila
Other Changes
@gabidavila
Changes on 5.7
● Passwords can now have expiration date
● NO_ZERO_DATE, NO_ZERO_IN_DATE, ERROR_FOR_DIVISION_BY_ZERO
are deprecated and being default in STRICT mode in future versions
● Triggers now supports more than one event per table
● YEAR(2) was deprecated on 5.6, removed on 5.7
@gabidavila
Thank you!
● Twitter: @gabidavila
● Blog: http://gabriela.io
● Freenode: gabidavila
● Feedback: https://joind.in/talk/18d42
● References: MySQL documentation

More Related Content

What's hot

The world's next top data model
The world's next top data modelThe world's next top data model
The world's next top data model
Patrick McFadin
 
Understanding Query Execution
Understanding Query ExecutionUnderstanding Query Execution
Understanding Query Execution
webhostingguy
 

What's hot (20)

BGOUG15: JSON support in MySQL 5.7
BGOUG15: JSON support in MySQL 5.7BGOUG15: JSON support in MySQL 5.7
BGOUG15: JSON support in MySQL 5.7
 
Modern solutions for modern database load: improvements in the latest MariaDB...
Modern solutions for modern database load: improvements in the latest MariaDB...Modern solutions for modern database load: improvements in the latest MariaDB...
Modern solutions for modern database load: improvements in the latest MariaDB...
 
Php forum2015 tomas_final
Php forum2015 tomas_finalPhp forum2015 tomas_final
Php forum2015 tomas_final
 
Data Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database AnalyticsData Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database Analytics
 
Load Data Fast!
Load Data Fast!Load Data Fast!
Load Data Fast!
 
Introduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sIntroduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]s
 
Optimizer Histograms: When they Help and When Do Not?
Optimizer Histograms: When they Help and When Do Not?Optimizer Histograms: When they Help and When Do Not?
Optimizer Histograms: When they Help and When Do Not?
 
Mentor Your Indexes
Mentor Your IndexesMentor Your Indexes
Mentor Your Indexes
 
Linq
LinqLinq
Linq
 
Laracon EU 2018: OMG MySQL 8.0 is out! are we there yet?
Laracon EU 2018: OMG MySQL 8.0 is out! are we there yet?Laracon EU 2018: OMG MySQL 8.0 is out! are we there yet?
Laracon EU 2018: OMG MySQL 8.0 is out! are we there yet?
 
Brief introduction of Slick
Brief introduction of SlickBrief introduction of Slick
Brief introduction of Slick
 
Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2
 
Sql query patterns, optimized
Sql query patterns, optimizedSql query patterns, optimized
Sql query patterns, optimized
 
Cassandra nice use cases and worst anti patterns no sql-matters barcelona
Cassandra nice use cases and worst anti patterns no sql-matters barcelonaCassandra nice use cases and worst anti patterns no sql-matters barcelona
Cassandra nice use cases and worst anti patterns no sql-matters barcelona
 
Cassandra 3 new features 2016
Cassandra 3 new features 2016Cassandra 3 new features 2016
Cassandra 3 new features 2016
 
The world's next top data model
The world's next top data modelThe world's next top data model
The world's next top data model
 
Billion Goods in Few Categories: how Histograms Save a Life?
Billion Goods in Few Categories: how Histograms Save a Life?Billion Goods in Few Categories: how Histograms Save a Life?
Billion Goods in Few Categories: how Histograms Save a Life?
 
Understanding Query Execution
Understanding Query ExecutionUnderstanding Query Execution
Understanding Query Execution
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query Tuning
 
Cassandra Materialized Views
Cassandra Materialized ViewsCassandra Materialized Views
Cassandra Materialized Views
 

Similar to Diving into MySQL 5.7: advanced features

Developers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman OracleDevelopers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman Oracle
mCloud
 

Similar to Diving into MySQL 5.7: advanced features (20)

MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
 
GRONINGEN PHP - MySQL 8.0 , not only good, great
GRONINGEN PHP - MySQL 8.0 , not only good, greatGRONINGEN PHP - MySQL 8.0 , not only good, great
GRONINGEN PHP - MySQL 8.0 , not only good, great
 
PHPDay 2019 - MySQL 8, not only good, great!
PHPDay 2019 - MySQL 8, not only good, great!PHPDay 2019 - MySQL 8, not only good, great!
PHPDay 2019 - MySQL 8, not only good, great!
 
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksQuery Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
 
Oracle SQL Tuning
Oracle SQL TuningOracle SQL Tuning
Oracle SQL Tuning
 
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
 
Developers’ mDay u Banjoj Luci - Bogdan Kecman, Oracle – MySQL Server 8.0
Developers’ mDay u Banjoj Luci - Bogdan Kecman, Oracle – MySQL Server 8.0Developers’ mDay u Banjoj Luci - Bogdan Kecman, Oracle – MySQL Server 8.0
Developers’ mDay u Banjoj Luci - Bogdan Kecman, Oracle – MySQL Server 8.0
 
Developers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman OracleDevelopers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman Oracle
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a Nutshell
 
Securing your MySQL / MariaDB Server data
Securing your MySQL / MariaDB Server dataSecuring your MySQL / MariaDB Server data
Securing your MySQL / MariaDB Server data
 
Postgres Performance for Humans
Postgres Performance for HumansPostgres Performance for Humans
Postgres Performance for Humans
 
15 MySQL Basics #burningkeyboards
15 MySQL Basics #burningkeyboards15 MySQL Basics #burningkeyboards
15 MySQL Basics #burningkeyboards
 
Love Your Database Railsconf 2017
Love Your Database Railsconf 2017Love Your Database Railsconf 2017
Love Your Database Railsconf 2017
 
Oracle goldengate 11g schema replication from standby database
Oracle goldengate 11g schema replication from standby databaseOracle goldengate 11g schema replication from standby database
Oracle goldengate 11g schema replication from standby database
 
Mysql56 replication
Mysql56 replicationMysql56 replication
Mysql56 replication
 
Oracle SQL Tuning
Oracle SQL TuningOracle SQL Tuning
Oracle SQL Tuning
 
Harness SharePoint and jQuery to Make Dynamic Displays and Applications
 Harness SharePoint and jQuery to Make Dynamic Displays and Applications Harness SharePoint and jQuery to Make Dynamic Displays and Applications
Harness SharePoint and jQuery to Make Dynamic Displays and Applications
 
Beginner guide to mysql command line
Beginner guide to mysql command lineBeginner guide to mysql command line
Beginner guide to mysql command line
 
DNN Database Tips & Tricks
DNN Database Tips & TricksDNN Database Tips & Tricks
DNN Database Tips & Tricks
 

More from Gabriela Ferrara

More from Gabriela Ferrara (13)

Serverless and you @ Women Who Code London 2020
Serverless and you  @ Women Who Code London 2020Serverless and you  @ Women Who Code London 2020
Serverless and you @ Women Who Code London 2020
 
Serverless and you - where do i run my stateless code
Serverless and you  - where do i run my stateless codeServerless and you  - where do i run my stateless code
Serverless and you - where do i run my stateless code
 
PyTexas - Machine learning APIs by Example
PyTexas - Machine learning APIs by ExamplePyTexas - Machine learning APIs by Example
PyTexas - Machine learning APIs by Example
 
MySQL 8.0 Preview: What Is Coming?
MySQL 8.0 Preview: What Is Coming?MySQL 8.0 Preview: What Is Coming?
MySQL 8.0 Preview: What Is Coming?
 
LaravelSP - MySQL 5.7: introdução ao JSON Data Type
LaravelSP - MySQL 5.7: introdução ao JSON Data TypeLaravelSP - MySQL 5.7: introdução ao JSON Data Type
LaravelSP - MySQL 5.7: introdução ao JSON Data Type
 
MySQL 5.7 - 
Tirando o Máximo Proveito
MySQL 5.7 - 
Tirando o Máximo ProveitoMySQL 5.7 - 
Tirando o Máximo Proveito
MySQL 5.7 - 
Tirando o Máximo Proveito
 
Strip your TEXT fields - Exeter Web Feb/2016
Strip your TEXT fields - Exeter Web Feb/2016Strip your TEXT fields - Exeter Web Feb/2016
Strip your TEXT fields - Exeter Web Feb/2016
 
Strip your TEXT fields
Strip your TEXT fieldsStrip your TEXT fields
Strip your TEXT fields
 
Coding like a girl - DjangoCon
Coding like a girl - DjangoConCoding like a girl - DjangoCon
Coding like a girl - DjangoCon
 
LAMP: Desenvolvendo além do trivial
LAMP: Desenvolvendo além do trivialLAMP: Desenvolvendo além do trivial
LAMP: Desenvolvendo além do trivial
 
Database Wizardry for Legacy Applications
Database Wizardry for Legacy ApplicationsDatabase Wizardry for Legacy Applications
Database Wizardry for Legacy Applications
 
Coding like a girl - Youtube presentation
Coding like a girl - Youtube presentationCoding like a girl - Youtube presentation
Coding like a girl - Youtube presentation
 
Coding like a Girl
Coding like a GirlCoding like a Girl
Coding like a Girl
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Diving into MySQL 5.7: advanced features

  • 1. Diving into MySQL 5.7 Advanced features Gabriela Ferrara 
 @gabidavila gabriela.io
  • 5. @gabidavila What to expect? ● Online DDL modes ● JSON Data type ● Generated Columns ● sql_mode ● `sys` schema @gabidavila
  • 6. Online DDL changes On InnoDB ● INPLACE ● COPY @gabidavila
  • 7. @gabidavila New Online DDL Changes on 5.7 | InnoDB Only In-place | ALGORITHM=INPLACE ● Rename Index ● Add a Virtual Column ● VARCHAR from 1 to 255 @gabidavila More info 🔗
  • 8. @gabidavila New Online DDL Changes on 5.7 | InnoDB Only Table-copy | ALGORITHM=COPY ● VARCHAR from 255 to 65535 ● Drop Stored Column @gabidavila More info 🔗
  • 10. @gabidavila Table `laps` Column Type id INT(10) athlete VARCHAR(255) distance (m) INT(10) time (s) INT(10) summary JSON
  • 11. @gabidavila SELECT * FROM `laps` LIMIT 1; ************************** 1. row ***************************
 id: 1
 athlete: Martha
 distance: 3200
 time: 1800
 summary: {"weight": 55, "nickname": "M", "professional": true}
 1 row in set (0.04 sec) @gabidavila
  • 12. @gabidavila Display athlete, nickname and professional status @gabidavila +---------+----------+--------------+ | athlete | nickname | professional | +---------+----------+--------------+ | Martha | "M" | true | | Marcus | "Flash" | false | | Martha | "M" | true | | James | NULL | NULL | | Marcus | "Flash" | false | +---------+----------+--------------+ 5 rows in set (0.04 sec) SELECT athlete, JSON_EXTRACT(summary, '$.nickname') AS nickname, JSON_EXTRACT(summary, '$.professional') AS professional FROM laps;
  • 13. @gabidavila JSON_EXTRACT shortcut @gabidavila SELECT athlete, summary->'$.nickname' AS nickname, summary->'$.professional' AS professional FROM laps; +---------+----------+--------------+ | athlete | nickname | professional | +---------+----------+--------------+ | Martha | "M" | true | | Marcus | "Flash" | false | | Martha | "M" | true | | James | NULL | NULL | | Marcus | "Flash" | false | +---------+----------+--------------+ 5 rows in set (0.04 sec)
  • 14. @gabidavila JSON_UNQUOTE + JSON_EXTRACT shortcut @gabidavila SELECT athlete, summary->>'$.nickname' AS nickname, summary->>'$.professional' AS professional FROM laps; +---------+----------+--------------+
 | athlete | nickname | professional |
 +---------+----------+--------------+
 | Martha | M | true |
 | Marcus | Flash | false |
 | Martha | M | true |
 | James | NULL | NULL |
 | Marcus | Flash | false |
 +---------+----------+--------------+
 5 rows in set (0.04 sec)
  • 15. @gabidavila JSON_UNQUOTE + JSON_EXTRACT vs. ->> @gabidavila SELECT athlete, summary->>'$.nickname' AS nickname, summary->>'$.professional' AS professional FROM laps; 😎 SELECT athlete, JSON_UNQUOTE(JSON_EXTRACT(summary, '$.nickname')) AS nickname, JSON_UNQUOTE(JSON_EXTRACT(summary, '$.professional')) AS professional FROM laps; 😕
  • 16. @gabidavila JSON Path ● Access key: ● `$` refers to the document itself ● Keys can contain spaces ● JSON_EXTRACT() and -> are the same ● JSON_UNQUOTE(JSON_EXTRACT()) and ->> are the same
  • 18. @gabidavila Types Virtual ● No disk space ● In-place change operation ● Value generated on demand and on every BEFORE triggers Stored ● Uses disk space ● Copy operation ● Updated on every INSERT and UPDATE @gabidavila
  • 19. @gabidavila Virtual & Stored similarities ● They only know the table domain ● They have a type ● Allows expressions to be used such as: ○ Operators (product * quantity) ○ Built-in functions (YEAR(dob)) ○ Literals ("expression", 1) ● Can be indexed
  • 20. @gabidavila Virtual & Stored limitations ● Subqueries ARE NOT allowed ● Custom functions ARE NOT supported ● Column rename is not possible ● Non deterministic functions are not supported (i.e. NOW())
  • 22. @gabidavila Modified table `laps` Column Type id INT(10) athlete VARCHAR(255) distance (m) INT(10) time (s) INT(10) summary JSON speed (m/s) DOUBLE Should it be VIRTUAL or STORED?
  • 23. @gabidavila Virtual Adding the `speed` field to the `laps` table Dropping the `speed` field to the `laps` table Gist 🔗 ALTER TABLE `laps` ADD COLUMN speed DOUBLE GENERATED ALWAYS AS (`distance` / `time`); ALTER TABLE `laps` DROP COLUMN speed;
  • 24. @gabidavila Virtual Adding the `speed` field to the `laps` table Dropping the `speed` field to the `laps` table Gist 🔗 ALTER TABLE `laps` ADD COLUMN speed DOUBLE GENERATED ALWAYS AS (`distance` / `time`); -- completed in 82ms ALTER TABLE `laps` DROP COLUMN speed; -- completed in 103ms
  • 25. @gabidavila Stored Adding the `speed` field to the `laps` table Dropping the `speed` field to the `laps` table Gist 🔗 ALTER TABLE `laps` ADD COLUMN speed DOUBLE GENERATED ALWAYS AS (`distance` / `time`) STORED; -- 548 rows affected in 778ms ALTER TABLE `laps` DROP COLUMN speed; -- completed in 3s 142ms
  • 27. DEMO!
  • 29. @gabidavila SQL Modes | SELECT @@GLOBAL.sql_mode; | MySQL 5.6 On MySQL 5.6: +--------------------------------------------+ | @@GLOBAL.sql_mode | +--------------------------------------------+ | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | +--------------------------------------------+ 1 row in set (0.00 sec) @gabidavila
  • 30. @gabidavila SQL Modes | SELECT @@GLOBAL.sql_mode; | MySQL 5.7 On MySQL 5.7: +-----------------------------------------------------------------------+ | @@GLOBAL.sql_mode | +-----------------------------------------------------------------------+ | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE, |
 | ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION | +-----------------------------------------------------------------------+ 1 row in set (0.00 sec) @gabidavila
  • 31. @gabidavila SQL Modes | Comparison On MySQL 5.6: ! STRICT_TRANS_TABLES ! NO_ENGINE_SUBSTITUTION On MySQL 5.7: ! STRICT_TRANS_TABLES ! NO_ENGINE_SUBSTITUTION ! NO_ZERO_IN_DATE* ! NO_ZERO_DATE* ! ERROR_FOR_DIVISION_BY_ZERO* ! ONLY_FULL_GROUP_BY @gabidavila
  • 33. @gabidavila Table `laps` Column Type id INT(10) athlete VARCHAR(255) distance (m) INT(10) time (s) INT(10) summary JSON speed (m/s) DOUBLE Gist 🔗 @gabidavila
  • 34. @gabidavila SELECT * FROM `laps`; +----+---------+----------+------+
 | id | athlete | distance | time |
 +----+---------+----------+------+
 | 1 | Martha | 3200 | 1800 |
 | 2 | Marcus | 10000 | 2100 |
 | 3 | Martha | 200 | 50 |
 | 4 | James | 1600 | 480 |
 | 5 | Marcus | 1600 | 240 |
 +----+---------+----------+------+
 5 rows in set (0.04 sec) @gabidavila
  • 35. @gabidavila mysql> SELECT * FROM `laps` GROUP BY athlete; ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'olympics.laps.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by SELECT * FROM `laps` GROUP BY athlete; SELECT `id`, `athlete`, `distance`, `time`, `summary` FROM `laps` GROUP BY athlete;
  • 36. @gabidavila mysql> SELECT * FROM `laps` GROUP BY athlete; ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'olympics.laps.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by SELECT * FROM `laps` GROUP BY athlete; SELECT `id`, `athlete`, `distance`, `time`, `summary` FROM `laps` GROUP BY athlete;
  • 37. @gabidavila Why? "Reject queries for which the select list, HAVING condition, or ORDER BY list refer to nonaggregated columns that are neither named in the GROUP BY clause nor are functionally dependent on (uniquely determined by) GROUP BY columns." @gabidavila
  • 38. @gabidavila Translation This happens because the query is grouping by athlete and MySQL is magically trying to “discover” which field should it bring as a result to the other columns since there are more than one possible value per row. 
 This mode is known as ONLY_FULL_GROUP_BY. More info 🔗 @gabidavila
  • 40. @gabidavila Group By ● Columns should either be on the GROUP BY clause OR be using an aggregator on the SELECT clause. ● Aggregators: ● ANY_VALUE() ● MIN() ● MAX() ● SUM() ● COUNT()
  • 43. @gabidavila MySQL `sys` schema ● Needs to be installed on 5.6 ● Installed by default on 5.7 ● MySQL Workbench 6.3 ships with a client for it ● If enabled, in production should be used for critical analytical cases
  • 45. @gabidavila What can I do with it? *High Cost SQL statements select * from sys.`x$statement_analysis` Top 5% slower queries select * from sys.`x$statements_with_runtimes_in_95th_percentile` Use temporary tables select * from sys.`statements_with_temp_tables` Unused Indexes select * from sys.`schema_unused_indexes` Full table scans select * from sys.`schema_tables_with_full_table_scans` *x$ is actually a view duplicated from a table with a more user friendly format
  • 48. @gabidavila Changes on 5.7 ● Passwords can now have expiration date ● NO_ZERO_DATE, NO_ZERO_IN_DATE, ERROR_FOR_DIVISION_BY_ZERO are deprecated and being default in STRICT mode in future versions ● Triggers now supports more than one event per table ● YEAR(2) was deprecated on 5.6, removed on 5.7
  • 49. @gabidavila Thank you! ● Twitter: @gabidavila ● Blog: http://gabriela.io ● Freenode: gabidavila ● Feedback: https://joind.in/talk/18d42 ● References: MySQL documentation