• 우아한 형제들 기술 블로그를 보다가, MySQL, PostgreSQL을 비교하는 글을 보게 되었다.

  • 글에서 더미데이터를 생성하는 방법 및 테이블에 있는 인덱스 크기를 확인하는 방법에 대해서 알게 되었다.

  • 실제로 많은 테스트를 해보려면, 이러한 테스트를 많이 해볼 수록 좋을 것이다.

더미 데이터 생성 방법

-- 테이블 생성
CREATE TABLE USERS (
    id int auto_increment primary key,
    id2 int,
    Name varchar(100),
    Address varchar(512)
);

-- 더미 데이터 생성
INSERT INTO USERS(id2, Name, Address)
SELECT FLOOR(1 + RAND() * 50000000),
A.table_name, A.table_name
FROM information_schema.tables A
CROSS JOIN information_schema.tables B
CROSS JOIN information_schema.tables C
CROSS JOIN information_schema.tables D
limit 10000000;

explain select count(*) from USERS A inner join USERS B ON A.id2=B.id2;
  • 위의 예제는 10000000의 데이터를 생성하는 방법이다.

인덱스 크기를 확인하는 방법

select table_name,index_name,
round(stat_value*16384/1024/1024) size_in_mb
from mysql.innodb_index_stats
  • 위의 예제는 MySQL에서 인덱스 크기를 확인하는 방법이다.

  • innodb_index.stats 라는 통계정보를 저장하는 테이블에서 이를 확인할 수 있다.

참고 문헌

>> Home