SlideShare a Scribd company logo
1 of 97
Download to read offline
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
1
MariaDB : Optimizer
Jong Jin Lee
SYS4U I&C EC Solution Lab / Software Engineer
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
2
Agenda
• Query execution process
• Optimizer
• Statistics
• Histogram-based Statistics
• Join Optimizer
• Analysis of the execution plan
• Optimizer Hint
• Tuning Point
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
3
MariaDB : Query execution process
SQL Parsing Optimization and Plan Join and Sort
Using SQL Parser
• Split from the SQL
statement
• Grammatical error
checking
• Create a parse tree
Using SQL Parse tree
• Select the tables and
indexes
• Simplify operations
• Join the ordering
• Set whether to use a
temporary table
Reading Record
• Reading Record From
Storage Engine
• Join & Sort Operations
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
4
MariaDB : Optimizer
 RBO(Rule-based optimizer)
 It is only present to provide backwards compatibility during the migration
to the query optimizer (Cost Based Optimizer).
 Do not collect statistics.
 CBO(Cost-based optimizer)
 The optimizer can use a rules-based approach to work without statistical
information, but this approach is less intelligent than the cost-based
approach.
 The optimizer factors in statistical information about the contents of the
particular schema objects (tables, clusters, or indexes) being accessed.
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
5
MariaDB : Statistics
 MariaDB 5.5 Version
 The statistics provided for each storage engine does not have sufficient
information about the contents.
 Column statistics are not collected (Only Index) – Using MYISAM engine
 MySQL 5.6 Version
 MariaDB 10.0
MariaDB [(none)]> use mysql;
MariaDB [(mysql)]> show tables like ‘%_stats’;
innodb_index_stats
innodb_table_stats
MariaDB [(none)]> use mysql;
MariaDB [(mysql)]> show tables like ‘%_stats’;
column_stats
index_stats
table_stats
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
6
MariaDB : Statistics
 Statistics collection
 DB : my.cnf (INNODB_STATS_AUTO_RECALE > ON)
 Table : STATS_AUTO_RECALE option
– STATS_AUTO_RECALC is available only in MariaDB 10.0+. It indicates whether to automatically
recalculate persistent statistics (see STATS_PERSISTENT, below) for an InnoDB table. If set to 1,
statistics will be recalculated when more than 10% of the data has changed. When set to 0, stats will be
recalculated only when an ANALYZE TABLE is run. If set to DEFAULT, or left out, the value set by the
innodb_stats_auto_recalc system variable applies.
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
7
MariaDB : Statistics
 CLIENT_STATISTICS
– The CLIENT_STATISTICS table holds statistics about client connections.
MariaDB [(mysql)]> SELECT * FROM INFORMATION_SCHEMA.CLIENT_STATISTICSG
*************************** 1. row ***************************
CLIENT: localhost
TOTAL_CONNECTIONS: 3
CONCURRENT_CONNECTIONS: 0
CONNECTED_TIME: 4883
BUSY_TIME: 0.009722
CPU_TIME: 0.0102131
BYTES_RECEIVED: 841
BYTES_SENT: 13897
BINLOG_BYTES_WRITTEN: 0
ROWS_READ: 0
ROWS_SENT: 214
ROWS_DELETED: 0
ROWS_INSERTED: 207
ROWS_UPDATED: 0
SELECT_COMMANDS: 10
UPDATE_COMMANDS: 0
OTHER_COMMANDS: 13
COMMIT_TRANSACTIONS: 0
ROLLBACK_TRANSACTIONS: 0
DENIED_CONNECTIONS: 0
LOST_CONNECTIONS: 0
ACCESS_DENIED: 0
EMPTY_QUERIES: 1
1 row in set (0.00 sec)
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
8
MariaDB : Statistics
 USER_STATISTICS
– The USER_STATISTICS table holds statistics about user activity. You can use this table to find out such
things as which user is causing the most load and which users are being abusive. You can also use this table
to measure how close to capacity the server may be.
SELECT * FROM INFORMATION_SCHEMA.USER_STATISTICSG
*************************** 1. row ***************************
USER: root
TOTAL_CONNECTIONS: 1
CONCURRENT_CONNECTIONS: 0
CONNECTED_TIME: 297
BUSY_TIME: 0.001725
CPU_TIME: 0.001982
BYTES_RECEIVED: 388
BYTES_SENT: 2327
BINLOG_BYTES_WRITTEN: 0
ROWS_READ: 0
ROWS_SENT: 12
ROWS_DELETED: 0
ROWS_INSERTED: 13
ROWS_UPDATED: 0
SELECT_COMMANDS: 4
UPDATE_COMMANDS: 0
OTHER_COMMANDS: 3
COMMIT_TRANSACTIONS: 0
ROLLBACK_TRANSACTIONS: 0
DENIED_CONNECTIONS: 0
LOST_CONNECTIONS: 0
ACCESS_DENIED: 0
EMPTY_QUERIES: 1
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
9
MariaDB : Statistics
 INDEX_STATISTICS
– The INDEX_STATISTICS table shows statistics on index usage and makes it possible to do such things as
locating unused indexes and generating the commands to remove them.
SELECT * FROM INFORMATION_SCHEMA.INDEX_STATISTICS WHERE TABLE_NAME = "author";
+--------------+------------+------------+-----------+
| TABLE_SCHEMA | TABLE_NAME | INDEX_NAME | ROWS_READ |
+--------------+------------+------------+-----------+
| books | author | by_name | 15 |
+--------------+------------+------------+-----------+
Field Type Notes
TABLE_SCHEMA varchar(192) The schema (database) name.
TABLE_NAME varchar(192) The table name.
INDEX_NAME varchar(192) The index name (as visible in SHOW CREATE TABLE).
ROWS_READ int(21) The number of rows read from this index.
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
10
MariaDB : Statistics
 TABLE_STATISTICS
– The TABLE_STATISTICS table is similar to the INDEX_STATISTICS table. It shows statistics on table usage.
SELECT * FROM INFORMATION_SCHEMA.TABLE_STATISTICS WHERE TABLE_NAME='user';
+--------------+------------+-----------+--------------+------------------------+
| TABLE_SCHEMA | TABLE_NAME | ROWS_READ | ROWS_CHANGED | ROWS_CHANGED_X_INDEXES |
+--------------+------------+-----------+--------------+------------------------+
| mysql | user | 5 | 2 | 2 |
+--------------+------------+-----------+--------------+------------------------+w
Field Type Notes
TABLE_SCHEMA varchar(192) The schema (database) name.
TABLE_NAME varchar(192) The table name.
ROWS_READ int(21) The number of rows read from the table.
ROWS_CHANGED int(21) The number of rows changed in the table.
ROWS_CHANGED_X_INDEXES int(21)
The number of rows changed in the table,
multiplied by the number of indexes changed.
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
11
 MariaDB 10.0 Version
– Histogram-based statistics were introduced in MariaDB 10.0.2 as a
mechanism to improve the query plan chosen by the optimizer in certain
situations. Until then, all conditions on non-indexed columns were
ignored when searching for the best execution plan. Histograms can be
collected for both indexed and non-indexed columns, and are made
available to the optimizer.
– MySQL : column_stats table
MariaDB : Histogram-based Statistics
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
12
 Height-Balanced Histogram algorithm
MariaDB : Histogram-based Statistics
A
B
C
B
C
C
B
A
A
B
B
B
C
C
A
A
1 B
2 C
3 A
4 B
Column Order Histogram
Column Bucket Size = System Variables(histogram_size)
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
13
 Exhaustive Search
– The combination of all the tables in the execution plan cost calculation
– Ex) Table : 10 , Join : 20! (Factorial, 3628800)
MariaDB : Join Optimizer
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
14
 Heuristic Search(Greedy Search)
– Join (optimizer_prune_level, optimizer_search_depth)
MariaDB : Join Optimizer
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
15
 HOW TO USE
– The EXPLAIN statement can be used either as a synonym for
DESCRIBE or as a way to obtain information about how MariaDB
executes a SELECT (as well as UPDATE and DELETE since MariaDB
10.0.5) statement:
MariaDB : Analysis of the execution plan
EXPLAIN
SELECT e.emp_no, e.first_name, s.from_date, s.salary
FROM employees e, salaries s
WHERE e.emp_no=s.emp_no
LIMIT 10;
Outer
Inner
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
16
 The columns in EXPLAIN ... SELECT
MariaDB : Analysis of the execution plan
Column name Description
id Sequence number that shows in which order tables are joined.
select_type What kind of SELECT the table comes from.
table Alias name of table. Materialized temporary tables for sub queries are named <subquery#>
type How rows are found from the table (join type).
possible_keys keys in table that could be used to find rows in the table
key The name of the key that is used to retrieve rows. NULL is no key was used.
key_len How many bytes of the key that was used (shows if we are using only parts of the multi-column key).
ref The reference that is used to as the key value.
rows An estimate of how many rows we will find in the table for each key lookup.
Extra Extra information about this join.
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
17
 ID column
MariaDB : Analysis of the execution plan
Select
( ( select count(*) from employees) + (select count(*) from departments) ) as total_counts;
select e.emp_no, e.first_name, s.from_Date, s.salary from employees e, salaries s where e.emp_no=s.emp_nolimit 10;
Column name
id
select_type
table
type
possible_keys
key
key_len
ref
rows
Extra
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
18
 Select_Type column
MariaDB : Analysis of the execution plan
Value Description
UNION
The SELECT is a UNION of the
PRIMARY.
DEPENDENT UNION The UNION is DEPENDENT.
UNION RESULT The result of the UNION.
SUBQUERY
The SELECT is a SUBQUERY of the
PRIMARY.
DEPENDENT SUBQUERY The SUBQUERY is DEPENDENT.
DERIVED
The SELECT is DERIVED from the
PRIMARY.
UNCACHEABLE SUBQUERY The SUBQUERY is UNCACHEABLE.
PRIMARY The SELECT is a PRIMARY one.
SIMPLE The SELECT is a SIMPLE one.
UNCACHEABLE UNION The UNION is UNCACHEABLE.
Column name
id
select_type
table
type
possible_keys
key
key_len
ref
rows
Extra
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
19
 Select_Type column [UNION]
MariaDB : Analysis of the execution plan
select *
from (
(select emp_no from employees e1 limit 10)
union all
(select emp_no from employees e1 limit 10)
union all
(select emp_no from employees e1 limit 10)
) tb;
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
20
 Select_Type column [DEPENDENT UNION]
MariaDB : Analysis of the execution plan
select *
from employees e1 where e1.emp_no in
(
select e2.emp_no from employees e2 where e2.first_name='Matt‘ (where e2.emp_no=e1.emp_no)
union
select e3.emp_no from employees e3 where e3.first_name='Matt‘ (where e3.emp_no=e1.emp_no)
)
Optimization
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
21
 Select_Type column [UNION RESULT]
MariaDB : Analysis of the execution plan
select emp_no
from salaries
where salary>100000
union all
select emp_no
from dept_emp
where from_date >'2001-01-01';
UNION RESULT < UNION 1,2 >
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
22
 Select_Type column [SUBQUERY]
MariaDB : Analysis of the execution plan
select e.first_name,
(select count(*) from dept_emp de, dept_manager dm where dm.dept_no=de.dept_no) as cnt
from employees e
where e.emp_no=10001;
SELECT : Nested Query
WHERE : Sub Query
FROM : DERIVED
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
23
 Select_Type column [DEPENDENT SUBQUERY]
MariaDB : Analysis of the execution plan
select e.first_name,
(select count(*)from dept_emp de, dept_manager dm where dm.dept_no=de.dept_no and de.emp_no=e.emp_no)
as cnt
from employees e
where e.first_name='Matt';
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
24
 Select_Type column [DERIVED]
