28. Global Transaction ID
●
トランザクションを一意に識別することができる ID
– UUID: トランザクション ID の形式で表現される
– 例) 095E0FF8-18AF-11E2-9E7C-5C260A2AA986:123456
●
トランザクション ID はシーケンス
– 1:N 環境で、どのスレーブが最も進んでいるか一目
瞭然!
● MASTER_AUTO_POSITION = 1
29. Global Transaction ID (つづき)
mysql> show binlog events in 'mysql-bin.000002'G
〜 省略 〜
*************************** 3. row ***************************
Log_name: mysql-bin.000002
Pos: 151
Event_type: Gtid
Server_id: 1
End_log_pos: 199
Info: SET @@SESSION.GTID_NEXT= '095E0FF8-18AF-11E2-9E7C-
5C260A2AA986:1'
〜 省略 〜
30. Global Transaction ID (つづき)
mysql> SHOW SLAVE STATUSG
*************************** 1. row ***************************
〜 略 〜
Master_UUID: 095e0ff8-18af-11e2-9e7c-5c260a2aa986
Master_Info_File: /path/to/datadir/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O
thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 095E0FF8-18AF-11E2-9E7C-5C260A2AA986:1
Executed_Gtid_Set: 095E0FF8-18AF-11E2-9E7C-5C260A2AA986:1
1 row in set (0.00 sec)
34. mysqlfailover サンプル
shell> mysqlfailover --master=root:msandbox@127.0.0.1:13032
--slaves=root:msandbox@127.0.0.1:13033,root:msandbox@127.0.0.1:13034
MySQL Replication Failover Utility
Failover Mode = auto Next Interval = Thu Oct 18 22:42:14 2012
Master Information
------------------
Binary Log File Position Binlog_Do_DB Binlog_Ignore_DB
mysql-bin.000006 191
Replication Health Status
+------------+--------+---------+--------+------------+---------+
| host | port | role | state | gtid_mode | health |
+------------+--------+---------+--------+------------+---------+
| 127.0.0.1 | 13032 | MASTER | UP | ON | OK |
| 127.0.0.1 | 13033 | SLAVE | UP | ON | OK |
| 127.0.0.1 | 13034 | SLAVE | UP | ON | OK |
+------------+--------+---------+--------+------------+---------+
35. mysqlfailover フェイルオーバー
MySQL Replication Failover Utility
Failover Mode = auto Next Interval = Thu Oct 18 22:43:31 2012
Master Information
------------------
Binary Log File Position Binlog_Do_DB Binlog_Ignore_DB
mysql-bin.000003 621
Replication Health Status
+------------+--------+---------+--------+------------+---------+
| host | port | role | state | gtid_mode | health |
+------------+--------+---------+--------+------------+---------+
| 127.0.0.1 | 13033 | MASTER | UP | ON | OK |
| 127.0.0.1 | 13034 | SLAVE | UP | ON | OK |
+------------+--------+---------+--------+------------+---------+
Q-quit R-refresh H-health G-GTID Lists U-UUIDs
45. デッドロックのログサンプル
InnoDB: transactions deadlock detected, dumping detailed information.
121018 2:28:28
*** (1) TRANSACTION:
TRANSACTION 6426, ACTIVE 16 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 376, 2 row lock(s), undo log entries 1
MySQL thread id 1, OS thread handle 0x7f126453c700, query id 53 localhost msandbox updating
update t set b='sss' where a=1
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 6 page no 3 n bits 72 index `PRIMARY` of table `test`.`t` trx id 6426
lock_mode X locks rec but not gap waiting
Record lock, heap no 2 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 4; hex 00000001; asc ;;
1: len 6; hex 000000001917; asc ;;
2: len 7; hex 13000001890110; asc ;;
3: len 3; hex 747474; asc ttt;;
*** (2) TRANSACTION:
TRANSACTION 6423, ACTIVE 65 sec starting index read
46. CPU スケーラビリティの向上
●
MySQL Connect のキーノートスピーチで言及された数値
– R/W sysbench … MySQL 5.5 比で 151% 改善!
– Read Only sysbench … MySQL 5.5 比で 234% 改善!
– http://medianetwork.oracle.com/video/player/1873154739001
●
kernel_mutex における処理の分散
●
リードオンリートランザクション
– 更新の準備が不要なためオーバーヘッドが小さい
● START TRANACTION READ ONLY
●
autocommit=1 における SELECT
50. MySQL 5.6 における
オプティマイザ改善点
● Disk Sweep Multi Range Read (MRR)
● Batched Key Access Join (BKA)
● Index Condition Pushdown (ICP)
●
ORDER BY … LIMIT の効率化
●
サブクエリのアルゴリズム改善
– Semi-Join
– FROM 句のサブクエリの改善
53. 〜 MySQL 5.5
Nested Loop Join
SELECT … FROM t1 JOIN t2 ON … WHERE ...
for each row in t1 matching where condition {
for each row in t2 matching join and where condition {
send joined row to client
}
}
59. ORDER BY … LIMIT の効率化
● SELECT column_list FROM single_table ORDER BY
non_indexed_colum LIMIT n
– というような構造のクエリが速くなる。
– Using sort buffer...
●
従来のアルゴリズム
– すべての結果をソートしてから上位の n 個を返す
●
MySQL 5.6 のアルゴリズム
– ソートバッファに n 個のレコードが確実に格納出来
るとわかっている場合、上位の結果だけをソート
バッファに格納する
– ソートバッファに収まらない場合は従来のアルゴリ
ズム
61. MySQL 5.5 の例 - EXPLAIN
EXPLAIN SELECT COUNT(1) FROM Country WHERE Country.Code IN (SELECT
City.CountryCode FROM City WHERE Name LIKE 'A%')G
*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: Country
type: index
possible_keys: NULL
key: PRIMARY
key_len: 3
ref: NULL
rows: 247
Extra: Using where; Using index
*************************** 2. row ***************************
id: 2
select_type: DEPENDENT SUBQUERY
table: City
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
62. MySQL 5.5 の例 - SELECT
mysql> SELECT COUNT(1) FROM Country WHERE Country.Code IN
(SELECT City.CountryCode FROM City WHERE Name LIKE 'A%')G
*************************** 1. row ***************************
COUNT(1): 71
1 row in set (0.26 sec)
mysql> SHOW STATUS LIKE 'handler_read%';
+-----------------------+--------+
| Variable_name | Value |
+-----------------------+--------+
| Handler_read_first | 240 |
| Handler_read_key | 240 |
| Handler_read_last | 0 |
| Handler_read_next | 239 |
| Handler_read_prev | 0 |
| Handler_read_rnd | 0 |
| Handler_read_rnd_next | 824291 |
63. MySQL 5.6 の例 - EXPLAIN
EXPLAIN SELECT COUNT(1) FROM Country WHERE Country.Code IN (SELECT
City.CountryCode FROM City WHERE Name LIKE 'A%')G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: Country
type: index
possible_keys: PRIMARY
key: PRIMARY
key_len: 3
ref: NULL
rows: 239
Extra: Using where; Using index
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: <subquery2>
type: eq_ref
possible_keys: <auto_key>
・・・つづく
64. MySQL 5.6 の例 - EXPLAIN
つづき
*************************** 3. row ***************************
id: 2
select_type: MATERIALIZED
table: City
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 4188
Extra: Using where
3 rows in set (0.00 sec)
65. MySQL 5.6 の例 - SELECT
mysql> SELECT COUNT(1) FROM Country WHERE Country.Code IN
(SELECT City.CountryCode FROM City WHERE Name LIKE 'A%')G
*************************** 1. row ***************************
COUNT(1): 71
1 row in set (0.00 sec)
mysql> SHOW STATUS LIKE 'handler_read%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| Handler_read_first | 2 |
| Handler_read_key | 241 |
| Handler_read_last | 0 |
| Handler_read_next | 239 |
| Handler_read_prev | 0 |
| Handler_read_rnd | 0 |
| Handler_read_rnd_next | 4080 |