LoginSignup
4
4

More than 5 years have passed since last update.

クエリーで or と in の処理時間差を確認する

Last updated at Posted at 2015-06-29

InfiniDB を使ってみる。
select で or を含む検索をしたときの処理時間パフォーマンスを確認する。

InfiniDB バージョン

$ idbmysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.1.73 InfiniDB 4.6 Beta

テーブル定義

mysql> show create table t1;
+-------+-------------------------------------------------------------+
| Table | Create Table                                                |
+-------+-------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `key1` char(50) DEFAULT NULL,
  `key2` char(50) DEFAULT NULL,
  `key3` char(50) DEFAULT NULL,
  `key4` char(50) DEFAULT NULL,
  `data1` char(50) DEFAULT NULL,
  `data2` int(11) DEFAULT NULL,
  `data3` int(11) DEFAULT NULL
) ENGINE=InfiniDB DEFAULT CHARSET=latin1 |

データ件数

mysql> select count(*) from t1;
+----------+
| count(*) |
+----------+
|  5754240 |
+----------+

※登録データのカーディナリティ
    key1 = 1
    key2 = 1
    key3 = 2
    key4 = 1000
    data1 = 10
    data2 = 2880
    data3 = 1 

クエリー

 key1, 2, 3 は固定
 key4 を or で検索
 key4, data1, data2 で sort (ASC)

(or クエリー)
select
    key4,data1,data2,data3
from
    t1
where
    data2 >= n1 and data2 < n2
and
    key1='aaa'
and
    key2='bbb'
and
    key3='ccc'
and
    (
        key4='ddd'
        or key4='eee'
        ・・・
    )
order by
    key4,data1,data2
;

(in クエリー)
select
    key4,data1,data2,data3
from
    t1
where
    data2 >= n1 and data2 < n2
and
    key1='aaa'
and
    key2='bbb'
and
    key3='ccc'
and
    key4 in (
        'ddd'
       ,'eee'
        ・・・
    )
order by
    key4,data1,data2
;

結果

処理時間(秒)

key4 数 (データ取得数) 10 (14400) 20 (28800) 30 (43200)
or 指定 0.971 1.767 2.561
in 指定 0.190 0.218 0.273
試しに union で 1.322 2.655 3.989

**断然、in 指定が有利!!

**or 指定って、union 並み ?

反省

すっかり油断して、or を使ってた。
どうりで検索スピードが上がらなかったわけです。

リンク

クエリーで or と in の処理時間差を確認する(その2)
クエリーで or と in の処理時間差を確認する (その3)

4
4
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
4
4