MariaDB : Analysis of the execution plan
select *
from
(select de.emp_no from dept_emp de group by de.emp_no) tb, (DERIVED)
employees e
where e.emp_no=tb.emp_no;
Tuning Point : 1. Check SELECT_TYPE (DERIVED)
2. SUBQUERY -> JOIN
Optimization
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
25
 Select_Type column [UNCACHEABLE SUBQUERY]
MariaDB : Analysis of the execution plan
select *
from employees e
where e.emp_no =
(
select @status from dept_emp de where de.dept_no ='d005'
);
UNCACHEABLE SUBQERY CASE :
1. Including User Variables
2. Including NOT-DETERMINISTIC
3. Including UUID(), RAND() Function
> Compare the number of records generated as a function call
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
26
 Select_Type column [MATERIALIZED]
MariaDB : Analysis of the execution plan
select *
from employees e
where e.emp_no in (select emp_no from salaries where salary between 100 and 1000); (DERIVED  Materialization)
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
27
 Table column [derived N]
MariaDB : Analysis of the execution plan
ID SELECT_TYPE TABLE …
1 PRIMARY <derived 2>
1 PRIMARY E
2 DERIVED Dept_emp
* Must Have : Temporary tables should have a alias
<derived N> = <Derived Table Number(ID)>
MariaDB [employees]> select dttm from (select now() as dttm);
ERROR 1248 (42000): Every derived table must have its own alias
MariaDB [employees]> select dttm from (select now() as dttm) derived_table_alias;
+---------------------+
| dttm |
+---------------------+
| 2014-07-08 21:10:29 |
+---------------------+
1 row in set (0.19 sec)
Column name
id
select_type
table
type
possible_keys
key
key_len
ref
rows
Extra
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
28
 Type column
MariaDB : Analysis of the execution plan
Value Description
ALL
A full table scan is done for the table
(all rows are read)
const
There is only one possibly matching
row in the table. (UNIQUE INDEX
SCAN)
eq_ref
A unique index is used to find the
rows. (Best Practice)
fulltext
A fulltext index is used to access the
rows.
index_merge
A 'range' access is done for several
index and the found rows are merged
index_subquery
This is similar as ref, but used for sub
queries that are transformed to key
lookups.
index
A full scan over the used index.
(Better than ALL but still bad)
Column name
id
select_type
table
type
possible_keys
key
key_len
ref
rows
Extra
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
29
 Type column
MariaDB : Analysis of the execution plan
Value Description
range
The table will be accessed with a key
over one or more value ranges.
ref_or_null ref or null comparison(is null)
ref
A non unique index or prefix of an
unique index is used to find the rows.
system The table has 0 or 1 rows.
unique_subquery
This is similar as eq_ref, but used for
sub queries that are transformed to
key lookups
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
30
 Type column [ALL]
MariaDB : Analysis of the execution plan
select * from employees;
ALL = Full Table Scan
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
31
 Type column [const]
MariaDB : Analysis of the execution plan
select * from employees where emp_no=10001;
select * from dept_emp where dept_no='d005';
select * from dept_emp where dept_no='d005' and emp_no=10001;
One of Consisting of a multi-column primary key, unique key
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
32
 Type column [ref]
MariaDB : Analysis of the execution plan
select * from dept_emp where dept_no='d005';
1. const
primary key/unique key column (equal) -> recode only one
2. eq_req
using read the column values of first table the second table values the retrieve condition -> recode only one
3. ref
Equal -> recode only one X
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
33
 Type column [eq_ref]
MariaDB : Analysis of the execution plan
select * from dept_emp de, employees e
where e.emp_no=de.emp_no and de.dept_no='d005';
1. Join Table (id = 1)
2. Process (dept_emp -> employee)
3. emp.no (primary) -> eq_ref
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
34
 Type column [fulltext]
MariaDB : Analysis of the execution plan
select *
from employee_name
where emp_no=10001 #const
and emp_no between 10001 and 10005 #range
and match(first_name, last_name) against('Facello' in boolean mode);
select *
from employee_name
#where emp_no=10001 #const
where emp_no between 10001 and 10005 #range
and match(first_name, last_name) against('Facello' in boolean mode);
1. A full-text index in MariaDB is an index of type FULLTEXT
2. Full-text searching is performed using MATCH() ... AGAINST syntax.
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
35
 Type column [index_merge]
MariaDB : Analysis of the execution plan
select *
from employees
where emp_no between 10001 and 11000
or first_name='Smith';
1. several index and the found rows are merged
2. efficiency is less than the range scan
3. Do not work “full-text” search
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
36
 Type column [index_subquery]
MariaDB : Analysis of the execution plan
select *
from departments where dept_no in (
select dept_no from dept_emp where dept_no between 'd001' and 'd003');
1. unique_subquery
IN(subquery): Deduplication does not need work
2. index_subquery
IN(subquery) : Possible duplicate values, Index(Remove duplicate values)
MariaDB 5.6 Over : index_subquery => ref
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
37
 Type column [index]
MariaDB : Analysis of the execution plan
select * from departments order by dept_name desc limit 10;
1. Type(index) = Index Full Scan (But, Not Data File Full Scan -> Index File Full Scan)
2. Best Practice : Operation is possible only index
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
38
 Possible_keys column
– To make the best execution plan that was nominated for an index list
– Actually unused indexes
– Ignore column
MariaDB : Analysis of the execution plan
Column name
id
select_type
table
type
possible_keys
key
key_len
ref
rows
Extra
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
39
 Key column
– The selected index in the best execution plan
– Tuning Point key (index)
– One or more indexes are "," separated (type - index_merge)
MariaDB : Analysis of the execution plan
Column name
id
select_type
table
type
possible_keys
key
key_len
ref
rows
Extra
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
40
 Key_len column
– The selected index in the best execution plan
– Tuning Point key (index)
– One or more indexes are "," separated (type - index_merge)
MariaDB : Analysis of the execution plan
Column name
id
select_type
table
type
possible_keys
key
key_len
ref
rows
Extra
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
41
 Key_len column
MariaDB : Analysis of the execution plan
select * from dept_emp where dept_no='d005';
* Description : Character – utf 8(1~3byte), dept_no – char(4 byte)
12 = 3 * 4
select * from dept_emp where dept_no='d005' and emp_no=10001;
* Description : Character – utf 8(1~3byte), dept_no – char(4 byte), emp_no – integer (4 byte)
16 = (4*3) + 4
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
42
 Key_len column
MariaDB : Analysis of the execution plan
select * from titles where to_date<='1985-10-10';
* Description : Character – utf 8(1~3byte), to_date – date(3 byte)
4 ? -> why? : to_date (3 byte + nullable(1 byte))
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
43
 Ref column
– reference column
– ex, Ref (Equal), other column (Table name, Column name), const
 “Func”
MariaDB : Analysis of the execution plan
Column name
id
select_type
table
type
possible_keys
key
key_len
ref
rows
Extra
select *
from employees e, dept_emp de
where e.emp_no=de.emp_no;
select *
from employees e, dept_emp de
where e.emp_no=(de.emp_no-1);
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
44
 Rows column
– Anticipated counting of records
– Based on statistical information (Record count, distribution of index
values … )
MariaDB : Analysis of the execution plan
Column name
id
select_type
table
type
possible_keys
key
key_len
ref
rows
Extra
# ix_formdate
select * from dept_emp where from_Date >='1985-01-01';
select * from dept_emp where from_Date >='2002-07-01'; Why ?
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
45
MariaDB : Analysis of the execution plan
Column name
id
select_type
table
type
possible_keys
key
key_len
ref
rows
Extra
 Extra column
– Displays important information about the performance-related
– 2-3 show generally
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
46
MariaDB : Analysis of the execution plan
 Extra column [const row not found]
– Display type : const
– Fact : 0 rows
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
47
MariaDB : Analysis of the execution plan
 Extra column [Distinct]
select distinct d.dept_no
from departments d, dept_emp de where de.dept_no=d.dept_no;
How to Handling Distinct on MariaDB ?
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
48
MariaDB : Analysis of the execution plan
 Extra column [Full scan on Null key]
select d.dept_no, null in (select id.dept_name from departments id)
from departments d; Solutions : Definition column Attribute (is not null)
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
49
MariaDB : Analysis of the execution plan
 Extra column [Impossible HAVING]
select e.emp_no, count(*) as cnt
from employees e
where e.emp_no=10001
group by e.emp_no
having e.emp_no is null; e.emp_no = primary key & not null columns
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
50
 Extra column [Impossible WHERE]
MariaDB : Analysis of the execution plan
select * from employees where emp_no is null; e.emp_no = primary key & not null columns
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
51
 Extra column [Impossible WHERE noticed after reading const tables]
MariaDB : Analysis of the execution plan
select * from employees where emp_no=0; Comparison(Equal) => const type
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
52
 Extra column [No matching min/max row]
MariaDB : Analysis of the execution plan
select min(dept_no), max(dept_no)
from dept_emp where dept_no=''; Not matching = 0 rows
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
53
 Extra column [No matching row in const table]
MariaDB : Analysis of the execution plan
select *
from dept_emp de,
(select emp_no from employees where emp_no=0) tb1
where tb1.emp_no=de.emp_no and de.dept_no='d005'; Not matching when const approaching
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
54
 Extra column [No tables used]
MariaDB : Analysis of the execution plan
select 1;
select 1 from dual; Handled internally by the optimizer
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
55
 Extra column [Not exists]
MariaDB : Analysis of the execution plan
select *
from dept_emp de
left join departments d on de.dept_no=d.dept_no
where d.dept_no is null; Anti-Join (When a lot of data : use Outer Join)
Optimization
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
56
 Extra column [Range checked for each recode(index map:N)]
MariaDB : Analysis of the execution plan
select *
from employees e1, employees e2
where e2.emp_no >= e1.emp_no;
Index map: 0x1 (16 Hexadecimal) => 1 (Transfer to 2 Hexadecimal)
1 => first index of e2(employees) table
Type ALL : if first index not good Performance => Plan change : ALL(Full Table Scan)
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
57
 Extra column [Select tables optimized away]
MariaDB : Analysis of the execution plan
select max(emp_no), min(emp_no) from employees;
# salaries table (pk : emp_no+from_date)
select max(from_date), min(from_date) from salaries where emp_no=10001;
Optimization
10002
10003
…
10009
10010
10001
MIN(emp_no)
MAX(emp_no)
CASE : Optimization (if NOT WHERE statement)
1996-01-01
…
2001-08-14
2014-07-09
1995-01-01
MIN(from_date)
Max(from_date)
CASE : Optimization (if the WHERE statement)
1991-03-15
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
58
 Extra column [Skip_open_table, Open_frm_only, Open_trigger_only,
Open_full_table]
– = “Scanned N databases”
– Select INFORMATION_SCHEMA (meta data)
MariaDB : Analysis of the execution plan
1. Skip_open_table : No need to read
2. Open_frm_only : Read only files stored in the meta information file(*.FRM)
3. Open_trigger_only : Read only files stored in the trigger information file (*.TRG)
4. Open_full_table : Not optimized , Read all meta information file(*FRM) & data file(*MYD), index file(*MYI)
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
59
 Extra column [Unique row not found]
