SlideShare une entreprise Scribd logo
1  sur  52
Télécharger pour lire hors ligne
Copyright © 2018 Oracle and/or its afliates. All rights reserved.
What Is New in Optmizer and Executor?
Norvald H. Ryeng
Sofware Development Senior Manager
MySQL Optmizer Team
October, 2018
MySQL 8.0:
3Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Safe Harbor Statement
The following is intended to outline our general product directon. It is intended for
informaton purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functonality, and should not be relied upon
in making purchasing decisions. The development, release, and tming of any features or
functonality described for Oracle’s products remains at the sole discreton of Oracle.
4Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Program Agenda
Common table expressions
Window functons
UTF-8 support
GIS
SKIP LOCKED, NOWAIT
JSON functons
Index extensions
Cost model
Hints
5Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Program Agenda
Common table expressions
Window functons
UTF-8 support
GIS
SKIP LOCKED, NOWAIT
JSON functons
Index extensions
Cost model
Hints
7Copyright © 2018 Oracle and/or its afliates. All rights reserved.
CTEs As Alternatve to Derived Tables
● A derived table is a subquery in the FROM clause:
SELECT … FROM (subquery) AS derived, t1 …
● A CTE is just like a derived table, but the declaraton comes
before the query block:
WITH derived AS (subquery)
SELECT … FROM derived, t1 …
● May precede SELECT, UPDATE, DELETE and be used in
subqueries:
WITH derived AS (subquery)
DELETE FROM t1 WHERE t1.a IN (SELECT b FROM derived);
8Copyright © 2018 Oracle and/or its afliates. All rights reserved.
CTEs vs. Derived Tables
● Beter readability
● Can be referenced multple tmes
● Can refer to other CTEs
● Improved performance
9Copyright © 2018 Oracle and/or its afliates. All rights reserved.
CTEs Provide Beter Readability
Derived table:
SELECT …
FROM t1 LEFT JOIN ((SELECT … FROM …) AS dt JOIN t2 ON …) ON …
CTE:
WITH dt AS (SELECT ... FROM ...)
SELECT ...
FROM t1 LEFT JOIN (dt JOIN t2 ON ...) ON …
10Copyright © 2018 Oracle and/or its afliates. All rights reserved.
CTEs Can Be Referenced Multple Times
● Derived tables can't be referenced twice
SELECT …
FROM (SELECT a, b, SUM(c) AS s FROM t1 GROUP BY a, b) AS d1
JOIN (SELECT a, b, SUM(c) AS s FROM t1 GROUP BY a, b) AS d2 ON d1.b = d2.a;
● CTEs can
WITH d AS (SELECT a, b, SUM(c) AS s FROM t1 GROUP BY a, b)
SELECT … FROM d AS d1 JOIN d AS d2 ON d1.b = d2.a;
● Beter performance with materializaton
– Multple CTE references are only materialized once
– Derived tables and views will be materialized once per reference
11Copyright © 2018 Oracle and/or its afliates. All rights reserved.
CTEs Can Refer to Other CTEs
● Derived tables can't refer to other derived tables
SELECT …
FROM (SELECT … FROM …) AS d1, (SELECT … FROM d1 …) AS d2 …
ERROR: 1146 (42S02): Table ‘db.d1’ doesn’t exist
● CTEs can refer other CTEs
WITH d1 AS (SELECT … FROM …),
d2 AS (SELECT … FROM d1 …)
SELECT …
FROM d1, d2 …
12Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Recursive CTEs
WITH RECURSIVE cte AS
(SELECT … FROM table_name /* "seed" SELECT */
UNION [DISTINCT|ALL]
SELECT … FROM cte, table_name) /* "recursive" SELECT */
SELECT … FROM cte;
● A recursive CTE refers to itself in a subquery
● The "seed" SELECT is executed once to create the inital data subset
● The "recursive" CTE is executed repeatedly
– Stops when iteraton doesn't generate any new rows
– Set cte_max_recursion_depth to limit recursion
● Useful to traverse hierarchies (parent/child, part/subpart)
14Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Program Agenda
Common table expressions
Window functons
UTF-8 support
GIS
SKIP LOCKED, NOWAIT
JSON functons
Index extensions
Cost model
Hints
16Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Window Functons
● Similar to aggregaton functons
– Computes one value based on multple rows
– But does not group
Aggregaton functon Window functon
17Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Window Functon Example
Sum up total salary per department
SELECT name, dept_id, salary,
SUM(salary) OVER (PARTITION BY
dept_id) AS dept_total
FROM employee
ORDER BY dept_id, name;
The OVER
keyword signals a
window functon
PARTITION ⇒
disjoint set of
rows in result set
name dept_id salary dept_total
Newt NULL 75000 75000
Dag 10 NULL 370000
Ed 10 100000 370000
Fred 10 60000 370000
Jon 10 60000 370000
Michael 10 70000 370000
Newt 10 80000 370000
Lebedev 20 65000 130000
Pete 20 65000 130000
Jef 30 300000 370000
Will 30 70000 370000
18Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Window Functon Example
Sum up total salary per department
SELECT name, dept_id, salary,
SUM(salary) OVER (PARTITION BY
dept_id) AS dept_total
FROM employee
ORDER BY dept_id, name;
The OVER
keyword signals a
window functon
PARTITION ⇒
disjoint set of
rows in result set
name dept_id salary dept_total
Newt NULL 75000 75000
Dag 10 NULL 370000
Ed 10 100000 370000
Fred 10 60000 370000
Jon 10 60000 370000
Michael 10 70000 370000
Newt 10 80000 370000
Lebedev 20 65000 130000
Pete 20 65000 130000
Jef 30 300000 370000
Will 30 70000 370000
20Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Program Agenda
Common table expressions
Window functons
UTF-8 support
GIS
SKIP LOCKED, NOWAIT
JSON functons
Index extensions
Cost model
Hints
22Copyright © 2018 Oracle and/or its afliates. All rights reserved.
UTF-8 Support
● Collatons based on Unicode 9.0
● ut8mb4 as default character set
– ut8mb4_0900_ai_ci as default collaton
● Accent and case sensitve collatons
– Including 20+ language specifc collatons
– Now also Japanese and Russian
● Signifcantly improved performance
● Unicode support in regular expressions
23Copyright © 2018 Oracle and/or its afliates. All rights reserved.
New Default Character Set
● No change to existng tables
● Only has efect on new tables/schemas when character set is not
explicitly specifed
Upgrade recommendatons
● Upgrade frst, change character set and collaton aferwards
● Don't mix collatons
– Error: "Illegal mix of collatons"
– Slower queries because indexes can't be used
24Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Program Agenda
Common table expressions
Window functons
UTF-8 support
GIS
SKIP LOCKED, NOWAIT
JSON functons
Index extensions
Cost model
Hints
26Copyright © 2018 Oracle and/or its afliates. All rights reserved.
GIS
● Geography support
– Lattude-longitude on an ellipsoid
● Spatal reference systems (SRSs)
– More than 5000 SRSs from the EPSG Geodetc Parameter Dataset
– INFORMATION_SCHEMA.ST_SPATIAL_REFERENCE_SYSTEMS
– CREATE/DROP SPATIAL REFERENCE SYSTEM
● SRID aware spatal datatypes, indexes and functons
● ST_Transform to convert between SRSs — New in MySQL 8.0.13!
● Functons and expressions as default values — New in MySQL 8.0.13!
– Including ST_GeomFromText
27Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Program Agenda
Common table expressions
Window functons
UTF-8 support
GIS
SKIP LOCKED, NOWAIT
JSON functons
Index extensions
Cost model
Hints
29Copyright © 2018 Oracle and/or its afliates. All rights reserved.
SELECT … FOR UPDATE SKIP LOCKED
Problem: Hot row contenton, multple worker threads accessing the same rows.
SKIP LOCKED Soluton:
● Only read rows that aren't locked
● InnoDB skips a locked row, and the next one goes to the result set
Example:
– Booking system: Skip orders that are pending
START TRANSACTION;
SELECT * FROM seats WHERE seat_no BETWEEN 2 AND 3 AND booked = 'NO'
FOR UPDATE SKIP LOCKED;
30Copyright © 2018 Oracle and/or its afliates. All rights reserved.
SELECT … FOR UPDATE NOWAIT
Problem: Hot row contenton, multple worker threads accessing the same rows.
NOWAIT Soluton:
● Fail immediately if any rows are locked
● Without NOWAIT, the query waits for innodb_lock_wait_tmeout (default 50 seconds)
before giving up
Example:
– Booking system: Fail if rows are locked
START TRANSACTION;
SELECT * FROM seats WHERE seat_no BETWEEN 2 AND 3 AND booked = 'NO'
FOR UPDATE NOWAIT;
ERROR 3572 (HY000): Statement aborted because lock(s) could not be acquired ...
31Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Program Agenda
Common table expressions
Window functons
UTF-8 support
GIS
SKIP LOCKED, NOWAIT
JSON functons
Index extensions
Cost model
Hints
33Copyright © 2018 Oracle and/or its afliates. All rights reserved.
JSON Functons
JSON_ARRAY_APPEND()
JSON_ARRAY_INSERT()
JSON_ARRAY()
JSON_CONTAINS_PATH()
JSON_CONTAINS()
JSON_DEPTH()
JSON_EXTRACT()
JSON_INSERT()
JSON_KEYS()
JSON_LENGTH()
JSON_MERGE[_PRESERVE]()
JSON_OBJECT()
JSON_QUOTE()
JSON_REMOVE()
JSON_REPLACE()
JSON_SEARCH()
JSON_SET()
JSON_TYPE()
JSON_UNQUOTE()
JSON_VALID()
JSON_PRETTY()
JSON_STORAGE_SIZE()
JSON_STORAGE_FREE()
JSON_ARRAYAGG()
JSON_OBJECTAGG()
JSON_MERGE_PATCH()
JSON_TABLE()
34Copyright © 2018 Oracle and/or its afliates. All rights reserved.
JSON Data Type
CREATE TABLE t1 (json_col JSON);
INSERT INTO t1 VALUES (
'{ "people": [
{ "name":"John Smith", "address":"780 Mission St, San Francisco, CA 94103"},
{ "name":"Sally Brown", "address":"75 37th Ave S, St Cloud, MN 94103"},
{ "name":"John Johnson", "address":"1262 Roosevelt Trail, Raymond, ME 04071"}
] }'
);
35Copyright © 2018 Oracle and/or its afliates. All rights reserved.
JSON_TABLE
Convert JSON documents to relatonal tables
SELECT people.*
FROM t1,
JSON_TABLE(json_col, '$.people[*]' COLUMNS (
name VARCHAR(40) PATH '$.name',
address VARCHAR(100) PATH '$.address')) AS people;
name address
John Smith 780 Mission St, San Francisco, CA 94103
Sally Brown 75 37th Ave S, St Cloud, MN 9410
John Johnson 1262 Roosevelt Trail, Raymond, ME 04071
36Copyright © 2018 Oracle and/or its afliates. All rights reserved.
JSON_TABLE
Filter JSON data on SQL expression
SELECT people.*
FROM t1,
JSON_TABLE(json_col, '$.people[*]' COLUMNS (
name VARCHAR(40) PATH '$.name',
address VARCHAR(100) PATH '$.address')) AS people
WHERE people.name LIKE 'John%';
name address
John Smith 780 Mission St, San Francisco, CA 94103
John Johnson 1262 Roosevelt Trail, Raymond, ME 04071
37Copyright © 2018 Oracle and/or its afliates. All rights reserved.
JSON_TABLE Nested Arrays
[
{ "father":"John", "mother":"Mary",
"marriage_date":"2003-12-05",
"children": [ { "name":"Eric", "age":12 },
{ "name":"Beth", "age":10 } ]
},
{ "father":"Paul", "mother":"Laura",
"children": [ { "name":"Sarah", "age":9},
{ "name":"Noah", "age":3} ,
{ "name":"Peter", "age":1} ]
}
]
id father married child_id child age
1 John 1 1 Eric 12
1 John 1 2 Beth 10
2 Paul 0 1 Sarah 9
2 Paul 0 2 Noah 3
2 Paul 0 3 Peter 1
38Copyright © 2018 Oracle and/or its afliates. All rights reserved.
JSON_TABLE Nested Arrays
JSON_TABLE (families, '$[*]' COLUMNS (
id FOR ORDINALITY,
father VARCHAR(30) PATH '$.father',
married INTEGER EXISTS PATH
'$.marriage_date',
NESTED PATH '$.children[*]' COLUMNS (
child_id FOR ORDINALITY,
child VARCHAR(30) PATH '$.name',
age INTEGER PATH '$.age'
)
))
id father married child_id child age
1 John 1 1 Eric 12
1 John 1 2 Beth 10
2 Paul 0 1 Sarah 9
2 Paul 0 2 Noah 3
2 Paul 0 3 Peter 1
39Copyright © 2018 Oracle and/or its afliates. All rights reserved.
JSON Array Aggregaton
CREATE TABLE t1 (id INT, grp INT,
jsoncol JSON);
INSERT INTO t1 VALUES (1, 1,
'{"key1":"value1","key2":"value2"}');
INSERT INTO t1 VALUES (2, 1,
'{"keyA":"valueA","keyB":"valueB"}');
INSERT INTO t1 VALUES (3, 2,
'{"keyX":"valueX","keyY":"valueY"}');
Yet to come: JSON_ARRAYAGG as window functon
SELECT JSON_ARRAYAGG(jsoncol)
FROM t1;
[{"key1":"value1","key2":"value2"},
{"keyA":"valueA","keyB":"valueB"},
{"keyX":"valueX","keyY":"valueY"}]
40Copyright © 2018 Oracle and/or its afliates. All rights reserved.
JSON Object Aggregaton
CREATE TABLE t1 (id INT, grp INT,
jsoncol JSON);
INSERT INTO t1 VALUES (1, 1,
'{"key1":"value1","key2":"value2"}');
INSERT INTO t1 VALUES (2, 1,
'{"keyA":"valueA","keyB":"valueB"}');
INSERT INTO t1 VALUES (3, 2,
'{"keyX":"valueX","keyY":"valueY"}');
Yet to come: JSON_OBJECTAGG as window functon
SELECT grp, JSON_OBJECTAGG(id, jsoncol)
FROM t1
GROUP BY grp;
1
{"1":{"key1":"value1","key2":"value2"},
"2":{"keyA":"valueA","keyB":"valueB"}}
2 {"3":{"keyX":"valueX","keyY":"valueY"}}
41Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Partal Update of JSON
● Automatcally detect potental in-place updates
– JSON_SET
– JSON_REPLACE
– JSON_REMOVE
– Source and target columns are the same
– Updatng existng value, not adding new one
– Sufcient space is available
● Smaller than or same size as some old value
● Only the dif is sent in binlog
42Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Program Agenda
Common table expressions
Window functons
UTF-8 support
GIS
SKIP LOCKED, NOWAIT
JSON functons
Index extensions
Cost model
Hints
44Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Invisible Index
● Index is maintained by the storage engine, but invisible to the
optmizer
– Override with SET optmizer_switch='use_invisible_indexes=on';
● Primary key can't be invisible
● Use case: Check for performance drope before removing index
ALTER TABLE t1 ALTER INDEX idx INVISIBLE;
SHOW INDEXES FROM t1;
+---------+------------------+----------------------+---------------+
| Table | Key_name | Column_name | Visible |
+---------+------------------+----------------------+---------------+
| t1 | idx | a | NO |
+---------+------------------+----------------------+---------------+
45Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Descending Index
CREATE TABLE t1 (
a INT,
b INT,
INDEX a_b (a DESC, b ASC)
);
● In 5.7: Index in ascending order is created, server scans it backwards
● In 8.0: Index in descending order is created, server scans it forwards
– Works on B-tree indexes only
– Benefts:
● Use indexes instead of flesort for ORDER BY clause with ASC/DESC sort key
● Forward index scan is slightly faster than backward index scan
46Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Functonal Index — New in 8.0.13
● Index over an expression
CREATE TABLE t1 (col1 INT, col2 INT, INDEX func_index ((ABS(col1))));
CREATE INDEX idx1 ON t1 ((col1 + col2));
CREATE INDEX idx2 ON t1 ((col1 + col2), (col1 - col2), col1);
ALTER TABLE t1 ADD INDEX ((col1 * 40));
● No longer necessary to create an indexed generated column
● Not allowed as PRIMARY KEY
47Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Index Skip-Scan — New in 8.0.13
● Used for mult-column index
● Conditon not on frst part of index
● Cost-based choice
Before MySQL 8.0.13:
Full index scan
MySQL 8.0.13:
Skip-scan
pk a b c
INDEX idx(a,b,c)
SELECT * FROM t1 WHERE b < 3;
1
1 2 3 4 5
2
1 2 3 4 5
3
1 2 3 4 5
4
1 2 3 4 5
a
b
c
Full index scan
1
1 2 3 4 5
2
1 2 3 4 5
3
1 2 3 4 5
4
1 2 3 4 5
a
b
c
b < 3 b < 3 b < 3 b < 3
48Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Thanks for the patch,
Facebook!
49Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Program Agenda
Common table expressions
Window functons
UTF-8 support
GIS
SKIP LOCKED, NOWAIT
JSON functons
Index extensions
Cost model
Hints
51Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Motvaton for Improving the MySQL Cost Model
● Produce more correct cost estmates
– Beter decisions by the optmizer should improve performance
● Adapt to new hardware architectures
– SSD, larger memories, caches
● More maintainable cost model implementaton
– Avoid hard coded “cost constants”
– Refactoring of existng cost model code
● Confgurable and tunable
● Make more of the optmizer cost-based
Faster
queries
52Copyright © 2018 Oracle and/or its afliates. All rights reserved.
New Storage Technologies
● Time to do a table scan of 10 million
records:
● Adjust cost model to support
diferent storage technologies
● Provide confgurable cost constants
for diferent storage technologies
Memory 5 s
SSD 20 - 146 s
Hard disk 32 - 1465 s
Provide a program that
could measure performance
and suggest good cost
constant confguraton for a
running MySQL server?
Provide a program that
could measure performance
and suggest good cost
constant confguraton for a
running MySQL server?
53Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Memory Bufer Aware Cost Estmates
● Storage engines:
– Estmate for how much of data and
indexes are in a memory bufer
– Estmate for hit rate for memory
bufer
● Optmizer cost model:
– Take into account whether data is
already in memory or need to be read
from disk
Server
Storage
engine
Disk data
Query
executor
Database
bufer
54Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Histograms
● Provides the optmizer with informaton about column value
distributon
● To create/recalculate histogram for a column:
ANALYZE TABLE table UPDATE HISTOGRAM ON column WITH n BUCKETS;
● May use sampling
– Sample size is based on available memory
(histogram_generaton_max_mem_size)
● Automatcally chooses between two histogram types:
– Singleton: One value per bucket
– Equi-height: Multple values per bucket
55Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Program Agenda
Common table expressions
Window functons
UTF-8 support
GIS
SKIP LOCKED, NOWAIT
JSON functons
Index extensions
Cost model
Hints
57Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Join Order Hints
● No need to reorganize the FROM clause to add join order
hints like you will for STRAIGHT_JOIN
● /*+ JOIN_ORDER(t1, t2, …) */
● /*+ JOIN_PREFIX(t1, t2, …) */
● /*+ JOIN_SUFFIX(…, ty, tz) */
● /*+ JOIN_FIXED_ORDER() */
– Replacement for STRAIGHT_JOIN
58Copyright © 2018 Oracle and/or its afliates. All rights reserved.
View/Derived Table/CTE Merge Hints
● Views, derived tables and CTEs are, if possible, merged into outer
query
● NO_MERGE can override default behavior
SELECT /*+ NO_MERGE(dt) */ *
FROM t1 JOIN (SELECT x, y FROM t2) dt ON t1.x = dt.x;
● MERGE will force a merge
SELECT /*+ MERGE(dt) */ *
FROM t1 JOIN (SELECT x, y FROM t2) dt ON t1.x = dt.x;
59Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Index Merge Executon
10INDEX(a)
10INDEX(b)
a=10 AND b=10Result:
Intersecton
SELECT * FROM t1 WHERE a=10 AND b=10
60Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Index Merge Hints
● Index merge: Merge rows from multple range scans on a
single table
● Algorithms: union, intersecton, sort union
● Users can specify which indexes to use for index merge
– /*+ INDEX_MERGE(t1 idx1, idx2, …) */
– /*+ NO_INDEX_MERGE(t1 idx1, idx2, …) */
61Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Hints to Set Session Variables
● Set a session variable for the duraton of a single statement
● Examples:
SELECT /*+ SET_VAR(sort_bufer_size = 16M) */ name FROM people ORDER BY name;
INSERT /*+ SET_VAR(foreign_key_checks = OFF) */ INTO t2 VALUES (1, 1), (2, 2), (3, 3);
SELECT /*+ SET_VAR(optmizer_switch = 'conditon_fanout_flter = of') */ *
FROM customer JOIN orders ON c_custkey = o_custkey
WHERE c_acctbal < 0 AND o_orderdate < '1993-01-01';
● Note: Not all session variables are setable through hints:
mysql> SELECT /*+ SET_VAR(max_allowed_packet=128M) */ * FROM t1;
Empty set, 1 warning (0,00 sec)
Warning (Code 4537): Variable 'max_allowed_packet' cannot be set using SET_VAR hint.
62Copyright © 2018 Oracle and/or its afliates. All rights reserved.
Feature descriptons and design details
directly from the source.
htp://mysqlserverteam.com/
63Copyright © 2018 Oracle and/or its afliates. All rights reserved.
MySQL 8.0: What Is New in Optimizer and Executor?

