이전글에서 생성한 6.6천만건의 데이터를 DB에 넣고 쿼리 테스트를 해본다.
예상되는 결과는 int 형이 압승일것 같은데, 일단 해보자.
실제 데이터가 들어 있는 테이블을 가정하기 위하여
auto increment 를 넣고, 문자열, datetime 과 int type으로 테이블을 생성 하였다.
테이블 스크립트는 다음과 같다.
(일단 인덱스 없이 테스트하고, 추후 인덱스를 추가해서 얼마나 차이나는지를 확인 해보겠다.)
CREATE TABLE `performance_test` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `str100byte` varchar(100) NOT NULL, `date_type_date` datetime NOT NULL, `int_type_date` int(11) unsigned NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
데이터는 2000년 1월 1일 ~ 2001년 1월 1일 까지 데이터를 생성 하였다.
unix time으로는 946684800 ~ 978343199 (GMT +9 기준으로.)
MariaDB [performance_test]> select max(date_type_date), min(date_type_date) from performance_test; +---------------------+---------------------+ | max(date_type_date) | min(date_type_date) | +---------------------+---------------------+ | 2001-01-01 09:59:59 | 2000-01-01 00:00:00 | +---------------------+---------------------+ 1 row in set (2 min 9.18 sec) |
검색기간 : 2001-06-01 ~ 2000-06-30
1. datetime 필드를 이용하여 검색(인덱스 없이)
MariaDB [performance_test]> SELECT SQL_NO_CACHE COUNT(id) -> FROM performance_test -> WHERE date_type_date > '2000-06-01 00:00:00' -> AND date_type_date < '2000-07-01 00:00:00' -> ; +-----------+ | COUNT(id) | +-----------+ | 5399995 | +-----------+ 1 row in set (2 min 12.10 sec) MariaDB [performance_test]> |
2. unixtime 필드를 이용하여 검색(인덱스 없이)
MariaDB [performance_test]> SELECT SQL_NO_CACHE COUNT(id) -> FROM performance_test -> WHERE int_type_date > UNIX_TIMESTAMP('2000-06-01 00:00:00') -> AND int_type_date < UNIX_TIMESTAMP('2000-07-01 00:00:00') -> ; +-----------+ | COUNT(id) | +-----------+ | 5400000 | +-----------+ 1 row in set (2 min 11.18 sec) MariaDB [performance_test]> |
어라.. 큰차이가 없다. (갯수가 다른것은 실은 조건식이 조금 잘못 됫다.^^)
[ 인덱스 추가 ]
MariaDB [performance_test]> ALTER TABLE `performance_test` -> ADD INDEX `date_type_date` (`date_type_date`), -> ADD INDEX `int_type_date` (`int_type_date`); Stage: 1 of 1 'altering table' 99.8% of stage done Query OK, 0 rows affected (13 min 3.47 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [performance_test]> |
데이터가 많긴 많데, 필드 2개를 인덱싱하는데 13분이나..
어찌됫것.. 다시 테스트..
3. date 필드를 이용하여 검색 (인덱스 사용)
MariaDB [performance_test]> SELECT SQL_NO_CACHE COUNT(id) -> FROM performance_test -> WHERE date_type_date > '2000-06-01 00:00:00' -> AND date_type_date < '2000-07-01 00:00:00' -> ; +-----------+ | COUNT(id) | +-----------+ | 5399995 | +-----------+ 1 row in set (1.79 sec) MariaDB [performance_test]> |
4. unixtime 필드를 이용하여 검색 (인덱스 사용)
MariaDB [performance_test]> SELECT SQL_NO_CACHE COUNT(id) -> FROM performance_test -> WHERE int_type_date > UNIX_TIMESTAMP('2000-06-01 00:00:00') -> AND int_type_date < UNIX_TIMESTAMP('2000-07-01 00:00:00') -> ; +-----------+ | COUNT(id) | +-----------+ | 5400000 | +-----------+ 1 row in set (1.30 sec) MariaDB [performance_test]> |
날짜형으로 비교 했을때는 1.7초대,
숫자형으로 비교 했을때는 1.3초대. 약 0.4초 정도의 차이를 갖고 있다.
int 가 약 23%정도의 속도 향상이 있다.
좀 더 많은 데이터를 넣었을때 동일한 비율로 높아지는지 한번더 확인 해봐야 겟다.
최종결론은 1.5억건을 넣고 비교한 후 결론을 정리 하도록 하겠다.
2018/02/27 - [DBMS/MySQL] - MySQL InnoDB DATETIME vs Unixtime (int type) #1
2018/02/27 - [DBMS/MySQL] - MySQL InnoDB DATETIME vs Unixtime (int type) #2 <
2018/02/27 - [DBMS/MySQL] - MySQL InnoDB DATETIME vs Unixtime (int type) #3 (1.5억건)
2018/02/27 - [DBMS/MySQL] - MySQL InnoDB DATETIME vs Unixtime (결론) #4
'DBMS > MySQL' 카테고리의 다른 글
MySQL InnoDB DATETIME vs Unixtime (결론) #4 (1) | 2018.02.27 |
---|---|
MySQL InnoDB DATETIME vs Unixtime (int type) #3 (1.5억건) (0) | 2018.02.27 |
MySQL InnoDB DATETIME vs Unixtime (int type) #1 (0) | 2018.02.27 |
MariaDB/Galera Cluster 기술 노트!! (0) | 2015.04.16 |
Haproxy로 .mysql 서비스까지 확인하도록 xinet 사용 (0) | 2015.04.16 |