Successfully reported this slideshow.
Your SlideShare is downloading. ×

MySQL Partition Engine

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 14 Ad

More Related Content

Slideshows for you (20)

Similar to MySQL Partition Engine (20)

Advertisement

More from Shinya Sugiyama (14)

Recently uploaded (20)

Advertisement

MySQL Partition Engine

  1. 1. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | MySQL Partition Engine 〜 中長期的なデータ蓄積とMySQL8.0以降の留意点〜 MySQL Global Business Unit Master Principal Sales Consultant/Shinya Sugiyama Updated: 2018/02/20
  2. 2. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Safe Harbor Statement 以下の事項は、弊社の一般的な製品の方向性に関する概要を説明するものです。 また、情報提供を唯一の目的とするものであり、いかなる契約にも組み込むことはでき ません。以下の事項は、マテリアルやコード、機能を提供することをコミットメントするも のではない為、購買決定を行う際の判断材料になさらないで下さい。 オラクル製品に関して記載されている機能の開発、リリースおよび時期については、 弊社の裁量により決定されます。 2
  3. 3. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | CREATE VALUE FROM DATA データ蓄積用データベースとしてのMySQL データ蓄積 機能 概要 MySQL データベース MySQL Cluster データベース: 書き込み自動シャーディング ストレージエンジン 用途によりデータ格納エンジンを選択 JSONデータ型 JSONドキュメント用スキーマレスデータ型 パーティション 大量データを分割して格納 NoSQL処理 memcached, x protocol, その他 レプリケーション 参照処理の分散・バックアップ用途で利用
  4. 4. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 4 MySQL Partition Engine 基本機能レビューとMySQL8.0以降の注意点
  5. 5. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 5 MySQL Partition Engineの基本検証 【環境】 Oracle Cloud MySQL Service インスタンス: OC1M (1OCPU, MEM 15GB) - InnoDB Buffer Pool (11GB) Cloud Trial: https://cloud.oracle.com/ja_JP/mysql Sample Database (world): https://dev.mysql.com/doc/index-other.html
  6. 6. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 6 [world]> explain SELECT `world`.`Continent` AS `CAT1`, `world`.`Region` AS `CAT2`, `world`.`Name` AS `CAT3`, SUM(`world`.`Population`) AS `SUM1`, SUM(`world`.`LifeExpectancy`) AS `SUM2`, SUM(`world`.`GNP`) AS `SUM3`, SUM(`world`.`Capital`) AS `SUM4` FROM `world`.`Country` `world` GROUP BY `world`.`Continent`, `world`.`Region`, `world`.`Name`¥G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: world partitions: NULL type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 239 filtered: 100.00 Extra: Using temporary; Using filesort 1 row in set, 1 warning (0.00 sec) [world]> show warnings¥G *************************** 1. row *************************** Level: Note Code: 1003 Message: /* select#1 */ select `world`.`world`.`Continent` AS `CAT1`,`world`.`world`.`Region` AS `CAT2`,`world`.`world`.`Name` AS `CAT3`,sum(`world`.`world`.`Population`) AS `SUM1`,sum(`world`.`world`.`LifeExpectancy`) AS `SUM2`,sum(`world`.`world`.`GNP`) AS `SUM3`,sum(`world`.`world`.`Capital`) AS `SUM4` from `world`.`Country` `world` group by `world`.`world`.`Continent`,`world`.`world`.`Region`,`world`.`world`.`Name` 1 row in set (0.00 sec) Indexが使えない処理で検証を実行 (Default Sample Data)
  7. 7. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 7 query: SELECT `world` . `Continent` A ... . `Region` , `world` . `Name` db: world full_scan: * exec_count: 1 err_count: 0 warn_count: 0 total_latency: 7.30 ms max_latency: 7.30 ms avg_latency: 7.30 ms lock_latency: 227.00 us rows_sent: 239 rows_sent_avg: 239 rows_examined: 717 rows_examined_avg: 717 rows_affected: 0 rows_affected_avg: 0 tmp_tables: 1 tmp_disk_tables: 0 rows_sorted: 239 sort_merge_passes: 0 digest: efcfa3ca13fb4b885768af2dd7c1971e first_seen: 2017-12-05 06:51:41 last_seen: 2017-12-05 06:51:41 データ数:239行 7.30ミリ秒 (Default:239行) データ数:23,900,000行 (SIZE: 7GB) query: SELECT `world` . `Continent` A ... . `Region` , `world` . `Name` db: world full_scan: * exec_count: 1 err_count: 0 warn_count: 0 total_latency: 47.30 s max_latency: 47.30 s avg_latency: 47.30 s lock_latency: 192.00 us rows_sent: 239 rows_sent_avg: 239 rows_examined: 23900000 rows_examined_avg: 23900000 rows_affected: 0 rows_affected_avg: 0 tmp_tables: 1 tmp_disk_tables: 0 rows_sorted: 239 sort_merge_passes: 0 digest: 038c9177ef6ba734d671a1e219d92fbd first_seen: 2017-12-12 05:10:02 last_seen: 2017-12-12 05:10:02 47.30秒 (データを100,000倍に)
  8. 8. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 8 データが肥大化した場合 MySQLでの対応方法は?
  9. 9. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 9 query: SELECT `world` . `Continent` A ... . `Region` , `world` . `Name` db: world full_scan: exec_count: 1 err_count: 0 warn_count: 0 total_latency: 567.18 ms max_latency: 567.18 ms avg_latency: 567.18 ms lock_latency: 236.00 us rows_sent: 3 rows_sent_avg: 3 rows_examined: 300006 rows_examined_avg: 300006 rows_affected: 0 rows_affected_avg: 0 tmp_tables: 1 tmp_disk_tables: 0 rows_sorted: 3 sort_merge_passes: 0 digest: d06c55a3c07e4a196e5585de198e173d first_seen: 2017-12-07 09:34:22 last_seen: 2017-12-07 09:34:22 567.18ミリ秒 Indexで1%程度のデータまでフィルターすると、 処理が高速化される為、1秒以下の処理に抑えられ ている。必要に応じて、日付、製品カテゴリー、 地域等様々なデータにインデックス付けして高速化。 例) “code like ‘J%’ “で特定のコードにフィルター INDEXを利用出来る処理に変更
  10. 10. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 10 パーティションの検討(参照:テーブル全体) query: SELECT `world` . `Continent` A ... . `Region` , `world` . `Name` db: world full_scan: * exec_count: 1 err_count: 0 warn_count: 0 total_latency: 46.90 s max_latency: 46.90 s avg_latency: 46.90 s lock_latency: 234.00 us rows_sent: 239 rows_sent_avg: 239 rows_examined: 23900000 rows_examined_avg: 23900000 rows_affected: 0 rows_affected_avg: 0 tmp_tables: 1 tmp_disk_tables: 0 rows_sorted: 239 sort_merge_passes: 0 digest: 7ad6bdd420bf52f1353af57082806771 first_seen: 2017-12-13 11:15:42 last_seen: 2017-12-13 11:15:42 46.90秒 mysql> show create table m57_Partition¥G ******************** 1. row ******************** <SNIP> ) ENGINE=InnoDB DEFAULT CHARSET=latin1 /*!50100 PARTITION BY LINEAR KEY (Continent) PARTITIONS 7 */ [oracle@benchmark01-mysql-1 ~]$ ls /u01/data/mysql/world/m57_Pa* /u01/data/mysql/world/m57_Partition.frm /u01/data/mysql/world/m57_Partition#P#p2.ibd /u01/data/mysql/world/m57_Partition#P#p5.ibd /u01/data/mysql/world/m57_Partition#P#p0.ibd /u01/data/mysql/world/m57_Partition#P#p3.ibd /u01/data/mysql/world/m57_Partition#P#p6.ibd /u01/data/mysql/world/m57_Partition#P#p1.ibd /u01/data/mysql/world/m57_Partition#P#p4.ibd [oracle@benchmark01-mysql-1 ~]$
  11. 11. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 11 mysql> explain select * from m57_Partition where Region = 'Southern and Central Asia'¥G *********************** 1. row *********************** id: 1 select_type: SIMPLE table: m57_Partition partitions: p1 type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 1631508 filtered: 10.00 Extra: Using where 1.10 秒 query: SELECT COUNT ( * ) FROM `m57_Partition` WHERE `Region` = ? db: world full_scan: * exec_count: 1 err_count: 0 warn_count: 0 total_latency: 1.10 s max_latency: 1.10 s avg_latency: 1.10 s lock_latency: 178.00 us rows_sent: 1 rows_sent_avg: 1 rows_examined: 1399972 rows_examined_avg: 1399972 rows_affected: 0 rows_affected_avg: 0 tmp_tables: 0 tmp_disk_tables: 0 rows_sorted: 0 sort_merge_passes: 0 digest: 64796ebd7962cf62aefa0cc38c7ae705 first_seen: 2017-12-12 14:01:46 last_seen: 2017-12-12 14:01:46 パーティションの検討(参照:特定パーティション) PARTITION BY LIST COLUMNS(Region) ( PARTITION p0 VALUES IN ('Caribbean'), PARTITION p1 VALUES IN ('Southern and Central Asia'), PARTITION p2 VALUES IN ('Central Africa'), NOTE: この例では,PK及びINDEXをテーブルに対して作成していません。 PKを作成する場合は、パーティション対象列を含めてPKを作成して下さい。
  12. 12. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 12 mysql> show create table m57_Archive¥G <SNIP> ) ENGINE=ARCHIVE DEFAULT CHARSET=latin1 query: SELECT `world` . `Continent` A ... . `Region` , `world` . `Name` db: world full_scan: * exec_count: 1 err_count: 0 warn_count: 0 total_latency: 48.69 s max_latency: 48.69 s avg_latency: 48.69 s lock_latency: 203.00 us rows_sent: 239 rows_sent_avg: 239 rows_examined: 23900000 rows_examined_avg: 23900000 rows_affected: 0 rows_affected_avg: 0 tmp_tables: 1 tmp_disk_tables: 0 rows_sorted: 239 sort_merge_passes: 0 digest: ede232d47ba72910b39d38c0f33483e8 first_seen: 2017-12-12 05:20:39 last_seen: 2017-12-12 05:20:39 48.69秒 Archiveストレージエンジンを検討(テーブル全体) +--------------+----------------+---------+-----------+ | TABLE_SCHEMA | table_name | engine | ToTal(MB) | +--------------+----------------+---------+-----------+ | world | m57_InnoDB | InnoDB | 6972 | | world | m57_Archive | ARCHIVE | 65 | +--------------+----------------+---------+-----------+ NOTE: 1) Archiveでもパーティションを利用可能です。 (※ MySQL8.0からはInnoDBのみ) 2) InnoDBの場合は、以下のように圧縮する事が可能。 ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPRESSED データは, Default 16Kから8Kに圧縮され、データサイズは約1/2程度になります。 InnoDB 23,900,000行 SIZE:7GB Archive 23,900,000行 SIZE:65MB
  13. 13. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 13 MySQL8.0以降の留意事項 データサイズが大きく、インデックスの最適化が出来無い場合、 Partitionは選択肢の一つとして、便利な機能でしたが、 MySQL8.0からは、partitionストレージエンジンが無くなります。 代わりに、MySQL5.7からサポートされている、 InnoDB Native Partitionを利用頂く事になります。 Archiveストレージエンジン同様の圧縮をかけたい場合や InnoDB Buffer Poolを最適に利用したい場合は、OSがサポート すれば、Punch Holeが良い選択肢になるかと思います。 WL#6035: Add native partitioning support to InnoDB https://dev.mysql.com/worklog/task/?id=6035 WL#8971: Deprecate and remove partitioning storage engine https://dev.mysql.com/worklog/task/?id=8971 WL#7696: InnoDB: Transparent page compression https://dev.mysql.com/worklog/task/?id=7696 mysql> select @@version; +-----------+ | @@version | +-----------+ | 8.0.1-dmr | +-----------+ +--------------------+---------+----------+ | Name | Version | Status | +--------------------+---------+----------+ | binlog | 1.0 | ACTIVE | | CSV | 1.0 | ACTIVE | | MEMORY | 1.0 | ACTIVE | | InnoDB | 8.0 | ACTIVE | | MyISAM | 1.0 | ACTIVE | | MRG_MYISAM | 1.0 | ACTIVE | | PERFORMANCE_SCHEMA | 0.1 | ACTIVE | | ARCHIVE | 3.0 | ACTIVE | | BLACKHOLE | 1.0 | ACTIVE | | FEDERATED | 1.0 | DISABLED | +--------------------+---------+----------+

×