Contenu connexe

Tendances

Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data StructureRabin BK
 
OLAP Reporting In CR v2
OLAP Reporting In CR v2OLAP Reporting In CR v2
OLAP Reporting In CR v2Mickey Wong
 
What does Rename Do: (detailed version)
What does Rename Do: (detailed version)What does Rename Do: (detailed version)
What does Rename Do: (detailed version)Steve Loughran
 
The age of rename() is over
The age of rename() is overThe age of rename() is over
The age of rename() is overSteve Loughran
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queuePulkitmodi1998
 
Integrate SparkR with existing R packages to accelerate data science workflows
 Integrate SparkR with existing R packages to accelerate data science workflows Integrate SparkR with existing R packages to accelerate data science workflows
Integrate SparkR with existing R packages to accelerate data science workflowsArtem Ervits
 
Data engineering and analytics using python
Data engineering and analytics using pythonData engineering and analytics using python
Data engineering and analytics using pythonPurna Chander
 
Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2Self-Employed
 
Efficient spatial queries on vanilla databases
Efficient spatial queries on vanilla databasesEfficient spatial queries on vanilla databases
Efficient spatial queries on vanilla databasesJulian Hyde
 
4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply FunctionSakthi Dasans
 
HEPData Open Repositories 2016 Talk
HEPData Open Repositories 2016 TalkHEPData Open Repositories 2016 Talk
HEPData Open Repositories 2016 TalkEamonn Maguire
 
