MySQL8 New Features: Temptable Engine

32
2 © The Pythian Group Inc., 2018 Tue Nov 5th 2018 - Percona Live Europe Frankfurt, Germany Pep Pla MySQL8 New Features: Temptable Engine

Transcript of MySQL8 New Features: Temptable Engine

Page 1: MySQL8 New Features: Temptable Engine

2© The Pythian Group Inc., 2018

Tue Nov 5th 2018 - Percona Live Europe Frankfurt, Germany

Pep Pla

MySQL8 New Features: Temptable Engine

Page 2: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 3

3© The Pythian Group Inc., 2018

Pep PlaBorn in Vinaròs, a small village near the Mediterranean and currently living in Barcelona.

Most of the time I’m busy with my three kids, my partner and our two cats.

And in my spare time I’m a DBC at Pythian, surrounded by some of the most brilliant DBAs in the world.

Page 3: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 4

4© The Pythian Group Inc., 2018

ABOUT PYTHIAN

Pythian’s 400+ IT professionals help companies adopt and manage disruptive technologies to better compete

Page 4: MySQL8 New Features: Temptable Engine

© 2018 Pythian. Confidential 5

Years in Business

20Pythian Experts in 35 Countries

400+Current Clients

Globally

350+

Page 5: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 6

AGENDA

6© The Pythian Group Inc., 2017

● Introduction● Sorting● Temporary space● Memory engine● Temptable engine● Benchmarks

Page 6: MySQL8 New Features: Temptable Engine

7© The Pythian Group Inc., 2018

Sorting

It can change your life

Page 7: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 8© The Pythian Group Inc., 2018 8

● Definition of “sort”● to put a number of things in an order or to separate them into groups

● It is a natural activity● Kids are taught how to sort things: colors, sizes, numbers…● As adults we classify everything and everybody.

● The results of “sorting” can change your life.

Sorting

Page 8: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 9© The Pythian Group Inc., 2018 9

The Sorting Hat

Page 9: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 10© The Pythian Group Inc., 2018 10

The Sorting Hat

Page 10: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 12© The Pythian Group Inc., 2018 12

● The Sorting Hat method is quite simple.● What if we want to perform more complex classifications?

● Place all the students born on the same month together.● Some methods:

● Sorting Hat and then order by age.● Order by age and then Sorting Hat.● Sorting Hat and order by age at the same time.

● Problem: We need a space to keep all the students during the process.

Sorting

Page 11: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 13© The Pythian Group Inc., 2018 13

● MySQL Sorting Hat is called Indexes.● What if we want to perform more complex classifications?

● MySQL has algorithms to perform complex classifications.● Problem: We need a space to keep all the data during the process.

Sorting

Page 12: MySQL8 New Features: Temptable Engine

14© The Pythian Group Inc., 2018

Temporary Space

Time flies

Page 13: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 15© The Pythian Group Inc., 2018 15

Temporary Space

Page 14: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 16© The Pythian Group Inc., 2018 16

● MySQL stores information on tables.● MySQL has two different types of “temporary tables”.

● Explicit temporary tables● Implicit temporary tables

Temporary Space

Page 15: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 17© The Pythian Group Inc., 2018 17

● MySQL explicit temporary tables.● Create temporary table statement.● Session based

■ Only visible from the session that creates the table■ Dropped when the session is closed.

● Create temporary table privilege.

Temporary Space

Page 16: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 18© The Pythian Group Inc., 2018 18

● MySQL implicit temporary tables.● Created internally without user intervention.● Statement based

■ Usually only available during the execution of the statement that required the table

● Invisible for the user, no privileges required.

Temporary Space

Page 17: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 19© The Pythian Group Inc., 2018 19

● Some operations that create an internal temporary table:● Evaluation of some UNION statements, of some views, of derived

tables, of common table expressions.● Subquery or semi-join materialization● Evaluation of statements that contain an ORDER BY clause and a

different GROUP BY clause, or for which the ORDER BY or GROUP BY contains columns from tables other than the first table in the join queue.

● Evaluation of DISTINCT combined with ORDER BY may require a temporary table.

● INSERT ... SELECT statements that select from and insert into the same table, .

● ….