# // test table creation
create table tb_test1 (fdpk int, primary key(fdpk));
create table tb_test2 (fdpk int, primary key(fdpk));
# // insert sample data
insert into tb_test1 values (1), (2);
insert into tb_test2 values (1);
select t2.fdpk
from tb_test1 t1
left join tb_test2 t2 on t2.fdpk=t1.fdpk
where t1.fdpk =2;
MariaDB : Analysis of the execution plan
* Each table has unique (PK included) columns in a query that performs an outer join, the outer table has a
matching record does not exist
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
60
 Extra column [Using filesort]
MariaDB : Analysis of the execution plan
select * from employees order by last_name desc;
* Use Quick soft algorithm
* Processing
1. read recode
2. Copy to soft buffer
3. Order by
4. Send to client
* Overhead -> create index, query tuning
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
61
 Quick soft algorithm
MariaDB : Analysis of the execution plan
Ex) Pivot = p, List Left Index I, List Right Index J
1.
5 - 3 - 7 - 6 - 2 - 1 - 4
p
2.
5 - 3 - 7 - 6 - 2 - 1 - 4
i j p
1 - 3 - 7 - 6 - 2 - 5 - 4
i j p
3.
1 - 3 - 7 - 6 - 2 - 5 - 4
i j p
4.
1 - 3 - 7 - 6 - 2 - 5 - 4
i j p
1 - 3 - 2 - 6 - 7 - 5 - 4
i j p
5.
1 - 3 - 2 - 6 - 7 - 5 - 4
p
1 - 3 - 2 - 4 - 7 - 5 - 6
p
6.
1 - 3 - 2
1 - 2 - 3
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
62
 Extra column [Using index(covering index)]
MariaDB : Analysis of the execution plan
# use index (ix_first_name) & disk access
select first_name, birth_date
from employees where first_name between 'Babette' and 'Gad';
# use index (ix_first_name)
select first_name
from employees where first_name between 'Babette' and 'Gad';
* Operation to Only index page
* Innodb table (default cluster index)
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
63
 Extra column [Using index for group-by]
MariaDB : Analysis of the execution plan
#tight index scan
select first_name, count(*) as counter from employees group by first_name;
#loose index scan
select emp_no, min(from_date) as first_changed_date, max(from_date) as last_changed_date
from salaries
group by emp_no;
1. Tight index scan
- A tight index scan may be either a full index scan or a range index scan, depending on the query conditions.
2. Loose index scan
- The most efficient way is when the index is used to directly retrieve the group fields
Since this access method considers only a fraction of the keys in an index, it is called a loose index scan
#loose index scan
select emp_no
from salaries where emp_no between 10001 and 10099
group by emp_no;
* Good performance in a large records.
* The optimizer to determine the break-even point
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
64
 Extra column [Using join buffer(Block Nested Loop),
Using join buffer(Batched Key Access)]
MariaDB : Analysis of the execution plan
select *
from dept_emp de, employees e
where de.from_date>'2005-01-01' and e.emp_no<10904;
Join Processing
- Using Join buffer
- Using Block Nested Loop (Nested Loop)
Recommend : Driven Table (Create Index)
 prevention (Full Tabe Scan, Index Full Scan)
* Using Join buffer
- Place to temporarily store the records
- OLTP Recommend Buffer Size : 1MB
- MariaDB 5.3 Over : Hash Join(Based on Block)
Batched Key Access = Multi Range Read(MRR)
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
65
 Extra column [Using soft_union, Using union, Using intersect,
Using sort_intersecion]
– Using intersect(…)
• AND operation (Intersection)
– Using union(…)
• OR operation (union)
– Using sort_union(…)
• OR operation associated with the relatively large quantity of RANGE operation
 1. Reading Primary key
 2. Order by
 3. Merge
 4. Output
– Using sort_intersection(…)
• 1. Order by
• 2. Intersection operation
MariaDB : Analysis of the execution plan
* MariaDB 5.3 Over (equal operator, the range of comparison operators)
* Only If the Plan Type Column = index_merge
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
66
 Extra column [Using temporary]
MariaDB : Analysis of the execution plan
select * from employees group by gender order by min(emp_no);
Create Temporary Table (Memory or Disk)
* When create a temporary table
- Subquery (From …) = Derived table
- COUNT(DISTINCT column1) (If the index is not available)
- Union & Union all
- Using filesort (Large sort operations)
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
67
 Extra column [Using where]
MariaDB : Analysis of the execution plan
select * from employees where emp_no between 1001 and 10100 and gender='F'
Engine
MariaDB Engine
(Join, Filtering, Aggregation)
100 rows
100 rows
3 rows
InnoDB
MyISAM
User
* Only when filtering process work "Using where" display
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
68
 Extra column [Using where with pushed condition]
– = “Condition push down”
MariaDB : Analysis of the execution plan
Management Node
SQL Node(MariaDB Engine)
Data Node
(Storage Engine)
TCP/IP
100 rows 100 rows
(Join, Filtering, Aggregation)
Passing
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
69
 Extra column [Deleting all rows]
– If you delete all of the records in the table : Deleting all rows
– If you delete of the records with where statement : Using where
MariaDB : Analysis of the execution plan
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
70
 Extra column [FirstMatch(tbl_name)]
– MariaDB 5.3 & MySQL 5.6 Over : Subquery optimization
MariaDB : Analysis of the execution plan
select *
from departments where dept_no in (
select dept_no from dept_emp where dept_no between 'd001' and 'd003');
Optimization
FirstMatch(tbl_name) : departments is outer table
* Depending on version
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
71
 Extra column [LooseScan(m..n)]
– IN(subquery) : If the results of sub-queries create duplicate records
– “Loose Index Scan” : delete duplicate records after Join(It’s driving table)
– Does not require a separate temporary table
MariaDB : Analysis of the execution plan
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
72
 Extra column [Materialize, Scan]
– Materialize : MySQL 5.6 & MariaDB 10.0 Over
– Scan : Materialized table without index -> Materialized table full scan
MariaDB : Analysis of the execution plan
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
73
 Extra column [Start temporary, End temporary]
– Duplicate Weedout (Display Start temporary, End temporary)
• 1. Select Subquery
• 2. Join with Outer table
 First table : Start temporary
 Last table : End temporary
• 3. Stored in a temporary table
• 4. Remove duplicate records
MariaDB : Analysis of the execution plan
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
74
 Extra column [Using index condition]
MariaDB : Analysis of the execution plan
select *
from employees
where first_name like 'Lee%' and first_name like '%matt';
Engine InnoDB
first_name like ‘Lee%’
and first_name like ‘%matt’ (ix_firstname)
Engine InnoDB
Index condition
Pushdown, ICP
SQL
first_name like ‘Lee%’ (Random Access – all recode)
and first_name like ‘%matt’(Efficient use of non)
SQL
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
75
 Extra column [Rowid-ordered scan, key-ordered scan]
MariaDB : Analysis of the execution plan
B-Tree
Index
Data Table
...
Where
=
...
Index Range Scan
(Random access)
MRR(Multi Range Read)
B-Tree
Index
Data Table
...
Where
=
...
Sort
By
Primary
Key
Optimization
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
76
MariaDB : Analysis of the execution plan
Column name
… (SKIP)
Extra
EXTENDED
EXTENTED
Partitions
 EXTENDED(Filtered) column
Engine
MariaDB Engine
(Join, Filtering, Aggregation)
100 rows
3 rows
InnoDB
User
93 Rows => Filtered
MySQL
(After)
DATA
employees(DATA + INDEX))
RANGE SCAN
(emp_no BETWEEN 10001 AND 10100)
Filtering
Gender=‘F’
FILTERD
ROWS
FILTERD
MySQL
(Before)
Storage
Engine
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
77
MariaDB : Analysis of the execution plan
Column name
… (SKIP)
Extra
EXTENDED
EXTENTED
Partitions
 EXTENDED(Additional information about the optimizer) column
EXPLAIN EXTENDED
select e.first_name,
(select count(*) from dept_emp de, dept_manager dm where dm.dept_no=de.dept_no) as cnt
from employees e
where e.emp_no=10001;
Show warnings;
select 'Georgi' AS `first_name`,
(select count(0)from `employees`.`dept_emp` `de` join `employees`.`dept_manager` `dm`
where (`employees`.`de`.`dept_no` = `employees`.`dm`.`dept_no`)) AS `cnt`
from `employees`.`employees` `e`where 1
How to interpret the query optimizer,
How to you convert the query,
What happened to the special processing is performed
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
78
MariaDB : Analysis of the execution plan
Column name
… (SKIP)
Extra
EXTENDED
EXTENTED
Partitions
 EXTENDED(Additional information about the optimizer) column
create table tb_partition (
reg_date date default null,
id int default null,
name varchar(50) default null
) engine=innodb
partition by range (year(reg_date)) (
partition p0 values less than (2008) engine = innodb,
partition p1 values less than (2009) engine = innodb,
partition p2 values less than (2010) engine = innodb,
partition p3 values less than (2011) engine = innodb
);
explain partitions
select * from tb_partition
where reg_date between '2010-01-01' and '2010-12-30';
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
79
 HOW TO USE
 MariaDB Version Control
– Divided into three parts: Major version, Minor version, Patch version
(ex MariaDB 5.5.8)
– Comment(Major(1), Minor(2), Patch(2) = 5-digit)
“/*!50508 TEMPORARY */”
MariaDB : Optimizer Hint
select * from employees USE INDEX (primary) where emp_no=1001;
select * from employees /*! USE INDEX (PRIMARY) */ where emp_no=1001;
SELECT /*!32302 temporary */ TABLE TEMP_EMP_STAT(hire_year INT NOT NULL, emp_count INT, PRIMARY KEY (hire_year));
SELECT TEMPORARY TABLE TEMP_EMP_STAT(hire_year INT NOT NULL, emp_count INT, PRIMARY KEY (hire_year));
=> (Version specific comment)
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
80
 STRAIGHT_JOIN
– This hint will tell MySQL to join the tables in the order that they are
specified in the FROM clause.
– Use EXPLAIN to make sure that MySQL has not already figured out the
optimal join order. And if you specify an ill order you can make MySQL do
a lot more work than it needs to.
MariaDB : Optimizer Hint
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
81
 STRAIGHT_JOIN