Morel, a Functional Query Language
Morel, a Functional Query LanguageMorel, a Functional Query Language
Morel, a Functional Query LanguageJulian Hyde
 

Tendances (20)

Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
OLAP Reporting In CR v2
OLAP Reporting In CR v2OLAP Reporting In CR v2
OLAP Reporting In CR v2
 
What does Rename Do: (detailed version)
What does Rename Do: (detailed version)What does Rename Do: (detailed version)
What does Rename Do: (detailed version)
 
HEPData
HEPDataHEPData
HEPData
 
Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)
 
The age of rename() is over
The age of rename() is overThe age of rename() is over
The age of rename() is over
 
Stack Data structure
Stack Data structureStack Data structure
Stack Data structure
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
Apriori algorithm
Apriori algorithmApriori algorithm
Apriori algorithm
 
Ds stacks
Ds stacksDs stacks
Ds stacks
 
Integrate SparkR with existing R packages to accelerate data science workflows
 Integrate SparkR with existing R packages to accelerate data science workflows Integrate SparkR with existing R packages to accelerate data science workflows
Integrate SparkR with existing R packages to accelerate data science workflows
 
07.bootstrapping
07.bootstrapping07.bootstrapping
07.bootstrapping
 
Queue
QueueQueue
Queue
 
Data engineering and analytics using python
Data engineering and analytics using pythonData engineering and analytics using python
Data engineering and analytics using python
 
Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2
 
