SlideShare a Scribd company logo
1 of 55
Download to read offline
Gabriela D'Avila Ferrara
@gabidavila
gabriela.io/feedback | https://joind.in/talk/8edff
Making the most out
of MySQL
1
@gabidavila
•Developer Advocate
•Lego Hoarder
•@gabidavila
•http://gabriela.io
2
$ whoami
•Ada's mom: @ada_doglace
@gabidavila
3
!
@gabidavila
What to expect?
•DDL Changes
•SQL Modes
•Generated Columns
•JSON Data Type
4
@gabidavila
5.7 to... 8.0? "
5
@gabidavila
DDL changes on
InnoDB
6
@gabidavila
•Table-copy (ALGORITHM=COPY)
• VARCHAR from 256B to 65535B
• Type conversion
• Add a column* (<=5.7)
Normal DDL changes
7
@gabidavila
ALTER TABLE with COPY
•1st step: create new table structure with newer definition
•2nd step: copy the data from the original table to the new table
•3rd step: drop the old table and rename the new table
8
@gabidavila
Normal DDL Change
9
ALTER TABLE addresses
CHANGE COLUMN user_id user_id BIGINT;
ALTER TABLE users
ADD COLUMN password_digest VARCHAR(255);
@gabidavila
Online DDL Changes
•In place (ALGORITHM=INPLACE)
• Rename index
• VARCHAR from 1B to 255B
• Add a Virtual Column
10
@gabidavila
Online DDL Changes
11
ALTER TABLE addresses
CHANGE COLUMN state state VARCHAR(255);
ALTER TABLE addresses
RENAME INDEX `state_index` TO `ix_state`;
@gabidavila
SQL Modes
12
@gabidavila
SQL Modes (SELECT @@GLOBAL.sql_mode;)
13
On MySQL 5.6:
+--------------------------------------------+
| @@GLOBAL.sql_mode |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+
1 row in set (0.00 sec)
On MySQL 5.7 and 8.0:
+-----------------------------------------------------------------------+
| @@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
MySQL 5.6:
•STRICT_TRANS_TABLES
•NO_ENGINE_SUBSTITUTION
MySQL 5.7 & 8.0:
•STRICT_TRANS_TABLES
•NO_ENGINE_SUBSTITUTION
•ONLY_FULL_GROUP_BY
•NO_ZERO_IN_DATE*
•NO_ZERO_DATE*
•ERROR_FOR_DIVISION_BY_ZERO*
SQL Modes comparison
14
Full list of sql_mode
@gabidavila
STRICT_TRANS_TABLES
•Affects transactional dates.
•No longer inserts '0000-00-00' in columns where DATE NOT NULL
15
@gabidavila
ERROR_FOR_DIVISION_BY_ZERO
•Write Operation: UPDATE
mysql> UPDATE users SET id = id/0 WHERE id = 2;
ERROR 1365 (22012): Division by 0
16
•Read Operation: SELECT
mysql> SELECT id, first_name, last_name, id/0 FROM users WHERE id = 2;
+----+------------+-----------+------+
| id | first_name | last_name | id/0 |
+----+------------+-----------+------+
| 2 | Gabriela | Ferrara | NULL |
+----+------------+-----------+------+
1 row in set, 1 warning (0.00 sec)
@gabidavila
17
@gabidavila
ONLY_FULL_GROUP_BY
18
@gabidavila
Table `users`
19
Field Type Null Key Default Extra
id int(10) unsigned NO PRI auto_increment
first_name varchar(255) NO NULL
last_name varchar(255) NO NULL
email varchar(255) NO NULL
twitter_info json YES
@gabidavila
Repeated emails 5.6
20
5.6
SELECT * FROM users GROUP BY email HAVING count(*) > 1
+-------+------------+-----------+---------------------+--------------------------------+
| id | first_name | last_name | email | twitter_info |
+-------+------------+-----------+---------------------+--------------------------------+
| 8965 | Conor | Quitzon | yjacobson@yahoo.com | {"id": 100838242, "url": "http |
| 69772 | Junius | Mante | nkuhlman@gmail.com | {"id": 20039476, "url": "https |
| 66525 | Katelynn | Feil | qgottlieb@gmail.com | {"id": 111644778, "url": "http |
| 92577 | Tillman | Nienow | zzieme@yahoo.com | {"id": 1359073920, "url": "htt |
| 18046 | Guillermo | Lebsack | cdoyle@gmail.com | {"id": 120064855, "url": null, |
+-------+------------+-----------+---------------------+--------------------------------+
5 rows in set (0.65 sec)
@gabidavila
Repeated emails
21
SELECT * FROM users WHERE email = 'cdoyle@gmail.com'
+-------+------------+-----------+------------------+--------------+
| id | first_name | last_name | email | twitter_info |
+-------+------------+-----------+------------------+--------------+
| 18046 | Guillermo | Lebsack | cdoyle@gmail.com | {...} |
| 20559 | Marietta | Quitzon | cdoyle@gmail.com | {...} |
+-------+------------+-----------+------------------+--------------+
2 rows in set (0.04 sec)
@gabidavila
Repeated emails 5.6 & 8.0
22
5.7 8.0
mysql> SELECT * FROM `users` GROUP BY `email` HAVING count(*) > 1;
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY
clause and contains nonaggregated column ‘social.users.id’ which is
not functionally dependent on columns in GROUP BY clause; this is
incompatible with sql_mode=only_full_group_by
SELECT * FROM users GROUP BY email HAVING count(*) > 1
@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."
23
@gabidavila
Hm...
24
@gabidavila
MySQL to human Translation
This happens because the query is grouping by email and MySQL is magically
trying to “guess” which field it should bring as a result to the other columns (id,
first_name, etc.) and it gives an error since there are more than one result per row
and no aggregator was used to specify the correct value.
25
More Info
@gabidavila
The Fix 🛠
26
@gabidavila
Aggregators!!!
•min(column)
•max(column)
•group_concat(column)
•count(column) or count(*)
•sum(column)
27
@gabidavila
Old way: using the magic 🎩
28
SELECT * FROM users GROUP BY email HAVING count(*) > 1
<?php
// Doctrine
$qb = $entityManager->createQueryBuilder();
$repeatedUsers = $qb->select('*')
    ->from('users', 'u')
    ->groupBy('u.email')
    ->having('count(*) > 1');
// Eloquent
$repeatedUsers = Capsule::table('users')
    ->select('*')
    ->groupBy('email')
    ->havingRaw('count(*) > 1');
@gabidavila
What is the "right"
way? 🤔
29
@gabidavila
1st step: say what you need
30
SELECT
id,
first_name,
last_name,
email,
twitter_info
FROM users
GROUP BY email
HAVING COUNT(*) > 1;
5.6 ✅ Works
5.7 ⛔ Doesn’t Work
8.0 ⛔ Doesn’t Work
@gabidavila
2nd step: adding aggregators
31
SELECT
group_concat(id) AS all_users_id,
first_name,
last_name,
email,
twitter_info
FROM users
GROUP BY email
HAVING COUNT(*) > 1;
5.6 ✅ Works
5.7 ⛔ Doesn’t Work
8.0 ⛔ Doesn’t Work
@gabidavila
2nd step: some more column aggregators...
32
SELECT
group_concat(id) AS all_users_id,
min(first_name) AS first_name,
last_name,
email,
twitter_info
FROM users
GROUP BY email
HAVING COUNT(*) > 1;
5.6 ✅ Works
5.7 ⛔ Doesn’t Work
8.0 ⛔ Doesn’t Work
@gabidavila
3rd step: almost everywhere
33
SELECT
group_concat(id) AS all_user_ids,
min(first_name) AS first_name,
min(last_name) AS last_name,
email,
any_value(twitter_info) AS twitter_info
FROM users
GROUP BY email
HAVING COUNT(*) > 1;
5.6 ✅ Works
5.7 ✅ Works
8.0 ✅ Works
You can change the min(column) aggregator to any_value(column)
if the row value for that column doesn't matter
@gabidavila
DEMO
34
@gabidavila
ONLY_FULL_GROUP_BY trends
35
@gabidavila
How do I disable it?
36
You don't.
@gabidavila
37
@gabidavila
Generated Columns
38
@gabidavila
Virtual
•No disk space
•In-place change operation
•Value generated on demand and on
every BEFORE triggers
•Faster creation/ slower read
Stored
•Uses disk space
•Copy operation
•Updated on every INSERT and
UPDATE
•Slow creation/ faster read
Types of Generated Columns
39
@gabidavila
•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
•Subqueries ARE NOT allowed
•Custom functions ARE NOT supported
•Non-deterministic expressions ARE NOT
supported
Virtual & Stored
40
@gabidavila
DEMO
41
@gabidavila
Division by Zero
42
Virtual
• Legal
• Returns NULL
Stored
• Illegal
• Returns a "Division by 0" error with these
side effects:
• Not inserting/updating the row
• Not creating the column at all if made
through an ALTER TABLE
Bug #88901
@gabidavila
Dependency
•Generated Columns can depend on other generated columns
•Ordering of Generated Columns matter when using another generated column
•It can reference a non-generated column no matter the definition order
43
@gabidavila
DEMO
44
@gabidavila
JSON
45
@gabidavila
Converting TEXT to JSON
•It is costly, uses table COPY operation
•All rows must be valid, else an error occurs
• Use JSON_VALID() before
46
@gabidavila
JSON
•Stored as Binary, not TEXT
•TEXT fields can be converted
•Accessible by column->"$.value" (JSON_EXTRACT alias)
•Indexing is possible only through Generated Columns (Virtual or Stored)
47
@gabidavila
DEMO
48
@gabidavila
New Functions
• MySQL 8.0 brought new functions:
• JSON_PRETTY()
• JSON_MERGE_PRESERVE()
• JSON_MERGE_PATCH()
• JSON_ARRAYAGG()
• JSON_OBJECTAGG()
• Ported to MySQL 5.7 after the 5.7.22 version
49
@gabidavila
New Behavior
50
SELECT JSON_OBJECT('clients', 32, 'options', '[active, inactive]',
'clients', 64, 'clients', 128) AS result;
+---------------------------------------------------+
| result |
+---------------------------------------------------+
| {"clients": 128, "options": "[active, inactive]"} |
+---------------------------------------------------+
1 row in set (0.00 sec)
•In >=5.7.22: last duplicate wins
+---------------------------------------------------+
| result |
+---------------------------------------------------+
| {"clients": 32, "options": "[active, inactive]"} |
+---------------------------------------------------+
1 row in set (0.00 sec)
• In < 5.7.22: first duplicate wins
@gabidavila
Other features
51
@gabidavila
Features & deprecations
•Passwords can now have an 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
•Tables now supports more than one trigger per event
•YEAR(2) was deprecated on 5.6 and completely removed on 5.7
•GRANT statement for user creation is deprecated on 5.7 and removed on 8.0
52
@gabidavila
MySQL 8.0 bits
53
@gabidavila
MySQL 8.0 bits
•New default encoding
•Data Dictionary
•Users now can have ROLES
•Instantaneously add columns (ALGORITHM=INSTANT)
•CATS instead of FIFO for high concurrency
•JSON partial update
•Window Functions
•Common Table Expressions
•Better Geospatial support
•Use MySQL without SQL (through MySQL Shell)
54
@gabidavila
Thank you! (.
•Feedback & Slides: gabriela.io/feedback
•Twitter: @gabidavila
•Don't be shy! Come on and talk to me!
55
QUESTIONS

More Related Content

What's hot

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.7Georgi Kodinov
 
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?Sveta Smirnova
 
SunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLSunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLGabriela Ferrara
 
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?Gabriela Ferrara
 
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.2Sergey Petrunya
 
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?Sveta Smirnova
 
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source SummitMySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source SummitDave Stokes
 
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]sSveta Smirnova
 
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 barcelonaDuyhai Doan
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query TuningAlexander Rubin
 
Cassandra Materialized Views
Cassandra Materialized ViewsCassandra Materialized Views
Cassandra Materialized ViewsCarl Yeksigian
 
Modern SQL in Open Source and Commercial Databases
Modern SQL in Open Source and Commercial DatabasesModern SQL in Open Source and Commercial Databases
Modern SQL in Open Source and Commercial DatabasesMarkus Winand
 
Standard SQL features where PostgreSQL beats its competitors
Standard SQL features where PostgreSQL beats its competitorsStandard SQL features where PostgreSQL beats its competitors
Standard SQL features where PostgreSQL beats its competitorsMarkus Winand
 
A Billion Goods in a Few Categories: When Optimizer Histograms Help and When ...
A Billion Goods in a Few Categories: When Optimizer Histograms Help and When ...A Billion Goods in a Few Categories: When Optimizer Histograms Help and When ...
A Billion Goods in a Few Categories: When Optimizer Histograms Help and When ...Sveta Smirnova
 
Cassandra 3 new features 2016
Cassandra 3 new features 2016Cassandra 3 new features 2016
Cassandra 3 new features 2016Duyhai Doan
 

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
 
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?
 
SunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLSunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQL
 
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?
 
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
 
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?
 
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source SummitMySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
 
Linq
LinqLinq
Linq
 
Mentor Your Indexes
Mentor Your IndexesMentor Your Indexes
Mentor Your Indexes
 
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
 
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
 
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
 
Load Data Fast!
Load Data Fast!Load Data Fast!
Load Data Fast!
 
Modern SQL in Open Source and Commercial Databases
Modern SQL in Open Source and Commercial DatabasesModern SQL in Open Source and Commercial Databases
Modern SQL in Open Source and Commercial Databases
 
Standard SQL features where PostgreSQL beats its competitors
Standard SQL features where PostgreSQL beats its competitorsStandard SQL features where PostgreSQL beats its competitors
Standard SQL features where PostgreSQL beats its competitors
 
Sql query patterns, optimized
Sql query patterns, optimizedSql query patterns, optimized
Sql query patterns, optimized
 
A Billion Goods in a Few Categories: When Optimizer Histograms Help and When ...
A Billion Goods in a Few Categories: When Optimizer Histograms Help and When ...A Billion Goods in a Few Categories: When Optimizer Histograms Help and When ...
A Billion Goods in a Few Categories: When Optimizer Histograms Help and When ...
 
Cassandra 3 new features 2016
Cassandra 3 new features 2016Cassandra 3 new features 2016
Cassandra 3 new features 2016
 
Become a super modeler
Become a super modelerBecome a super modeler
Become a super modeler
 

Similar to php[tek] - Making the most out of MySQL

MariaDB for Developers and Operators (DevOps)
MariaDB for Developers and Operators (DevOps)MariaDB for Developers and Operators (DevOps)
MariaDB for Developers and Operators (DevOps)Colin Charles
 
[B14] A MySQL Replacement by Colin Charles
[B14] A MySQL Replacement by Colin Charles[B14] A MySQL Replacement by Colin Charles
[B14] A MySQL Replacement by Colin CharlesInsight Technology, Inc.
 
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, greatGabriela Ferrara
 
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!Gabriela Ferrara
 
Need for Speed: Mysql indexing
Need for Speed: Mysql indexingNeed for Speed: Mysql indexing
Need for Speed: Mysql indexingFromDual GmbH
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesDave Stokes
 
DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...
DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...
DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...DevOpsDays Riga
 
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?Sveta Smirnova
 
MariaDB for developers
MariaDB for developersMariaDB for developers
MariaDB for developersColin Charles
 
Don't Do This [FOSDEM 2023]
Don't Do This [FOSDEM 2023]Don't Do This [FOSDEM 2023]
Don't Do This [FOSDEM 2023]Jimmy Angelakos
 
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 ApplicationsInnoTech
 
Why Use EXPLAIN FORMAT=JSON?
 Why Use EXPLAIN FORMAT=JSON?  Why Use EXPLAIN FORMAT=JSON?
Why Use EXPLAIN FORMAT=JSON? Sveta Smirnova
 
DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptgourav kottawar
 
Need for Speed: MySQL Indexing
Need for Speed: MySQL IndexingNeed for Speed: MySQL Indexing
Need for Speed: MySQL IndexingMYXPLAIN
 
Postgres for MySQL (and other database) people
Postgres for MySQL (and other database) peoplePostgres for MySQL (and other database) people
Postgres for MySQL (and other database) peopleCommand Prompt., Inc
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQLJussi Pohjolainen
 
15 MySQL Basics #burningkeyboards
15 MySQL Basics #burningkeyboards15 MySQL Basics #burningkeyboards
15 MySQL Basics #burningkeyboardsDenis Ristic
 
Cassandra Community Webinar | Become a Super Modeler
Cassandra Community Webinar | Become a Super ModelerCassandra Community Webinar | Become a Super Modeler
Cassandra Community Webinar | Become a Super ModelerDataStax
 
Introduction into MySQL Query Tuning
Introduction into MySQL Query TuningIntroduction into MySQL Query Tuning
Introduction into MySQL Query TuningSveta Smirnova
 
DNN Database Tips & Tricks
DNN Database Tips & TricksDNN Database Tips & Tricks
DNN Database Tips & TricksWill Strohl
 

Similar to php[tek] - Making the most out of MySQL (20)

MariaDB for Developers and Operators (DevOps)
MariaDB for Developers and Operators (DevOps)MariaDB for Developers and Operators (DevOps)
MariaDB for Developers and Operators (DevOps)
 
[B14] A MySQL Replacement by Colin Charles
[B14] A MySQL Replacement by Colin Charles[B14] A MySQL Replacement by Colin Charles
[B14] A MySQL Replacement by Colin Charles
 
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!
 
Need for Speed: Mysql indexing
Need for Speed: Mysql indexingNeed for Speed: Mysql indexing
Need for Speed: Mysql indexing
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New Features
 
DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...
DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...
DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...
 
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?
 
MariaDB for developers
MariaDB for developersMariaDB for developers
MariaDB for developers
 
Don't Do This [FOSDEM 2023]
Don't Do This [FOSDEM 2023]Don't Do This [FOSDEM 2023]
Don't Do This [FOSDEM 2023]
 
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
 
Why Use EXPLAIN FORMAT=JSON?
 Why Use EXPLAIN FORMAT=JSON?  Why Use EXPLAIN FORMAT=JSON?
Why Use EXPLAIN FORMAT=JSON?
 
DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) ppt
 
Need for Speed: MySQL Indexing
Need for Speed: MySQL IndexingNeed for Speed: MySQL Indexing
Need for Speed: MySQL Indexing
 
Postgres for MySQL (and other database) people
Postgres for MySQL (and other database) peoplePostgres for MySQL (and other database) people
Postgres for MySQL (and other database) people
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
 
15 MySQL Basics #burningkeyboards
15 MySQL Basics #burningkeyboards15 MySQL Basics #burningkeyboards
15 MySQL Basics #burningkeyboards
 
Cassandra Community Webinar | Become a Super Modeler
Cassandra Community Webinar | Become a Super ModelerCassandra Community Webinar | Become a Super Modeler
Cassandra Community Webinar | Become a Super Modeler
 
Introduction into MySQL Query Tuning
Introduction into MySQL Query TuningIntroduction into MySQL Query Tuning
Introduction into MySQL Query Tuning
 
DNN Database Tips & Tricks
DNN Database Tips & TricksDNN Database Tips & Tricks
DNN Database Tips & Tricks
 

More from Gabriela Ferrara

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 2020Gabriela Ferrara
 
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 codeGabriela Ferrara
 
PyTexas - Machine learning APIs by Example
PyTexas - Machine learning APIs by ExamplePyTexas - Machine learning APIs by Example
PyTexas - Machine learning APIs by ExampleGabriela Ferrara
 
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?Gabriela Ferrara
 
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 TypeGabriela Ferrara
 
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 ProveitoGabriela Ferrara
 
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/2016Gabriela Ferrara
 
Coding like a girl - DjangoCon
Coding like a girl - DjangoConCoding like a girl - DjangoCon
Coding like a girl - DjangoConGabriela Ferrara
 
LAMP: Desenvolvendo além do trivial
LAMP: Desenvolvendo além do trivialLAMP: Desenvolvendo além do trivial
LAMP: Desenvolvendo além do trivialGabriela Ferrara
 
Database Wizardry for Legacy Applications
Database Wizardry for Legacy ApplicationsDatabase Wizardry for Legacy Applications
Database Wizardry for Legacy ApplicationsGabriela Ferrara
 
Coding like a girl - Youtube presentation
Coding like a girl - Youtube presentationCoding like a girl - Youtube presentation
Coding like a girl - Youtube presentationGabriela 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

Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profileakrivarotava
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 

Recently uploaded (20)

Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profile
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 

php[tek] - Making the most out of MySQL

  • 1. Gabriela D'Avila Ferrara @gabidavila gabriela.io/feedback | https://joind.in/talk/8edff Making the most out of MySQL 1
  • 4. @gabidavila What to expect? •DDL Changes •SQL Modes •Generated Columns •JSON Data Type 4
  • 7. @gabidavila •Table-copy (ALGORITHM=COPY) • VARCHAR from 256B to 65535B • Type conversion • Add a column* (<=5.7) Normal DDL changes 7
  • 8. @gabidavila ALTER TABLE with COPY •1st step: create new table structure with newer definition •2nd step: copy the data from the original table to the new table •3rd step: drop the old table and rename the new table 8
  • 9. @gabidavila Normal DDL Change 9 ALTER TABLE addresses CHANGE COLUMN user_id user_id BIGINT; ALTER TABLE users ADD COLUMN password_digest VARCHAR(255);
  • 10. @gabidavila Online DDL Changes •In place (ALGORITHM=INPLACE) • Rename index • VARCHAR from 1B to 255B • Add a Virtual Column 10
  • 11. @gabidavila Online DDL Changes 11 ALTER TABLE addresses CHANGE COLUMN state state VARCHAR(255); ALTER TABLE addresses RENAME INDEX `state_index` TO `ix_state`;
  • 13. @gabidavila SQL Modes (SELECT @@GLOBAL.sql_mode;) 13 On MySQL 5.6: +--------------------------------------------+ | @@GLOBAL.sql_mode | +--------------------------------------------+ | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | +--------------------------------------------+ 1 row in set (0.00 sec) On MySQL 5.7 and 8.0: +-----------------------------------------------------------------------+ | @@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)
  • 14. @gabidavila MySQL 5.6: •STRICT_TRANS_TABLES •NO_ENGINE_SUBSTITUTION MySQL 5.7 & 8.0: •STRICT_TRANS_TABLES •NO_ENGINE_SUBSTITUTION •ONLY_FULL_GROUP_BY •NO_ZERO_IN_DATE* •NO_ZERO_DATE* •ERROR_FOR_DIVISION_BY_ZERO* SQL Modes comparison 14 Full list of sql_mode
  • 15. @gabidavila STRICT_TRANS_TABLES •Affects transactional dates. •No longer inserts '0000-00-00' in columns where DATE NOT NULL 15
  • 16. @gabidavila ERROR_FOR_DIVISION_BY_ZERO •Write Operation: UPDATE mysql> UPDATE users SET id = id/0 WHERE id = 2; ERROR 1365 (22012): Division by 0 16 •Read Operation: SELECT mysql> SELECT id, first_name, last_name, id/0 FROM users WHERE id = 2; +----+------------+-----------+------+ | id | first_name | last_name | id/0 | +----+------------+-----------+------+ | 2 | Gabriela | Ferrara | NULL | +----+------------+-----------+------+ 1 row in set, 1 warning (0.00 sec)
  • 19. @gabidavila Table `users` 19 Field Type Null Key Default Extra id int(10) unsigned NO PRI auto_increment first_name varchar(255) NO NULL last_name varchar(255) NO NULL email varchar(255) NO NULL twitter_info json YES
  • 20. @gabidavila Repeated emails 5.6 20 5.6 SELECT * FROM users GROUP BY email HAVING count(*) > 1 +-------+------------+-----------+---------------------+--------------------------------+ | id | first_name | last_name | email | twitter_info | +-------+------------+-----------+---------------------+--------------------------------+ | 8965 | Conor | Quitzon | yjacobson@yahoo.com | {"id": 100838242, "url": "http | | 69772 | Junius | Mante | nkuhlman@gmail.com | {"id": 20039476, "url": "https | | 66525 | Katelynn | Feil | qgottlieb@gmail.com | {"id": 111644778, "url": "http | | 92577 | Tillman | Nienow | zzieme@yahoo.com | {"id": 1359073920, "url": "htt | | 18046 | Guillermo | Lebsack | cdoyle@gmail.com | {"id": 120064855, "url": null, | +-------+------------+-----------+---------------------+--------------------------------+ 5 rows in set (0.65 sec)
  • 21. @gabidavila Repeated emails 21 SELECT * FROM users WHERE email = 'cdoyle@gmail.com' +-------+------------+-----------+------------------+--------------+ | id | first_name | last_name | email | twitter_info | +-------+------------+-----------+------------------+--------------+ | 18046 | Guillermo | Lebsack | cdoyle@gmail.com | {...} | | 20559 | Marietta | Quitzon | cdoyle@gmail.com | {...} | +-------+------------+-----------+------------------+--------------+ 2 rows in set (0.04 sec)
  • 22. @gabidavila Repeated emails 5.6 & 8.0 22 5.7 8.0 mysql> SELECT * FROM `users` GROUP BY `email` HAVING count(*) > 1; ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘social.users.id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by SELECT * FROM users GROUP BY email HAVING count(*) > 1
  • 23. @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." 23
  • 25. @gabidavila MySQL to human Translation This happens because the query is grouping by email and MySQL is magically trying to “guess” which field it should bring as a result to the other columns (id, first_name, etc.) and it gives an error since there are more than one result per row and no aggregator was used to specify the correct value. 25 More Info
  • 28. @gabidavila Old way: using the magic 🎩 28 SELECT * FROM users GROUP BY email HAVING count(*) > 1 <?php // Doctrine $qb = $entityManager->createQueryBuilder(); $repeatedUsers = $qb->select('*')     ->from('users', 'u')     ->groupBy('u.email')     ->having('count(*) > 1'); // Eloquent $repeatedUsers = Capsule::table('users')     ->select('*')     ->groupBy('email')     ->havingRaw('count(*) > 1');
  • 29. @gabidavila What is the "right" way? 🤔 29
  • 30. @gabidavila 1st step: say what you need 30 SELECT id, first_name, last_name, email, twitter_info FROM users GROUP BY email HAVING COUNT(*) > 1; 5.6 ✅ Works 5.7 ⛔ Doesn’t Work 8.0 ⛔ Doesn’t Work
  • 31. @gabidavila 2nd step: adding aggregators 31 SELECT group_concat(id) AS all_users_id, first_name, last_name, email, twitter_info FROM users GROUP BY email HAVING COUNT(*) > 1; 5.6 ✅ Works 5.7 ⛔ Doesn’t Work 8.0 ⛔ Doesn’t Work
  • 32. @gabidavila 2nd step: some more column aggregators... 32 SELECT group_concat(id) AS all_users_id, min(first_name) AS first_name, last_name, email, twitter_info FROM users GROUP BY email HAVING COUNT(*) > 1; 5.6 ✅ Works 5.7 ⛔ Doesn’t Work 8.0 ⛔ Doesn’t Work
  • 33. @gabidavila 3rd step: almost everywhere 33 SELECT group_concat(id) AS all_user_ids, min(first_name) AS first_name, min(last_name) AS last_name, email, any_value(twitter_info) AS twitter_info FROM users GROUP BY email HAVING COUNT(*) > 1; 5.6 ✅ Works 5.7 ✅ Works 8.0 ✅ Works You can change the min(column) aggregator to any_value(column) if the row value for that column doesn't matter
  • 36. @gabidavila How do I disable it? 36 You don't.
  • 39. @gabidavila Virtual •No disk space •In-place change operation •Value generated on demand and on every BEFORE triggers •Faster creation/ slower read Stored •Uses disk space •Copy operation •Updated on every INSERT and UPDATE •Slow creation/ faster read Types of Generated Columns 39
  • 40. @gabidavila •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 •Subqueries ARE NOT allowed •Custom functions ARE NOT supported •Non-deterministic expressions ARE NOT supported Virtual & Stored 40
  • 42. @gabidavila Division by Zero 42 Virtual • Legal • Returns NULL Stored • Illegal • Returns a "Division by 0" error with these side effects: • Not inserting/updating the row • Not creating the column at all if made through an ALTER TABLE Bug #88901
  • 43. @gabidavila Dependency •Generated Columns can depend on other generated columns •Ordering of Generated Columns matter when using another generated column •It can reference a non-generated column no matter the definition order 43
  • 46. @gabidavila Converting TEXT to JSON •It is costly, uses table COPY operation •All rows must be valid, else an error occurs • Use JSON_VALID() before 46
  • 47. @gabidavila JSON •Stored as Binary, not TEXT •TEXT fields can be converted •Accessible by column->"$.value" (JSON_EXTRACT alias) •Indexing is possible only through Generated Columns (Virtual or Stored) 47
  • 49. @gabidavila New Functions • MySQL 8.0 brought new functions: • JSON_PRETTY() • JSON_MERGE_PRESERVE() • JSON_MERGE_PATCH() • JSON_ARRAYAGG() • JSON_OBJECTAGG() • Ported to MySQL 5.7 after the 5.7.22 version 49
  • 50. @gabidavila New Behavior 50 SELECT JSON_OBJECT('clients', 32, 'options', '[active, inactive]', 'clients', 64, 'clients', 128) AS result; +---------------------------------------------------+ | result | +---------------------------------------------------+ | {"clients": 128, "options": "[active, inactive]"} | +---------------------------------------------------+ 1 row in set (0.00 sec) •In >=5.7.22: last duplicate wins +---------------------------------------------------+ | result | +---------------------------------------------------+ | {"clients": 32, "options": "[active, inactive]"} | +---------------------------------------------------+ 1 row in set (0.00 sec) • In < 5.7.22: first duplicate wins
  • 52. @gabidavila Features & deprecations •Passwords can now have an 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 •Tables now supports more than one trigger per event •YEAR(2) was deprecated on 5.6 and completely removed on 5.7 •GRANT statement for user creation is deprecated on 5.7 and removed on 8.0 52
  • 54. @gabidavila MySQL 8.0 bits •New default encoding •Data Dictionary •Users now can have ROLES •Instantaneously add columns (ALGORITHM=INSTANT) •CATS instead of FIFO for high concurrency •JSON partial update •Window Functions •Common Table Expressions •Better Geospatial support •Use MySQL without SQL (through MySQL Shell) 54
  • 55. @gabidavila Thank you! (. •Feedback & Slides: gabriela.io/feedback •Twitter: @gabidavila •Don't be shy! Come on and talk to me! 55 QUESTIONS