– Fixed the order of the join (looks like ordered hint at oracle)
MariaDB : Optimizer Hint
select *
from employees e, dept_emp de, departments d
where e.emp_no=de.emp_no and d.dept_no=de.dept_no;
DRIVING_TABLE
(matching where statement and small counting of records
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
82
 STRAIGHT_JOIN
MariaDB : Optimizer Hint
select straight_join e.first_name, e.last_name, d.dept_name
from employees e, dept_emp de, departments d
where e.emp_no=de.emp_no and d.dept_no=de.dept_no;
Join Access Path : employees -> dept_emp -> departments
select straight_join e.first_name, e.last_name, d.dept_name
from employees e, departments d, dept_emp de
where e.emp_no=de.emp_no and d.dept_no=de.dept_no;
Join Access Path : employees -> departments -> dept_emp
Recode Count : (299920 * 1 * 1)
Recode Count : (299920 * 9 * 1)
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
83
 STRAIGHT_JOIN
– Temporary tables and regular tables join
• A temporary table is good driving table
– Join between the temp table
• A small size table is good driving table
– Join between the regular tables join
• If there is index columns of both sides or no index columns of both
 small size table
• Else
 no index table
MariaDB : Optimizer Hint
Recode counting : The counting of records that satisfy the conditions
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
84
 USE INDEX / FORCE INDEX /IGNORE INDEX
– USE INDEX
• Recommended to use that index
• Using the index but it is not always
– FORCE INDEX
• More powerful than USE INDEX Hint
– IGNORE INDEX
• Prevent the use of the that index
• To use the full table scan.
MariaDB : Optimizer Hint
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
85
 USE INDEX / FORCE INDEX /IGNORE INDEX
– USE INDEX FOR JOIN
• Purpose of Join & select record
– USE INDEX FOR ORDER BY
• Order by statement use only
– USE INDEX FOR GROUP BY
• Group by statement use only
MariaDB : Optimizer Hint
Depending on the type
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
86
 USE INDEX / FORCE INDEX /IGNORE INDEX
MariaDB : Optimizer Hint
select * from employees where emp_no=10001;
select * from employees force index(primary) where emp_no=10001;
select * from employees use index(primary) where emp_no=10001;
select * from employees ignore index(primary) where emp_no=10001;
select * from employees force index(ix_firstname) where emp_no=10001;
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
87
 SQL_CACHE / SQL_NO_CACHE
– if you have setup MySQL Query Caching to explicit mode (set
query_cache_type = 2) then you can use the SQL_CACHE hint to tell
MySQL which queries to cache.
– The SQL_NO_CACHE hint turns off MySQL's builtin query caching
mechanism for a particular query.
MariaDB : Optimizer Hint
Query_cache_type(System variable settings)
0 or OFF 1 or ON 2 or DEMAND
No Hint NO Caching Caching NO Caching
SQL_CACHE NO Caching Caching Caching
SQL_NO_CACHE NO Caching NO Caching NO Caching
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
88
 Tuning Point [Select_Type column]
– DERIVED
• Large size data table when it is stored on disk temporary tables
– UNCACHEABLE SUBQUERY
• Leads to caching as much as possible
• Leads to reusing as much as possible (ex. Remove a user variable)
– DEPENDENT SUBQUERY
• Leads to Join operation
• Remove the dependence of the outer table
MariaDB : Tuning Point
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
89
 Tuning Point [Type column]
– ALL, index
• Index is Index Full Scan, ALL is Full Table Scan
• Add new index or Query changing
MariaDB : Tuning Point
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
90
 Tuning Point [Key column]
– When not using the index is not displayed.
– Add new index or Change the WHERE statement condition
MariaDB : Tuning Point
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
91
 Tuning Point [Rows column]
– If you see a much larger value, check the index & configure the index
column
– If index is not efficient, re-generated.
MariaDB : Tuning Point
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
92
 Tuning Point [Extra]
– That word is displayed, the more detailed review is preferred.
– If the query is not good requirements
• Full scan on Null key
• Impossible HAVING (MariaDB 5.1 Over)
• Impossible WHERE (MariaDB 5.1 Over)
• Impossible WHERE noticed after reading const tables
• No matching min/max row (MariaDB 5.1 Over)
• No matching row in const table (MariaDB 5.1 Over)
• Unique row not found (MariaDB 5.1 Over)
MariaDB : Tuning Point
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
93
 Tuning Point [Extra]
– If the plan is not good enough
• Range checked for each record (index map:N)
• Using filesort
• Using join buffer (MariaDB 5.1 Over)
• Using temporary
• Using where
– If the plan is good
• Distinct
• Using index (best practice : Covering index)
• Using index for group-by
MariaDB : Tuning Point
Recommend that a covering index.
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
94
MariaDB : Tuning Point
Select_Type Type Extra
SIMPLE system Distinct
PRIMARY const Using index
UNION eq_ref Using index for group-by
DEPENDENT UNION ref Range checked for each record
UNION RESULT fulltext Using filesort
SUBQUERY ref_or_null Using join buffer
DEPENDENT SUBQUERY unique_subquery Using temporary
DERIVED index_subquery Using where
UNCACHEABLE SUBQUERY range Full scan on Null key
UNCACHEABLE UNION index_merge Impossible HAVING
MATERIALIZED index Impossible WHERE
ALL Impossible WHERE noticed after reading const tables
No matching min/max row
No matching row in const table
Unique row not found
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
95
Reference
 Site : MariaDB Knowledge Base(EXPLAIN)
PETE FREITAG(MySQL Optimization Hints)
 Book : “Real MariaDB”
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
96
Q & A
Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee
Blog : http://ora-sysdba.tistory.com/
97

More Related Content

What's hot

MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 MinutesSveta Smirnova
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 
Query optimization: from 0 to 10 (and up to 5.7)
Query optimization: from 0 to 10 (and up to 5.7)Query optimization: from 0 to 10 (and up to 5.7)
Query optimization: from 0 to 10 (and up to 5.7)Jaime Crespo
 
High-Performance Hibernate - JDK.io 2018
High-Performance Hibernate - JDK.io 2018High-Performance Hibernate - JDK.io 2018
High-Performance Hibernate - JDK.io 2018Vlad Mihalcea
 
My sql storage engines
My sql storage enginesMy sql storage engines
My sql storage enginesVasudeva Rao
 
MySQL database replication
MySQL database replicationMySQL database replication
MySQL database replicationPoguttuezhiniVP
 
JPA and Hibernate Performance Tips
JPA and Hibernate Performance TipsJPA and Hibernate Performance Tips
JPA and Hibernate Performance TipsVlad Mihalcea
 
MySQL Performance Tuning Variables
MySQL Performance Tuning VariablesMySQL Performance Tuning Variables
MySQL Performance Tuning VariablesFromDual GmbH
 
A26 MariaDB : The New&Implemented MySQL Branch by Colin Charles
A26 MariaDB : The New&Implemented MySQL Branch by Colin CharlesA26 MariaDB : The New&Implemented MySQL Branch by Colin Charles
A26 MariaDB : The New&Implemented MySQL Branch by Colin CharlesInsight Technology, Inc.
 
Amazon Aurora로 안전하게 migration 하기
Amazon Aurora로 안전하게 migration 하기Amazon Aurora로 안전하게 migration 하기
Amazon Aurora로 안전하게 migration 하기Jesang Yoon
 
High-Performance JDBC Voxxed Bucharest 2016
High-Performance JDBC Voxxed Bucharest 2016High-Performance JDBC Voxxed Bucharest 2016
High-Performance JDBC Voxxed Bucharest 2016Vlad Mihalcea
 
Maxscale_메뉴얼
Maxscale_메뉴얼Maxscale_메뉴얼
Maxscale_메뉴얼NeoClova
 
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013
 MySQL PHP native driver  : Advanced Functions / PHP forum Paris 2013   MySQL PHP native driver  : Advanced Functions / PHP forum Paris 2013
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013 Serge Frezefond
 
MySQL shell and It's utilities - Praveen GR (Mydbops Team)
MySQL shell and It's utilities - Praveen GR (Mydbops Team)MySQL shell and It's utilities - Praveen GR (Mydbops Team)
MySQL shell and It's utilities - Praveen GR (Mydbops Team)Mydbops
 
MySQL 5.6 config 優化
MySQL 5.6 config 優化MySQL 5.6 config 優化
MySQL 5.6 config 優化Alexis Li
 
Introduction to MariaDB MaxScale
Introduction to MariaDB MaxScaleIntroduction to MariaDB MaxScale
Introduction to MariaDB MaxScaleI Goo Lee
 
Mysql 57-upcoming-changes
Mysql 57-upcoming-changesMysql 57-upcoming-changes
Mysql 57-upcoming-changesMorgan Tocker
 

What's hot (20)

MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 Minutes
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Query optimization: from 0 to 10 (and up to 5.7)
Query optimization: from 0 to 10 (and up to 5.7)Query optimization: from 0 to 10 (and up to 5.7)
Query optimization: from 0 to 10 (and up to 5.7)
 
Optimizing MySQL
Optimizing MySQLOptimizing MySQL
Optimizing MySQL
 
High-Performance Hibernate - JDK.io 2018
High-Performance Hibernate - JDK.io 2018High-Performance Hibernate - JDK.io 2018
High-Performance Hibernate - JDK.io 2018
 
My sql storage engines
My sql storage enginesMy sql storage engines
My sql storage engines
 
MySQL database replication
MySQL database replicationMySQL database replication
MySQL database replication
 
PPT
PPTPPT
PPT
 
JPA and Hibernate Performance Tips
JPA and Hibernate Performance TipsJPA and Hibernate Performance Tips
JPA and Hibernate Performance Tips
 
MySQL Performance Tuning Variables
MySQL Performance Tuning VariablesMySQL Performance Tuning Variables
MySQL Performance Tuning Variables
 
A26 MariaDB : The New&Implemented MySQL Branch by Colin Charles
A26 MariaDB : The New&Implemented MySQL Branch by Colin CharlesA26 MariaDB : The New&Implemented MySQL Branch by Colin Charles
A26 MariaDB : The New&Implemented MySQL Branch by Colin Charles
 
Amazon Aurora로 안전하게 migration 하기
Amazon Aurora로 안전하게 migration 하기Amazon Aurora로 안전하게 migration 하기
Amazon Aurora로 안전하게 migration 하기
 
High-Performance JDBC Voxxed Bucharest 2016
High-Performance JDBC Voxxed Bucharest 2016High-Performance JDBC Voxxed Bucharest 2016
High-Performance JDBC Voxxed Bucharest 2016
 
Maxscale_메뉴얼
Maxscale_메뉴얼Maxscale_메뉴얼
Maxscale_메뉴얼
 
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013
 MySQL PHP native driver  : Advanced Functions / PHP forum Paris 2013   MySQL PHP native driver  : Advanced Functions / PHP forum Paris 2013
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013
 
MySQL shell and It's utilities - Praveen GR (Mydbops Team)
MySQL shell and It's utilities - Praveen GR (Mydbops Team)MySQL shell and It's utilities - Praveen GR (Mydbops Team)
MySQL shell and It's utilities - Praveen GR (Mydbops Team)
 
MySQL 5.6 config 優化
MySQL 5.6 config 優化MySQL 5.6 config 優化
MySQL 5.6 config 優化
 
Introduction to MariaDB MaxScale
Introduction to MariaDB MaxScaleIntroduction to MariaDB MaxScale
Introduction to MariaDB MaxScale
 
My sql administration
My sql administrationMy sql administration
My sql administration
 
Mysql 57-upcoming-changes
Mysql 57-upcoming-changesMysql 57-upcoming-changes
Mysql 57-upcoming-changes
 

Viewers also liked

MariaDB Optimization
MariaDB OptimizationMariaDB Optimization
MariaDB OptimizationJongJin Lee
 
조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝
조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝
조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝Mungyu Choi
 
Ch6 대용량서비스레퍼런스아키텍처 part.1
Ch6 대용량서비스레퍼런스아키텍처 part.1Ch6 대용량서비스레퍼런스아키텍처 part.1
Ch6 대용량서비스레퍼런스아키텍처 part.1Minchul Jung
 
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013Sergey Petrunya
 
Maria db vs mysql
Maria db vs mysqlMaria db vs mysql
Maria db vs mysqlNitin KR
 
Introduction to MariaDB
Introduction to MariaDBIntroduction to MariaDB
Introduction to MariaDBJongJin Lee
 
Oracle University - Your Complete Training Source for Oracle Software and Har...
Oracle University - Your Complete Training Source for Oracle Software and Har...Oracle University - Your Complete Training Source for Oracle Software and Har...
Oracle University - Your Complete Training Source for Oracle Software and Har...ORACLE USER GROUP ESTONIA
 
MariaDB 10: The Complete Tutorial
MariaDB 10: The Complete TutorialMariaDB 10: The Complete Tutorial
MariaDB 10: The Complete TutorialColin Charles
 
MariaDB
MariaDBMariaDB
MariaDBymtech
 
개발자가 도전하는 MariaDB 서버구축
개발자가 도전하는 MariaDB 서버구축개발자가 도전하는 MariaDB 서버구축
개발자가 도전하는 MariaDB 서버구축정해 이
 
개발자도 알아야 하는 DBMS튜닝
개발자도 알아야 하는 DBMS튜닝개발자도 알아야 하는 DBMS튜닝
개발자도 알아야 하는 DBMS튜닝정해 이
 
MySQL Atchitecture and Concepts
MySQL Atchitecture and ConceptsMySQL Atchitecture and Concepts
MySQL Atchitecture and ConceptsTuyen Vuong
 
대용량 분산 아키텍쳐 설계 #2 대용량 분산 시스템 아키텍쳐 디자인 패턴
대용량 분산 아키텍쳐 설계 #2 대용량 분산 시스템 아키텍쳐 디자인 패턴대용량 분산 아키텍쳐 설계 #2 대용량 분산 시스템 아키텍쳐 디자인 패턴
대용량 분산 아키텍쳐 설계 #2 대용량 분산 시스템 아키텍쳐 디자인 패턴Terry Cho
 
NOSQL Meets Relational - The MySQL Ecosystem Gains More Flexibility
NOSQL Meets Relational - The MySQL Ecosystem Gains More FlexibilityNOSQL Meets Relational - The MySQL Ecosystem Gains More Flexibility
NOSQL Meets Relational - The MySQL Ecosystem Gains More FlexibilityIvan Zoratti
 
MariaDB ColumnStore - LONDON MySQL Meetup
MariaDB ColumnStore - LONDON MySQL MeetupMariaDB ColumnStore - LONDON MySQL Meetup
MariaDB ColumnStore - LONDON MySQL MeetupIvan Zoratti
 

Viewers also liked (15)

MariaDB Optimization
MariaDB OptimizationMariaDB Optimization
MariaDB Optimization
 
조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝
조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝
조대협의 서버 사이드 - 대용량 아키텍처와 성능튜닝
 
Ch6 대용량서비스레퍼런스아키텍처 part.1
Ch6 대용량서비스레퍼런스아키텍처 part.1Ch6 대용량서비스레퍼런스아키텍처 part.1
Ch6 대용량서비스레퍼런스아키텍처 part.1
 
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
 
Maria db vs mysql
Maria db vs mysqlMaria db vs mysql
Maria db vs mysql
 
Introduction to MariaDB
Introduction to MariaDBIntroduction to MariaDB
Introduction to MariaDB
 
Oracle University - Your Complete Training Source for Oracle Software and Har...
Oracle University - Your Complete Training Source for Oracle Software and Har...Oracle University - Your Complete Training Source for Oracle Software and Har...
Oracle University - Your Complete Training Source for Oracle Software and Har...
 
MariaDB 10: The Complete Tutorial
MariaDB 10: The Complete TutorialMariaDB 10: The Complete Tutorial
MariaDB 10: The Complete Tutorial
 
MariaDB
MariaDBMariaDB
MariaDB
 
개발자가 도전하는 MariaDB 서버구축
개발자가 도전하는 MariaDB 서버구축개발자가 도전하는 MariaDB 서버구축
개발자가 도전하는 MariaDB 서버구축
 
개발자도 알아야 하는 DBMS튜닝
개발자도 알아야 하는 DBMS튜닝개발자도 알아야 하는 DBMS튜닝
개발자도 알아야 하는 DBMS튜닝
 
MySQL Atchitecture and Concepts
MySQL Atchitecture and ConceptsMySQL Atchitecture and Concepts
MySQL Atchitecture and Concepts
 
대용량 분산 아키텍쳐 설계 #2 대용량 분산 시스템 아키텍쳐 디자인 패턴
대용량 분산 아키텍쳐 설계 #2 대용량 분산 시스템 아키텍쳐 디자인 패턴대용량 분산 아키텍쳐 설계 #2 대용량 분산 시스템 아키텍쳐 디자인 패턴
대용량 분산 아키텍쳐 설계 #2 대용량 분산 시스템 아키텍쳐 디자인 패턴
 
NOSQL Meets Relational - The MySQL Ecosystem Gains More Flexibility
NOSQL Meets Relational - The MySQL Ecosystem Gains More FlexibilityNOSQL Meets Relational - The MySQL Ecosystem Gains More Flexibility
NOSQL Meets Relational - The MySQL Ecosystem Gains More Flexibility
 
MariaDB ColumnStore - LONDON MySQL Meetup
MariaDB ColumnStore - LONDON MySQL MeetupMariaDB ColumnStore - LONDON MySQL Meetup
MariaDB ColumnStore - LONDON MySQL Meetup
 

Similar to MariaDB Optimizer Guide

What's new in MariaDB Platform X3
What's new in MariaDB Platform X3What's new in MariaDB Platform X3
What's new in MariaDB Platform X3MariaDB plc
 
PostgreSQL 9.5 - Major Features
PostgreSQL 9.5 - Major FeaturesPostgreSQL 9.5 - Major Features
PostgreSQL 9.5 - Major FeaturesInMobi Technology
 
Migration from mysql to elasticsearch
Migration from mysql to elasticsearchMigration from mysql to elasticsearch
Migration from mysql to elasticsearchRyosuke Nakamura
 
Sql server lesson13
Sql server lesson13Sql server lesson13
Sql server lesson13Ala Qunaibi
 
When and Why to Use MariaDB: New Features in 10.0 to 10.5
When and Why to Use MariaDB: New Features in 10.0 to 10.5When and Why to Use MariaDB: New Features in 10.0 to 10.5
When and Why to Use MariaDB: New Features in 10.0 to 10.5Ian Gilfillan
 
How to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performanceHow to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performanceoysteing
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007paulguerin
 
L203326 intro-maria db-techu2020-v9
L203326 intro-maria db-techu2020-v9L203326 intro-maria db-techu2020-v9
L203326 intro-maria db-techu2020-v9Tony Pearson
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cRonald Francisco Vargas Quesada
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index TuningManikanda kumar
 
Mysql database basic user guide
Mysql database basic user guideMysql database basic user guide
Mysql database basic user guidePoguttuezhiniVP
 
Db2考试测试题
Db2考试测试题Db2考试测试题
Db2考试测试题fm2008
 
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
 
2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗
2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗
2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗YUCHENG HU
 
How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15oysteing
 
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)Hemant Kumar Singh
 

