前回 の Infobright の確認で、ひょっとしてクエリーで union する方がいいのではないかと思ったので確認してみた。
クエリー
select
key4,data1,data2,data3
from
t2
where
key1='aaa' and key2='bbb' and key3='ccc' and key4='ddd'
and
data2 >= n1 and data2 < n2
union all
select
key4,data1,data2,data3
from
t2
where
key1='aaa' and key2='bbb' and key3='ccc' and key4='eee'
and
data2 >= n1 and data2 < n2
union all
・・・
order by
key4,data1,data2
;
結果
** 処理時間(秒)**
key4 数 (データ取得数) | 10 (14400) | 20 (28800) | 30 (43200) |
---|---|---|---|
in 指定 (前回) | 1.898 | 3.290 | 4.679 |
union all 指定 | 2.668 | 5.355 | 7.955 |
連結でパフォーマンス低下
ここで、テーブルのつくりをちょっと変えてみる。
テーブル
mysql> show create table t3;
+-------+-------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------+
| t3 | CREATE TABLE `t3` (
`key5` char(200) DEFAULT NULL, <- これまでのkey1+key2+key3+key4
`data1` char(50) DEFAULT NULL,
`data2` int(11) DEFAULT NULL,
`data3` int(11) DEFAULT NULL
) ENGINE=InfiniDB DEFAULT CHARSET=latin1 |
クエリー
(in)
select
key5,data1,data2,data3
from
t3
where
data2 >= n1 and data2 < n2
and
(
id='aaa'
or
id='bbb'
or
・・・
)
order by
key5,data1,data2
;
(union all)
select
key5,data1,data2,data3
from
t3
where
data2 >= n1 and data2 < n2
and
id='aaa'
union all
select
key5,data1,data2,data3
from
t3
where
data2 >= n1 and data2 < n2
and
id='bbb'
・・・
order by
key5,
data1,
data2
;
結果
処理時間(秒)
key5 数 (データ取得数) | 10 (14400) | 20 (28800) | 30 (43200) |
---|---|---|---|
in 指定 | 4.763 | 9.111 | 13.203 |
union all | 2.034 | 4.149 | 6.138 |
連結でパフォーマンス向上
気付き
テーブルのつくり、クエリーの書き方で、大分とパフォーマンス傾向が異なるようだ。
ただ、いずれにしても、InfiniDB で確認したときのようなパフォーマンスは出せていない。