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 29565 게시물 읽기
No. 29565
join 속도 문제
작성자
박종선(kokuma)
작성일
2010-03-04 18:49
조회수
6,867

테이블 두개를 join 하는데 너무 시간이 결러서 문의 드립니다.

속도를 어떻게 빠르게 할 방법이 없을까요?

 

==========================================
첫 번째 테이블 스키마
==========================================
CREATE TABLE w_60_fixed (
  stid int(11) NOT NULL DEFAULT '0',
  utime int(11) NOT NULL DEFAULT '0',
  year int(11) NOT NULL DEFAULT '0',
  day int(11) NOT NULL DEFAULT '0',
  tod int(11) NOT NULL DEFAULT '0',
  airtemp double(16,4) NOT NULL DEFAULT '0.0000',
  rh double(16,4) NOT NULL DEFAULT '0.0000',
  gndtemp double(16,4) NOT NULL DEFAULT '0.0000',
  rad double(16,4) NOT NULL DEFAULT '0.0000',
  rain double(16,4) NOT NULL DEFAULT '0.0000',
  wet1 double(16,4) NOT NULL DEFAULT '0.0000',
  wet2 double(16,4) NOT NULL DEFAULT '0.0000',
  wspd double(16,4) NOT NULL DEFAULT '0.0000',
  wdir double(16,4) NOT NULL DEFAULT '0.0000',
  sdwdir double(16,4) NOT NULL DEFAULT '0.0000',
  rain05 double(16,4) NOT NULL DEFAULT '0.0000',
  rain_day double(16,4) NOT NULL DEFAULT '0.0000',
  rain05_day double(16,4) NOT NULL DEFAULT '0.0000',
  sundur double(16,4) NOT NULL DEFAULT '0.0000',
  PRIMARY KEY (stid,utime)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

==========================================
두 번째 테이블 스키마
==========================================
CREATE TABLE w_60_org (
  stid int(11) NOT NULL DEFAULT '0',
  utime int(11) NOT NULL DEFAULT '0',
  year int(11) NOT NULL DEFAULT '0',
  day int(11) NOT NULL DEFAULT '0',
  tod int(11) NOT NULL DEFAULT '0',
  airtemp double(16,4) NOT NULL DEFAULT '0.0000',
  rh double(16,4) NOT NULL DEFAULT '0.0000',
  gndtemp double(16,4) NOT NULL DEFAULT '0.0000',
  rad double(16,4) NOT NULL DEFAULT '0.0000',
  rain double(16,4) NOT NULL DEFAULT '0.0000',
  wet1 double(16,4) NOT NULL DEFAULT '0.0000',
  wet2 double(16,4) NOT NULL DEFAULT '0.0000',
  wspd double(16,4) NOT NULL DEFAULT '0.0000',
  wdir double(16,4) NOT NULL DEFAULT '0.0000',
  sdwdir double(16,4) NOT NULL DEFAULT '0.0000',
  rain05 double(16,4) NOT NULL DEFAULT '0.0000',
  rain_day double(16,4) NOT NULL DEFAULT '0.0000',
  rain05_day double(16,4) NOT NULL DEFAULT '0.0000',
  sundur double(16,4) NOT NULL DEFAULT '0.0000',
  f_airtemp varchar(10) DEFAULT NULL,
  f_rh varchar(10) DEFAULT NULL,
  f_gndtemp varchar(10) DEFAULT NULL,
  f_rad varchar(10) DEFAULT NULL,
  f_rain varchar(10) DEFAULT NULL,
  f_wet1 varchar(10) DEFAULT NULL,
  f_wet2 varchar(10) DEFAULT NULL,
  f_wspd varchar(10) DEFAULT NULL,
  f_wdir varchar(10) DEFAULT NULL,
  f_sdwdir varchar(10) DEFAULT NULL,
  f_rain05 varchar(10) DEFAULT NULL,
  f_rain_day varchar(10) DEFAULT NULL,
  f_rain05_day varchar(10) DEFAULT NULL,
  f_sundur varchar(10) DEFAULT NULL,
  PRIMARY KEY (stid,utime)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

 

w_60_fixed  테이블에는 10만건 정도의 row가 있고요.
w_60_org  테이블에는 300만건 정도의 row가 있습니다.

 

===============================================
쿼리문
===============================================
select
    count(1)
from
( select stid,utime,airtemp,rh,gndtemp,rad,rain,wet1,wet2,wspd,wdir,sdwdir,rain05,rain_day,rain05_day,sundur from w_60_fixed where utime BETWEEN 1230735600 AND 1230818400 ) a,
( select stid,utime,airtemp,rh,gndtemp,rad,rain,wet1,wet2,wspd,wdir,sdwdir,rain05,rain_day,rain05_day,sundur from w_60_org where utime BETWEEN 1230735600 AND 1230818400 ) b
where a.stid = b.stid
  and a.utime = b.utime

위 쿼리를 던졌는데 10분이 다 되도록 결과가 안나오네요.

 

===============================================
위 쿼리에 대한 explain 결과
===============================================

id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY               Impossible WHERE noticed after reading const tables
3 DERIVED w_60_org ALL         3340566 Using where
2 DERIVED w_60_fixed ALL         1 Using where

 

===============================================
show index from  w_60_fixed 결과
===============================================

Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
w_60_fixed 0 PRIMARY 1 stid A 0       BTREE  
w_60_fixed 0 PRIMARY 2 utime A 0       BTREE  

 

===============================================
show index from  w_60_org 결과
===============================================

Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
w_60_org 0 PRIMARY 1 stid A 18       BTREE  
w_60_org 0 PRIMARY 2 utime A 3340566       BTREE  

 

의심이 가는건 MySQL Administrator 에서 스키마를 보면 위 두 테이블의 Index length가 0 으로 나온다는 겁니다.
테이블 생성시 PRIMARY KEY 로 잡았는데 왜 Index length 가 0 일까요?
 

속도가 느린 정말 이유를 모르겠습니다.
많은 지도편달 부탁드립니다.

이 글에 대한 댓글이 총 1건 있습니다.

kldp에서도 봤었는데, 어떤 분께서 답변을 달아주신 듯 하더군요 ^^

박현우(lqez)님이 2010-03-05 11:47에 작성한 댓글입니다.
[Top]
No.
제목
작성자
작성일
조회
29568out of memory 문제 질문이요. 급해요. ㅠㅠ 힝~ [2]
이제노
2010-03-08
6969
29567informix--> mysql [1]
ㅇㅇ
2010-03-08
6104
29566InnoDB에는 index 가 안걸리나요? [3]
박종선
2010-03-04
6506
29565join 속도 문제 [1]
박종선
2010-03-04
6867
29564모델링 - 테이블/엔티티 통합에 대해 문의드립니다. [2]
pithecus
2010-03-03
6877
29563mysql 업그레이드 [1]
이하사
2010-02-26
7230
29561한글 입력 문제.
유기양
2010-02-26
7353
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.021초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다