Efficient spatial queries on vanilla databases
Efficient spatial queries on vanilla databasesEfficient spatial queries on vanilla databases
Efficient spatial queries on vanilla databases
 
4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function
 
Data structures project
Data structures projectData structures project
Data structures project
 
HEPData Open Repositories 2016 Talk
HEPData Open Repositories 2016 TalkHEPData Open Repositories 2016 Talk
HEPData Open Repositories 2016 Talk
 
Morel, a Functional Query Language
Morel, a Functional Query LanguageMorel, a Functional Query Language
Morel, a Functional Query Language
 

Similaire à MySQL 8.0: What Is New in Optimizer and Executor?

MySQL Optimizer: What's New in 8.0
MySQL Optimizer: What's New in 8.0MySQL Optimizer: What's New in 8.0
MySQL Optimizer: What's New in 8.0Manyi Lu
 
Reading The Source Code of Presto
Reading The Source Code of PrestoReading The Source Code of Presto
Reading The Source Code of PrestoTaro L. Saito
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer OverviewOlav Sandstå
 
MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0oysteing
 
MySQL 8.0 GIS Overview
MySQL 8.0 GIS OverviewMySQL 8.0 GIS Overview
MySQL 8.0 GIS OverviewNorvald Ryeng
 
University of Applied Science Esslingen @ Scilab Conference 2018
University of Applied Science Esslingen @ Scilab Conference 2018University of Applied Science Esslingen @ Scilab Conference 2018
University of Applied Science Esslingen @ Scilab Conference 2018Scilab
 
Presto At Arm Treasure Data - 2019 Updates
Presto At Arm Treasure Data - 2019 UpdatesPresto At Arm Treasure Data - 2019 Updates
Presto At Arm Treasure Data - 2019 UpdatesTaro L. Saito
 
“Quantum” Performance Effects: beyond the Core
“Quantum” Performance Effects: beyond the Core“Quantum” Performance Effects: beyond the Core
“Quantum” Performance Effects: beyond the CoreC4Media
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAsConnor McDonald
 
Перехват функций (хуки) под Windows в приложениях с помощью C/C++
Перехват функций (хуки) под Windows в приложениях с помощью C/C++Перехват функций (хуки) под Windows в приложениях с помощью C/C++
Перехват функций (хуки) под Windows в приложениях с помощью C/C++corehard_by
 
Compile ahead of time. It's fine?
Compile ahead of time. It's fine?Compile ahead of time. It's fine?
Compile ahead of time. It's fine?Dmitry Chuyko
 
PHP Detroit -- MySQL 8 A New Beginning (updated presentation)
PHP Detroit -- MySQL 8 A New Beginning (updated presentation)PHP Detroit -- MySQL 8 A New Beginning (updated presentation)
PHP Detroit -- MySQL 8 A New Beginning (updated presentation)Dave Stokes
 
Java and Serverless - A Match Made In Heaven, Part 2
Java and Serverless - A Match Made In Heaven, Part 2Java and Serverless - A Match Made In Heaven, Part 2
Java and Serverless - A Match Made In Heaven, Part 2Curity
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featuesConnor McDonald
 
Module 6: YANG Tutorial - part 2
Module 6: YANG Tutorial - part 2Module 6: YANG Tutorial - part 2
Module 6: YANG Tutorial - part 2Tail-f Systems
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer OverviewOlav Sandstå
 
Oracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration HustleOracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration HustleEDB
 
Using The Mysql Binary Log As A Change Stream
Using The Mysql Binary Log As A Change StreamUsing The Mysql Binary Log As A Change Stream
Using The Mysql Binary Log As A Change StreamLuís Soares
 

Similaire à MySQL 8.0: What Is New in Optimizer and Executor? (20)

MySQL Optimizer: What's New in 8.0
MySQL Optimizer: What's New in 8.0MySQL Optimizer: What's New in 8.0
MySQL Optimizer: What's New in 8.0
 
Reading The Source Code of Presto
Reading The Source Code of PrestoReading The Source Code of Presto
Reading The Source Code of Presto
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer Overview
 
MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0
 
MySQL 8.0 GIS Overview
MySQL 8.0 GIS OverviewMySQL 8.0 GIS Overview
MySQL 8.0 GIS Overview
 
University of Applied Science Esslingen @ Scilab Conference 2018
University of Applied Science Esslingen @ Scilab Conference 2018University of Applied Science Esslingen @ Scilab Conference 2018
University of Applied Science Esslingen @ Scilab Conference 2018
 
