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
운영게시판
최근게시물
PostgreSQL Q&A 8520 게시물 읽기
No. 8520
아래 쿼리의 EXPLAIN.
작성자
이기자(k3i2)
작성일
2009-10-08 12:08
조회수
7,238

혹시 이거말씀하신건가요?


"Nested Loop Left Join  (cost=0.00..34045933.70 rows=39 width=143)"
"  ->  Seq Scan on t_sugangsave_gita a  (cost=0.00..34031887.45 rows=39 width=129)"
"        Filter: (((mid)::text = 'scall'::text) AND ((((subplan) >= '20090101'::text) AND ((subplan) <= '20091010'::text)) OR (((subplan) >= '20090101'::text) AND ((subplan) <= '20091010'::text))) AND (((subplan) = 'D6'::text) OR ((subplan) = 'D96'::text)))"
"        SubPlan"
"          ->  Aggregate  (cost=905.65..905.66 rows=1 width=6)"
"                ->  Index Scan using t_sugangsave_pkey on t_sugangsave s3  (cost=0.00..905.65 rows=1 width=6)"
"                      Index Cond: (((mid)::text = ($0)::text) AND ((yb)::text = ($2)::text))"
"                      Filter: (((COALESCE(cancel, ''::character varying))::text <> 'Y'::text) AND (((m_jjdc)::text = 'D6'::text) OR ((m_jjdc)::text = 'D96'::text)))"
"          ->  Aggregate  (cost=905.65..905.66 rows=1 width=6)"
"                ->  Index Scan using t_sugangsave_pkey on t_sugangsave s3  (cost=0.00..905.65 rows=1 width=6)"
"                      Index Cond: (((mid)::text = ($0)::text) AND ((yb)::text = ($2)::text))"
"                      Filter: (((COALESCE(cancel, ''::character varying))::text <> 'Y'::text) AND (((m_jjdc)::text = 'D6'::text) OR ((m_jjdc)::text = 'D96'::text)))"
"          ->  Aggregate  (cost=4.34..4.35 rows=1 width=12)"
"                ->  Index Scan using t_sugangsave_pkey on t_sugangsave b  (cost=0.00..4.33 rows=1 width=12)"
"                      Index Cond: (((mid)::text = ($0)::text) AND (stu_c = $1) AND ((yb)::text = ($2)::text))"
"          ->  Aggregate  (cost=4.34..4.35 rows=1 width=12)"
"                ->  Index Scan using t_sugangsave_pkey on t_sugangsave b  (cost=0.00..4.33 rows=1 width=12)"
"                      Index Cond: (((mid)::text = ($0)::text) AND (stu_c = $1) AND ((yb)::text = ($2)::text))"
"          ->  Aggregate  (cost=4.34..4.35 rows=1 width=12)"
"                ->  Index Scan using t_sugangsave_pkey on t_sugangsave b  (cost=0.00..4.33 rows=1 width=12)"
"                      Index Cond: (((mid)::text = ($0)::text) AND (stu_c = $1) AND ((yb)::text = ($2)::text))"
"          ->  Aggregate  (cost=4.34..4.35 rows=1 width=12)"
"                ->  Index Scan using t_sugangsave_pkey on t_sugangsave b  (cost=0.00..4.33 rows=1 width=12)"
"                      Index Cond: (((mid)::text = ($0)::text) AND (stu_c = $1) AND ((yb)::text = ($2)::text))"
"  ->  Index Scan using t_student_pkey on t_student st  (cost=0.00..351.37 rows=1 width=31)"
"        Index Cond: (((st.mid)::text = 'scall'::text) AND (st.stu_c = "outer".stu_c))"
"  SubPlan"
"    ->  Aggregate  (cost=4.34..4.35 rows=1 width=12)"
"          ->  Index Scan using t_sugangsave_pkey on t_sugangsave b  (cost=0.00..4.33 rows=1 width=12)"
"                Index Cond: (((mid)::text = ($0)::text) AND (stu_c = $1) AND ((yb)::text = ($2)::text))"
"    ->  Aggregate  (cost=4.34..4.35 rows=1 width=12)"
"          ->  Index Scan using t_sugangsave_pkey on t_sugangsave b  (cost=0.00..4.33 rows=1 width=12)"
"                Index Cond: (((mid)::text = ($0)::text) AND (stu_c = $1) AND ((yb)::text = ($2)::text))"



