7
col3 に関しては下記 SQLで a から j までの 5 文字の組合わせデータを 38098 通り作成した。
update test set col3 = 'aaaaa' where mod(id,10) = truncate(rand()*10,0);
update test set col3 = 'bbbbb' where mod(id,10) = truncate(rand()*10,0);
update test set col3 = 'ccccc' where mod(id,10) = truncate(rand()*10,0);
update test set col3 = 'ddddd' where mod(id,10) = truncate(rand()*10,0);
update test set col3 = 'eeeee' where mod(id,10) = truncate(rand()*10,0);
update test set col3 = 'fffff' where mod(id,10) = truncate(rand()*10,0);
update test set col3 = 'ggggg' where mod(id,10) = truncate(rand()*10,0);
update test set col3 = 'hhhhh' where mod(id,10) = truncate(rand()*10,0);
update test set col3 = 'iiiii' where mod(id,10) = truncate(rand()*10,0);
update test set col3 = 'jjjjj' where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,1),'a'),substr(col3,3,3)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,1),'b'),substr(col3,3,3)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,1),'c'),substr(col3,3,3)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,1),'d'),substr(col3,3,3)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,1),'e'),substr(col3,3,3)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,1),'f'),substr(col3,3,3)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,1),'g'),substr(col3,3,3)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,1),'h'),substr(col3,3,3)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,1),'i'),substr(col3,3,3)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,1),'j'),substr(col3,3,3)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,2),'a'),substr(col3,4,2)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,2),'b'),substr(col3,4,2)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,2),'c'),substr(col3,4,2)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,2),'d'),substr(col3,4,2)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,2),'e'),substr(col3,4,2)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,2),'f'),substr(col3,4,2)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,2),'g'),substr(col3,4,2)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,2),'h'),substr(col3,4,2)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,2),'i'),substr(col3,4,2)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,2),'j'),substr(col3,4,2)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,3),'a'),substr(col3,5,1)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,3),'b'),substr(col3,5,1)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,3),'c'),substr(col3,5,1)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,3),'d'),substr(col3,5,1)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,3),'e'),substr(col3,5,1)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,3),'f'),substr(col3,5,1)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,3),'g'),substr(col3,5,1)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,3),'h'),substr(col3,5,1)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,3),'i'),substr(col3,5,1)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat(concat (substr(col3,1,3),'j'),substr(col3,5,1)) where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat (substr(col3,1,4),'a') where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat (substr(col3,1,4),'b') where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat (substr(col3,1,4),'c') where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat (substr(col3,1,4),'d') where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat (substr(col3,1,4),'e') where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat (substr(col3,1,4),'f') where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat (substr(col3,1,4),'g') where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat (substr(col3,1,4),'h') where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat (substr(col3,1,4),'i') where mod(id,10) = truncate(rand()*10,0);
update test set col3 = concat (substr(col3,1,4),'j') where mod(id,10) = truncate(rand()*10,0);
8.
8
4-3 性能検証
下記 SQLを実行し、ICP、非 ICP で検索された結果を用いてを検証比較した。col3 の「?」は a から
任意の値を設定した。又、col1=8 で合致するデータ数(今回の母数)は前述のデータ分布から 100776
件となる。
上記 SQL を実行した際に ICP、非 ICP で出力される実行計画は全て以下となる。
ICP
非 ICP
SQL 実行前に innodb 用のバッファーキャッシュ、OS のページキャッシュを下記コマンドにてクリア
し各 SQL 実行時にキャッシュデータが無い状態で実行した。
select * from test where col1 = 8 and col3 like ‘%?%’;
# service mysql restart
# sync
# sysctl –w vm.drop_caches=3
# sysctl –w vm.drop_caches=0
id: 1
select_type: SIMPLE
table: test
type: ref
possible_keys: multi_idx1
key: multi_idx1
key_len: 5
ref: const
rows: 244860
Extra: Using index condition
id: 1
select_type: SIMPLE
table: test
type: ref
possible_keys: multi_idx1
key: multi_idx1
key_len: 5
ref: const
rows: 244860
Extra: Using where