SlideShare a Scribd company logo
OMG MySQL 8.0 is out! Are
we there yet?
Gabriela Ferrara
@gabidavila
http://gabriela.io | gabi.fyi/feedback
@gabidavila
Gabi
!
Developer Advocate
@gabidavila
Cloud SQL
PostgreSQLMySQL
@gabidavila
MySQL 8.0.12
@gabidavila
Are we there yet?
🤔
● Created to handle from up to
10 to 100M rows or around
100MB/table
● Now supports terabyte-sized
databases
● Supports parts of SQL
standards as new as SQL 2016
● But... some stuff from SQL
2003 just became available
(Window Functions, CTEs)
● What can we go from here?
@gabidavila
What Happened to 6.0 and 7.0?
@gabidavila
Topics
● New Defaults & Variables
● InnoDB Performance
● Window Functions
● CTE - Common Table Expressions
@gabidavila
New Defaults & Variables
@gabidavila
New default Charset
● Default:
● 5.7: latin1
● 8.0: utf8mb4
● Improvements:
● ➕ Mathematical Equations 𝑒=𝑚·𝑐²
● 😁 🙄 &
● & more SMP (Supplementary Multilingual Plane) Characters
@gabidavila
New default Collation
● utf8mb4_0900_ai_ci
● UTF-8 version 9.0 support
● Accent Insensitive
● Case Insensitive
● No more 🍣 = 🍺 bug
● Caused by utf8mb4_general_ci or utf8mb4_unicode_ci
More information on how collations behave here.
@gabidavila
Other defaults & variables
● Binary log (log_bin) is enabled by default
● SHA-2 for authentication
● Mandatory default value for TIMESTAMP NOT NULL
● New variable to dedicated servers (default OFF),
innodb_dedicated_server=ON , controls dynamically:
● innodb_buffer_pool_size
● innodb_log_file_size
● innodb_flush_method
@gabidavila
InnoDB Performance
@gabidavila
Transaction Scheduling
RDBMS usually works on a FIFO architecture
Transaction A
Transaction B
Transaction C
Start
End
@gabidavila
CATS
First database in the world to
implement
@gabidavila
Contention Aware Transaction Scheduling
@gabidavila
CATS vs FIFO | Transactions per Second (TPS)
0
5500
11000
16500
22000
32 64 128 256 512
FIFO CATS
DataextractedfromMySQLServerTeamwebsite.
Transactions per Second x # Clients
Higher is better
@gabidavila
CATS vs FIFO | Latency
0
45
90
135
180
32 64 128 256 512
FIFO CATS
DataextractedfromMySQLServerTeamwebsite.
Mean Latency x # Clients
Lower is better
@gabidavila
ALGORITHM=INSTANT
● If possible, the default is INSTANT, else it will be INPLACE
● Only metadata changed on the Data Dictionary
● Supported on:
● Change index
● Rename Table
● SET/DROP DEFAULT
● MODIFY COLUMN
● ADD/DROP Virtual Columns
● ADD COLUMN (non-generated)
🐞 Tiny bug if you are migrating from 8.0.11
@gabidavila
Indexes
@gabidavila
DESCRIBE `lines`;
type null extra
id int(11) NO AUTO_INCREMENT
number int(11) YES
timpestamp_in_ms timestamp YES
character_id int(11) NO
episode_id int(11) NO
location_id int(11) NO
character_line text YES
word_count int(11) YES
@gabidavila
Invisible Indexes
● Not used by the optimizer
● Visible by default, to create an invisible index:
ALTER TABLE lines
ADD INDEX ix_word_count (word_count) INVISIBLE;
ALTER TABLE lines ALTER INDEX ix_word_count INVISIBLE;
ALTER TABLE lines ALTER INDEX ix_word_count VISIBLE;
● Toggle visibility:
@gabidavila
Now imagine if an Eloquent migration…
@gabidavila
Could do…
@gabidavila
Laravel
Taylor will be waiting your pull request!
@gabidavila
Invisible Indexes
SELECT *
FROM lines
WHERE word_count > 25
ORDER BY word_count DESC;
Invisible
Query cost: 59175.37
Visible
Query cost: 2847.86
@gabidavila
Descending Indexes
Up to 5.7
● Syntax allowed ASC or DESC when defining an index
However...
An index_col_name specification can end with ASC or DESC. These keywords are
permitted for future extensions for specifying ascending or descending index value
storage. Currently, they are parsed but ignored; index values are always stored in
ascending order.
@gabidavila
MySQL 8.0 has it!!!
@gabidavila
Descending Indexes
● No longer ignored and forcibly created as ASC
ALTER TABLE lines
ADD INDEX ix_word_count (word_count DESC);
@gabidavila
Descending Indexes
Can be scanned as intended or backwards
SELECT *
FROM lines
WHERE word_count > 25
ORDER BY word_count DESC;
-- OR WITH THE SAME COST
SELECT *
FROM lines
WHERE word_count > 25
ORDER BY word_count;
@gabidavila
DEMO
@gabidavila
More cool features!
@gabidavila
Window Functions
@gabidavila
What they do?
● Allows to analyze the rows of a given result set
● Can behave like a GROUP BY without changing the result set
● Allows you to use a frame to "peek" OVER a PARTITION of a window
@gabidavila
Window Functions
● Examples:
● Enumerate rows - ROW_NUMBER()
● Show Aggregated sums - SUM()
● Rank results - RANK(), DENSE_RANK()
● Look at neighboring rows - LEAD(), LAG()
@gabidavila
DESCRIBE `episodes`;
CREATE TABLE `episodes` (
`id` int(11) NOT NULL,
`title` varchar(255),
`episode_date` date,
`season` int(11),
`number_in_season` int(11),
`number_in_series` int(11),
`million_viewers` decimal(10, 2),
`imdb_rating` decimal(10, 2),
`imdb_votes` decimal(10, 2),
`image_url` text,
`video_url` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
@gabidavila
SELECT … FROM `episodes` LIMIT 10;
+----+--------------+-----------------------------------+--------+------------------+-----------------+
| id | episode_date | title | season | number_in_season | million_viewers |
+----+--------------+-----------------------------------+--------+------------------+-----------------+
| 1 | 1989-12-17 | Simpsons Roasting on an Open Fire | 1 | 1 | 26.70 |
| 2 | 1990-01-14 | Bart the Genius | 1 | 2 | 24.50 |
| 3 | 1990-01-21 | Homer's Odyssey | 1 | 3 | 27.50 |
| 4 | 1990-01-28 | There's No Disgrace Like Home | 1 | 4 | 20.20 |
| 5 | 1990-02-04 | Bart the General | 1 | 5 | 27.10 |
| 6 | 1990-02-11 | Moaning Lisa | 1 | 6 | 27.40 |
| 7 | 1990-02-18 | The Call of the Simpsons | 1 | 7 | 27.60 |
| 8 | 1990-02-25 | The Telltale Head | 1 | 8 | 28.00 |
| 9 | 1990-03-18 | Life on the Fast Lane | 1 | 9 | 33.50 |
| 10 | 1990-03-25 | Homer's Night Out | 1 | 10 | 30.30 |
+----+--------------+-----------------------------------+--------+------------------+-----------------+
10 rows in set (0.00 sec)
@gabidavila
Previous and Next episodes | LAG and LEAD
SELECT
id,
title,
LAG(episode_date, 1) OVER (ORDER BY episode_date) AS previous_episode,
episode_date,
LEAD(episode_date, 1) OVER (ORDER BY episode_date) AS next_episode,
million_viewers
FROM episodes;
@gabidavila
SELECT … FROM `episodes` LIMIT 10;
+----+-----------------------------------+------------------+--------------+--------------+-----------------+
| id | title | previous_episode | episode_date | next_episode | million_viewers |
+----+-----------------------------------+------------------+--------------+--------------+-----------------+
| 1 | Simpsons Roasting on an Open Fire | NULL | 1989-12-17 | 1990-01-14 | 26.70 |
| 2 | Bart the Genius | 1989-12-17 | 1990-01-14 | 1990-01-21 | 24.50 |
| 3 | Homer's Odyssey | 1990-01-14 | 1990-01-21 | 1990-01-28 | 27.50 |
| 4 | There's No Disgrace Like Home | 1990-01-21 | 1990-01-28 | 1990-02-04 | 20.20 |
| 5 | Bart the General | 1990-01-28 | 1990-02-04 | 1990-02-11 | 27.10 |
| 6 | Moaning Lisa | 1990-02-04 | 1990-02-11 | 1990-02-18 | 27.40 |
| 7 | The Call of the Simpsons | 1990-02-11 | 1990-02-18 | 1990-02-25 | 27.60 |
| 8 | The Telltale Head | 1990-02-18 | 1990-02-25 | 1990-03-18 | 28.00 |
| 9 | Life on the Fast Lane | 1990-02-25 | 1990-03-18 | 1990-03-25 | 33.50 |
| 10 | Homer's Night Out | 1990-03-18 | 1990-03-25 | 1990-04-15 | 30.30 |
+----+-----------------------------------+------------------+--------------+--------------+-----------------+
10 rows in set (0.01 sec)
@gabidavila
Break down
LAG(episode_date, 1) OVER (ORDER BY episode_date)
windowfunction
column
# rows preceding
@gabidavila
Repetition?
SELECT
id,
title,
LAG(episode_date, 1) OVER (ORDER BY episode_date) AS previous_episode,
episode_date,
LEAD(episode_date, 1) OVER (ORDER BY episode_date) AS next_episode,
million_viewers
FROM episodes;
@gabidavila
SELECT
id,
title,
LAG(episode_date, 1) OVER (dates) AS previous_episode,
episode_date,
LEAD(episode_date, 1) OVER (dates) AS next_episode,
million_viewers
FROM episodes
WINDOW dates AS (ORDER BY episode_date);
Named Windows!
@gabidavila
DEMO
Rank episodes by million_viewers
@gabidavila
CTE

Common Table Expressions
@gabidavila
Common Table Expressions
● Similar to CREATE [TEMPORARY] TABLE
● Doesn’t need CREATE privilege
● Can reference other CTEs (if those are already defined)
● Can be recursive
● Easier to read
@gabidavila
Rank episodes by million_viewers
SELECT
id,
season,
number_in_season AS '# in season',
title,
episode_date,
million_viewers,
DENSE_RANK() OVER (season_viewers) AS episode_rank
FROM episodes
WINDOW season_viewers
AS (PARTITION BY season ORDER BY million_viewers DESC)
@gabidavila
DEMO
Filter ranked episodes
@gabidavila
Recursive CTE
● Useful with hierarchical data
● The Recipe is:
● Base query comes first
● Second query comes after a UNION statement
● And the stop condition should be on the recursive call
@gabidavila
Fibonacci
WITH RECURSIVE fibonacci(recursion_level, fibonacci_number, next_number)
AS (
# Base Case
SELECT 0 AS recursion_level,
0 AS fibonacci_number,
1 AS next_number
UNION ALL
# Recursion query
SELECT recursion_level + 1,
next_number,
fibonacci_number + next_number
FROM fibonacci
# Stopping condition
WHERE
recursion_level < 10
)
SELECT * FROM fibonacci;
@gabidavila
Fibonacci
WITH RECURSIVE fibonacci(recursion_level, fibonacci_number, next_number)
AS (
# Base Case
SELECT 0 AS recursion_level,
0 AS fibonacci_number,
1 AS next_number
UNION ALL
# Recursion query
SELECT recursion_level + 1,
next_number,
fibonacci_number + next_number
FROM fibonacci
# Stopping condition
WHERE
recursion_level < 10
)
SELECT * FROM fibonacci;
@gabidavila
Fibonacci
+-----------------+------------------+-------------+
| recursion_level | fibonacci_number | next_number |
+-----------------+------------------+-------------+
| 0 | 0 | 1 |
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 2 | 3 |
| 4 | 3 | 5 |
| 5 | 5 | 8 |
| 6 | 8 | 13 |
| 7 | 13 | 21 |
| 8 | 21 | 34 |
| 9 | 34 | 55 |
| 10 | 55 | 89 |
+-----------------+------------------+-------------+
11 rows in set (0.00 sec)
Base case
Recursive Query
@gabidavila
Other Bits
@gabidavila
Other MySQL 8.0 Bits
● Users now can have ROLES
● JSON partial update
● Better Geospatial support
● Better UUID support
● Use MySQL without SQL (through MySQL Shell or X-DevApi)
@gabidavila
Thank you!
Please give me feedback on my talk!
gabi.fyi/feedback

More Related Content

PDF
Sql query patterns, optimized
Karwin Software Solutions LLC
 
PDF
Firebird 3 Windows Functions
Mind The Firebird
 
PDF
Sql server windowing functions
Enrique Catala Bañuls
 
PDF
Percona toolkit
Karwin Software Solutions LLC
 
PDF
PerlApp2Postgresql (2)
Jerome Eteve
 
ODP
Chetan postgresql partitioning
suniltomar04
 
PDF
Integrating React.js with PHP projects
Ignacio Martín
 
PDF
QuirksofR
Ankur Gupta
 
Sql query patterns, optimized
Karwin Software Solutions LLC
 
Firebird 3 Windows Functions
Mind The Firebird
 
Sql server windowing functions
Enrique Catala Bañuls
 
PerlApp2Postgresql (2)
Jerome Eteve
 
Chetan postgresql partitioning
suniltomar04
 
Integrating React.js with PHP projects
Ignacio Martín
 
QuirksofR
Ankur Gupta
 

What's hot (10)

PDF
The Beautiful Simplicity of ES2015
Brandon Belvin
 
ODP
Building a Hierarchical Data Model Using the Latest IBM Informix Features
Ajay Gupte
 
PPTX
Java script advance-auroskills (2)
BoneyGawande
 
PPTX
Simplifying SQL with CTE's and windowing functions
Clayton Groom
 
PDF
Sql 99 and_some_techniques
Alexey Kiselyov
 
PDF
Building Smart Async Functions For Mobile
Glan Thomas
 
PPTX
Java script – basic auroskills (2)
BoneyGawande
 
PPTX
Session #4: Treating Databases as First-Class Citizens in Development
Steve Lange
 
PDF
The Ring programming language version 1.5.4 book - Part 181 of 185
Mahmoud Samir Fayed
 
PPTX
Mcs011 solved assignment by divya singh
DIVYA SINGH
 
The Beautiful Simplicity of ES2015
Brandon Belvin
 
Building a Hierarchical Data Model Using the Latest IBM Informix Features
Ajay Gupte
 
Java script advance-auroskills (2)
BoneyGawande
 
Simplifying SQL with CTE's and windowing functions
Clayton Groom
 
Sql 99 and_some_techniques
Alexey Kiselyov
 
Building Smart Async Functions For Mobile
Glan Thomas
 
Java script – basic auroskills (2)
BoneyGawande
 
Session #4: Treating Databases as First-Class Citizens in Development
Steve Lange
 
The Ring programming language version 1.5.4 book - Part 181 of 185
Mahmoud Samir Fayed
 
Mcs011 solved assignment by divya singh
DIVYA SINGH
 
Ad

Similar to Laracon EU 2018: OMG MySQL 8.0 is out! are we there yet? (20)

PDF
DPC18 - OMG MySQL 8.0 is out! are we there yet?
Gabriela Ferrara
 
PDF
MySQL 8.0: not only good, it’s GREAT! - PHP UK 2019
Gabriela Ferrara
 
PDF
MySQL Goes to 8! FOSDEM 2020 Database Track, January 2nd, 2020
Geir Høydalsvik
 
PPTX
MySQL 8.0 Released Update
Keith Hollman
 
PDF
PHPDay 2019 - MySQL 8, not only good, great!
Gabriela Ferrara
 
PDF
MySQL Cookbook 1st ed Edition Paul Dubois
uzielklael28
 
PDF
MariaDB workshop
Alex Chistyakov
 
PDF
MySQL Cookbook 1st ed Edition Paul Dubois
outqwzytic3178
 
PDF
MySQL Cheat Sheet & Quick Referenece.pdf
vaibhavar253
 
PPTX
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
Dave Stokes
 
PPTX
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
Dave Stokes
 
PDF
MySQL Cookbook 1st ed Edition Paul Dubois
giupnziyfo714
 
PDF
Scaling MySQL Strategies for Developers
Jonathan Levin
 
PDF
MySQL Indexing Crash Course
Aaron Silverman
 
PDF
Database Design most common pitfalls
Federico Razzoli
 
PDF
RivieraJUG - MySQL 8.0 - What's new for developers.pdf
Frederic Descamps
 
PPTX
cPanel now supports MySQL 8.0 - My Top Seven Features
Dave Stokes
 
PDF
MySQL for beginners
Saeid Zebardast
 
PDF
MySQL 8.0 Preview: What Is Coming?
Gabriela Ferrara
 
PPT
Explain that explain
Fabrizio Parrella
 
DPC18 - OMG MySQL 8.0 is out! are we there yet?
Gabriela Ferrara
 
MySQL 8.0: not only good, it’s GREAT! - PHP UK 2019
Gabriela Ferrara
 
MySQL Goes to 8! FOSDEM 2020 Database Track, January 2nd, 2020
Geir Høydalsvik
 
MySQL 8.0 Released Update
Keith Hollman
 
PHPDay 2019 - MySQL 8, not only good, great!
Gabriela Ferrara
 
MySQL Cookbook 1st ed Edition Paul Dubois
uzielklael28
 
MariaDB workshop
Alex Chistyakov
 
MySQL Cookbook 1st ed Edition Paul Dubois
outqwzytic3178
 
MySQL Cheat Sheet & Quick Referenece.pdf
vaibhavar253
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
Dave Stokes
 
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
Dave Stokes
 
MySQL Cookbook 1st ed Edition Paul Dubois
giupnziyfo714
 
Scaling MySQL Strategies for Developers
Jonathan Levin
 
MySQL Indexing Crash Course
Aaron Silverman
 
Database Design most common pitfalls
Federico Razzoli
 
RivieraJUG - MySQL 8.0 - What's new for developers.pdf
Frederic Descamps
 
cPanel now supports MySQL 8.0 - My Top Seven Features
Dave Stokes
 
MySQL for beginners
Saeid Zebardast
 
MySQL 8.0 Preview: What Is Coming?
Gabriela Ferrara
 
Explain that explain
Fabrizio Parrella
 
Ad

More from Gabriela Ferrara (16)

PDF
Serverless and you @ Women Who Code London 2020
Gabriela Ferrara
 
PDF
Serverless and you - where do i run my stateless code
Gabriela Ferrara
 
PDF
PyTexas - Machine learning APIs by Example
Gabriela Ferrara
 
PDF
DPC18 - Making the most out of MySQL
Gabriela Ferrara
 
PDF
php[tek] - Making the most out of MySQL
Gabriela Ferrara
 
PDF
Diving into MySQL 5.7: advanced features
Gabriela Ferrara
 
PDF
LaravelSP - MySQL 5.7: introdução ao JSON Data Type
Gabriela Ferrara
 
PDF
SunshinePHP 2017 - Making the most out of MySQL
Gabriela Ferrara
 
PDF
MySQL 5.7 - 
Tirando o Máximo Proveito
Gabriela Ferrara
 
PDF
Strip your TEXT fields - Exeter Web Feb/2016
Gabriela Ferrara
 
PDF
Strip your TEXT fields
Gabriela Ferrara
 
PDF
Coding like a girl - DjangoCon
Gabriela Ferrara
 
PDF
LAMP: Desenvolvendo além do trivial
Gabriela Ferrara
 
PDF
Database Wizardry for Legacy Applications
Gabriela Ferrara
 
PDF
Coding like a girl - Youtube presentation
Gabriela Ferrara
 
PDF
Coding like a Girl
Gabriela Ferrara
 
Serverless and you @ Women Who Code London 2020
Gabriela Ferrara
 
Serverless and you - where do i run my stateless code
Gabriela Ferrara
 
PyTexas - Machine learning APIs by Example
Gabriela Ferrara
 
DPC18 - Making the most out of MySQL
Gabriela Ferrara
 
php[tek] - Making the most out of MySQL
Gabriela Ferrara
 
Diving into MySQL 5.7: advanced features
Gabriela Ferrara
 
LaravelSP - MySQL 5.7: introdução ao JSON Data Type
Gabriela Ferrara
 
SunshinePHP 2017 - Making the most out of MySQL
Gabriela Ferrara
 
MySQL 5.7 - 
Tirando o Máximo Proveito
Gabriela Ferrara
 
Strip your TEXT fields - Exeter Web Feb/2016
Gabriela Ferrara
 
Strip your TEXT fields
Gabriela Ferrara
 
Coding like a girl - DjangoCon
Gabriela Ferrara
 
LAMP: Desenvolvendo além do trivial
Gabriela Ferrara
 
Database Wizardry for Legacy Applications
Gabriela Ferrara
 
Coding like a girl - Youtube presentation
Gabriela Ferrara
 
Coding like a Girl
Gabriela Ferrara
 

Recently uploaded (20)

PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Software Development Methodologies in 2025
KodekX
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 

Laracon EU 2018: OMG MySQL 8.0 is out! are we there yet?

  • 1. OMG MySQL 8.0 is out! Are we there yet? Gabriela Ferrara @gabidavila http://gabriela.io | gabi.fyi/feedback
  • 5. @gabidavila Are we there yet? 🤔 ● Created to handle from up to 10 to 100M rows or around 100MB/table ● Now supports terabyte-sized databases ● Supports parts of SQL standards as new as SQL 2016 ● But... some stuff from SQL 2003 just became available (Window Functions, CTEs) ● What can we go from here?
  • 7. @gabidavila Topics ● New Defaults & Variables ● InnoDB Performance ● Window Functions ● CTE - Common Table Expressions
  • 9. @gabidavila New default Charset ● Default: ● 5.7: latin1 ● 8.0: utf8mb4 ● Improvements: ● ➕ Mathematical Equations 𝑒=𝑚·𝑐² ● 😁 🙄 & ● & more SMP (Supplementary Multilingual Plane) Characters
  • 10. @gabidavila New default Collation ● utf8mb4_0900_ai_ci ● UTF-8 version 9.0 support ● Accent Insensitive ● Case Insensitive ● No more 🍣 = 🍺 bug ● Caused by utf8mb4_general_ci or utf8mb4_unicode_ci More information on how collations behave here.
  • 11. @gabidavila Other defaults & variables ● Binary log (log_bin) is enabled by default ● SHA-2 for authentication ● Mandatory default value for TIMESTAMP NOT NULL ● New variable to dedicated servers (default OFF), innodb_dedicated_server=ON , controls dynamically: ● innodb_buffer_pool_size ● innodb_log_file_size ● innodb_flush_method
  • 13. @gabidavila Transaction Scheduling RDBMS usually works on a FIFO architecture Transaction A Transaction B Transaction C Start End
  • 14. @gabidavila CATS First database in the world to implement
  • 16. @gabidavila CATS vs FIFO | Transactions per Second (TPS) 0 5500 11000 16500 22000 32 64 128 256 512 FIFO CATS DataextractedfromMySQLServerTeamwebsite. Transactions per Second x # Clients Higher is better
  • 17. @gabidavila CATS vs FIFO | Latency 0 45 90 135 180 32 64 128 256 512 FIFO CATS DataextractedfromMySQLServerTeamwebsite. Mean Latency x # Clients Lower is better
  • 18. @gabidavila ALGORITHM=INSTANT ● If possible, the default is INSTANT, else it will be INPLACE ● Only metadata changed on the Data Dictionary ● Supported on: ● Change index ● Rename Table ● SET/DROP DEFAULT ● MODIFY COLUMN ● ADD/DROP Virtual Columns ● ADD COLUMN (non-generated) 🐞 Tiny bug if you are migrating from 8.0.11
  • 20. @gabidavila DESCRIBE `lines`; type null extra id int(11) NO AUTO_INCREMENT number int(11) YES timpestamp_in_ms timestamp YES character_id int(11) NO episode_id int(11) NO location_id int(11) NO character_line text YES word_count int(11) YES
  • 21. @gabidavila Invisible Indexes ● Not used by the optimizer ● Visible by default, to create an invisible index: ALTER TABLE lines ADD INDEX ix_word_count (word_count) INVISIBLE; ALTER TABLE lines ALTER INDEX ix_word_count INVISIBLE; ALTER TABLE lines ALTER INDEX ix_word_count VISIBLE; ● Toggle visibility:
  • 22. @gabidavila Now imagine if an Eloquent migration…
  • 24. @gabidavila Laravel Taylor will be waiting your pull request!
  • 25. @gabidavila Invisible Indexes SELECT * FROM lines WHERE word_count > 25 ORDER BY word_count DESC; Invisible Query cost: 59175.37 Visible Query cost: 2847.86
  • 26. @gabidavila Descending Indexes Up to 5.7 ● Syntax allowed ASC or DESC when defining an index However... An index_col_name specification can end with ASC or DESC. These keywords are permitted for future extensions for specifying ascending or descending index value storage. Currently, they are parsed but ignored; index values are always stored in ascending order.
  • 28. @gabidavila Descending Indexes ● No longer ignored and forcibly created as ASC ALTER TABLE lines ADD INDEX ix_word_count (word_count DESC);
  • 29. @gabidavila Descending Indexes Can be scanned as intended or backwards SELECT * FROM lines WHERE word_count > 25 ORDER BY word_count DESC; -- OR WITH THE SAME COST SELECT * FROM lines WHERE word_count > 25 ORDER BY word_count;
  • 33. @gabidavila What they do? ● Allows to analyze the rows of a given result set ● Can behave like a GROUP BY without changing the result set ● Allows you to use a frame to "peek" OVER a PARTITION of a window
  • 34. @gabidavila Window Functions ● Examples: ● Enumerate rows - ROW_NUMBER() ● Show Aggregated sums - SUM() ● Rank results - RANK(), DENSE_RANK() ● Look at neighboring rows - LEAD(), LAG()
  • 35. @gabidavila DESCRIBE `episodes`; CREATE TABLE `episodes` ( `id` int(11) NOT NULL, `title` varchar(255), `episode_date` date, `season` int(11), `number_in_season` int(11), `number_in_series` int(11), `million_viewers` decimal(10, 2), `imdb_rating` decimal(10, 2), `imdb_votes` decimal(10, 2), `image_url` text, `video_url` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  • 36. @gabidavila SELECT … FROM `episodes` LIMIT 10; +----+--------------+-----------------------------------+--------+------------------+-----------------+ | id | episode_date | title | season | number_in_season | million_viewers | +----+--------------+-----------------------------------+--------+------------------+-----------------+ | 1 | 1989-12-17 | Simpsons Roasting on an Open Fire | 1 | 1 | 26.70 | | 2 | 1990-01-14 | Bart the Genius | 1 | 2 | 24.50 | | 3 | 1990-01-21 | Homer's Odyssey | 1 | 3 | 27.50 | | 4 | 1990-01-28 | There's No Disgrace Like Home | 1 | 4 | 20.20 | | 5 | 1990-02-04 | Bart the General | 1 | 5 | 27.10 | | 6 | 1990-02-11 | Moaning Lisa | 1 | 6 | 27.40 | | 7 | 1990-02-18 | The Call of the Simpsons | 1 | 7 | 27.60 | | 8 | 1990-02-25 | The Telltale Head | 1 | 8 | 28.00 | | 9 | 1990-03-18 | Life on the Fast Lane | 1 | 9 | 33.50 | | 10 | 1990-03-25 | Homer's Night Out | 1 | 10 | 30.30 | +----+--------------+-----------------------------------+--------+------------------+-----------------+ 10 rows in set (0.00 sec)
  • 37. @gabidavila Previous and Next episodes | LAG and LEAD SELECT id, title, LAG(episode_date, 1) OVER (ORDER BY episode_date) AS previous_episode, episode_date, LEAD(episode_date, 1) OVER (ORDER BY episode_date) AS next_episode, million_viewers FROM episodes;
  • 38. @gabidavila SELECT … FROM `episodes` LIMIT 10; +----+-----------------------------------+------------------+--------------+--------------+-----------------+ | id | title | previous_episode | episode_date | next_episode | million_viewers | +----+-----------------------------------+------------------+--------------+--------------+-----------------+ | 1 | Simpsons Roasting on an Open Fire | NULL | 1989-12-17 | 1990-01-14 | 26.70 | | 2 | Bart the Genius | 1989-12-17 | 1990-01-14 | 1990-01-21 | 24.50 | | 3 | Homer's Odyssey | 1990-01-14 | 1990-01-21 | 1990-01-28 | 27.50 | | 4 | There's No Disgrace Like Home | 1990-01-21 | 1990-01-28 | 1990-02-04 | 20.20 | | 5 | Bart the General | 1990-01-28 | 1990-02-04 | 1990-02-11 | 27.10 | | 6 | Moaning Lisa | 1990-02-04 | 1990-02-11 | 1990-02-18 | 27.40 | | 7 | The Call of the Simpsons | 1990-02-11 | 1990-02-18 | 1990-02-25 | 27.60 | | 8 | The Telltale Head | 1990-02-18 | 1990-02-25 | 1990-03-18 | 28.00 | | 9 | Life on the Fast Lane | 1990-02-25 | 1990-03-18 | 1990-03-25 | 33.50 | | 10 | Homer's Night Out | 1990-03-18 | 1990-03-25 | 1990-04-15 | 30.30 | +----+-----------------------------------+------------------+--------------+--------------+-----------------+ 10 rows in set (0.01 sec)
  • 39. @gabidavila Break down LAG(episode_date, 1) OVER (ORDER BY episode_date) windowfunction column # rows preceding
  • 40. @gabidavila Repetition? SELECT id, title, LAG(episode_date, 1) OVER (ORDER BY episode_date) AS previous_episode, episode_date, LEAD(episode_date, 1) OVER (ORDER BY episode_date) AS next_episode, million_viewers FROM episodes;
  • 41. @gabidavila SELECT id, title, LAG(episode_date, 1) OVER (dates) AS previous_episode, episode_date, LEAD(episode_date, 1) OVER (dates) AS next_episode, million_viewers FROM episodes WINDOW dates AS (ORDER BY episode_date); Named Windows!
  • 44. @gabidavila Common Table Expressions ● Similar to CREATE [TEMPORARY] TABLE ● Doesn’t need CREATE privilege ● Can reference other CTEs (if those are already defined) ● Can be recursive ● Easier to read
  • 45. @gabidavila Rank episodes by million_viewers SELECT id, season, number_in_season AS '# in season', title, episode_date, million_viewers, DENSE_RANK() OVER (season_viewers) AS episode_rank FROM episodes WINDOW season_viewers AS (PARTITION BY season ORDER BY million_viewers DESC)
  • 47. @gabidavila Recursive CTE ● Useful with hierarchical data ● The Recipe is: ● Base query comes first ● Second query comes after a UNION statement ● And the stop condition should be on the recursive call
  • 48. @gabidavila Fibonacci WITH RECURSIVE fibonacci(recursion_level, fibonacci_number, next_number) AS ( # Base Case SELECT 0 AS recursion_level, 0 AS fibonacci_number, 1 AS next_number UNION ALL # Recursion query SELECT recursion_level + 1, next_number, fibonacci_number + next_number FROM fibonacci # Stopping condition WHERE recursion_level < 10 ) SELECT * FROM fibonacci;
  • 49. @gabidavila Fibonacci WITH RECURSIVE fibonacci(recursion_level, fibonacci_number, next_number) AS ( # Base Case SELECT 0 AS recursion_level, 0 AS fibonacci_number, 1 AS next_number UNION ALL # Recursion query SELECT recursion_level + 1, next_number, fibonacci_number + next_number FROM fibonacci # Stopping condition WHERE recursion_level < 10 ) SELECT * FROM fibonacci;
  • 50. @gabidavila Fibonacci +-----------------+------------------+-------------+ | recursion_level | fibonacci_number | next_number | +-----------------+------------------+-------------+ | 0 | 0 | 1 | | 1 | 1 | 1 | | 2 | 1 | 2 | | 3 | 2 | 3 | | 4 | 3 | 5 | | 5 | 5 | 8 | | 6 | 8 | 13 | | 7 | 13 | 21 | | 8 | 21 | 34 | | 9 | 34 | 55 | | 10 | 55 | 89 | +-----------------+------------------+-------------+ 11 rows in set (0.00 sec) Base case Recursive Query
  • 52. @gabidavila Other MySQL 8.0 Bits ● Users now can have ROLES ● JSON partial update ● Better Geospatial support ● Better UUID support ● Use MySQL without SQL (through MySQL Shell or X-DevApi)
  • 53. @gabidavila Thank you! Please give me feedback on my talk! gabi.fyi/feedback