SlideShare a Scribd company logo
Sergei Petrunia
MariaDB devroom
FOSDEM 2021
New optimizer features
in MariaDB releases before 10.12
MariaDB Fest 2022
Sergei Petrunia
MariaDB developer
select *
from optimizer_features
where
release_date is not null and
release_date > date_sub(now(), interval 1 year)
2
Optimizer features in MariaDB 10.8
MariaDB 10.8: Stable since May, 2022
Optimizer features:
●
JSOH_HB Histogram type
– Covered in “Improved histograms in MariaDB 10.8” talk at FOSDEM 2022.
●
Reverse-ordered index support
●
JSON produced by the optimizer is now
– Valid :-)
– Processible
3
Optimizer produces JSON documents
●
Optimizer produces JSON
– EXPLAIN FORMAT=JSON …
– ANALYZE FORMAT=JSON …
– Optimizer Trace
●
Reasons for using JSON
– Human-readable, well-known syntax
– Can be processed
●
e.g. extract interesting parts of trace
4
JSON data structures
●
Array:
[ elem1, elem2, …]
●
Object:
{ "name1":elem1, "name2":elem2, … }
●
What if there are duplicate names?
●
This is still valid JSON: { "name1":foo, "name1":bar, … }
●
Possible gotchas in processing
– Some tools work
– Some tools will ignore “foo”
– Some will concatenate (merge): “foobar”
5
Most common: EXPLAIN FORMAT=JSON
EXPLAIN: {
"query_block": {
"select_id": 1,
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 10,
"filtered": 100,
},
"table": {
"table_name": "t2",
"access_type": "ref",
"possible_keys": ["a"],
"key": "a",
...
EXPLAIN: {
"query_block": {
"select_id": 1,
"nested_loop": [
{
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 10,
"filtered": 100,
}
},
{
"table": {
"table_name": "t2",
"access_type": "ref",
"possible_keys": ["a"],
...
6
Now JSON is processible
●
Before 10.8:
– EXPLAIN/ANALYZE had duplicate names
– Optimizer trace also had that
●
Starting from 10.8:
– All JSON docs are processible
– Can develop tools
●
EXPLAIN/ANALYZE visualizer (Highlight heaviest parts of the
query)
●
Optimizer trace: show details about the chosen query plan
7
MariaDB 10.9
8
MariaDB 10.9
MariaDB 10.9: Stable since August, 2022
Optimizer features:
●
SHOW EXPLAIN FORMAT=JSON
●
SHOW ANALYZE [FORMAT=JSON]
●
EXPLAIN FOR CONNECTION
9
Remember SHOW EXPLAIN?
Lets one see the EXPLAIN of a running statement:
-- Run a long query
select ... from ...
-- Find the target's connection_id N
select * from information_schema.processlist;
-- See the query plan it is using
show explain for N;
Connection 1:
Connection 2:
10
Better SHOW EXPLAIN in 10.9
●
Support for SHOW EXPLAIN FORMAT=JSON
– One could only get tabular SHOW EXPLAIN before
●
Due to implementation details
– Now one can get the JSON form, too. It has more data.
●
Compatibility with MySQL-8:
– MySQL’s syntax:
EXPLAIN [FORMAT=JSON] FOR CONNECTION n
– Now, MariaDB supports it, too.
11
Remember ANALYZE?
●
ANALYZE SELECT …
shows explain with execution data
●
Has FORMAT=JSON form
●
Very useful for optimizer
troubleshooting
– IF you can wait for the query to
finish...
"query_block": {
"select_id": 1,
"r_loops": 1,
"r_total_time_ms": 0.947815181,
"nested_loop": [
{
"table": {
"table_name": "t1",
"access_type": "ALL",
"r_loops": 1,
"rows": 10,
"r_rows": 10,
"r_table_time_ms": 0.804191,
"r_other_time_ms": 0.1051569,
"filtered": 100,
"r_filtered": 20,
12
Problem with ANALYZE
●
Query takes forever to finish
●
Query has constructs with large potential for
optimization errors
– Derived tables
– Many-table joins
– Dependent subqueries
●
What is the query doing?
– How long will it take?
13
SHOW ANALYZE
●
Shows r_ members describing the
execution so far
●
Can check r_rows vs rows, r_filtered vs
filtered.
– r_total_time_ms will be present if the
target is collecting timings (is itself
running an ANALYZE command)
●
r_loops=1 – the first iteration
●
Low r_loops: last iteration is incomplete
{
"r_query_time_in_progress_ms": 7801,
"query_optimization": {
"r_total_time_ms": 0.402132271
},
"query_block": {
"select_id": 1,
"r_loops": 1,
"nested_loop": [
{
"table": {
"table_name": "one_m",
"access_type": "index",
"key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["a"],
"r_loops": 1,
"rows": 1000000,
"r_rows": 69422,
"filtered": 100,
"r_filtered": 100,
"using_index": true
}
}
]
}
}
show analyze format=json for <thread_id>;
14
SHOW ANALYZE take aways
●
Get ANALYZE [FORMAT=JSON] output for a running query
●
Useful for troubleshooting long-running queries
●
Run it repeatedly to see the progress
– Get a clue about the result ETA.
15
MariaDB 10.10
16
MariaDB 10.10
MariaDB 10.10: RC since August, 2022
Optimizer features:
●
Table elimination works for derived tables (MDEV-26278)
●
Improved optimization for many-table joins (MDEV-28852)
17
Remember Table Elimination?
●
A normalized schema, optional attributes in separate tables
create table user (
user_id int primary key,
user_name varchar(32),
...
);
create view user_info as
select U.user_id, user_name, address
from
user U
left join shipping_address ADDR on U.user_id=ADDR.user_id;
●
A view to present the attribute(s)
create table shipping_address (
user_id int primary key,
address text
);
18
Remember Table Elimination (2) ?
select user_name from user_info where user_id=1234;
select user_name, address from user_info where user_id=1234;
●
Table ADDR was eliminated from the query plan
create view user_info as
select U.user_id, user_name, address
from
user U
left join shipping_address ADDR on U.user_id=ADDR.user_id;
+------+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | U | const | PRIMARY | PRIMARY | 4 | const | 1 | |
| 1 | SIMPLE | ADDR | const | PRIMARY | PRIMARY | 4 | const | 1 | |
+------+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
+------+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | U | const | PRIMARY | PRIMARY | 4 | const | 1 | |
+------+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
19
Summary attributes and derived tables
create table user (
user_id int primary key,
user_name varchar(32),
...
);
create view user_info2 as
select U.user_id, user_name, ORD_TOTAL
from
user U
left join (select
user_id, sum(amount) as ORD_TOTAL
from orders
group by user_id
) ORD_TOTALS
on ORD_TOTALS.user_id=U.user_id;
●
A view to show users with order totals:
create table orders (
order_id int primary key,
user_id int,
amount double,
key(user_id)
);
20
Table elimination for derived tables
select user_name, ORD_TOTAL from user_info2 where user_id in (1,2);
●
ORD_TOTALS was eliminated from the query plan
+------+-----------------+------------+-------+---------------+---------+---------+----------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-----------------+------------+-------+---------------+---------+---------+----------------+------+-------------+
| 1 | PRIMARY | u | range | PRIMARY | PRIMARY | 4 | NULL | 2 | Using where |
| 1 | PRIMARY | <derived3> | ref | key0 | key0 | 5 | test.u.user_id | 4 | |
| 3 | LATERAL DERIVED | orders | ref | user_id | user_id | 5 | test.u.user_id | 49 | |
+------+-----------------+------------+-------+---------------+---------+---------+----------------+------+-------------+
+------+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
| 1 | PRIMARY | u | range | PRIMARY | PRIMARY | 4 | NULL | 2 | Using where |
+------+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
select user_name from user_info2 where user_id in (1,2);
user U
left join (select
user_id, sum(amount) as ORD_TOTAL
from orders
group by user_id
) ORD_TOTALS
on ORD_TOTALS.user_id=U.user_id;
21
Summary
●
MariaDB has Table Elimination optimization
●
Applicable for inner sides of OUTER JOINs.
– Can eliminate unused tables
– Unused table must be joined with a unique key.
●
Starting from MariaDB 10.8:
– also applicable for derived tables with GROUP BY.
– Use case: derived tables providing summaries.
22
Optimization for many-table joins
23
Join order search
●
Total number of possible join orders is:
N * (N-1) * (N-2) *… = N!
●
Join orders are built left-to-right
●
Cannot enumerate all possible join
orders.
– Pruning away prefixes that are:
●
Already too expensive,or
●
Do not look primising.
t1
t1
t2
t2
t3
t4
t3
t4
t2
t4
t2
t3
t4
t3
t4
t2
t3
t2
t1
t3
t4
t3
t4
t1
t4
t1
t3
t4
t3
t4
t1
t3
t1
select ... from t1, t2, t3, t4 where ...
t3
24
Join order search
●
optimizer_prune_level=
– 0 – Don’t prune
– 1 – Standard pruning (the default)
– 2 – New. Extra pruning
●
optimizer_extra_pruning_depth=N
– If search depth >=N, enable extra pruning
select ... from t1, t2, t3, …, tN where ...
25
MariaDB 10.11
MariaDB 10.11: alpha since Sept, 2022
●
MDEV-20609: Optimization for queries reading from
INFORMATION_SCHEMA.{PROC,PARAMETERS}
– “Don’t parse the stored routine if it doesn’t match the WHERE”
– Java connector queries these tables.
●
MDEV-28926: Make ANALYZE FORMAT=JSON show time spent
in the query optimizer. ...
"query_optimization": {
"r_total_time_ms": 0.402132271
},
26
Summary
Optimizer Trace
Improvements
10.8
10.9
10.10
10.11
10.12
●
JSON_HB histograms
●
Optimizer produces valid, processible JSON
●
SHOW EXPLAIN FORMAT=JSON
●
SHOW ANALYZE [FORMAT=JSON]
●
Table elimination for derived tables
●
Improved optimization for many-table joins
●
Optimization for INFORMATION_SCHEMA.{PROC,PARAMETERS}
●
New cost model
●
Fixed selectivity computations
27
Thanks for your attention!

More Related Content

What's hot

Why MySQL Replication Fails, and How to Get it Back
Why MySQL Replication Fails, and How to Get it BackWhy MySQL Replication Fails, and How to Get it Back
Why MySQL Replication Fails, and How to Get it Back
Sveta Smirnova
 
Parallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDBParallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDB
Mydbops
 
Maxscale switchover, failover, and auto rejoin
Maxscale switchover, failover, and auto rejoinMaxscale switchover, failover, and auto rejoin
Maxscale switchover, failover, and auto rejoin
Wagner Bianchi
 
MariaDB MaxScale monitor 매뉴얼
MariaDB MaxScale monitor 매뉴얼MariaDB MaxScale monitor 매뉴얼
MariaDB MaxScale monitor 매뉴얼
NeoClova
 
Evolution of MySQL Parallel Replication
Evolution of MySQL Parallel Replication Evolution of MySQL Parallel Replication
Evolution of MySQL Parallel Replication
Mydbops
 
Histogram-in-Parallel-universe-of-MySQL-and-MariaDB
Histogram-in-Parallel-universe-of-MySQL-and-MariaDBHistogram-in-Parallel-universe-of-MySQL-and-MariaDB
Histogram-in-Parallel-universe-of-MySQL-and-MariaDB
Mydbops
 
MariaDB Optimization
MariaDB OptimizationMariaDB Optimization
MariaDB Optimization
JongJin Lee
 
MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxMySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptx
NeoClova
 
MariaDB MaxScale
MariaDB MaxScaleMariaDB MaxScale
MariaDB MaxScale
MariaDB plc
 
MariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & OptimizationMariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & Optimization
MariaDB plc
 
Galera cluster for high availability
Galera cluster for high availability Galera cluster for high availability
Galera cluster for high availability
Mydbops
 
MySQL_MariaDB-성능개선-202201.pptx
MySQL_MariaDB-성능개선-202201.pptxMySQL_MariaDB-성능개선-202201.pptx
MySQL_MariaDB-성능개선-202201.pptx
NeoClova
 
MySQL Data Encryption at Rest
MySQL Data Encryption at RestMySQL Data Encryption at Rest
MySQL Data Encryption at Rest
Mydbops
 
[2018] MySQL 이중화 진화기
[2018] MySQL 이중화 진화기[2018] MySQL 이중화 진화기
[2018] MySQL 이중화 진화기
NHN FORWARD
 
ProxySQL Cluster - Percona Live 2022
ProxySQL Cluster - Percona Live 2022ProxySQL Cluster - Percona Live 2022
ProxySQL Cluster - Percona Live 2022
René Cannaò
 
MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용
I Goo Lee
 
MySQL GTID 시작하기
MySQL GTID 시작하기MySQL GTID 시작하기
MySQL GTID 시작하기
I Goo Lee
 
MongoDB Backup & Disaster Recovery
MongoDB Backup & Disaster RecoveryMongoDB Backup & Disaster Recovery
MongoDB Backup & Disaster Recovery
Elankumaran Srinivasan
 
Innodb에서의 Purge 메커니즘 deep internal (by 이근오)
Innodb에서의 Purge 메커니즘 deep internal (by  이근오)Innodb에서의 Purge 메커니즘 deep internal (by  이근오)
Innodb에서의 Purge 메커니즘 deep internal (by 이근오)
I Goo Lee.
 
MyRocks introduction and production deployment
MyRocks introduction and production deploymentMyRocks introduction and production deployment
MyRocks introduction and production deployment
Yoshinori Matsunobu
 

What's hot (20)

Why MySQL Replication Fails, and How to Get it Back
Why MySQL Replication Fails, and How to Get it BackWhy MySQL Replication Fails, and How to Get it Back
Why MySQL Replication Fails, and How to Get it Back
 
Parallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDBParallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDB
 
Maxscale switchover, failover, and auto rejoin
Maxscale switchover, failover, and auto rejoinMaxscale switchover, failover, and auto rejoin
Maxscale switchover, failover, and auto rejoin
 
MariaDB MaxScale monitor 매뉴얼
MariaDB MaxScale monitor 매뉴얼MariaDB MaxScale monitor 매뉴얼
MariaDB MaxScale monitor 매뉴얼
 
Evolution of MySQL Parallel Replication
Evolution of MySQL Parallel Replication Evolution of MySQL Parallel Replication
Evolution of MySQL Parallel Replication
 
Histogram-in-Parallel-universe-of-MySQL-and-MariaDB
Histogram-in-Parallel-universe-of-MySQL-and-MariaDBHistogram-in-Parallel-universe-of-MySQL-and-MariaDB
Histogram-in-Parallel-universe-of-MySQL-and-MariaDB
 
MariaDB Optimization
MariaDB OptimizationMariaDB Optimization
MariaDB Optimization
 
MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxMySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptx
 
MariaDB MaxScale
MariaDB MaxScaleMariaDB MaxScale
MariaDB MaxScale
 
MariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & OptimizationMariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & Optimization
 
Galera cluster for high availability
Galera cluster for high availability Galera cluster for high availability
Galera cluster for high availability
 
MySQL_MariaDB-성능개선-202201.pptx
MySQL_MariaDB-성능개선-202201.pptxMySQL_MariaDB-성능개선-202201.pptx
MySQL_MariaDB-성능개선-202201.pptx
 
MySQL Data Encryption at Rest
MySQL Data Encryption at RestMySQL Data Encryption at Rest
MySQL Data Encryption at Rest
 
[2018] MySQL 이중화 진화기
[2018] MySQL 이중화 진화기[2018] MySQL 이중화 진화기
[2018] MySQL 이중화 진화기
 
ProxySQL Cluster - Percona Live 2022
ProxySQL Cluster - Percona Live 2022ProxySQL Cluster - Percona Live 2022
ProxySQL Cluster - Percona Live 2022
 
MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용
 
MySQL GTID 시작하기
MySQL GTID 시작하기MySQL GTID 시작하기
MySQL GTID 시작하기
 
MongoDB Backup & Disaster Recovery
MongoDB Backup & Disaster RecoveryMongoDB Backup & Disaster Recovery
MongoDB Backup & Disaster Recovery
 
Innodb에서의 Purge 메커니즘 deep internal (by 이근오)
Innodb에서의 Purge 메커니즘 deep internal (by  이근오)Innodb에서의 Purge 메커니즘 deep internal (by  이근오)
Innodb에서의 Purge 메커니즘 deep internal (by 이근오)
 
MyRocks introduction and production deployment
MyRocks introduction and production deploymentMyRocks introduction and production deployment
MyRocks introduction and production deployment
 

Similar to New optimizer features in MariaDB releases before 10.12

Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.
Mydbops
 
ANALYZE for Statements - MariaDB's hidden gem
ANALYZE for Statements - MariaDB's hidden gemANALYZE for Statements - MariaDB's hidden gem
ANALYZE for Statements - MariaDB's hidden gem
Sergey Petrunya
 
Need for Speed: MySQL Indexing
Need for Speed: MySQL IndexingNeed for Speed: MySQL Indexing
Need for Speed: MySQL Indexing
MYXPLAIN
 
Explain
ExplainExplain
MariaDB: ANALYZE for statements (lightning talk)
MariaDB:  ANALYZE for statements (lightning talk)MariaDB:  ANALYZE for statements (lightning talk)
MariaDB: ANALYZE for statements (lightning talk)
Sergey Petrunya
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
Dave Stokes
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
Dave Stokes
 
Need for Speed: Mysql indexing
Need for Speed: Mysql indexingNeed for Speed: Mysql indexing
Need for Speed: Mysql indexing
FromDual GmbH
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
Valeriy Kravchuk
 
Applied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System PresentationApplied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System Presentation
Richard Crowley
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQL
Georgi Sotirov
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Using histograms to get better performance
Using histograms to get better performanceUsing histograms to get better performance
Using histograms to get better performance
Sergey Petrunya
 
How to use histograms to get better performance
How to use histograms to get better performanceHow to use histograms to get better performance
How to use histograms to get better performance
MariaDB plc
 
Parallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQLParallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQL
Mydbops
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfz
Joshua Thijssen
 
Advanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisAdvanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and Analysis
MYXPLAIN
 
Explain2
Explain2Explain2
Explain2
Anis Berejeb
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
Jussi Pohjolainen
 

Similar to New optimizer features in MariaDB releases before 10.12 (20)

Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.
 
ANALYZE for Statements - MariaDB's hidden gem
ANALYZE for Statements - MariaDB's hidden gemANALYZE for Statements - MariaDB's hidden gem
ANALYZE for Statements - MariaDB's hidden gem
 
Need for Speed: MySQL Indexing
Need for Speed: MySQL IndexingNeed for Speed: MySQL Indexing
Need for Speed: MySQL Indexing
 
Explain
ExplainExplain
Explain
 
MariaDB: ANALYZE for statements (lightning talk)
MariaDB:  ANALYZE for statements (lightning talk)MariaDB:  ANALYZE for statements (lightning talk)
MariaDB: ANALYZE for statements (lightning talk)
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
 
Need for Speed: Mysql indexing
Need for Speed: Mysql indexingNeed for Speed: Mysql indexing
Need for Speed: Mysql indexing
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
 
Applied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System PresentationApplied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System Presentation
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQL
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Using histograms to get better performance
Using histograms to get better performanceUsing histograms to get better performance
Using histograms to get better performance
 
How to use histograms to get better performance
How to use histograms to get better performanceHow to use histograms to get better performance
How to use histograms to get better performance
 
Parallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQLParallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQL
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfz
 
Advanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisAdvanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and Analysis
 
Explain2
Explain2Explain2
Explain2
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
 

More from Sergey Petrunya

MariaDB's join optimizer: how it works and current fixes
MariaDB's join optimizer: how it works and current fixesMariaDB's join optimizer: how it works and current fixes
MariaDB's join optimizer: how it works and current fixes
Sergey Petrunya
 
Improved histograms in MariaDB 10.8
Improved histograms in MariaDB 10.8Improved histograms in MariaDB 10.8
Improved histograms in MariaDB 10.8
Sergey Petrunya
 
Improving MariaDB’s Query Optimizer with better selectivity estimates
Improving MariaDB’s Query Optimizer with better selectivity estimatesImproving MariaDB’s Query Optimizer with better selectivity estimates
Improving MariaDB’s Query Optimizer with better selectivity estimates
Sergey Petrunya
 
JSON Support in MariaDB: News, non-news and the bigger picture
JSON Support in MariaDB: News, non-news and the bigger pictureJSON Support in MariaDB: News, non-news and the bigger picture
JSON Support in MariaDB: News, non-news and the bigger picture
Sergey Petrunya
 
Optimizer Trace Walkthrough
Optimizer Trace WalkthroughOptimizer Trace Walkthrough
Optimizer Trace Walkthrough
Sergey Petrunya
 
Optimizer features in recent releases of other databases
Optimizer features in recent releases of other databasesOptimizer features in recent releases of other databases
Optimizer features in recent releases of other databases
Sergey Petrunya
 
MariaDB 10.4 - что нового
MariaDB 10.4 - что новогоMariaDB 10.4 - что нового
MariaDB 10.4 - что нового
Sergey Petrunya
 
MariaDB Optimizer - further down the rabbit hole
MariaDB Optimizer - further down the rabbit holeMariaDB Optimizer - further down the rabbit hole
MariaDB Optimizer - further down the rabbit hole
Sergey Petrunya
 
Query Optimizer in MariaDB 10.4
Query Optimizer in MariaDB 10.4Query Optimizer in MariaDB 10.4
Query Optimizer in MariaDB 10.4
Sergey Petrunya
 
Lessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmarkLessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmark
Sergey Petrunya
 
MariaDB 10.3 Optimizer - where does it stand
MariaDB 10.3 Optimizer - where does it standMariaDB 10.3 Optimizer - where does it stand
MariaDB 10.3 Optimizer - where does it stand
Sergey Petrunya
 
MyRocks in MariaDB | M18
MyRocks in MariaDB | M18MyRocks in MariaDB | M18
MyRocks in MariaDB | M18
Sergey Petrunya
 
New Query Optimizer features in MariaDB 10.3
New Query Optimizer features in MariaDB 10.3New Query Optimizer features in MariaDB 10.3
New Query Optimizer features in MariaDB 10.3
Sergey Petrunya
 
MyRocks in MariaDB
MyRocks in MariaDBMyRocks in MariaDB
MyRocks in MariaDB
Sergey Petrunya
 
Histograms in MariaDB, MySQL and PostgreSQL
Histograms in MariaDB, MySQL and PostgreSQLHistograms in MariaDB, MySQL and PostgreSQL
Histograms in MariaDB, MySQL and PostgreSQL
Sergey Petrunya
 
Say Hello to MyRocks
Say Hello to MyRocksSay Hello to MyRocks
Say Hello to MyRocks
Sergey Petrunya
 
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
Sergey Petrunya
 
MyRocks in MariaDB: why and how
MyRocks in MariaDB: why and howMyRocks in MariaDB: why and how
MyRocks in MariaDB: why and how
Sergey Petrunya
 
Эволюция репликации в MySQL и MariaDB
Эволюция репликации в MySQL и MariaDBЭволюция репликации в MySQL и MariaDB
Эволюция репликации в MySQL и MariaDB
Sergey Petrunya
 
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Sergey Petrunya
 

More from Sergey Petrunya (20)

MariaDB's join optimizer: how it works and current fixes
MariaDB's join optimizer: how it works and current fixesMariaDB's join optimizer: how it works and current fixes
MariaDB's join optimizer: how it works and current fixes
 
Improved histograms in MariaDB 10.8
Improved histograms in MariaDB 10.8Improved histograms in MariaDB 10.8
Improved histograms in MariaDB 10.8
 
Improving MariaDB’s Query Optimizer with better selectivity estimates
Improving MariaDB’s Query Optimizer with better selectivity estimatesImproving MariaDB’s Query Optimizer with better selectivity estimates
Improving MariaDB’s Query Optimizer with better selectivity estimates
 
JSON Support in MariaDB: News, non-news and the bigger picture
JSON Support in MariaDB: News, non-news and the bigger pictureJSON Support in MariaDB: News, non-news and the bigger picture
JSON Support in MariaDB: News, non-news and the bigger picture
 
Optimizer Trace Walkthrough
Optimizer Trace WalkthroughOptimizer Trace Walkthrough
Optimizer Trace Walkthrough
 
Optimizer features in recent releases of other databases
Optimizer features in recent releases of other databasesOptimizer features in recent releases of other databases
Optimizer features in recent releases of other databases
 
MariaDB 10.4 - что нового
MariaDB 10.4 - что новогоMariaDB 10.4 - что нового
MariaDB 10.4 - что нового
 
MariaDB Optimizer - further down the rabbit hole
MariaDB Optimizer - further down the rabbit holeMariaDB Optimizer - further down the rabbit hole
MariaDB Optimizer - further down the rabbit hole
 
Query Optimizer in MariaDB 10.4
Query Optimizer in MariaDB 10.4Query Optimizer in MariaDB 10.4
Query Optimizer in MariaDB 10.4
 
Lessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmarkLessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmark
 
MariaDB 10.3 Optimizer - where does it stand
MariaDB 10.3 Optimizer - where does it standMariaDB 10.3 Optimizer - where does it stand
MariaDB 10.3 Optimizer - where does it stand
 
MyRocks in MariaDB | M18
MyRocks in MariaDB | M18MyRocks in MariaDB | M18
MyRocks in MariaDB | M18
 
New Query Optimizer features in MariaDB 10.3
New Query Optimizer features in MariaDB 10.3New Query Optimizer features in MariaDB 10.3
New Query Optimizer features in MariaDB 10.3
 
MyRocks in MariaDB
MyRocks in MariaDBMyRocks in MariaDB
MyRocks in MariaDB
 
Histograms in MariaDB, MySQL and PostgreSQL
Histograms in MariaDB, MySQL and PostgreSQLHistograms in MariaDB, MySQL and PostgreSQL
Histograms in MariaDB, MySQL and PostgreSQL
 
Say Hello to MyRocks
Say Hello to MyRocksSay Hello to MyRocks
Say Hello to MyRocks
 
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
 
MyRocks in MariaDB: why and how
MyRocks in MariaDB: why and howMyRocks in MariaDB: why and how
MyRocks in MariaDB: why and how
 
Эволюция репликации в MySQL и MariaDB
Эволюция репликации в MySQL и MariaDBЭволюция репликации в MySQL и MariaDB
Эволюция репликации в MySQL и MariaDB
 
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
 

Recently uploaded

14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
Tier1 app
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
Maitrey Patel
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
kgyxske
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
gapen1
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Kubernetes at Scale: Going Multi-Cluster with Istio
Kubernetes at Scale:  Going Multi-Cluster  with IstioKubernetes at Scale:  Going Multi-Cluster  with Istio
Kubernetes at Scale: Going Multi-Cluster with Istio
Severalnines
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
Karya Keeper
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 

Recently uploaded (20)

14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Kubernetes at Scale: Going Multi-Cluster with Istio
Kubernetes at Scale:  Going Multi-Cluster  with IstioKubernetes at Scale:  Going Multi-Cluster  with Istio
Kubernetes at Scale: Going Multi-Cluster with Istio
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 

New optimizer features in MariaDB releases before 10.12

  • 1. Sergei Petrunia MariaDB devroom FOSDEM 2021 New optimizer features in MariaDB releases before 10.12 MariaDB Fest 2022 Sergei Petrunia MariaDB developer select * from optimizer_features where release_date is not null and release_date > date_sub(now(), interval 1 year)
  • 2. 2 Optimizer features in MariaDB 10.8 MariaDB 10.8: Stable since May, 2022 Optimizer features: ● JSOH_HB Histogram type – Covered in “Improved histograms in MariaDB 10.8” talk at FOSDEM 2022. ● Reverse-ordered index support ● JSON produced by the optimizer is now – Valid :-) – Processible
  • 3. 3 Optimizer produces JSON documents ● Optimizer produces JSON – EXPLAIN FORMAT=JSON … – ANALYZE FORMAT=JSON … – Optimizer Trace ● Reasons for using JSON – Human-readable, well-known syntax – Can be processed ● e.g. extract interesting parts of trace
  • 4. 4 JSON data structures ● Array: [ elem1, elem2, …] ● Object: { "name1":elem1, "name2":elem2, … } ● What if there are duplicate names? ● This is still valid JSON: { "name1":foo, "name1":bar, … } ● Possible gotchas in processing – Some tools work – Some tools will ignore “foo” – Some will concatenate (merge): “foobar”
  • 5. 5 Most common: EXPLAIN FORMAT=JSON EXPLAIN: { "query_block": { "select_id": 1, "table": { "table_name": "t1", "access_type": "ALL", "rows": 10, "filtered": 100, }, "table": { "table_name": "t2", "access_type": "ref", "possible_keys": ["a"], "key": "a", ... EXPLAIN: { "query_block": { "select_id": 1, "nested_loop": [ { "table": { "table_name": "t1", "access_type": "ALL", "rows": 10, "filtered": 100, } }, { "table": { "table_name": "t2", "access_type": "ref", "possible_keys": ["a"], ...
  • 6. 6 Now JSON is processible ● Before 10.8: – EXPLAIN/ANALYZE had duplicate names – Optimizer trace also had that ● Starting from 10.8: – All JSON docs are processible – Can develop tools ● EXPLAIN/ANALYZE visualizer (Highlight heaviest parts of the query) ● Optimizer trace: show details about the chosen query plan
  • 8. 8 MariaDB 10.9 MariaDB 10.9: Stable since August, 2022 Optimizer features: ● SHOW EXPLAIN FORMAT=JSON ● SHOW ANALYZE [FORMAT=JSON] ● EXPLAIN FOR CONNECTION
  • 9. 9 Remember SHOW EXPLAIN? Lets one see the EXPLAIN of a running statement: -- Run a long query select ... from ... -- Find the target's connection_id N select * from information_schema.processlist; -- See the query plan it is using show explain for N; Connection 1: Connection 2:
  • 10. 10 Better SHOW EXPLAIN in 10.9 ● Support for SHOW EXPLAIN FORMAT=JSON – One could only get tabular SHOW EXPLAIN before ● Due to implementation details – Now one can get the JSON form, too. It has more data. ● Compatibility with MySQL-8: – MySQL’s syntax: EXPLAIN [FORMAT=JSON] FOR CONNECTION n – Now, MariaDB supports it, too.
  • 11. 11 Remember ANALYZE? ● ANALYZE SELECT … shows explain with execution data ● Has FORMAT=JSON form ● Very useful for optimizer troubleshooting – IF you can wait for the query to finish... "query_block": { "select_id": 1, "r_loops": 1, "r_total_time_ms": 0.947815181, "nested_loop": [ { "table": { "table_name": "t1", "access_type": "ALL", "r_loops": 1, "rows": 10, "r_rows": 10, "r_table_time_ms": 0.804191, "r_other_time_ms": 0.1051569, "filtered": 100, "r_filtered": 20,
  • 12. 12 Problem with ANALYZE ● Query takes forever to finish ● Query has constructs with large potential for optimization errors – Derived tables – Many-table joins – Dependent subqueries ● What is the query doing? – How long will it take?
  • 13. 13 SHOW ANALYZE ● Shows r_ members describing the execution so far ● Can check r_rows vs rows, r_filtered vs filtered. – r_total_time_ms will be present if the target is collecting timings (is itself running an ANALYZE command) ● r_loops=1 – the first iteration ● Low r_loops: last iteration is incomplete { "r_query_time_in_progress_ms": 7801, "query_optimization": { "r_total_time_ms": 0.402132271 }, "query_block": { "select_id": 1, "r_loops": 1, "nested_loop": [ { "table": { "table_name": "one_m", "access_type": "index", "key": "PRIMARY", "key_length": "4", "used_key_parts": ["a"], "r_loops": 1, "rows": 1000000, "r_rows": 69422, "filtered": 100, "r_filtered": 100, "using_index": true } } ] } } show analyze format=json for <thread_id>;
  • 14. 14 SHOW ANALYZE take aways ● Get ANALYZE [FORMAT=JSON] output for a running query ● Useful for troubleshooting long-running queries ● Run it repeatedly to see the progress – Get a clue about the result ETA.
  • 16. 16 MariaDB 10.10 MariaDB 10.10: RC since August, 2022 Optimizer features: ● Table elimination works for derived tables (MDEV-26278) ● Improved optimization for many-table joins (MDEV-28852)
  • 17. 17 Remember Table Elimination? ● A normalized schema, optional attributes in separate tables create table user ( user_id int primary key, user_name varchar(32), ... ); create view user_info as select U.user_id, user_name, address from user U left join shipping_address ADDR on U.user_id=ADDR.user_id; ● A view to present the attribute(s) create table shipping_address ( user_id int primary key, address text );
  • 18. 18 Remember Table Elimination (2) ? select user_name from user_info where user_id=1234; select user_name, address from user_info where user_id=1234; ● Table ADDR was eliminated from the query plan create view user_info as select U.user_id, user_name, address from user U left join shipping_address ADDR on U.user_id=ADDR.user_id; +------+-------------+-------+-------+---------------+---------+---------+-------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+-------------+-------+-------+---------------+---------+---------+-------+------+-------+ | 1 | SIMPLE | U | const | PRIMARY | PRIMARY | 4 | const | 1 | | | 1 | SIMPLE | ADDR | const | PRIMARY | PRIMARY | 4 | const | 1 | | +------+-------------+-------+-------+---------------+---------+---------+-------+------+-------+ +------+-------------+-------+-------+---------------+---------+---------+-------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+-------------+-------+-------+---------------+---------+---------+-------+------+-------+ | 1 | SIMPLE | U | const | PRIMARY | PRIMARY | 4 | const | 1 | | +------+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
  • 19. 19 Summary attributes and derived tables create table user ( user_id int primary key, user_name varchar(32), ... ); create view user_info2 as select U.user_id, user_name, ORD_TOTAL from user U left join (select user_id, sum(amount) as ORD_TOTAL from orders group by user_id ) ORD_TOTALS on ORD_TOTALS.user_id=U.user_id; ● A view to show users with order totals: create table orders ( order_id int primary key, user_id int, amount double, key(user_id) );
  • 20. 20 Table elimination for derived tables select user_name, ORD_TOTAL from user_info2 where user_id in (1,2); ● ORD_TOTALS was eliminated from the query plan +------+-----------------+------------+-------+---------------+---------+---------+----------------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+-----------------+------------+-------+---------------+---------+---------+----------------+------+-------------+ | 1 | PRIMARY | u | range | PRIMARY | PRIMARY | 4 | NULL | 2 | Using where | | 1 | PRIMARY | <derived3> | ref | key0 | key0 | 5 | test.u.user_id | 4 | | | 3 | LATERAL DERIVED | orders | ref | user_id | user_id | 5 | test.u.user_id | 49 | | +------+-----------------+------------+-------+---------------+---------+---------+----------------+------+-------------+ +------+-------------+-------+-------+---------------+---------+---------+------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+-------------+-------+-------+---------------+---------+---------+------+------+-------------+ | 1 | PRIMARY | u | range | PRIMARY | PRIMARY | 4 | NULL | 2 | Using where | +------+-------------+-------+-------+---------------+---------+---------+------+------+-------------+ select user_name from user_info2 where user_id in (1,2); user U left join (select user_id, sum(amount) as ORD_TOTAL from orders group by user_id ) ORD_TOTALS on ORD_TOTALS.user_id=U.user_id;
  • 21. 21 Summary ● MariaDB has Table Elimination optimization ● Applicable for inner sides of OUTER JOINs. – Can eliminate unused tables – Unused table must be joined with a unique key. ● Starting from MariaDB 10.8: – also applicable for derived tables with GROUP BY. – Use case: derived tables providing summaries.
  • 23. 23 Join order search ● Total number of possible join orders is: N * (N-1) * (N-2) *… = N! ● Join orders are built left-to-right ● Cannot enumerate all possible join orders. – Pruning away prefixes that are: ● Already too expensive,or ● Do not look primising. t1 t1 t2 t2 t3 t4 t3 t4 t2 t4 t2 t3 t4 t3 t4 t2 t3 t2 t1 t3 t4 t3 t4 t1 t4 t1 t3 t4 t3 t4 t1 t3 t1 select ... from t1, t2, t3, t4 where ... t3
  • 24. 24 Join order search ● optimizer_prune_level= – 0 – Don’t prune – 1 – Standard pruning (the default) – 2 – New. Extra pruning ● optimizer_extra_pruning_depth=N – If search depth >=N, enable extra pruning select ... from t1, t2, t3, …, tN where ...
  • 25. 25 MariaDB 10.11 MariaDB 10.11: alpha since Sept, 2022 ● MDEV-20609: Optimization for queries reading from INFORMATION_SCHEMA.{PROC,PARAMETERS} – “Don’t parse the stored routine if it doesn’t match the WHERE” – Java connector queries these tables. ● MDEV-28926: Make ANALYZE FORMAT=JSON show time spent in the query optimizer. ... "query_optimization": { "r_total_time_ms": 0.402132271 },
  • 26. 26 Summary Optimizer Trace Improvements 10.8 10.9 10.10 10.11 10.12 ● JSON_HB histograms ● Optimizer produces valid, processible JSON ● SHOW EXPLAIN FORMAT=JSON ● SHOW ANALYZE [FORMAT=JSON] ● Table elimination for derived tables ● Improved optimization for many-table joins ● Optimization for INFORMATION_SCHEMA.{PROC,PARAMETERS} ● New cost model ● Fixed selectivity computations
  • 27. 27 Thanks for your attention!