5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Aurora@MySQL上のパーティションテーブルでオンラインDDLが効かない

Last updated at Posted at 2018-08-02

※ソースは見つかっていません、わかるいたら情報いただけるとありがたいです。
ソース見つけました、追記参照。

3行でまとめると

  • 10億行オーダーの分析軸が増えたのでインデックスを追加しようとした
  • 一応検証環境で試してみたらオンラインで変更できなかった
  • 細かく検証したら Aurora × パーティション化 がまずいみたい
    • MySQL.5.6.10 × パーティション化 がまずいみたい

実行環境

> select @@aurora_version;
+------------------+
| @@aurora_version |
+------------------+
| 1.14             |
+------------------+

> select @@version;
+-----------+
| @@version |
+-----------+
| 5.6.10    |
+-----------+

何が起きたか

Aurora@MySQL上でパーティション化テーブルのインデックス作成がオンラインでできなかった。
もうちょっと言うと lock = none での更新ができないみたい。

対象テーブル
CREATE TABLE `test1` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `userId` int(11) NOT NULL,
  `value` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`,`userId`)
) ENGINE=InnoDB
PARTITION BY HASH (userId)
PARTITIONS 4;
インデックス追加
-- ※実際には数億行入れたから実行したと思ってください。
create index ix_value on test1(value);

-- →流したらシステムが止まったと怒られた(。>﹏<。)
試しにロックなしを明示して実行
create index ix_value on test1(value) lock = none;

-- → ERROR 1845 (0A000): LOCK=NONE is not supported for this operation. Try LOCK=SHARED.

オンラインDDL

オンライン DDL の概要

MySQL5.6から create index の実行がロックなしでできるようになったはず。
実際にEC2で立てたMySQL上ではちゃんと稼働する。

EC2上のMySQL5.6
> select @@version;
+------------+
| @@version  |
+------------+
| 5.6.28-log |
+------------+

> create index ix_value on test1(value) lock = none;
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0

パーティションなし

パーティション化していないテーブルではDDLの実行は可能だった。
元々こちらは確認していたのでオンラインで実行可能と高をくくったら痛い目見ました(´・ω・`)

-- パーティションだけ定義されてない別のテーブル
CREATE TABLE `test2` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `userId` int(11) NOT NULL,
  `value` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`,`userId`)
) ENGINE=InnoDB;

> create index ix_value on test2(value) lock = none;
Query OK, 0 rows affected (0.06 sec)
Records: 0  Duplicates: 0  Warnings: 0

結局

数時間がかりのメンテでなんとかしました(゜-゜)
同じような構成作ってる人は注意しましょう。


原因

2019/07/01追記

Changes in MySQL 5.6.11 (2013-04-18, General Availability)

  • Partitioning: ALGORITHM = INPLACE, which was disallowed in MySQL 5.6.10 for DDL statements operating on partitioned tables, can once again be used with such statements. (Bug #16216513)

パーティションテーブルでオンラインDDLが5.6.10まで効かないのはMySQLのバグだったとのこと。
試しにAmazon Linux - MySQL5.6.10 で lock = none やってみたら怒られれました_(:3」∠)_
5.6系のauroraは5.6.10なので5.7系に上げるしか対処できないのだろうか(´-﹏-`;)

5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?