//------- 쿼리입니다. 속도때문에 대분류,중분류는 빼고 과목만 조건절에 넣었습니다. -------------------------------------------------------------------------///
EXPLAIN SELECT a.stu_c,
   '수강생명' AS stu_n,
   (substring(a.yb,1,4)||'-'||substring(a.yb,5,4))as yb,
   case length(coalesce(st.ptel,''))
    when 11 then (substr(st.ptel,1,3)||'-'||substr(st.ptel,4,4)||'-'||'0000')
    when 10 then (substr(st.ptel,1,3)||'-'||substr(st.ptel,4,3)||'-'||'0000')
    when 8 then (substr(st.ptel,1,4)||'-'||'0000')
    when 7 then (substr(st.ptel,1,3)||'-'||'0000')
    else '' end as tel,
   coalesce(a.so_j,0)+ coalesce(a.so_d,0)as geum,
   a.deung_day,
   (case coalesce(a.msin_text,'')when''then''else'종합:'||a.msin_text end ||
    case coalesce(a.dan_sin_text,'')when''then''else' 단과:'||a.dan_sin_text end)as disp_sin,
   (select min(b.dan_date1) from t_sugangsave b
    where b.mid=a.mid and b.stu_c=a.stu_c and b.yb=a.yb)as gigan,
    (select max(b.dan_date2) from t_sugangsave b
    where b.mid=a.mid and b.stu_c=a.stu_c and b.yb=a.yb)as gigan2,
   case coalesce(a.j_jjdn,'')when''then'단과'else
    case coalesce(a.dan_sin_text,'')when''then a.j_jjdn else '단과/'|| a.j_jjdn end end as j_jjdn,
   0 as chk
    FROM t_sugangsave_gita a left outer join
   t_student st on st.mid=a.mid and st.stu_c=a.stu_c
 Where a.mid='scall' and
   ( ((select min(b.dan_date1) from t_sugangsave b
     where b.mid=a.mid and b.stu_c=a.stu_c and b.yb=a.yb) between '20090101' and '20091010') or
     ((select min(b.dan_date2) from t_sugangsave b
     where b.mid=a.mid and b.stu_c=a.stu_c and b.yb=a.yb) between '20090101' and '20091010')) and

   ((select max(s3.m_jjdc) from t_sugangsave s3 
          where s3.mid=a.mid and s3.yb=a.yb and
            coalesce(s3.cancel,'')<>'Y' and s3.m_jjdc in('D6','D96'))in('D6','D96'));  <-- 속도때문에 과목도 두개코드만 했음.



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

관련 테이블의 pk 및 다른 인덱스 구성도 알려주세요. :)

SHK(rusion)님이 2009-10-08 13:32에 작성한 댓글입니다.

인덱스는 없고,

t_sugangsave 의 Pkey 는 mid, stu_c, yb, g_jjdc, gubun, j_jjdc, m_jjdc 이고,

t_sugangsave_gita 의 Pkey 는 mid, yb 이고,

t_student  의 Pkey 는 mid, saupjangc, stu_c 입니다.

이기자님이 2009-10-08 14:01에 작성한 댓글입니다. Edit

g_jjdc, m_jjdc, j_jjdc 컬럼에 각각 인덱스를 생성하고
다시 시도해 보세요.

복합인덱스 말고, 단독으로 ~_~

그래도 느리면 그 explain 을 떠서 올려주세요.

SHK(rusion)님이 2009-10-08 14:42에 작성한 댓글입니다.
[Top]
No.
제목
작성자
작성일
조회
8523윈도우즈에서 postgresql 설치 메뉴얼은? [1]
박병호
2009-10-09
7687
8522속도 [2]
eee
2009-10-09
7107
8521아래 쿼리 속도 문제.. [4]
이기자
2009-10-08
7510
8520아래 쿼리의 EXPLAIN. [3]
이기자
2009-10-08
7238
8519쿼리문좀 봐주세요 T.T 거북이 보다 더 느립니다. [3]
이기자
2009-10-08
7602
8518연달아서 질문입니다 ㅡ,.ㅡ [1]
초보자
2009-10-06
6728
8517PostgreSQL 초보적인 질문입니다.. [2]
초보자
2009-10-06
10817
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.021초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다