MySQL 2024
Зачем переходить на MySQL 8, если в 5.х всё устраивает?
• Света Смирнова
• Инженер тех. поддержки MySQL
• Автор
MySQL Troubleshooting
MySQL Cookbook, 4th Edition
• JSON UDF функции
• FILTER clause для MySQL
• Докладчик
• Percona Live, OOW, Fosdem,
DevConf, HighLoad...
2 ©2024 Percona
MySQL 5.7
больше не
поддерживается
3 ©2024 Percona
•Словарь
•Современный SQL
•JSON
•Улучшения в Оптимизаторе
•Понятная
Диагностика
Содержание
4 ©2024 Percona
Словарь
• Transactional
• InnoDB
• Убраны *frm, *TRG и др. файлы
• Atomic DDL
• Crash safe DDL
MySQL Data
Dictionary
6 ©2024 Percona
ACID
online hot
backup
ibdata1
ib_logfile1
ib_logfile2
db1
————–
t1.ibd
t2.ibd
db2
————–
t1.ibd
t2.ibd
db1
————–
t1.frm
t2.frm
db2
————–
t1.frm
t2.frm
Другое:
binary, error, audit log files
База MySQL до
8.0
7 ©2024 Percona
ACID
online hot
backup
ibdata1
ib_logfile1
ib_logfile2
mysql.ibd
db1
————–
t1.ibd
t2.ibd
db2
————–
t1.ibd
t2.ibd
Другое:
binary, error, audit log files
База MySQL в
8.0
8 ©2024 Percona
• Копирует базу при помощи одной
команды
• Быстрое создание реплики
CLONE
INSTANCE
9 ©2024 Percona
Современный SQL
• Обычное сканирование
1
2
3
4
5
Locked
1
2
NOWAIT и
SKIP LOCKED
11 ©2024 Percona
• SKIP LOCKED
1
2
3
4
5
Locked
1
2
4
5
NOWAIT и
SKIP LOCKED
12 ©2024 Percona
• NOWAIT
1
2
3
4
5
Locked
1
2
Error
NOWAIT и
SKIP LOCKED
13 ©2024 Percona
mysql> with
-> dept_data as
-> (select emp_no, dept_name from dept_emp
-> join departments using (dept_no))
-> select first_name, last_name, dept_name
-> from employees join dept_data using(emp_no)
-> order by hire_date desc limit 3;
+––––––––––––+–––––––––––+––––––––––––––––––––+
| first_name | last_name | dept_name |
+––––––––––––+–––––––––––+––––––––––––––––––––+
| Bikash | Covnot | Quality Management |
| Yucai | Gerlach | Production |
| Hideyuki | Delgrande | Development |
+––––––––––––+–––––––––––+––––––––––––––––––––+
3 rows in set (0.00 sec)
Нерекурсивные
CTEs
14 ©2024 Percona
mysql> with recursive rand_generator(id, rand_value) as
-> (select 1, rand() union all select id+1, rand()
-> from rand_generator where id < 5)
-> select * from rand_generator;
+––––––+–––––––––––––––––––––+
| id | rand_value |
+––––––+–––––––––––––––––––––+
| 1 | 0.5599308382346582 |
| 2 | 0.2151867702744778 |
| 3 | 0.39614136740205935 |
| 4 | 0.33514655692050843 |
| 5 | 0.4873087131300091 |
+––––––+–––––––––––––––––––––+
5 rows in set (0.00 sec)
Рекурсивные
CTEs
15 ©2024 Percona
mysql> select
-> row_number() over win as id, dept_no, dept_name
-> from departments window win
-> as (order by dept_no);
+––––+–––––––––+––––––––––––––––––––+
| id | dept_no | dept_name |
+––––+–––––––––+––––––––––––––––––––+
| 1 | d001 | Marketing |
| 2 | d002 | Finance |
| 3 | d003 | Human Resources |
| 4 | d004 | Production |
| 5 | d005 | Development |
| 6 | d006 | Quality Management |
| 7 | d007 | Sales |
| 8 | d008 | Research |
| 9 | d009 | Customer Service |
+––––+–––––––––+––––––––––––––––––––+
Оконные
функции
16 ©2024 Percona
mysql> SELECT * FROM SEQUENCE_TABLE(36) AS tt
-> WHERE value%4 = 0 AND value > 0;
+–––––––+
| value |
+–––––––+
| 4 |
| 8 |
| 12 |
| 16 |
| 20 |
| 24 |
| 28 |
| 32 |
+–––––––+
8 rows in set (0,00 sec)
SEQUENCE_TABLE
in Percona
Server
17 ©2024 Percona
mysql> SELECT GROUP_CONCAT(value)
-> FROM SEQUENCE_TABLE(20) AS tt;
+–––––––––––––––––––––––––––––––––––––––––––––––––––+
| GROUP_CONCAT(value) |
+–––––––––––––––––––––––––––––––––––––––––––––––––––+
| 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 |
+–––––––––––––––––––––––––––––––––––––––––––––––––––+
1 row in set (0,00 sec)
SEQUENCE_TABLE
in Percona
Server
18 ©2024 Percona
MariaDB [test]> CREATE SEQUENCE s
-> START WITH 10 INCREMENT BY 10;
Query OK, 0 rows affected (0,001 sec)
MariaDB [test]> SELECT NEXT VALUE FOR sG
************************ 1. row ************************
NEXT VALUE FOR s: 10
1 row in set (0,000 sec)
MariaDB [test]> SELECT NEXT VALUE FOR sG
************************ 1. row ************************
NEXT VALUE FOR s: 20
1 row in set (0,001 sec)
SEQUENCES
in MariaDB
19 ©2024 Percona
MariaDB [test]> ALTER SEQUENCE s RESTART WITH 100;
Query OK, 0 rows affected (0,000 sec)
MariaDB [test]> SELECT NEXT VALUE FOR s;
+––––––––––––––––––+
| NEXT VALUE FOR s |
+––––––––––––––––––+
| 100 |
+––––––––––––––––––+
1 row in set (0,001 sec)
SEQUENCES
in MariaDB
20 ©2024 Percona
JSON
• Появился в 5.7
8+ ВалидацияJSON schema
8+ Индексы для массивов JSON
8+ Обновления "на месте"
• В том числе на реплике
Тип данных
JSON
22 ©2024 Percona
• Новый клиент
• Три интерфейса
• SQL
• Python
• JavaScript
• Возможность обращаться с
данными в MySQL как с
объектами
• MySQL как Document Store
MySQL Shell
23 ©2024 Percona
mysql-sql> use employees
Default schema set to ‘employees‘.
Fetching global names, object names from ‘employees‘ 
for auto-completion... Press ^C to stop.
mysql-sql> SELECT * FROM departments LIMIT 5;
+–––––––––+––––––––––––––––––+
| dept_no | dept_name |
+–––––––––+––––––––––––––––––+
| d009 | Customer Service |
| d005 | Development |
| d002 | Finance |
| d003 | Human Resources |
| d001 | Marketing |
+–––––––––+––––––––––––––––––+
5 rows in set (0.0008 sec)
MySQL Shell:
SQL mode
24 ©2024 Percona
mysql-js> session.getSchema(’employees’).
-> getTable(’departments’).select()
->
+–––––––––+––––––––––––––––––––+
| dept_no | dept_name |
+–––––––––+––––––––––––––––––––+
| d009 | Customer Service |
| d005 | Development |
| d002 | Finance |
| d003 | Human Resources |
| d001 | Marketing |
| d004 | Production |
| d006 | Quality Management |
| d008 | Research |
| d007 | Sales |
+–––––––––+––––––––––––––––––––+
9 rows in set (0.0001 sec)
MySQL Shell:
JavaScript
mode
25 ©2024 Percona
mysql-js> employees = session.getSchema(’employees’).
-> getTable(’employees’)
->
<Table:employees>
MySQL Shell:
JavaScript
objects
26 ©2024 Percona
mysql-js> employees.select(’emp_no’, ’first_name’,
-> ’last_name’, ’hire_date’).
-> where("hire_date > ’2000-01-10’").
-> orderBy(’hire_date’)
->
+––––––––+––––––––––––+–––––––––––+––––––––––––+
| emp_no | first_name | last_name | hire_date |
+––––––––+––––––––––––+–––––––––––+––––––––––––+
| 422990 | Jaana | Verspoor | 2000-01-11 |
| 47291 | Ulf | Flexer | 2000-01-12 |
| 222965 | Volkmar | Perko | 2000-01-13 |
| 499553 | Hideyuki | Delgrande | 2000-01-22 |
| 428377 | Yucai | Gerlach | 2000-01-23 |
| 463807 | Bikash | Covnot | 2000-01-28 |
+––––––––+––––––––––––+–––––––––––+––––––––––––+
6 rows in set (0.0517 sec)
MySQL Shell:
JavaScript
objects
27 ©2024 Percona
mysql-js> employeesCol = session.getCurrentSchema().
-> createCollection(’EmployeesCol’)
<Collection:EmployeesCol>
MySQL Shell:
JavaScript
Document Store
28 ©2024 Percona
mysql-js> {
-> employees = session.getSchema(’employees’).
-> getTable(’employees’).select().execute();
-> while (emp = employees.fetchOneObject()) {
-> employeesCol.add(
-> mysqlx.expr(JSON.stringify(emp))
-> ).execute();
-> }
-> }
->
Query OK, 1 item affected (0.0016 sec)
MySQL Shell:
JavaScript
Document Store
29 ©2024 Percona
mysql-js> employeesCol.count()
300024
mysql-js> employeesCol.
-> find("hire_date > ’2000-01-10’").
-> fields(’emp_no’, ’first_name’, ’last_name’);
{
"emp_no": 47291,
"last_name": "Flexer",
"first_name": "Ulf"
}
{
"emp_no": 222965,
"last_name": "Perko",
"first_name": "Volkmar"
}
...
MySQL Shell:
JavaScript
Document Store
30 ©2024 Percona
mysql-py> titles = session.get_current_schema().
-> get_table(’titles’)
->
mysql-py> titles.select(’title’).group_by(’title’)
+––––––––––––––––––––+
| title |
+––––––––––––––––––––+
| Senior Engineer |
| Staff |
| Engineer |
| Senior Staff |
| Assistant Engineer |
| Technique Leader |
| Manager |
+––––––––––––––––––––+
7 rows in set (0.1116 sec)
MySQL Shell:
Python
31 ©2024 Percona
mysql-py> session.start_transaction()
Query OK, 0 rows affected (0.0005 sec)
mysql-py> titles.update().
-> set(’title’, ’Principal Engineer’).
-> where("title=’Senior Engineer’")
->
Query OK, 97750 items affected (1.5102 sec)
Rows matched: 97750 Changed: 97750 Warnings: 0
mysql-py> titles.update().
-> set(’title’, ’Senior Engineer’).
-> where("title=’Engineer’")
->
Query OK, 115003 items affected (1.3901 sec)
Rows matched: 115003 Changed: 115003 Warnings: 0
MySQL Shell:
Python
32 ©2024 Percona
mysql-py> titles.update().
-> set(’title’, ’Engineer’).
-> where("title=’Assistant Engineer’")
->
Query OK, 15128 items affected (0.4094 sec)
Rows matched: 15128 Changed: 15128 Warnings: 0
mysql-py> session.commit()
MySQL Shell:
Python
33 ©2024 Percona
mysql-py> employees_col = session.get_current_schema().
-> get_collection(’EmployeesCol’)
->
mysql-py> employees_col.add(
-> mysqlx.expr(’{
-> "gender": "F", "hire_date": NOW(),
-> "last_name": "Smirnova",
-> "first_name": "Sveta"}’
-> )
-> )
->
Query OK, 1 item affected (0.0183 sec)
MySQL Shell:
Python
Document Store
34 ©2024 Percona
mysql-py> employees_col.find("first_name = ’Sveta’");
{
"_id": "0000661562ed00000000000493f9",
"gender": "F",
"hire_date": "2024-04-18 13:23:50.000000",
"last_name": "Smirnova",
"first_name": "Sveta"
}
1 document in set (0.1731 sec)
MySQL Shell:
Python
Document Store
35 ©2024 Percona
Function 8 5.7 MariaDB
− > ✓ ✓
− >> ✓ ✓
JSON_ARRAY ✓ ✓ ✓
JSON_ARRAY_AGG ✓
JSON_ARRAY_APPEND ✓ ✓ ✓
JSON_ARRAY_INSERT ✓ ✓ ✓
JSON_ARRAY_INTERSECT ✓
JSON_COMPACT ✓
JSON_CONTAINS ✓ ✓ ✓
JSON_CONTAINS_PATH ✓ ✓ ✓
Функции JSON
36 ©2024 Percona
Function 8 5.7 MariaDB
JSON_DEPTH ✓ ✓ ✓
JSON_DETAILED ✓
JSON_EQUALS ✓
JSON_EXTRACT ✓ ✓ ✓
JSON_INSERT ✓ ✓ ✓
JSON_KEYS ✓ ✓ ✓
JSON_LENGTH ✓ ✓ ✓
JSON_LOOSE ✓
JSON_MERGE ✓ ✓ ✓
Функции JSON
37 ©2024 Percona
Function 8 5.7 MariaDB
JSON_MERGE_PATCH ✓ ✓ ✓
JSON_MERGE_PRESERVE ✓ ✓ ✓
JSON_NORMALIZE ✓
JSON_OBJECT ✓ ✓ ✓
JSON_OBJECT_FILTER_KEYS ✓
JSON_OBJECT_TO_ARRAY ✓
JSON_OBJECT_AGG ✓
JSON_OVERLAPS ✓ ✓
JSON_PRETTY ✓ ✓ ✓
JSON_QUERY ✓
Функции JSON
38 ©2024 Percona
Function 8 5.7 MariaDB
JSON_QUOTE ✓ ✓ ✓
JSON_REMOVE ✓ ✓ ✓
JSON_REPLACE ✓ ✓ ✓
JSON_SCHEMA_VALID ✓ ✓
JSON_SCHEMA_VALIDATION_REPORT ✓
JSON_SEARCH ✓ ✓ ✓
JSON_SET ✓ ✓ ✓
JSON_STORAGE_FREE ✓
JSON_STORAGE_SIZE ✓ ✓
Функции JSON
39 ©2024 Percona
Function 8 5.7 MariaDB
JSON_TABLE ✓ ✓
JSON_TYPE ✓ ✓ ✓
JSON_UNQUOTE ✓ ✓ ✓
JSON_VALID ✓ ✓ ✓
JSON_VALUE ✓ ✓
MEMBER_OF ✓
Функции JSON
40 ©2024 Percona
Улучшения в
Оптимизаторе
• Статистика оптимизатора
• Гистограммы
• Собирает и хранит оптимизатор
• Минимальная нагрузка на систему
• Индексы
• Создаёт и хранит табличный
движок
• Занимают место на диске
• Создавать долго
• Влияют на производительность при
обновлении
Гистограммы
42 ©2024 Percona
1 2 3 4 5 6 7 8 9 10
0
200
400
600
800
Индексы:
Данные с
Одинаковыми
Значениями
43 ©2024 Percona
1 2 3 4 5 6 7 8 9 10
0
200
400
600
800
Индексы:
Cardinality
44 ©2024 Percona
1 2 3 4 5 6 7 8 9 10
0
200
400
600
800
Histograms:
Данные с
Одинаковыми
Значениями
45 ©2024 Percona
1 2 3 4 5 6 7 8 9 10
0
0.2
0.4
0.6
0.8
1
Histograms:
Данные в
Histogram
46 ©2024 Percona
Nested-Loop Join Algorithm
for each row in t1 matching range {
for each row in t2 matching reference key {
for each row in t3 {
if row satisfies join conditions, send to client
}
}
}
Before 8.0:
Block Nested
Loop
47 ©2024 Percona
Nested-Loop Join Algorithm
for each row in t1 matching range {
for each row in t2 matching reference key {
for each row in t3 {
if row satisfies join conditions, send to client
}
}
}
• Неэффективный!
- Циклы!
Before 8.0:
Block Nested
Loop
48 ©2024 Percona
Hash join в MySQL 8
• SELECT first_name,
last_name, dept_no
FROM employees STRAIGHT_JOIN
emp_dept USING(emp_no)
WHERE last_name=’Neiman’ AND
to_date=’9999-01-01’;
Hash Joins
49 ©2024 Percona
Hash join в MySQL 8
• Фаза build
employees
emp_dept
Hash table в памяти
By JOIN condition
hash
Hash Joins
50 ©2024 Percona
Hash join в MySQL 8
• Фаза probe
employees
emp_dept
Hash table
в памяти
hash
Client
Hash Joins
51 ©2024 Percona
• Многоколоночные индексы
■ key_part_1, key_part_2
• ... WHERE key_part_2 > N
• Запросы к одной таблице
• Обращается только к колонкам
индекса
Index skip scan
52 ©2024 Percona
mysql> show create table salariesG
************************ 1. row ************************
Table: salaries
Create Table: CREATE TABLE ‘salaries‘ (
‘emp_no‘ int NOT NULL,
‘salary‘ int NOT NULL,
‘from_date‘ date NOT NULL,
‘to_date‘ date NOT NULL,
PRIMARY KEY (‘emp_no‘,‘from_date‘),
KEY ‘from_date‘ (‘from_date‘,‘to_date‘),
CONSTRAINT ‘salaries_ibfk_1‘ FOREIGN KEY (‘emp_no‘)
REFERENCES ‘employees‘ (‘emp_no‘) ON DELETE CASCADE
) /*!50100 TABLESPACE ‘innodb_system‘ */ ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
1 row in set (0.00 sec)
Index skip scan
53 ©2024 Percona
mysql> explain select emp_no, from_date, to_date, salary
-> from salaries where to_date > ’1999-01-01’G
************************ 1. row ************************
id: 1
select_type: SIMPLE
table: salaries
partitions: NULL
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 2632946
filtered: 33.33
Extra: Using where
Index skip scan
54 ©2024 Percona
mysql> explain select emp_no, from_date, to_date
-> from salaries where to_date > ’1999-01-01’G
************************ 1. row ************************
id: 1
select_type: SIMPLE
table: salaries
partitions: NULL
type: range
possible_keys: from_date
key: from_date
key_len: 6
ref: NULL
rows: 877560
filtered: 100.00
Extra: Using where; Using index for skip scan
Index skip scan
55 ©2024 Percona
mysql> explain format=tree select * from ol
-> where thread_id=10432 and site_id != 9939
-> order by id limit 3G
************************ 1. row ************************
EXPLAIN: -> Limit: 3 row(s)
-> Filter: ((ol.thread_id = 10432) and
(ol.site_id <> 9939)) (cost=0.06 rows=3)
-> Index scan on ol using PRIMARY
(cost=0.06 rows=33)
Пример по мотивам MySQL bug #78651
EXPLAIN
ANALYZE
56 ©2024 Percona
Пример по мотивам MySQL bug #78651
mysql> explain analyze select * from ol
-> where thread_id=10432 and site_id != 9939
-> order by id limit 3G
************************ 1. row ************************
EXPLAIN: -> Limit: 3 row(s)
(actual time=364.792..364.792 rows=0 loops=1)
-> Filter: ((ol.thread_id = 10432) and
(ol.site_id <> 9939)) (cost=0.06 rows=3)
(actual time=364.789..364.789 rows=0 loops=1)
-> Index scan on ol using PRIMARY
(cost=0.06 rows=33)
(actual time=0.417..337.585 rows=100000 loops=1)
EXPLAIN
ANALYZE
57 ©2024 Percona
mysql> EXPLAIN FORMAT=TREE
-> SELECT * FROM employees JOIN titles USING(emp_no)G
************************ 1. row ************************
EXPLAIN: -> Nested loop inner join (cost=149574 rows=440041)
-> Table scan on employees (cost=30780 rows=299157)
-> Index lookup on titles using PRIMARY
(emp_no=employees.emp_no) (cost=0.25 rows=1.47)
1 row in set (0,01 sec)
EXPLAIN FOR-
MAT=TREE
58 ©2024 Percona
mysql> EXPLAIN SELECT ’MySQL’G
************************ 1. row ************************
id: 1
select_type: SIMPLE
table: NULL
partitions: NULL
type: NULL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: NULL
filtered: NULL
Extra: No tables used
1 row in set, 1 warning (0,01 sec)
Формат по
умолчанию для
EXPLAIN
59 ©2024 Percona
mysql> SET explain_format = ’JSON’;
Query OK, 0 rows affected (0,00 sec)
mysql> EXPLAIN SELECT ’MySQL’G
************************ 1. row *************************
EXPLAIN: {
"query_block": {
"select_id": 1,
"message": "No tables used"
}
}
1 row in set, 1 warning (0,00 sec)
Формат по
умолчанию для
EXPLAIN
60 ©2024 Percona
• mysql> SET explain_format = ’tree’;
Query OK, 0 rows affected (0,00 sec)
mysql> EXPLAIN SELECT ’MySQL’G
************************ 1. row ************************
EXPLAIN: -> Rows fetched before execution
(cost=0..0 rows=1)
1 row in set (0,00 sec)
Формат по
умолчанию для
EXPLAIN
61 ©2024 Percona
mysql> EXPLAIN FORMAT=JSON INTO @exp
-> SELECT * FROM employees JOIN titles USING(emp_no);
Query OK, 0 rows affected (0,00 sec)
mysql> SELECT JSON_EXTRACT(@exp, ’$.query_block.cost_info’)
-> AS cost_infoG
********************* 1. row *********************
cost_info:: "query_cost": "529370.85"
1 row in set (0,00 sec)
EXPLAIN
FORMAT=JSON
INTO
var_name
62 ©2024 Percona
mysql> SELECT JSON_EXTRACT(@exp,
-> ’$.query_block.nested_loop[*].table.cost_info’)
-> AS cost_infoG
*********************** 1. row *********************
cost_info: [{"eval_cost": "44201.00",
"read_cost": "1203.83", "prefix_cost": "45404.83",
"data_read_per_join": "91M"},
{"eval_cost": "44201.00", "read_cost": "439765.03",
"prefix_cost": "529370.85", "data_read_per_join": "57M"}]
1 row in set (0,00 sec)
EXPLAIN
FORMAT=JSON
INTO
var_name
63 ©2024 Percona
mysql> explain format=tree select first_name, last_name,
-> dept_name from employees join dept_emp
-> using(emp_no) join departments using(dept_no)G
************************ 1. row ************************
EXPLAIN: -> Nested loop inner join
(cost=426808.36 rows=354369)
-> Nested loop inner join (cost=37002.05 rows=354369)
-> Index scan on departments using dept_name
(cost=1.90 rows=9)
-> Index lookup on dept_emp using dept_no
(dept_no=departments.dept_no)
(cost=611.18 rows=39374)
-> Single-row index lookup on employees using PRIMARY
(emp_no=dept_emp.emp_no)
(cost=1.00 rows=1)
Невидимые
индексы
64 ©2024 Percona
mysql> alter table dept_emp alter index dept_no
-> invisible;
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
Невидимые
индексы
65 ©2024 Percona
mysql> explain format=tree select first_name, last_name,
-> dept_name from employees join dept_emp
-> using(emp_no) join departments using(dept_no)G
************************ 1. row ************************
EXPLAIN: -> Nested loop inner join
(cost=359050.19 rows=354369)
-> Inner hash join
(dept_emp.dept_no = departments.dept_no)
(cost=284238.88 rows=354369)
-> Index scan on dept_emp using PRIMARY
(cost=519.88 rows=314995)
-> Hash
-> Index scan on departments using dept_name
(cost=1.90 rows=9)
-> Single-row index lookup on employees using PRIMARY
(emp_no=dept_emp.emp_no) (cost=0.11 rows=1)
Невидимые
индексы
66 ©2024 Percona
mysql> alter table salaries
-> add index(from_date, to_date);
mysql> explain select * from salaries
-> order by from_date, to_date desc limit 10G
************************ 1. row ************************
id: 1
select_type: SIMPLE
table: salaries
partitions: NULL
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 2632946
filtered: 100.00
Extra: Using filesort
Индексы по
убыванию
(DESC)
67 ©2024 Percona
mysql> alter table salaries drop index from_date;
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table salaries
-> add index(from_date asc, to_date desc);
Query OK, 0 rows affected (1 min 5.45 sec)
Records: 0 Duplicates: 0 Warnings: 0
Индексы по
убыванию
(DESC)
68 ©2024 Percona
mysql> explain select * from salaries
-> order by from_date, to_date desc limit 10G
************************ 1. row ************************
id: 1
select_type: SIMPLE
table: salaries
partitions: NULL
type: index
possible_keys: NULL
key: from_date
key_len: 6
ref: NULL
rows: 10
filtered: 100.00
Extra: NULL
1 row in set, 1 warning (0.00 sec)
Индексы по
убыванию
(DESC)
69 ©2024 Percona
mysql> explain select year(hire_date), count(*) as hired
-> from employees
-> group by year(hire_date)G
************************ 1. row ************************
id: 1
select_type: SIMPLE
table: employees
partitions: NULL
type: ALL
possible_keys: hire_date
key: NULL
key_len: NULL
ref: NULL
rows: 299645
filtered: 100.00
Extra: Using temporary
Функциональные
индексы
70 ©2024 Percona
mysql> alter table employees
-> add index hire_date_year((year(hire_date)));
mysql> explain select year(hire_date),
-> count(gender) as hired from employees
-> group by year(hire_date)G
************************ 1. row ************************
id: 1
select_type: SIMPLE
table: employees
partitions: NULL
type: index
possible_keys: hire_date_year
key: hire_date_year
key_len: 5
ref: NULL
rows: 299468
filtered: 100.00
Extra: NULL
Функциональные
индексы
71 ©2024 Percona
• Постоянные обновления
• Поддержка SRID
• 5.7 их игнорировала
• Новые функции
Spatial
72 ©2024 Percona
Понятная
Диагностика
{
"prio" : 3, "err_code" : 10914, "source_line" : 1046,
"source_file" : "sql_connect.cc",
"function" : "end_connection",
"msg" : "Aborted connection 32 to db: ’sbtest’ user: ’root’
host: ’localhost’
(Got an error reading communication packets).",
"time" : "2020-07-09T11:39:28.905387Z",
"thread" : 32,
"err_symbol" : "ER_ABORTING_USER_CONNECTION",
"SQL_state" : "HY000",
"subsystem" : "Server",
"label" : "Note"
}
Ошибки в
формате JSON
74 ©2024 Percona
mysql> tail -n 1 /tmp/12346/data/mysqld.log
2024-04-18T15:08:53.800418Z 101 [Warning] [MY-013360]
[Server] Plugin mysql_native_password reported:
”mysql_native_password’ is deprecated and will
be removed in a future release. Please use
caching_sha2_password instead’
mysql> SET GLOBAL log_error_suppression_list=’MY-013360’;
Query OK, 0 rows affected (0,00 sec)
mysql> q
Bye
Фильтры для
ошибок
75 ©2024 Percona
$ sleep 10; mysql
...
mysql> tail -n 1 /tmp/12346/data/mysqld.log
2024-04-18T15:08:53.800418Z 101 [Warning] [MY-013360]
[Server] Plugin mysql_native_password reported:
”mysql_native_password’ is deprecated and will
be removed in a future release. Please use
caching_sha2_password instead’
Фильтры для
ошибок
76 ©2024 Percona
• Где установлены переменные
mysql> select variable_name, variable_source
-> from performance_schema.variables_info
-> group by variable_source;
+––––––––––––––––––––––––––––-+–––––––––––––––––+
| variable_name | variable_source |
+––––––––––––––––––––––––––––-+–––––––––––––––––+
| activate_all_roles_on_login | COMPILED |
| binlog_cache_size | COMMAND_LINE |
| foreign_key_checks | DYNAMIC |
+––––––––––––––––––––––––––––-+–––––––––––––––––+
3 rows in set (0.01 sec)
Performance
Schema
77 ©2024 Percona
• Новые поля в таблицах
events_statements_* и threads
• CPU_TIME
• CONTROLLED_MEMORY
• TOTAL_MEMORY
• MAX_CONTROLLED_MEMORY
• MAX_TOTAL_MEMORY
Performance
Schema
78 ©2024 Percona
Смайлики!
79 ©2024 Percona
The complete list of new features in MySQL 8.0
Modern SQL
Dimitri KRAVTCHUK про MySQL 8.0
Чем отличается Percona Server от MySQL
Дополнительная
Информация
80 ©2024 Percona
Канал по MySQL в Телеграм
www.slideshare.net/SvetaSmirnova
twitter.com/svetsmirnova
github.com/svetasmirnova
Спасибо!
81 ©2024 Percona