SlideShare a Scribd company logo
Submit Search
Upload
Login
Signup
New index features in MySQL 8
Report
Erik Frøseth
Follow
Feb. 5, 2019
•
0 likes
•
546 views
1
of
30
New index features in MySQL 8
Feb. 5, 2019
•
0 likes
•
546 views
Download Now
Download to read offline
Report
Software
An introduction to three of the new index features in MySQL 8
Erik Frøseth
Follow
Recommended
My sql 5.7-upcoming-changes-v2
Morgan Tocker
1.1K views
•
33 slides
MySQL Performance Schema in Action
Sveta Smirnova
505 views
•
125 slides
Exploring mysql cluster 7.4
Ivan Ma
561 views
•
29 slides
MySQL 5.7 + JSON
Morgan Tocker
13.6K views
•
40 slides
What's New MySQL 8.0?
OracleMySQL
669 views
•
45 slides
Introduction into MySQL Query Tuning
Sveta Smirnova
672 views
•
100 slides
More Related Content
What's hot
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
Dave Stokes
5.3K views
•
42 slides
Mysql8 advance tuning with resource group
Marco Tusa
350 views
•
26 slides
Optimizing MySQL
Morgan Tocker
2.4K views
•
12 slides
MySQL For Linux Sysadmins
Morgan Tocker
1.6K views
•
47 slides
MySQL partitioning
OracleMySQL
711 views
•
68 slides
DBA Commands and Concepts That Every Developer Should Know - Part 2
Alex Zaballa
91 views
•
137 slides
What's hot
(20)
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
Dave Stokes
•
5.3K views
Mysql8 advance tuning with resource group
Marco Tusa
•
350 views
Optimizing MySQL
Morgan Tocker
•
2.4K views
MySQL For Linux Sysadmins
Morgan Tocker
•
1.6K views
MySQL partitioning
OracleMySQL
•
711 views
DBA Commands and Concepts That Every Developer Should Know - Part 2
Alex Zaballa
•
91 views
MySQL Server Defaults
Morgan Tocker
•
2.3K views
MySQL Query Optimization
Morgan Tocker
•
1.8K views
Solving Performance Problems Using MySQL Enterprise Monitor
OracleMySQL
•
132 views
DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
•
1.1K views
MySQL Monitoring Mechanisms
Mark Leith
•
2.2K views
Mysql server query path
Wenjie Wu
•
164 views
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
Dave Stokes
•
181 views
MySQL NoSQL APIs
Morgan Tocker
•
1.4K views
Oracle SQL Tuning
Alex Zaballa
•
1.6K views
MySQL Performance Best Practices
Olivier DASINI
•
898 views
MySQL JSON Functions
Sveta Smirnova
•
18.3K views
Performance schema and sys schema
Mark Leith
•
11.3K views
Mini Session - Using GDB for Profiling
Enkitec
•
903 views
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
•
3.9K views
Similar to New index features in MySQL 8
Five more things about Oracle SQL and PLSQL
Connor McDonald
58 views
•
76 slides
2019 indit blackhat_honeypot your database server
Georgi Kodinov
134 views
•
25 slides
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Guatemala User Group
1.6K views
•
76 slides
Developers' mDay 2017. - Bogdan Kecman Oracle
mCloud
203 views
•
40 slides
Developers’ mDay u Banjoj Luci - Bogdan Kecman, Oracle – MySQL Server 8.0
mCloud
29 views
•
40 slides
15 protips for mysql users pfz
Joshua Thijssen
2.6K views
•
63 slides
Similar to New index features in MySQL 8
(20)
Five more things about Oracle SQL and PLSQL
Connor McDonald
•
58 views
2019 indit blackhat_honeypot your database server
Georgi Kodinov
•
134 views
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Guatemala User Group
•
1.6K views
Developers' mDay 2017. - Bogdan Kecman Oracle
mCloud
•
203 views
Developers’ mDay u Banjoj Luci - Bogdan Kecman, Oracle – MySQL Server 8.0
mCloud
•
29 views
15 protips for mysql users pfz
Joshua Thijssen
•
2.6K views
MySQL 8.0 Released Update
Keith Hollman
•
127 views
DBA Commands and Concepts That Every Developer Should Know - Part 2
Alex Zaballa
•
276 views
Top 10 tips for Oracle performance
Guy Harrison
•
10.8K views
5 Cool Things About SQL
Connor McDonald
•
63 views
Windowing Functions - Little Rock Tech Fest 2019
Dave Stokes
•
79 views
Windowing Functions - Little Rock Tech fest 2019
Dave Stokes
•
378 views
Php forum2015 tomas_final
Bertrand Matthelie
•
1.4K views
Sql and PL/SQL Best Practices I
Carlos Oliveira
•
2.3K views
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
Dave Stokes
•
591 views
MySQL Performance Schema in 20 Minutes
Sveta Smirnova
•
1.5K views
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Connor McDonald
•
136 views
My sql 5.6&MySQL Cluster 7.3
Oleksii(Alexey) Porytskyi
•
1.8K views
Everything you always wanted to know about datetime types but didn’t have tim...
MartinHanssonOracle
•
134 views
MySQL 8.0: Secure your replication deployment
Pedro Figueiredo
•
12 views
Recently uploaded
Alliance Expedition Battle
Silver Caprice
1.5K views
•
16 slides
Document WhatsApp Messaging
Geminate Consultancy Services
8 views
•
45 slides
Our Story, Orange Nile
ManolodelaFuente1
7 views
•
14 slides
BMC Software.pptx
Cloudaction
5 views
•
7 slides
Empowering Advanced Users: Extending OutSystems UI Framework with Openness an...
Bernardo Cardoso
39 views
•
41 slides
Tracking user activity logs using Loggastic #ApiPlatformCon
Paula Čučuk
24 views
•
64 slides
Recently uploaded
(20)
Alliance Expedition Battle
Silver Caprice
•
1.5K views
Document WhatsApp Messaging
Geminate Consultancy Services
•
8 views
Our Story, Orange Nile
ManolodelaFuente1
•
7 views
BMC Software.pptx
Cloudaction
•
5 views
Empowering Advanced Users: Extending OutSystems UI Framework with Openness an...
Bernardo Cardoso
•
39 views
Tracking user activity logs using Loggastic #ApiPlatformCon
Paula Čučuk
•
24 views
Winter 24 Highlights.pdf
PatrickYANG48
•
5 views
LangChain + Docugami Webinar
Taqi Jaffri
•
62 views
baklink.docx
AbdAsisHusainSalam
•
5 views
TorfsBot or Not? Evaluating User Perception on Imitative Text Generation (CLI...
Thomas Winters
•
11 views
PostgreSQL Prologue
Md. Golam Hossain
•
12 views
Test Automation at Scale: Lessons from Top-Performing Distributed Teams
Applitools
•
8 views
Semantic Search_ NLP_ ML.pdf
PlamenaDzharadat
•
13 views
The Never Landing Stream with HTAP and Streaming
Timothy Spann
•
167 views
DevOps and SF.pdf
PatrickYANG48
•
5 views
The art of AI Art
Dennis Vroegop
•
13 views
OutSystems Security Specialization - Study Help Deck
Fábio Godinho
•
47 views
Why Should You Choose a Personal Trainer over Group Gym Classes?
Neighborhood Trainer
•
38 views
A Guide to Java Dynamic Proxies and It in Coding
MikeConner22
•
5 views
Climate Impact of Software Testing
Kari Kakkonen
•
54 views
New index features in MySQL 8
1.
Copyright © 2019
Oracle and/or its affiliates. All rights reserved. New index features in MySQL 8 Erik Frøseth Software Developer MySQL Optimizer Team February 1st, 2019
2.
2Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
3.
3Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Program Agenda Functional indexes Index skip scan Invisible indexes 1 2 3 4 5 6 7
4.
4Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Program Agenda Functional indexes Index skip scan Invisible indexes 1 2 3 4 5 6 7
5.
5Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Terminology # This creates a single index/key with two index/key parts CREATE INDEX my_index ON my_table (column_a, column_b);
6.
6Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Functional index – what is it? ● A functional index is an index where at least one of the index parts is a function instead of a column. 1) CREATE INDEX my_index ON my_table ((ABS(column_a))); 2) CREATE INDEX my_index ON my_table ((ABS(column_a)), column_b); 3) CREATE TABLE my_table ( column_a VARCHAR(255), INDEX my_index ((UPPER(column_a))) );
7.
7Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Functional index – how do you use it? ● A functional index is created, used and removed exactly like any other index. mysql> CREATE TABLE my_table ( -> column_a VARCHAR(255), -> INDEX my_index ((UPPER(column_a))) -> ); Query OK, 0 rows affected (0.04 sec) mysql> EXPLAIN SELECT * FROM my_table WHERE UPPER(column_a) = "FOOBAR"; +-------------+----------+------+----------+---------+-------+------+----------+ | select_type | table | type | key | key_len | ref | rows | filtered | +-------------+----------+------+----------+---------+-------+------+----------+ | SIMPLE | my_table | ref | my_index | 1023 | const | 1 | 100.00 | +-------------+----------+------+----------+---------+-------+------+----------+ 1 row in set, 1 warning (0.00 sec)
8.
8Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Functional index – how do you use it? mysql> CREATE TABLE my_table ( -> column_a VARCHAR(255), -> column_b INT, -> INDEX my_index ((UPPER(column_a)), column_b) -> ); Query OK, 0 rows affected (0.04 sec) mysql> EXPLAIN SELECT * FROM my_table WHERE UPPER(column_a) = "FOOBAR" AND column_b < 20; +-------------+----------+-------+---------------+----------+---------+------+----------+ | select_type | table | type | possible_keys | key | key_len | rows | filtered | +-------------+----------+-------+---------------+----------+---------+------+----------+ | SIMPLE | my_table | range | my_index | my_index | 1028 | 1 | 100.00 | +-------------+----------+-------+---------------+----------+---------+------+----------+ 1 row in set, 1 warning (0.00 sec) ● You can mix functional and non-functional index parts
9.
9Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Functional index – observability mysql> SHOW INDEX FROM t1; +-------+------------+----------+--------------+-------------+...+-------------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name |...| Expression | +-------+------------+----------+--------------+-------------+...+-------------------+ | t1 | 1 | idx | 1 | NULL |...| (`col1` + `col1`) | +-------+------------+----------+--------------+-------------+...+-------------------+ 1 row in set (0.01 sec) mysql> SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_NAME = "t1"; +...+------------+--------------+-------------+...+-------------------+ |...| INDEX_NAME | SEQ_IN_INDEX | COLUMN_NAME |...| EXPRESSION | +...+------------+--------------+-------------+...+-------------------+ |...| idx | 1 | NULL |...| (`col1` + `col1`) | +...+------------+--------------+-------------+...+-------------------+ 1 row in set (0.00 sec)
10.
10Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Functional index – observability mysql> SHOW CREATE TABLE t1; +-------+-----------------------------------------------------------+ | Table | Create Table | +-------+-----------------------------------------------------------+ | t1 | CREATE TABLE `t1` ( `col1` int(11) DEFAULT NULL, KEY `idx` (((`col1` + `col1`))) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci | +-------+----------------------------------------------------------+ 1 row in set (0.00 sec)
11.
11Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Functional index – use cases The main use case is indexing complex type such as geometries and (especially) JSON. CREATE INDEX json_extract_idx ON my_table ((CAST(data->>'$.person.id' AS CHAR(100)))); { “person”: { “first_name”: “Erik”, “last_name”: “Frøseth”, “id”: 8 } }
12.
12Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Functional index – limitations and other notes ● The primary key cannot be a functional index ● You cannot index a function that returns a BLOB or TEXT ● You can not index non-deterministic functions (RAND(), NOW(), UUID() etc...) ● Each functional index part “uses” one column ● It’s more costly to maintain a functional index than a regular index. Do not overuse it!
13.
13Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Program Agenda Functional indexes Index skip scan Invisible indexes 1 2 3 4 5 6 7
14.
14Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Index skip scan ● Based on a contribution from Facebook ● An index can only be used if the first/leading column(s) is referenced in the WHERE-condition CREATE INDEX my_index ON my_table (column1, column2); # Works! SELECT * FROM my_table WHERE column1 = 33; SELECT * FROM my_table WHERE column1 = 33 AND column2 > 3; # Does not work... SELECT * FROM my_table WHERE column2 > 3;
15.
15Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Index skip scan ● With index skip scan, the first index part can be omitted in the WHERE condition CREATE INDEX my_index ON my_table (column1, column2); # Works! SELECT * FROM my_table WHERE column1 = 33; SELECT * FROM my_table WHERE column1 = 33 AND column2 > 3; # This works too! SELECT * FROM my_table WHERE column2 > 3;
16.
16Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Index skip scan column1 column2 1 1 1 2 1 3 1 4 2 1 2 2 2 3 2 4 2 5 SELECT * FROM my_table WHERE column2 > 3; column1 = 1 AND column2 > 3 column1 = 2 AND column2 > 3
17.
17Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Index skip scan mysql> EXPLAIN SELECT * FROM my_table WHERE column2 > 3; +----------+-------+------+------+----------+----------------------------------------+ | table | type | key | rows | filtered | Extra | +----------+-------+------+------+----------+----------------------------------------+ | my_table | range | idx1 | 85 | 100.00 | Using where; Using index for skip scan | +----------+-------+------+------+----------+----------------------------------------+ 1 row in set, 1 warning (0.00 sec)
18.
18Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Index skip scan ● Usage criterias: – The query must only reference columns that exists in the in the index. – The estimated cost must be the lowest of any alternative (many distinct values in the first key part will most likely results in a high cost).
19.
19Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Index skip scan Few distinct values "skip_scan_range": { "potential_skip_scan_indexes": [{ "index": "idx2", "tree_travel_cost": 0.45, "num_groups": 12, "rows": 138, "cost": 31.817 } ] } Many distinct values "skip_scan_range": { "potential_skip_scan_indexes": [{ "index": "idx2", "tree_travel_cost": 0.5, "num_groups": 421, "rows": 832, "cost": 546.45 } ] }
20.
20Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Index skip scan ● Can be controlled by optimizer switch and query hints 1) SET optimizer_switch='skip_scan=off'; 2) SELECT /*+ SKIP_SCAN(t3) */ col1 FROM t3 WHERE col2 < 10; 3) SELECT /*+ SKIP_SCAN(t3 idx1) */ col1 FROM t3 WHERE col2 < 10; 4) SELECT /*+ NO_SKIP_SCAN(t3) */ col1 FROM t3 WHERE col2 < 10;
21.
21Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Program Agenda Functional indexes Index skip scan Invisible indexes 1 2 3 4 5 6 7
22.
22Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Invisible indexes – What is it? ● Lets you turn off any index ● Global setting ● Invisible to the optimizer, but it’s still maintained by the storage engine ● Can be turned on/off completely by setting the optimizer switch «use_invisible_indexes» ● Primary keys cannot be made invisible
23.
23Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Invisible indexes – How is it used? 1) ALTER TABLE t1 ALTER INDEX idx INVISIBLE; 2) CREATE INDEX idx ON my_table (a_column) INVISIBLE; 3) CREATE TABLE t1 ( col1 INT, INDEX idx (col1) INVISIBLE );
24.
24Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Invisible indexes - Example mysql> EXPLAIN SELECT COUNT(*) FROM lineitem WHERE l_suppkey = 7706; ...+------+---------------+-------------+---------+-------+------+----------+-------------+ ...| type | possible_keys | key | key_len | ref | rows | filtered | Extra | ...+------+---------------+-------------+---------+-------+------+----------+-------------+ ...| ref | i_l_suppkey | i_l_suppkey | 5 | const | 604 | 100.00 | Using index | ...+------+---------------+-------------+---------+-------+------+----------+-------------+ 1 row in set, 1 warning (0.00 sec) mysql> ALTER TABLE lineitem ALTER INDEX i_l_suppkey INVISIBLE; Query OK, 0 rows affected (0.18 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> EXPLAIN SELECT COUNT(*) FROM lineitem WHERE l_suppkey = 7706; ...+------+---------------+------+---------+------+---------+----------+-------------+ ...| type | possible_keys | key | key_len | ref | rows | filtered | Extra | ...+------+---------------+------+---------+------+---------+----------+-------------+ ...| ALL | NULL | NULL | NULL | NULL | 5941264 | 0.01 | Using where | ...+------+---------------+------+---------+------+---------+----------+-------------+ 1 row in set, 1 warning (0.00 sec)
25.
25Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Invisible indexes - Observability ● See the visibility using INFORMATION_SCHEMA or SHOW INDEXES mysql> SHOW INDEXES FROM my_table; +----------+------------+---------------------+...+---------+ | Table | Non_unique | Key_name |...| Visible | +----------+------------+---------------------+...+---------+ | my_table | 1 | just_to_be_safe_idx |...| NO | +----------+------------+---------------------+...+---------+ mysql> SELECT INDEX_NAME, IS_VISIBLE FROM INFORMATION_SCHEMA.STATISTICS > WHERE TABLE_NAME = "my_table"; +---------------------+------------+ | INDEX_NAME | IS_VISIBLE | +---------------------+------------+ | just_to_be_safe_idx | NO | +---------------------+------------+ 1 row in set (0.01 sec)
26.
26Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Invisible indexes - Observability mysql> SHOW CREATE TABLE t1; +-------+----------------------------------------------------------+ | Table | Create Table | +-------+----------------------------------------------------------+ | t1 | CREATE TABLE `t1` ( `col1` int(11) DEFAULT NULL, KEY `just_to_be_safe_index` (((`col1` * 2))) /*!80000 INVISIBLE */ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci | +-------+----------------------------------------------------------+
27.
27Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Invisible indexes – what you should remember ● See if you get any errors due to index hints referring to the index ● Slow query log ● Performance schema ● Application performance ● Check sys.schema_unused_indexes
28.
28Copyright © 2019
Oracle and/or its affiliates. All rights reserved.
29.
29Copyright © 2019
Oracle and/or its affiliates. All rights reserved. Safe Harbor Statement The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.