Similar to MariaDB Optimizer Guide (20)

What's new in MariaDB Platform X3
What's new in MariaDB Platform X3What's new in MariaDB Platform X3
What's new in MariaDB Platform X3
 
PostgreSQL 9.5 - Major Features
PostgreSQL 9.5 - Major FeaturesPostgreSQL 9.5 - Major Features
PostgreSQL 9.5 - Major Features
 
Migration from mysql to elasticsearch
Migration from mysql to elasticsearchMigration from mysql to elasticsearch
Migration from mysql to elasticsearch
 
Sql server lesson13
Sql server lesson13Sql server lesson13
Sql server lesson13
 
When and Why to Use MariaDB: New Features in 10.0 to 10.5
When and Why to Use MariaDB: New Features in 10.0 to 10.5When and Why to Use MariaDB: New Features in 10.0 to 10.5
When and Why to Use MariaDB: New Features in 10.0 to 10.5
 
How to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performanceHow to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performance
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
Performance Tuning
Performance TuningPerformance Tuning
Performance Tuning
 
L203326 intro-maria db-techu2020-v9
L203326 intro-maria db-techu2020-v9L203326 intro-maria db-techu2020-v9
L203326 intro-maria db-techu2020-v9
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12c
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
MySQL performance tuning
MySQL performance tuningMySQL performance tuning
MySQL performance tuning
 
Mysql database basic user guide
Mysql database basic user guideMysql database basic user guide
Mysql database basic user guide
 
Db2考试测试题
Db2考试测试题Db2考试测试题
Db2考试测试题
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
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)
 
2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗
2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗
2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15
 
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
 

Recently uploaded

MK KOMUNIKASI DATA (TI)komdat komdat.docx
MK KOMUNIKASI DATA (TI)komdat komdat.docxMK KOMUNIKASI DATA (TI)komdat komdat.docx
MK KOMUNIKASI DATA (TI)komdat komdat.docxUnduhUnggah1
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home ServiceSapana Sha
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
Defining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryDefining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryJeremy Anderson
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Colleen Farrelly
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...soniya singh
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Cantervoginip
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort servicejennyeacort
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一fhwihughh
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一F sss
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPTBoston Institute of Analytics
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceSapana Sha
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhijennyeacort
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 

Recently uploaded (20)

MK KOMUNIKASI DATA (TI)komdat komdat.docx
MK KOMUNIKASI DATA (TI)komdat komdat.docxMK KOMUNIKASI DATA (TI)komdat komdat.docx
MK KOMUNIKASI DATA (TI)komdat komdat.docx
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
Defining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryDefining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data Story
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Canter
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts Service
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 