Presto At Arm Treasure Data - 2019 Updates
Presto At Arm Treasure Data - 2019 UpdatesPresto At Arm Treasure Data - 2019 Updates
Presto At Arm Treasure Data - 2019 Updates
 
“Quantum” Performance Effects: beyond the Core
“Quantum” Performance Effects: beyond the Core“Quantum” Performance Effects: beyond the Core
“Quantum” Performance Effects: beyond the Core
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAs
 
Перехват функций (хуки) под Windows в приложениях с помощью C/C++
Перехват функций (хуки) под Windows в приложениях с помощью C/C++Перехват функций (хуки) под Windows в приложениях с помощью C/C++
Перехват функций (хуки) под Windows в приложениях с помощью C/C++
 
Compile ahead of time. It's fine?
Compile ahead of time. It's fine?Compile ahead of time. It's fine?
Compile ahead of time. It's fine?
 
PHP Detroit -- MySQL 8 A New Beginning (updated presentation)
PHP Detroit -- MySQL 8 A New Beginning (updated presentation)PHP Detroit -- MySQL 8 A New Beginning (updated presentation)
PHP Detroit -- MySQL 8 A New Beginning (updated presentation)
 
Java and Serverless - A Match Made In Heaven, Part 2
Java and Serverless - A Match Made In Heaven, Part 2Java and Serverless - A Match Made In Heaven, Part 2
Java and Serverless - A Match Made In Heaven, Part 2
 
Doc store
Doc storeDoc store
Doc store
 
Matopt
MatoptMatopt
Matopt
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featues
 
Module 6: YANG Tutorial - part 2
Module 6: YANG Tutorial - part 2Module 6: YANG Tutorial - part 2
Module 6: YANG Tutorial - part 2
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer Overview
 
Oracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration HustleOracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration Hustle
 
Using The Mysql Binary Log As A Change Stream
Using The Mysql Binary Log As A Change StreamUsing The Mysql Binary Log As A Change Stream
Using The Mysql Binary Log As A Change Stream
 

Dernier

6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...Dr Arash Najmaei ( Phd., MBA, BSc)
 
convolutional neural network and its applications.pdf
convolutional neural network and its applications.pdfconvolutional neural network and its applications.pdf
convolutional neural network and its applications.pdfSubhamKumar3239
 
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...KarteekMane1
 
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
 
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...Boston Institute of Analytics
 
Principles and Practices of Data Visualization
Principles and Practices of Data VisualizationPrinciples and Practices of Data Visualization
Principles and Practices of Data VisualizationKianJazayeri1
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsVICTOR MAESTRE RAMIREZ
 
What To Do For World Nature Conservation Day by Slidesgo.pptx
What To Do For World Nature Conservation Day by Slidesgo.pptxWhat To Do For World Nature Conservation Day by Slidesgo.pptx
What To Do For World Nature Conservation Day by Slidesgo.pptxSimranPal17
 
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...Boston Institute of Analytics
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 217djon017
 
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Boston Institute of Analytics
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our WorldEduminds Learning
 
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdfEnglish-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdfblazblazml
 
Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Seán Kennedy
 
SMOTE and K-Fold Cross Validation-Presentation.pptx
SMOTE and K-Fold Cross Validation-Presentation.pptxSMOTE and K-Fold Cross Validation-Presentation.pptx
SMOTE and K-Fold Cross Validation-Presentation.pptxHaritikaChhatwal1
 
Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)Cathrine Wilhelmsen
 
Cyber awareness ppt on the recorded data
Cyber awareness ppt on the recorded dataCyber awareness ppt on the recorded data
Cyber awareness ppt on the recorded dataTecnoIncentive
 
Unveiling the Role of Social Media Suspect Investigators in Preventing Online...
Unveiling the Role of Social Media Suspect Investigators in Preventing Online...Unveiling the Role of Social Media Suspect Investigators in Preventing Online...
Unveiling the Role of Social Media Suspect Investigators in Preventing Online...Milind Agarwal
 
modul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptxmodul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptxaleedritatuxx
 

Dernier (20)

6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
 
Insurance Churn Prediction Data Analysis Project
Insurance Churn Prediction Data Analysis ProjectInsurance Churn Prediction Data Analysis Project
Insurance Churn Prediction Data Analysis Project
 
convolutional neural network and its applications.pdf
convolutional neural network and its applications.pdfconvolutional neural network and its applications.pdf
convolutional neural network and its applications.pdf
 
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...
 
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
 
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
 
Principles and Practices of Data Visualization
Principles and Practices of Data VisualizationPrinciples and Practices of Data Visualization
Principles and Practices of Data Visualization
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business Professionals
 
What To Do For World Nature Conservation Day by Slidesgo.pptx
What To Do For World Nature Conservation Day by Slidesgo.pptxWhat To Do For World Nature Conservation Day by Slidesgo.pptx
What To Do For World Nature Conservation Day by Slidesgo.pptx
 
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2
 
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our World
 
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdfEnglish-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
 
Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...
 
SMOTE and K-Fold Cross Validation-Presentation.pptx
SMOTE and K-Fold Cross Validation-Presentation.pptxSMOTE and K-Fold Cross Validation-Presentation.pptx
SMOTE and K-Fold Cross Validation-Presentation.pptx
 
Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)
 
Cyber awareness ppt on the recorded data
Cyber awareness ppt on the recorded dataCyber awareness ppt on the recorded data
Cyber awareness ppt on the recorded data
 
Unveiling the Role of Social Media Suspect Investigators in Preventing Online...
Unveiling the Role of Social Media Suspect Investigators in Preventing Online...Unveiling the Role of Social Media Suspect Investigators in Preventing Online...
Unveiling the Role of Social Media Suspect Investigators in Preventing Online...
 
modul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptxmodul pembelajaran robotic Workshop _ by Slidesgo.pptx
modul pembelajaran robotic Workshop _ by Slidesgo.pptx
 

