database.sarang.net
UserID
Passwd
Database
DBMS
ㆍMySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
MySQL Q&A 31027 게시물 읽기
No. 31027
index 질문입니다.
작성자
원형이정
작성일
2017-02-22 19:05
조회수
6,048
 create table login_history (
 
idx BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT ,
 
user_id varchar(50) not null default '',
 
user_type varchar(10) not null,
 
regDate datetime not null,
 
loginDate datetime not null,
 
devKey char(1) not null default '0',
 
primary key (idx)
 
index `devKey_userType_regDate` (`devKey`, `user_type`, `regDate`),
 
index `devKey_userType_loginDate` (`devKey`, `user_type`, `loginDate`)
 
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;
 
 
테이블 구성은 이렇게 되어있습니다. 데이터는 약 6,000,000건 정도 있습니다.
 
user_type 컬럼에는 A ~ D 의 4가지 값이 전체 데이터의 4분의 1 정도씩 균일하게 들어가 있습니다. (type 당 이백만건정도씩)
 
devKey 컬럼에는 0 값은 전체데이터의 99% 정도 들어있고, 1 값이 1% 정도 들어 있습니다.
 
user_id 는 중복된 값이 들어갈수 있으므로 유니크한 카운트를 구하려면 distinct 를 해야합니다.
 
주로 조회 하는 쿼리는 아래와 같습니다.
 
1. select count(distinct(user_id)) from login_history where devKey = 0 and user_type = 'A' and regDate between '2017-02-01 00:00:00' and '2017-02-22 23:59:59'
 
2. select count(distinct(user_id)) from login_history where devKey = 0 and user_type = 'B' and loginDate between '2017-02-01 00:00:00' and '2017-02-22 23:59:59'
 
3. select count(distinct(user_id)) from login_history where devKey = 0 and regDate <= '2017-02-22 23:59:59'
 
1번을 조회하면 devKey_userType_regDate 인덱스가 설정되어 적절한 속도가 나오는데요
 
2번을 조회하면 devKey_userType_regDate 와 devKey_userType_loginDate 가 같이 적용 되는군요..
 
위와 같이 3개의 쿼리를 사용하고, 테이블 스키마가 위와 같다면 어떻게 인덱스를 설정하는게 좋은지 조언 구합니다.
 
 
 
 
 
 
[Top]
No.
제목
작성자
작성일
조회
31030MHA 구성 중 에러 발생
MHA
2017-03-01
6272
31029mysql c++ 연동 관련 질문입니다.
코딩코딩
2017-02-28
6050
31028longblob필드백업 및 복구 [1]
이청하
2017-02-25
5760
31027index 질문입니다.
원형이정
2017-02-22
6048
31026mysql 접속이 안되는데 어떤것들을 확인해봐야 될까요? [4]
김지철
2017-02-22
6058
31025저장 프로시저 관련 문의입니다.
김태호
2017-02-17
5970
31023root가 아닌계정이 모든정보를 볼수 있는방법이 있을까요 ?
이상준
2017-01-24
7006
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2023 DSN, All rights reserved.
작업시간: 0.050초, 이곳 서비스는
	PostgreSQL v16.1로 자료를 관리합니다