MariaDB Optimizer Guide

  • 1. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 1 MariaDB : Optimizer Jong Jin Lee SYS4U I&C EC Solution Lab / Software Engineer
  • 2. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 2 Agenda • Query execution process • Optimizer • Statistics • Histogram-based Statistics • Join Optimizer • Analysis of the execution plan • Optimizer Hint • Tuning Point
  • 3. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 3 MariaDB : Query execution process SQL Parsing Optimization and Plan Join and Sort Using SQL Parser • Split from the SQL statement • Grammatical error checking • Create a parse tree Using SQL Parse tree • Select the tables and indexes • Simplify operations • Join the ordering • Set whether to use a temporary table Reading Record • Reading Record From Storage Engine • Join & Sort Operations
  • 4. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 4 MariaDB : Optimizer  RBO(Rule-based optimizer)  It is only present to provide backwards compatibility during the migration to the query optimizer (Cost Based Optimizer).  Do not collect statistics.  CBO(Cost-based optimizer)  The optimizer can use a rules-based approach to work without statistical information, but this approach is less intelligent than the cost-based approach.  The optimizer factors in statistical information about the contents of the particular schema objects (tables, clusters, or indexes) being accessed.
  • 5. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 5 MariaDB : Statistics  MariaDB 5.5 Version  The statistics provided for each storage engine does not have sufficient information about the contents.  Column statistics are not collected (Only Index) – Using MYISAM engine  MySQL 5.6 Version  MariaDB 10.0 MariaDB [(none)]> use mysql; MariaDB [(mysql)]> show tables like ‘%_stats’; innodb_index_stats innodb_table_stats MariaDB [(none)]> use mysql; MariaDB [(mysql)]> show tables like ‘%_stats’; column_stats index_stats table_stats
  • 6. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 6 MariaDB : Statistics  Statistics collection  DB : my.cnf (INNODB_STATS_AUTO_RECALE > ON)  Table : STATS_AUTO_RECALE option – STATS_AUTO_RECALC is available only in MariaDB 10.0+. It indicates whether to automatically recalculate persistent statistics (see STATS_PERSISTENT, below) for an InnoDB table. If set to 1, statistics will be recalculated when more than 10% of the data has changed. When set to 0, stats will be recalculated only when an ANALYZE TABLE is run. If set to DEFAULT, or left out, the value set by the innodb_stats_auto_recalc system variable applies.
  • 7. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 7 MariaDB : Statistics  CLIENT_STATISTICS – The CLIENT_STATISTICS table holds statistics about client connections. MariaDB [(mysql)]> SELECT * FROM INFORMATION_SCHEMA.CLIENT_STATISTICSG *************************** 1. row *************************** CLIENT: localhost TOTAL_CONNECTIONS: 3 CONCURRENT_CONNECTIONS: 0 CONNECTED_TIME: 4883 BUSY_TIME: 0.009722 CPU_TIME: 0.0102131 BYTES_RECEIVED: 841 BYTES_SENT: 13897 BINLOG_BYTES_WRITTEN: 0 ROWS_READ: 0 ROWS_SENT: 214 ROWS_DELETED: 0 ROWS_INSERTED: 207 ROWS_UPDATED: 0 SELECT_COMMANDS: 10 UPDATE_COMMANDS: 0 OTHER_COMMANDS: 13 COMMIT_TRANSACTIONS: 0 ROLLBACK_TRANSACTIONS: 0 DENIED_CONNECTIONS: 0 LOST_CONNECTIONS: 0 ACCESS_DENIED: 0 EMPTY_QUERIES: 1 1 row in set (0.00 sec)
  • 8. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 8 MariaDB : Statistics  USER_STATISTICS – The USER_STATISTICS table holds statistics about user activity. You can use this table to find out such things as which user is causing the most load and which users are being abusive. You can also use this table to measure how close to capacity the server may be. SELECT * FROM INFORMATION_SCHEMA.USER_STATISTICSG *************************** 1. row *************************** USER: root TOTAL_CONNECTIONS: 1 CONCURRENT_CONNECTIONS: 0 CONNECTED_TIME: 297 BUSY_TIME: 0.001725 CPU_TIME: 0.001982 BYTES_RECEIVED: 388 BYTES_SENT: 2327 BINLOG_BYTES_WRITTEN: 0 ROWS_READ: 0 ROWS_SENT: 12 ROWS_DELETED: 0 ROWS_INSERTED: 13 ROWS_UPDATED: 0 SELECT_COMMANDS: 4 UPDATE_COMMANDS: 0 OTHER_COMMANDS: 3 COMMIT_TRANSACTIONS: 0 ROLLBACK_TRANSACTIONS: 0 DENIED_CONNECTIONS: 0 LOST_CONNECTIONS: 0 ACCESS_DENIED: 0 EMPTY_QUERIES: 1
  • 9. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 9 MariaDB : Statistics  INDEX_STATISTICS – The INDEX_STATISTICS table shows statistics on index usage and makes it possible to do such things as locating unused indexes and generating the commands to remove them. SELECT * FROM INFORMATION_SCHEMA.INDEX_STATISTICS WHERE TABLE_NAME = "author"; +--------------+------------+------------+-----------+ | TABLE_SCHEMA | TABLE_NAME | INDEX_NAME | ROWS_READ | +--------------+------------+------------+-----------+ | books | author | by_name | 15 | +--------------+------------+------------+-----------+ Field Type Notes TABLE_SCHEMA varchar(192) The schema (database) name. TABLE_NAME varchar(192) The table name. INDEX_NAME varchar(192) The index name (as visible in SHOW CREATE TABLE). ROWS_READ int(21) The number of rows read from this index.
  • 10. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 10 MariaDB : Statistics  TABLE_STATISTICS – The TABLE_STATISTICS table is similar to the INDEX_STATISTICS table. It shows statistics on table usage. SELECT * FROM INFORMATION_SCHEMA.TABLE_STATISTICS WHERE TABLE_NAME='user'; +--------------+------------+-----------+--------------+------------------------+ | TABLE_SCHEMA | TABLE_NAME | ROWS_READ | ROWS_CHANGED | ROWS_CHANGED_X_INDEXES | +--------------+------------+-----------+--------------+------------------------+ | mysql | user | 5 | 2 | 2 | +--------------+------------+-----------+--------------+------------------------+w Field Type Notes TABLE_SCHEMA varchar(192) The schema (database) name. TABLE_NAME varchar(192) The table name. ROWS_READ int(21) The number of rows read from the table. ROWS_CHANGED int(21) The number of rows changed in the table. ROWS_CHANGED_X_INDEXES int(21) The number of rows changed in the table, multiplied by the number of indexes changed.
  • 11. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 11  MariaDB 10.0 Version – Histogram-based statistics were introduced in MariaDB 10.0.2 as a mechanism to improve the query plan chosen by the optimizer in certain situations. Until then, all conditions on non-indexed columns were ignored when searching for the best execution plan. Histograms can be collected for both indexed and non-indexed columns, and are made available to the optimizer. – MySQL : column_stats table MariaDB : Histogram-based Statistics
  • 12. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 12  Height-Balanced Histogram algorithm MariaDB : Histogram-based Statistics A B C B C C B A A B B B C C A A 1 B 2 C 3 A 4 B Column Order Histogram Column Bucket Size = System Variables(histogram_size)
  • 13. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 13  Exhaustive Search – The combination of all the tables in the execution plan cost calculation – Ex) Table : 10 , Join : 20! (Factorial, 3628800) MariaDB : Join Optimizer
  • 14. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 14  Heuristic Search(Greedy Search) – Join (optimizer_prune_level, optimizer_search_depth) MariaDB : Join Optimizer
  • 15. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 15  HOW TO USE – The EXPLAIN statement can be used either as a synonym for DESCRIBE or as a way to obtain information about how MariaDB executes a SELECT (as well as UPDATE and DELETE since MariaDB 10.0.5) statement: MariaDB : Analysis of the execution plan EXPLAIN SELECT e.emp_no, e.first_name, s.from_date, s.salary FROM employees e, salaries s WHERE e.emp_no=s.emp_no LIMIT 10; Outer Inner
  • 16. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 16  The columns in EXPLAIN ... SELECT MariaDB : Analysis of the execution plan Column name Description id Sequence number that shows in which order tables are joined. select_type What kind of SELECT the table comes from. table Alias name of table. Materialized temporary tables for sub queries are named <subquery#> type How rows are found from the table (join type). possible_keys keys in table that could be used to find rows in the table key The name of the key that is used to retrieve rows. NULL is no key was used. key_len How many bytes of the key that was used (shows if we are using only parts of the multi-column key). ref The reference that is used to as the key value. rows An estimate of how many rows we will find in the table for each key lookup. Extra Extra information about this join.
  • 17. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 17  ID column MariaDB : Analysis of the execution plan Select ( ( select count(*) from employees) + (select count(*) from departments) ) as total_counts; select e.emp_no, e.first_name, s.from_Date, s.salary from employees e, salaries s where e.emp_no=s.emp_nolimit 10; Column name id select_type table type possible_keys key key_len ref rows Extra
  • 18. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 18  Select_Type column MariaDB : Analysis of the execution plan Value Description UNION The SELECT is a UNION of the PRIMARY. DEPENDENT UNION The UNION is DEPENDENT. UNION RESULT The result of the UNION. SUBQUERY The SELECT is a SUBQUERY of the PRIMARY. DEPENDENT SUBQUERY The SUBQUERY is DEPENDENT. DERIVED The SELECT is DERIVED from the PRIMARY. UNCACHEABLE SUBQUERY The SUBQUERY is UNCACHEABLE. PRIMARY The SELECT is a PRIMARY one. SIMPLE The SELECT is a SIMPLE one. UNCACHEABLE UNION The UNION is UNCACHEABLE. Column name id select_type table type possible_keys key key_len ref rows Extra
  • 19. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 19  Select_Type column [UNION] MariaDB : Analysis of the execution plan select * from ( (select emp_no from employees e1 limit 10) union all (select emp_no from employees e1 limit 10) union all (select emp_no from employees e1 limit 10) ) tb;
  • 20. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 20  Select_Type column [DEPENDENT UNION] MariaDB : Analysis of the execution plan select * from employees e1 where e1.emp_no in ( select e2.emp_no from employees e2 where e2.first_name='Matt‘ (where e2.emp_no=e1.emp_no) union select e3.emp_no from employees e3 where e3.first_name='Matt‘ (where e3.emp_no=e1.emp_no) ) Optimization
  • 21. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 21  Select_Type column [UNION RESULT] MariaDB : Analysis of the execution plan select emp_no from salaries where salary>100000 union all select emp_no from dept_emp where from_date >'2001-01-01'; UNION RESULT < UNION 1,2 >
  • 22. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 22  Select_Type column [SUBQUERY] MariaDB : Analysis of the execution plan select e.first_name, (select count(*) from dept_emp de, dept_manager dm where dm.dept_no=de.dept_no) as cnt from employees e where e.emp_no=10001; SELECT : Nested Query WHERE : Sub Query FROM : DERIVED
  • 23. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 23  Select_Type column [DEPENDENT SUBQUERY] MariaDB : Analysis of the execution plan select e.first_name, (select count(*)from dept_emp de, dept_manager dm where dm.dept_no=de.dept_no and de.emp_no=e.emp_no) as cnt from employees e where e.first_name='Matt';
  • 24. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 24  Select_Type column [DERIVED] MariaDB : Analysis of the execution plan select * from (select de.emp_no from dept_emp de group by de.emp_no) tb, (DERIVED) employees e where e.emp_no=tb.emp_no; Tuning Point : 1. Check SELECT_TYPE (DERIVED) 2. SUBQUERY -> JOIN Optimization
  • 25. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 25  Select_Type column [UNCACHEABLE SUBQUERY] MariaDB : Analysis of the execution plan select * from employees e where e.emp_no = ( select @status from dept_emp de where de.dept_no ='d005' ); UNCACHEABLE SUBQERY CASE : 1. Including User Variables 2. Including NOT-DETERMINISTIC 3. Including UUID(), RAND() Function > Compare the number of records generated as a function call
  • 26. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 26  Select_Type column [MATERIALIZED] MariaDB : Analysis of the execution plan select * from employees e where e.emp_no in (select emp_no from salaries where salary between 100 and 1000); (DERIVED  Materialization)
  • 27. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 27  Table column [derived N] MariaDB : Analysis of the execution plan ID SELECT_TYPE TABLE … 1 PRIMARY <derived 2> 1 PRIMARY E 2 DERIVED Dept_emp * Must Have : Temporary tables should have a alias <derived N> = <Derived Table Number(ID)> MariaDB [employees]> select dttm from (select now() as dttm); ERROR 1248 (42000): Every derived table must have its own alias MariaDB [employees]> select dttm from (select now() as dttm) derived_table_alias; +---------------------+ | dttm | +---------------------+ | 2014-07-08 21:10:29 | +---------------------+ 1 row in set (0.19 sec) Column name id select_type table type possible_keys key key_len ref rows Extra
  • 28. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 28  Type column MariaDB : Analysis of the execution plan Value Description ALL A full table scan is done for the table (all rows are read) const There is only one possibly matching row in the table. (UNIQUE INDEX SCAN) eq_ref A unique index is used to find the rows. (Best Practice) fulltext A fulltext index is used to access the rows. index_merge A 'range' access is done for several index and the found rows are merged index_subquery This is similar as ref, but used for sub queries that are transformed to key lookups. index A full scan over the used index. (Better than ALL but still bad) Column name id select_type table type possible_keys key key_len ref rows Extra
  • 29. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 29  Type column MariaDB : Analysis of the execution plan Value Description range The table will be accessed with a key over one or more value ranges. ref_or_null ref or null comparison(is null) ref A non unique index or prefix of an unique index is used to find the rows. system The table has 0 or 1 rows. unique_subquery This is similar as eq_ref, but used for sub queries that are transformed to key lookups
  • 30. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 30  Type column [ALL] MariaDB : Analysis of the execution plan select * from employees; ALL = Full Table Scan
  • 31. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 31  Type column [const] MariaDB : Analysis of the execution plan select * from employees where emp_no=10001; select * from dept_emp where dept_no='d005'; select * from dept_emp where dept_no='d005' and emp_no=10001; One of Consisting of a multi-column primary key, unique key
  • 32. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 32  Type column [ref] MariaDB : Analysis of the execution plan select * from dept_emp where dept_no='d005'; 1. const primary key/unique key column (equal) -> recode only one 2. eq_req using read the column values of first table the second table values the retrieve condition -> recode only one 3. ref Equal -> recode only one X
  • 33. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 33  Type column [eq_ref] MariaDB : Analysis of the execution plan select * from dept_emp de, employees e where e.emp_no=de.emp_no and de.dept_no='d005'; 1. Join Table (id = 1) 2. Process (dept_emp -> employee) 3. emp.no (primary) -> eq_ref
  • 34. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 34  Type column [fulltext] MariaDB : Analysis of the execution plan select * from employee_name where emp_no=10001 #const and emp_no between 10001 and 10005 #range and match(first_name, last_name) against('Facello' in boolean mode); select * from employee_name #where emp_no=10001 #const where emp_no between 10001 and 10005 #range and match(first_name, last_name) against('Facello' in boolean mode); 1. A full-text index in MariaDB is an index of type FULLTEXT 2. Full-text searching is performed using MATCH() ... AGAINST syntax.
  • 35. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 35  Type column [index_merge] MariaDB : Analysis of the execution plan select * from employees where emp_no between 10001 and 11000 or first_name='Smith'; 1. several index and the found rows are merged 2. efficiency is less than the range scan 3. Do not work “full-text” search
  • 36. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 36  Type column [index_subquery] MariaDB : Analysis of the execution plan select * from departments where dept_no in ( select dept_no from dept_emp where dept_no between 'd001' and 'd003'); 1. unique_subquery IN(subquery): Deduplication does not need work 2. index_subquery IN(subquery) : Possible duplicate values, Index(Remove duplicate values) MariaDB 5.6 Over : index_subquery => ref
  • 37. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 37  Type column [index] MariaDB : Analysis of the execution plan select * from departments order by dept_name desc limit 10; 1. Type(index) = Index Full Scan (But, Not Data File Full Scan -> Index File Full Scan) 2. Best Practice : Operation is possible only index
  • 38. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 38  Possible_keys column – To make the best execution plan that was nominated for an index list – Actually unused indexes – Ignore column MariaDB : Analysis of the execution plan Column name id select_type table type possible_keys key key_len ref rows Extra
  • 39. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 39  Key column – The selected index in the best execution plan – Tuning Point key (index) – One or more indexes are "," separated (type - index_merge) MariaDB : Analysis of the execution plan Column name id select_type table type possible_keys key key_len ref rows Extra
  • 40. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 40  Key_len column – The selected index in the best execution plan – Tuning Point key (index) – One or more indexes are "," separated (type - index_merge) MariaDB : Analysis of the execution plan Column name id select_type table type possible_keys key key_len ref rows Extra
  • 41. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 41  Key_len column MariaDB : Analysis of the execution plan select * from dept_emp where dept_no='d005'; * Description : Character – utf 8(1~3byte), dept_no – char(4 byte) 12 = 3 * 4 select * from dept_emp where dept_no='d005' and emp_no=10001; * Description : Character – utf 8(1~3byte), dept_no – char(4 byte), emp_no – integer (4 byte) 16 = (4*3) + 4
  • 42. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 42  Key_len column MariaDB : Analysis of the execution plan select * from titles where to_date<='1985-10-10'; * Description : Character – utf 8(1~3byte), to_date – date(3 byte) 4 ? -> why? : to_date (3 byte + nullable(1 byte))
  • 43. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 43  Ref column – reference column – ex, Ref (Equal), other column (Table name, Column name), const  “Func” MariaDB : Analysis of the execution plan Column name id select_type table type possible_keys key key_len ref rows Extra select * from employees e, dept_emp de where e.emp_no=de.emp_no; select * from employees e, dept_emp de where e.emp_no=(de.emp_no-1);
  • 44. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 44  Rows column – Anticipated counting of records – Based on statistical information (Record count, distribution of index values … ) MariaDB : Analysis of the execution plan Column name id select_type table type possible_keys key key_len ref rows Extra # ix_formdate select * from dept_emp where from_Date >='1985-01-01'; select * from dept_emp where from_Date >='2002-07-01'; Why ?
  • 45. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 45 MariaDB : Analysis of the execution plan Column name id select_type table type possible_keys key key_len ref rows Extra  Extra column – Displays important information about the performance-related – 2-3 show generally
  • 46. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 46 MariaDB : Analysis of the execution plan  Extra column [const row not found] – Display type : const – Fact : 0 rows
  • 47. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 47 MariaDB : Analysis of the execution plan  Extra column [Distinct] select distinct d.dept_no from departments d, dept_emp de where de.dept_no=d.dept_no; How to Handling Distinct on MariaDB ?
  • 48. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 48 MariaDB : Analysis of the execution plan  Extra column [Full scan on Null key] select d.dept_no, null in (select id.dept_name from departments id) from departments d; Solutions : Definition column Attribute (is not null)
  • 49. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 49 MariaDB : Analysis of the execution plan  Extra column [Impossible HAVING] select e.emp_no, count(*) as cnt from employees e where e.emp_no=10001 group by e.emp_no having e.emp_no is null; e.emp_no = primary key & not null columns
  • 50. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 50  Extra column [Impossible WHERE] MariaDB : Analysis of the execution plan select * from employees where emp_no is null; e.emp_no = primary key & not null columns
  • 51. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 51  Extra column [Impossible WHERE noticed after reading const tables] MariaDB : Analysis of the execution plan select * from employees where emp_no=0; Comparison(Equal) => const type
  • 52. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 52  Extra column [No matching min/max row] MariaDB : Analysis of the execution plan select min(dept_no), max(dept_no) from dept_emp where dept_no=''; Not matching = 0 rows
  • 53. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 53  Extra column [No matching row in const table] MariaDB : Analysis of the execution plan select * from dept_emp de, (select emp_no from employees where emp_no=0) tb1 where tb1.emp_no=de.emp_no and de.dept_no='d005'; Not matching when const approaching
  • 54. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 54  Extra column [No tables used] MariaDB : Analysis of the execution plan select 1; select 1 from dual; Handled internally by the optimizer
  • 55. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 55  Extra column [Not exists] MariaDB : Analysis of the execution plan select * from dept_emp de left join departments d on de.dept_no=d.dept_no where d.dept_no is null; Anti-Join (When a lot of data : use Outer Join) Optimization
  • 56. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 56  Extra column [Range checked for each recode(index map:N)] MariaDB : Analysis of the execution plan select * from employees e1, employees e2 where e2.emp_no >= e1.emp_no; Index map: 0x1 (16 Hexadecimal) => 1 (Transfer to 2 Hexadecimal) 1 => first index of e2(employees) table Type ALL : if first index not good Performance => Plan change : ALL(Full Table Scan)
  • 57. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 57  Extra column [Select tables optimized away] MariaDB : Analysis of the execution plan select max(emp_no), min(emp_no) from employees; # salaries table (pk : emp_no+from_date) select max(from_date), min(from_date) from salaries where emp_no=10001; Optimization 10002 10003 … 10009 10010 10001 MIN(emp_no) MAX(emp_no) CASE : Optimization (if NOT WHERE statement) 1996-01-01 … 2001-08-14 2014-07-09 1995-01-01 MIN(from_date) Max(from_date) CASE : Optimization (if the WHERE statement) 1991-03-15
  • 58. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 58  Extra column [Skip_open_table, Open_frm_only, Open_trigger_only, Open_full_table] – = “Scanned N databases” – Select INFORMATION_SCHEMA (meta data) MariaDB : Analysis of the execution plan 1. Skip_open_table : No need to read 2. Open_frm_only : Read only files stored in the meta information file(*.FRM) 3. Open_trigger_only : Read only files stored in the trigger information file (*.TRG) 4. Open_full_table : Not optimized , Read all meta information file(*FRM) & data file(*MYD), index file(*MYI)
  • 59. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 59  Extra column [Unique row not found] # // test table creation create table tb_test1 (fdpk int, primary key(fdpk)); create table tb_test2 (fdpk int, primary key(fdpk)); # // insert sample data insert into tb_test1 values (1), (2); insert into tb_test2 values (1); select t2.fdpk from tb_test1 t1 left join tb_test2 t2 on t2.fdpk=t1.fdpk where t1.fdpk =2; MariaDB : Analysis of the execution plan * Each table has unique (PK included) columns in a query that performs an outer join, the outer table has a matching record does not exist
  • 60. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 60  Extra column [Using filesort] MariaDB : Analysis of the execution plan select * from employees order by last_name desc; * Use Quick soft algorithm * Processing 1. read recode 2. Copy to soft buffer 3. Order by 4. Send to client * Overhead -> create index, query tuning
  • 61. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 61  Quick soft algorithm MariaDB : Analysis of the execution plan Ex) Pivot = p, List Left Index I, List Right Index J 1. 5 - 3 - 7 - 6 - 2 - 1 - 4 p 2. 5 - 3 - 7 - 6 - 2 - 1 - 4 i j p 1 - 3 - 7 - 6 - 2 - 5 - 4 i j p 3. 1 - 3 - 7 - 6 - 2 - 5 - 4 i j p 4. 1 - 3 - 7 - 6 - 2 - 5 - 4 i j p 1 - 3 - 2 - 6 - 7 - 5 - 4 i j p 5. 1 - 3 - 2 - 6 - 7 - 5 - 4 p 1 - 3 - 2 - 4 - 7 - 5 - 6 p 6. 1 - 3 - 2 1 - 2 - 3
  • 62. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 62  Extra column [Using index(covering index)] MariaDB : Analysis of the execution plan # use index (ix_first_name) & disk access select first_name, birth_date from employees where first_name between 'Babette' and 'Gad'; # use index (ix_first_name) select first_name from employees where first_name between 'Babette' and 'Gad'; * Operation to Only index page * Innodb table (default cluster index)
  • 63. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 63  Extra column [Using index for group-by] MariaDB : Analysis of the execution plan #tight index scan select first_name, count(*) as counter from employees group by first_name; #loose index scan select emp_no, min(from_date) as first_changed_date, max(from_date) as last_changed_date from salaries group by emp_no; 1. Tight index scan - A tight index scan may be either a full index scan or a range index scan, depending on the query conditions. 2. Loose index scan - The most efficient way is when the index is used to directly retrieve the group fields Since this access method considers only a fraction of the keys in an index, it is called a loose index scan #loose index scan select emp_no from salaries where emp_no between 10001 and 10099 group by emp_no; * Good performance in a large records. * The optimizer to determine the break-even point
  • 64. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 64  Extra column [Using join buffer(Block Nested Loop), Using join buffer(Batched Key Access)] MariaDB : Analysis of the execution plan select * from dept_emp de, employees e where de.from_date>'2005-01-01' and e.emp_no<10904; Join Processing - Using Join buffer - Using Block Nested Loop (Nested Loop) Recommend : Driven Table (Create Index)  prevention (Full Tabe Scan, Index Full Scan) * Using Join buffer - Place to temporarily store the records - OLTP Recommend Buffer Size : 1MB - MariaDB 5.3 Over : Hash Join(Based on Block) Batched Key Access = Multi Range Read(MRR)
  • 65. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 65  Extra column [Using soft_union, Using union, Using intersect, Using sort_intersecion] – Using intersect(…) • AND operation (Intersection) – Using union(…) • OR operation (union) – Using sort_union(…) • OR operation associated with the relatively large quantity of RANGE operation  1. Reading Primary key  2. Order by  3. Merge  4. Output – Using sort_intersection(…) • 1. Order by • 2. Intersection operation MariaDB : Analysis of the execution plan * MariaDB 5.3 Over (equal operator, the range of comparison operators) * Only If the Plan Type Column = index_merge
  • 66. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 66  Extra column [Using temporary] MariaDB : Analysis of the execution plan select * from employees group by gender order by min(emp_no); Create Temporary Table (Memory or Disk) * When create a temporary table - Subquery (From …) = Derived table - COUNT(DISTINCT column1) (If the index is not available) - Union & Union all - Using filesort (Large sort operations)
  • 67. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 67  Extra column [Using where] MariaDB : Analysis of the execution plan select * from employees where emp_no between 1001 and 10100 and gender='F' Engine MariaDB Engine (Join, Filtering, Aggregation) 100 rows 100 rows 3 rows InnoDB MyISAM User * Only when filtering process work "Using where" display
  • 68. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 68  Extra column [Using where with pushed condition] – = “Condition push down” MariaDB : Analysis of the execution plan Management Node SQL Node(MariaDB Engine) Data Node (Storage Engine) TCP/IP 100 rows 100 rows (Join, Filtering, Aggregation) Passing
  • 69. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 69  Extra column [Deleting all rows] – If you delete all of the records in the table : Deleting all rows – If you delete of the records with where statement : Using where MariaDB : Analysis of the execution plan
  • 70. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 70  Extra column [FirstMatch(tbl_name)] – MariaDB 5.3 & MySQL 5.6 Over : Subquery optimization MariaDB : Analysis of the execution plan select * from departments where dept_no in ( select dept_no from dept_emp where dept_no between 'd001' and 'd003'); Optimization FirstMatch(tbl_name) : departments is outer table * Depending on version
  • 71. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 71  Extra column [LooseScan(m..n)] – IN(subquery) : If the results of sub-queries create duplicate records – “Loose Index Scan” : delete duplicate records after Join(It’s driving table) – Does not require a separate temporary table MariaDB : Analysis of the execution plan
  • 72. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 72  Extra column [Materialize, Scan] – Materialize : MySQL 5.6 & MariaDB 10.0 Over – Scan : Materialized table without index -> Materialized table full scan MariaDB : Analysis of the execution plan
  • 73. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 73  Extra column [Start temporary, End temporary] – Duplicate Weedout (Display Start temporary, End temporary) • 1. Select Subquery • 2. Join with Outer table  First table : Start temporary  Last table : End temporary • 3. Stored in a temporary table • 4. Remove duplicate records MariaDB : Analysis of the execution plan
  • 74. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 74  Extra column [Using index condition] MariaDB : Analysis of the execution plan select * from employees where first_name like 'Lee%' and first_name like '%matt'; Engine InnoDB first_name like ‘Lee%’ and first_name like ‘%matt’ (ix_firstname) Engine InnoDB Index condition Pushdown, ICP SQL first_name like ‘Lee%’ (Random Access – all recode) and first_name like ‘%matt’(Efficient use of non) SQL
  • 75. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 75  Extra column [Rowid-ordered scan, key-ordered scan] MariaDB : Analysis of the execution plan B-Tree Index Data Table ... Where = ... Index Range Scan (Random access) MRR(Multi Range Read) B-Tree Index Data Table ... Where = ... Sort By Primary Key Optimization
  • 76. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 76 MariaDB : Analysis of the execution plan Column name … (SKIP) Extra EXTENDED EXTENTED Partitions  EXTENDED(Filtered) column Engine MariaDB Engine (Join, Filtering, Aggregation) 100 rows 3 rows InnoDB User 93 Rows => Filtered MySQL (After) DATA employees(DATA + INDEX)) RANGE SCAN (emp_no BETWEEN 10001 AND 10100) Filtering Gender=‘F’ FILTERD ROWS FILTERD MySQL (Before) Storage Engine
  • 77. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 77 MariaDB : Analysis of the execution plan Column name … (SKIP) Extra EXTENDED EXTENTED Partitions  EXTENDED(Additional information about the optimizer) column EXPLAIN EXTENDED select e.first_name, (select count(*) from dept_emp de, dept_manager dm where dm.dept_no=de.dept_no) as cnt from employees e where e.emp_no=10001; Show warnings; select 'Georgi' AS `first_name`, (select count(0)from `employees`.`dept_emp` `de` join `employees`.`dept_manager` `dm` where (`employees`.`de`.`dept_no` = `employees`.`dm`.`dept_no`)) AS `cnt` from `employees`.`employees` `e`where 1 How to interpret the query optimizer, How to you convert the query, What happened to the special processing is performed
  • 78. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 78 MariaDB : Analysis of the execution plan Column name … (SKIP) Extra EXTENDED EXTENTED Partitions  EXTENDED(Additional information about the optimizer) column create table tb_partition ( reg_date date default null, id int default null, name varchar(50) default null ) engine=innodb partition by range (year(reg_date)) ( partition p0 values less than (2008) engine = innodb, partition p1 values less than (2009) engine = innodb, partition p2 values less than (2010) engine = innodb, partition p3 values less than (2011) engine = innodb ); explain partitions select * from tb_partition where reg_date between '2010-01-01' and '2010-12-30';
  • 79. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 79  HOW TO USE  MariaDB Version Control – Divided into three parts: Major version, Minor version, Patch version (ex MariaDB 5.5.8) – Comment(Major(1), Minor(2), Patch(2) = 5-digit) “/*!50508 TEMPORARY */” MariaDB : Optimizer Hint select * from employees USE INDEX (primary) where emp_no=1001; select * from employees /*! USE INDEX (PRIMARY) */ where emp_no=1001; SELECT /*!32302 temporary */ TABLE TEMP_EMP_STAT(hire_year INT NOT NULL, emp_count INT, PRIMARY KEY (hire_year)); SELECT TEMPORARY TABLE TEMP_EMP_STAT(hire_year INT NOT NULL, emp_count INT, PRIMARY KEY (hire_year)); => (Version specific comment)
  • 80. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 80  STRAIGHT_JOIN – This hint will tell MySQL to join the tables in the order that they are specified in the FROM clause. – Use EXPLAIN to make sure that MySQL has not already figured out the optimal join order. And if you specify an ill order you can make MySQL do a lot more work than it needs to. MariaDB : Optimizer Hint
  • 81. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 81  STRAIGHT_JOIN – Fixed the order of the join (looks like ordered hint at oracle) MariaDB : Optimizer Hint select * from employees e, dept_emp de, departments d where e.emp_no=de.emp_no and d.dept_no=de.dept_no; DRIVING_TABLE (matching where statement and small counting of records
  • 82. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 82  STRAIGHT_JOIN MariaDB : Optimizer Hint select straight_join e.first_name, e.last_name, d.dept_name from employees e, dept_emp de, departments d where e.emp_no=de.emp_no and d.dept_no=de.dept_no; Join Access Path : employees -> dept_emp -> departments select straight_join e.first_name, e.last_name, d.dept_name from employees e, departments d, dept_emp de where e.emp_no=de.emp_no and d.dept_no=de.dept_no; Join Access Path : employees -> departments -> dept_emp Recode Count : (299920 * 1 * 1) Recode Count : (299920 * 9 * 1)
  • 83. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 83  STRAIGHT_JOIN – Temporary tables and regular tables join • A temporary table is good driving table – Join between the temp table • A small size table is good driving table – Join between the regular tables join • If there is index columns of both sides or no index columns of both  small size table • Else  no index table MariaDB : Optimizer Hint Recode counting : The counting of records that satisfy the conditions
  • 84. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 84  USE INDEX / FORCE INDEX /IGNORE INDEX – USE INDEX • Recommended to use that index • Using the index but it is not always – FORCE INDEX • More powerful than USE INDEX Hint – IGNORE INDEX • Prevent the use of the that index • To use the full table scan. MariaDB : Optimizer Hint
  • 85. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 85  USE INDEX / FORCE INDEX /IGNORE INDEX – USE INDEX FOR JOIN • Purpose of Join & select record – USE INDEX FOR ORDER BY • Order by statement use only – USE INDEX FOR GROUP BY • Group by statement use only MariaDB : Optimizer Hint Depending on the type
  • 86. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 86  USE INDEX / FORCE INDEX /IGNORE INDEX MariaDB : Optimizer Hint select * from employees where emp_no=10001; select * from employees force index(primary) where emp_no=10001; select * from employees use index(primary) where emp_no=10001; select * from employees ignore index(primary) where emp_no=10001; select * from employees force index(ix_firstname) where emp_no=10001;
  • 87. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 87  SQL_CACHE / SQL_NO_CACHE – if you have setup MySQL Query Caching to explicit mode (set query_cache_type = 2) then you can use the SQL_CACHE hint to tell MySQL which queries to cache. – The SQL_NO_CACHE hint turns off MySQL's builtin query caching mechanism for a particular query. MariaDB : Optimizer Hint Query_cache_type(System variable settings) 0 or OFF 1 or ON 2 or DEMAND No Hint NO Caching Caching NO Caching SQL_CACHE NO Caching Caching Caching SQL_NO_CACHE NO Caching NO Caching NO Caching
  • 88. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 88  Tuning Point [Select_Type column] – DERIVED • Large size data table when it is stored on disk temporary tables – UNCACHEABLE SUBQUERY • Leads to caching as much as possible • Leads to reusing as much as possible (ex. Remove a user variable) – DEPENDENT SUBQUERY • Leads to Join operation • Remove the dependence of the outer table MariaDB : Tuning Point
  • 89. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 89  Tuning Point [Type column] – ALL, index • Index is Index Full Scan, ALL is Full Table Scan • Add new index or Query changing MariaDB : Tuning Point
  • 90. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 90  Tuning Point [Key column] – When not using the index is not displayed. – Add new index or Change the WHERE statement condition MariaDB : Tuning Point
  • 91. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 91  Tuning Point [Rows column] – If you see a much larger value, check the index & configure the index column – If index is not efficient, re-generated. MariaDB : Tuning Point
  • 92. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 92  Tuning Point [Extra] – That word is displayed, the more detailed review is preferred. – If the query is not good requirements • Full scan on Null key • Impossible HAVING (MariaDB 5.1 Over) • Impossible WHERE (MariaDB 5.1 Over) • Impossible WHERE noticed after reading const tables • No matching min/max row (MariaDB 5.1 Over) • No matching row in const table (MariaDB 5.1 Over) • Unique row not found (MariaDB 5.1 Over) MariaDB : Tuning Point
  • 93. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 93  Tuning Point [Extra] – If the plan is not good enough • Range checked for each record (index map:N) • Using filesort • Using join buffer (MariaDB 5.1 Over) • Using temporary • Using where – If the plan is good • Distinct • Using index (best practice : Covering index) • Using index for group-by MariaDB : Tuning Point Recommend that a covering index.
  • 94. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 94 MariaDB : Tuning Point Select_Type Type Extra SIMPLE system Distinct PRIMARY const Using index UNION eq_ref Using index for group-by DEPENDENT UNION ref Range checked for each record UNION RESULT fulltext Using filesort SUBQUERY ref_or_null Using join buffer DEPENDENT SUBQUERY unique_subquery Using temporary DERIVED index_subquery Using where UNCACHEABLE SUBQUERY range Full scan on Null key UNCACHEABLE UNION index_merge Impossible HAVING MATERIALIZED index Impossible WHERE ALL Impossible WHERE noticed after reading const tables No matching min/max row No matching row in const table Unique row not found
  • 95. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 95 Reference  Site : MariaDB Knowledge Base(EXPLAIN) PETE FREITAG(MySQL Optimization Hints)  Book : “Real MariaDB”
  • 96. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 96 Q & A
  • 97. Copyright(c)2014 by ora-sysdba. All Page content is property of dbjongjin.lee Blog : http://ora-sysdba.tistory.com/ 97