MySQL 8.0: What Is New in Optimizer and Executor?

  • 1. Copyright © 2018 Oracle and/or its afliates. All rights reserved. What Is New in Optmizer and Executor? Norvald H. Ryeng Sofware Development Senior Manager MySQL Optmizer Team October, 2018 MySQL 8.0:
  • 2. 3Copyright © 2018 Oracle and/or its afliates. All rights reserved. Safe Harbor Statement The following is intended to outline our general product directon. It is intended for informaton purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functonality, and should not be relied upon in making purchasing decisions. The development, release, and tming of any features or functonality described for Oracle’s products remains at the sole discreton of Oracle.
  • 3. 4Copyright © 2018 Oracle and/or its afliates. All rights reserved. Program Agenda Common table expressions Window functons UTF-8 support GIS SKIP LOCKED, NOWAIT JSON functons Index extensions Cost model Hints
  • 4. 5Copyright © 2018 Oracle and/or its afliates. All rights reserved. Program Agenda Common table expressions Window functons UTF-8 support GIS SKIP LOCKED, NOWAIT JSON functons Index extensions Cost model Hints
  • 5. 7Copyright © 2018 Oracle and/or its afliates. All rights reserved. CTEs As Alternatve to Derived Tables ● A derived table is a subquery in the FROM clause: SELECT … FROM (subquery) AS derived, t1 … ● A CTE is just like a derived table, but the declaraton comes before the query block: WITH derived AS (subquery) SELECT … FROM derived, t1 … ● May precede SELECT, UPDATE, DELETE and be used in subqueries: WITH derived AS (subquery) DELETE FROM t1 WHERE t1.a IN (SELECT b FROM derived);
  • 6. 8Copyright © 2018 Oracle and/or its afliates. All rights reserved. CTEs vs. Derived Tables ● Beter readability ● Can be referenced multple tmes ● Can refer to other CTEs ● Improved performance
  • 7. 9Copyright © 2018 Oracle and/or its afliates. All rights reserved. CTEs Provide Beter Readability Derived table: SELECT … FROM t1 LEFT JOIN ((SELECT … FROM …) AS dt JOIN t2 ON …) ON … CTE: WITH dt AS (SELECT ... FROM ...) SELECT ... FROM t1 LEFT JOIN (dt JOIN t2 ON ...) ON …
  • 8. 10Copyright © 2018 Oracle and/or its afliates. All rights reserved. CTEs Can Be Referenced Multple Times ● Derived tables can't be referenced twice SELECT … FROM (SELECT a, b, SUM(c) AS s FROM t1 GROUP BY a, b) AS d1 JOIN (SELECT a, b, SUM(c) AS s FROM t1 GROUP BY a, b) AS d2 ON d1.b = d2.a; ● CTEs can WITH d AS (SELECT a, b, SUM(c) AS s FROM t1 GROUP BY a, b) SELECT … FROM d AS d1 JOIN d AS d2 ON d1.b = d2.a; ● Beter performance with materializaton – Multple CTE references are only materialized once – Derived tables and views will be materialized once per reference
  • 9. 11Copyright © 2018 Oracle and/or its afliates. All rights reserved. CTEs Can Refer to Other CTEs ● Derived tables can't refer to other derived tables SELECT … FROM (SELECT … FROM …) AS d1, (SELECT … FROM d1 …) AS d2 … ERROR: 1146 (42S02): Table ‘db.d1’ doesn’t exist ● CTEs can refer other CTEs WITH d1 AS (SELECT … FROM …), d2 AS (SELECT … FROM d1 …) SELECT … FROM d1, d2 …
  • 10. 12Copyright © 2018 Oracle and/or its afliates. All rights reserved. Recursive CTEs WITH RECURSIVE cte AS (SELECT … FROM table_name /* "seed" SELECT */ UNION [DISTINCT|ALL] SELECT … FROM cte, table_name) /* "recursive" SELECT */ SELECT … FROM cte; ● A recursive CTE refers to itself in a subquery ● The "seed" SELECT is executed once to create the inital data subset ● The "recursive" CTE is executed repeatedly – Stops when iteraton doesn't generate any new rows – Set cte_max_recursion_depth to limit recursion ● Useful to traverse hierarchies (parent/child, part/subpart)
  • 11. 14Copyright © 2018 Oracle and/or its afliates. All rights reserved. Program Agenda Common table expressions Window functons UTF-8 support GIS SKIP LOCKED, NOWAIT JSON functons Index extensions Cost model Hints
  • 12. 16Copyright © 2018 Oracle and/or its afliates. All rights reserved. Window Functons ● Similar to aggregaton functons – Computes one value based on multple rows – But does not group Aggregaton functon Window functon
  • 13. 17Copyright © 2018 Oracle and/or its afliates. All rights reserved. Window Functon Example Sum up total salary per department SELECT name, dept_id, salary, SUM(salary) OVER (PARTITION BY dept_id) AS dept_total FROM employee ORDER BY dept_id, name; The OVER keyword signals a window functon PARTITION ⇒ disjoint set of rows in result set name dept_id salary dept_total Newt NULL 75000 75000 Dag 10 NULL 370000 Ed 10 100000 370000 Fred 10 60000 370000 Jon 10 60000 370000 Michael 10 70000 370000 Newt 10 80000 370000 Lebedev 20 65000 130000 Pete 20 65000 130000 Jef 30 300000 370000 Will 30 70000 370000
  • 14. 18Copyright © 2018 Oracle and/or its afliates. All rights reserved. Window Functon Example Sum up total salary per department SELECT name, dept_id, salary, SUM(salary) OVER (PARTITION BY dept_id) AS dept_total FROM employee ORDER BY dept_id, name; The OVER keyword signals a window functon PARTITION ⇒ disjoint set of rows in result set name dept_id salary dept_total Newt NULL 75000 75000 Dag 10 NULL 370000 Ed 10 100000 370000 Fred 10 60000 370000 Jon 10 60000 370000 Michael 10 70000 370000 Newt 10 80000 370000 Lebedev 20 65000 130000 Pete 20 65000 130000 Jef 30 300000 370000 Will 30 70000 370000
  • 15. 20Copyright © 2018 Oracle and/or its afliates. All rights reserved. Program Agenda Common table expressions Window functons UTF-8 support GIS SKIP LOCKED, NOWAIT JSON functons Index extensions Cost model Hints
  • 16. 22Copyright © 2018 Oracle and/or its afliates. All rights reserved. UTF-8 Support ● Collatons based on Unicode 9.0 ● ut8mb4 as default character set – ut8mb4_0900_ai_ci as default collaton ● Accent and case sensitve collatons – Including 20+ language specifc collatons – Now also Japanese and Russian ● Signifcantly improved performance ● Unicode support in regular expressions
  • 17. 23Copyright © 2018 Oracle and/or its afliates. All rights reserved. New Default Character Set ● No change to existng tables ● Only has efect on new tables/schemas when character set is not explicitly specifed Upgrade recommendatons ● Upgrade frst, change character set and collaton aferwards ● Don't mix collatons – Error: "Illegal mix of collatons" – Slower queries because indexes can't be used
  • 18. 24Copyright © 2018 Oracle and/or its afliates. All rights reserved. Program Agenda Common table expressions Window functons UTF-8 support GIS SKIP LOCKED, NOWAIT JSON functons Index extensions Cost model Hints
  • 19. 26Copyright © 2018 Oracle and/or its afliates. All rights reserved. GIS ● Geography support – Lattude-longitude on an ellipsoid ● Spatal reference systems (SRSs) – More than 5000 SRSs from the EPSG Geodetc Parameter Dataset – INFORMATION_SCHEMA.ST_SPATIAL_REFERENCE_SYSTEMS – CREATE/DROP SPATIAL REFERENCE SYSTEM ● SRID aware spatal datatypes, indexes and functons ● ST_Transform to convert between SRSs — New in MySQL 8.0.13! ● Functons and expressions as default values — New in MySQL 8.0.13! – Including ST_GeomFromText
  • 20. 27Copyright © 2018 Oracle and/or its afliates. All rights reserved. Program Agenda Common table expressions Window functons UTF-8 support GIS SKIP LOCKED, NOWAIT JSON functons Index extensions Cost model Hints
  • 21. 29Copyright © 2018 Oracle and/or its afliates. All rights reserved. SELECT … FOR UPDATE SKIP LOCKED Problem: Hot row contenton, multple worker threads accessing the same rows. SKIP LOCKED Soluton: ● Only read rows that aren't locked ● InnoDB skips a locked row, and the next one goes to the result set Example: – Booking system: Skip orders that are pending START TRANSACTION; SELECT * FROM seats WHERE seat_no BETWEEN 2 AND 3 AND booked = 'NO' FOR UPDATE SKIP LOCKED;
  • 22. 30Copyright © 2018 Oracle and/or its afliates. All rights reserved. SELECT … FOR UPDATE NOWAIT Problem: Hot row contenton, multple worker threads accessing the same rows. NOWAIT Soluton: ● Fail immediately if any rows are locked ● Without NOWAIT, the query waits for innodb_lock_wait_tmeout (default 50 seconds) before giving up Example: – Booking system: Fail if rows are locked START TRANSACTION; SELECT * FROM seats WHERE seat_no BETWEEN 2 AND 3 AND booked = 'NO' FOR UPDATE NOWAIT; ERROR 3572 (HY000): Statement aborted because lock(s) could not be acquired ...
  • 23. 31Copyright © 2018 Oracle and/or its afliates. All rights reserved. Program Agenda Common table expressions Window functons UTF-8 support GIS SKIP LOCKED, NOWAIT JSON functons Index extensions Cost model Hints
  • 24. 33Copyright © 2018 Oracle and/or its afliates. All rights reserved. JSON Functons JSON_ARRAY_APPEND() JSON_ARRAY_INSERT() JSON_ARRAY() JSON_CONTAINS_PATH() JSON_CONTAINS() JSON_DEPTH() JSON_EXTRACT() JSON_INSERT() JSON_KEYS() JSON_LENGTH() JSON_MERGE[_PRESERVE]() JSON_OBJECT() JSON_QUOTE() JSON_REMOVE() JSON_REPLACE() JSON_SEARCH() JSON_SET() JSON_TYPE() JSON_UNQUOTE() JSON_VALID() JSON_PRETTY() JSON_STORAGE_SIZE() JSON_STORAGE_FREE() JSON_ARRAYAGG() JSON_OBJECTAGG() JSON_MERGE_PATCH() JSON_TABLE()
  • 25. 34Copyright © 2018 Oracle and/or its afliates. All rights reserved. JSON Data Type CREATE TABLE t1 (json_col JSON); INSERT INTO t1 VALUES ( '{ "people": [ { "name":"John Smith", "address":"780 Mission St, San Francisco, CA 94103"}, { "name":"Sally Brown", "address":"75 37th Ave S, St Cloud, MN 94103"}, { "name":"John Johnson", "address":"1262 Roosevelt Trail, Raymond, ME 04071"} ] }' );
  • 26. 35Copyright © 2018 Oracle and/or its afliates. All rights reserved. JSON_TABLE Convert JSON documents to relatonal tables SELECT people.* FROM t1, JSON_TABLE(json_col, '$.people[*]' COLUMNS ( name VARCHAR(40) PATH '$.name', address VARCHAR(100) PATH '$.address')) AS people; name address John Smith 780 Mission St, San Francisco, CA 94103 Sally Brown 75 37th Ave S, St Cloud, MN 9410 John Johnson 1262 Roosevelt Trail, Raymond, ME 04071
  • 27. 36Copyright © 2018 Oracle and/or its afliates. All rights reserved. JSON_TABLE Filter JSON data on SQL expression SELECT people.* FROM t1, JSON_TABLE(json_col, '$.people[*]' COLUMNS ( name VARCHAR(40) PATH '$.name', address VARCHAR(100) PATH '$.address')) AS people WHERE people.name LIKE 'John%'; name address John Smith 780 Mission St, San Francisco, CA 94103 John Johnson 1262 Roosevelt Trail, Raymond, ME 04071
  • 28. 37Copyright © 2018 Oracle and/or its afliates. All rights reserved. JSON_TABLE Nested Arrays [ { "father":"John", "mother":"Mary", "marriage_date":"2003-12-05", "children": [ { "name":"Eric", "age":12 }, { "name":"Beth", "age":10 } ] }, { "father":"Paul", "mother":"Laura", "children": [ { "name":"Sarah", "age":9}, { "name":"Noah", "age":3} , { "name":"Peter", "age":1} ] } ] id father married child_id child age 1 John 1 1 Eric 12 1 John 1 2 Beth 10 2 Paul 0 1 Sarah 9 2 Paul 0 2 Noah 3 2 Paul 0 3 Peter 1
  • 29. 38Copyright © 2018 Oracle and/or its afliates. All rights reserved. JSON_TABLE Nested Arrays JSON_TABLE (families, '$[*]' COLUMNS ( id FOR ORDINALITY, father VARCHAR(30) PATH '$.father', married INTEGER EXISTS PATH '$.marriage_date', NESTED PATH '$.children[*]' COLUMNS ( child_id FOR ORDINALITY, child VARCHAR(30) PATH '$.name', age INTEGER PATH '$.age' ) )) id father married child_id child age 1 John 1 1 Eric 12 1 John 1 2 Beth 10 2 Paul 0 1 Sarah 9 2 Paul 0 2 Noah 3 2 Paul 0 3 Peter 1
  • 30. 39Copyright © 2018 Oracle and/or its afliates. All rights reserved. JSON Array Aggregaton CREATE TABLE t1 (id INT, grp INT, jsoncol JSON); INSERT INTO t1 VALUES (1, 1, '{"key1":"value1","key2":"value2"}'); INSERT INTO t1 VALUES (2, 1, '{"keyA":"valueA","keyB":"valueB"}'); INSERT INTO t1 VALUES (3, 2, '{"keyX":"valueX","keyY":"valueY"}'); Yet to come: JSON_ARRAYAGG as window functon SELECT JSON_ARRAYAGG(jsoncol) FROM t1; [{"key1":"value1","key2":"value2"}, {"keyA":"valueA","keyB":"valueB"}, {"keyX":"valueX","keyY":"valueY"}]
  • 31. 40Copyright © 2018 Oracle and/or its afliates. All rights reserved. JSON Object Aggregaton CREATE TABLE t1 (id INT, grp INT, jsoncol JSON); INSERT INTO t1 VALUES (1, 1, '{"key1":"value1","key2":"value2"}'); INSERT INTO t1 VALUES (2, 1, '{"keyA":"valueA","keyB":"valueB"}'); INSERT INTO t1 VALUES (3, 2, '{"keyX":"valueX","keyY":"valueY"}'); Yet to come: JSON_OBJECTAGG as window functon SELECT grp, JSON_OBJECTAGG(id, jsoncol) FROM t1 GROUP BY grp; 1 {"1":{"key1":"value1","key2":"value2"}, "2":{"keyA":"valueA","keyB":"valueB"}} 2 {"3":{"keyX":"valueX","keyY":"valueY"}}
  • 32. 41Copyright © 2018 Oracle and/or its afliates. All rights reserved. Partal Update of JSON ● Automatcally detect potental in-place updates – JSON_SET – JSON_REPLACE – JSON_REMOVE – Source and target columns are the same – Updatng existng value, not adding new one – Sufcient space is available ● Smaller than or same size as some old value ● Only the dif is sent in binlog
  • 33. 42Copyright © 2018 Oracle and/or its afliates. All rights reserved. Program Agenda Common table expressions Window functons UTF-8 support GIS SKIP LOCKED, NOWAIT JSON functons Index extensions Cost model Hints
  • 34. 44Copyright © 2018 Oracle and/or its afliates. All rights reserved. Invisible Index ● Index is maintained by the storage engine, but invisible to the optmizer – Override with SET optmizer_switch='use_invisible_indexes=on'; ● Primary key can't be invisible ● Use case: Check for performance drope before removing index ALTER TABLE t1 ALTER INDEX idx INVISIBLE; SHOW INDEXES FROM t1; +---------+------------------+----------------------+---------------+ | Table | Key_name | Column_name | Visible | +---------+------------------+----------------------+---------------+ | t1 | idx | a | NO | +---------+------------------+----------------------+---------------+
  • 35. 45Copyright © 2018 Oracle and/or its afliates. All rights reserved. Descending Index CREATE TABLE t1 ( a INT, b INT, INDEX a_b (a DESC, b ASC) ); ● In 5.7: Index in ascending order is created, server scans it backwards ● In 8.0: Index in descending order is created, server scans it forwards – Works on B-tree indexes only – Benefts: ● Use indexes instead of flesort for ORDER BY clause with ASC/DESC sort key ● Forward index scan is slightly faster than backward index scan
  • 36. 46Copyright © 2018 Oracle and/or its afliates. All rights reserved. Functonal Index — New in 8.0.13 ● Index over an expression CREATE TABLE t1 (col1 INT, col2 INT, INDEX func_index ((ABS(col1)))); CREATE INDEX idx1 ON t1 ((col1 + col2)); CREATE INDEX idx2 ON t1 ((col1 + col2), (col1 - col2), col1); ALTER TABLE t1 ADD INDEX ((col1 * 40)); ● No longer necessary to create an indexed generated column ● Not allowed as PRIMARY KEY
  • 37. 47Copyright © 2018 Oracle and/or its afliates. All rights reserved. Index Skip-Scan — New in 8.0.13 ● Used for mult-column index ● Conditon not on frst part of index ● Cost-based choice Before MySQL 8.0.13: Full index scan MySQL 8.0.13: Skip-scan pk a b c INDEX idx(a,b,c) SELECT * FROM t1 WHERE b < 3; 1 1 2 3 4 5 2 1 2 3 4 5 3 1 2 3 4 5 4 1 2 3 4 5 a b c Full index scan 1 1 2 3 4 5 2 1 2 3 4 5 3 1 2 3 4 5 4 1 2 3 4 5 a b c b < 3 b < 3 b < 3 b < 3
  • 38. 48Copyright © 2018 Oracle and/or its afliates. All rights reserved. Thanks for the patch, Facebook!
  • 39. 49Copyright © 2018 Oracle and/or its afliates. All rights reserved. Program Agenda Common table expressions Window functons UTF-8 support GIS SKIP LOCKED, NOWAIT JSON functons Index extensions Cost model Hints
  • 40. 51Copyright © 2018 Oracle and/or its afliates. All rights reserved. Motvaton for Improving the MySQL Cost Model ● Produce more correct cost estmates – Beter decisions by the optmizer should improve performance ● Adapt to new hardware architectures – SSD, larger memories, caches ● More maintainable cost model implementaton – Avoid hard coded “cost constants” – Refactoring of existng cost model code ● Confgurable and tunable ● Make more of the optmizer cost-based Faster queries
  • 41. 52Copyright © 2018 Oracle and/or its afliates. All rights reserved. New Storage Technologies ● Time to do a table scan of 10 million records: ● Adjust cost model to support diferent storage technologies ● Provide confgurable cost constants for diferent storage technologies Memory 5 s SSD 20 - 146 s Hard disk 32 - 1465 s Provide a program that could measure performance and suggest good cost constant confguraton for a running MySQL server? Provide a program that could measure performance and suggest good cost constant confguraton for a running MySQL server?
  • 42. 53Copyright © 2018 Oracle and/or its afliates. All rights reserved. Memory Bufer Aware Cost Estmates ● Storage engines: – Estmate for how much of data and indexes are in a memory bufer – Estmate for hit rate for memory bufer ● Optmizer cost model: – Take into account whether data is already in memory or need to be read from disk Server Storage engine Disk data Query executor Database bufer
  • 43. 54Copyright © 2018 Oracle and/or its afliates. All rights reserved. Histograms ● Provides the optmizer with informaton about column value distributon ● To create/recalculate histogram for a column: ANALYZE TABLE table UPDATE HISTOGRAM ON column WITH n BUCKETS; ● May use sampling – Sample size is based on available memory (histogram_generaton_max_mem_size) ● Automatcally chooses between two histogram types: – Singleton: One value per bucket – Equi-height: Multple values per bucket
  • 44. 55Copyright © 2018 Oracle and/or its afliates. All rights reserved. Program Agenda Common table expressions Window functons UTF-8 support GIS SKIP LOCKED, NOWAIT JSON functons Index extensions Cost model Hints
  • 45. 57Copyright © 2018 Oracle and/or its afliates. All rights reserved. Join Order Hints ● No need to reorganize the FROM clause to add join order hints like you will for STRAIGHT_JOIN ● /*+ JOIN_ORDER(t1, t2, …) */ ● /*+ JOIN_PREFIX(t1, t2, …) */ ● /*+ JOIN_SUFFIX(…, ty, tz) */ ● /*+ JOIN_FIXED_ORDER() */ – Replacement for STRAIGHT_JOIN
  • 46. 58Copyright © 2018 Oracle and/or its afliates. All rights reserved. View/Derived Table/CTE Merge Hints ● Views, derived tables and CTEs are, if possible, merged into outer query ● NO_MERGE can override default behavior SELECT /*+ NO_MERGE(dt) */ * FROM t1 JOIN (SELECT x, y FROM t2) dt ON t1.x = dt.x; ● MERGE will force a merge SELECT /*+ MERGE(dt) */ * FROM t1 JOIN (SELECT x, y FROM t2) dt ON t1.x = dt.x;
  • 47. 59Copyright © 2018 Oracle and/or its afliates. All rights reserved. Index Merge Executon 10INDEX(a) 10INDEX(b) a=10 AND b=10Result: Intersecton SELECT * FROM t1 WHERE a=10 AND b=10
  • 48. 60Copyright © 2018 Oracle and/or its afliates. All rights reserved. Index Merge Hints ● Index merge: Merge rows from multple range scans on a single table ● Algorithms: union, intersecton, sort union ● Users can specify which indexes to use for index merge – /*+ INDEX_MERGE(t1 idx1, idx2, …) */ – /*+ NO_INDEX_MERGE(t1 idx1, idx2, …) */
  • 49. 61Copyright © 2018 Oracle and/or its afliates. All rights reserved. Hints to Set Session Variables ● Set a session variable for the duraton of a single statement ● Examples: SELECT /*+ SET_VAR(sort_bufer_size = 16M) */ name FROM people ORDER BY name; INSERT /*+ SET_VAR(foreign_key_checks = OFF) */ INTO t2 VALUES (1, 1), (2, 2), (3, 3); SELECT /*+ SET_VAR(optmizer_switch = 'conditon_fanout_flter = of') */ * FROM customer JOIN orders ON c_custkey = o_custkey WHERE c_acctbal < 0 AND o_orderdate < '1993-01-01'; ● Note: Not all session variables are setable through hints: mysql> SELECT /*+ SET_VAR(max_allowed_packet=128M) */ * FROM t1; Empty set, 1 warning (0,00 sec) Warning (Code 4537): Variable 'max_allowed_packet' cannot be set using SET_VAR hint.
  • 50. 62Copyright © 2018 Oracle and/or its afliates. All rights reserved. Feature descriptons and design details directly from the source. htp://mysqlserverteam.com/
  • 51. 63Copyright © 2018 Oracle and/or its afliates. All rights reserved.