Temporary Space

Page 18: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 20© The Pythian Group Inc., 2018 20

● Some misconceptions● Table rebuilds do not create a “temporary” table.● Memory engine tables.

● Performance requirements● Use the fastest possible storage: memory● Overflow to disk if required.

Temporary Space

Page 19: MySQL8 New Features: Temptable Engine

21© The Pythian Group Inc., 2018

Memory engine

All alone in the moonlight

Page 20: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 22© The Pythian Group Inc., 2018 22

● Default engine for internal temporary tables before MySQL8● Fixed row format

● Bad for “oversized” columns● Configured using per session parameters.

● Tmp_table_size or (max_heap_table_size if lower)● Data migrated to disk table in case of an overflow.● No additional features required: partitioning, privileges or MVCC

Memory engine

Page 21: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 23© The Pythian Group Inc., 2018 23

● Status information:● Created_tmp_tables● Created_tmp_disk_tables● Sort_merge_passes● Sort_range● Sort_rows● Sort_scan

● Performance schema● memory/memory/HP_SHARE● memory/memory/HP_INFO● memory/memory/HP_PTRS● memory/memory/HP_KEYDEF

Memory engine

Page 22: MySQL8 New Features: Temptable Engine

24© The Pythian Group Inc., 2018

Temptable

No Barbra Streisand songs with Temptable, I’m sorry.

Page 23: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 25© The Pythian Group Inc., 2018 25

● Default engine for internal temporary in MySQL8● Not “really” an engine.

● Only for internal temporary tables.● It is not shown with show engines.

● Variable width row format● Great for “oversized” columns

● Configured using global parameters.● temptable_max_ram

● Data is not migrated to disk table in case of an overflow. (Documentation)

● No additional features required: partitioning, privileges or MVCC

Temptable engine

Page 24: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 26© The Pythian Group Inc., 2018 26

● Status information:● Created_tmp_tables● Sort_merge_passes● Sort_range● Sort_rows● Sort_scan

● Performance schema● memory/temptable/physical_disk● memory/temptable/physical_ram

Temptable engine

Page 25: MySQL8 New Features: Temptable Engine

27© The Pythian Group Inc., 2018

Temptable vs. Memory

Fight!

Page 26: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 28© The Pythian Group Inc., 2018 28

● Memory utilization● Temptable memory usage is global.● Memory memory usage is controlled per session.● Both are allocated and released on demand.● Memory can bring your system to its knees.

● Efficiency● Temptable uses variable row format.● Memory uses a fixed row format.● Temptable usually needs far less memory.

● No data migration● Temptable does not migrate data.● Memory converts the ALL the table to a disk engine if required.

Temptable vs. Memory

Page 27: MySQL8 New Features: Temptable Engine

29© The Pythian Group Inc., 2018

Benchmarks

BYOB

Page 28: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 30© The Pythian Group Inc., 2018 30

● Not a real production environment● One table with 20.000.000 rows.● Only one session. No concurrency.

● Three tests● One large temporary table without sorting (cursor).● One large temporary table with sorting.● 500 small temporary tables without sorting.

● Four memory configurations● 5Gb, 1Gb, 512Mb and 256Mb.● The same values where used for both engines.

Benchmarks

Page 29: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 31© The Pythian Group Inc., 2018 31

● One large temporary table without sorting (cursor).● Temptable is 13% faster.● Temptable needs 1% Write operations.(!)

● One large temporary table with sorting.● Temptable is 15% faster.● Temptable again needs 1% Write operations.(!)

● Multiple small operations without sorting● Temptable is 42% faster.● Temptable again needs 1% Write operations

Benchmarks

Page 30: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 32© The Pythian Group Inc., 2018 32

● Conclusions:● Temptable is faster.● Temptable is safer.● Concurrent tests are needed (mutex contention could be an issue)● More detailed analysis of write operations is also needed.

Benchmarks

Page 31: MySQL8 New Features: Temptable Engine

© The Pythian Group Inc., 2018 33

33© The Pythian Group Inc., 2018

THANK YOU We’re hiring!

https://www.pythian.com/careers/

Page 32: MySQL8 New Features: Temptable Engine

35© 2018 Pythian. Confidential