//--------------- 인덱스는 아래처럼 생성했습니다. --------------------//
CREATE INDEX t_sale_idx1
ON t_sugangsave
USING btree
(g_jjdc);
CREATE INDEX t_sale_idx2
ON t_sugangsave
USING btree
(j_jjdc);
CREATE INDEX t_sale_idx3
ON t_sugangsave
USING btree
(m_jjdc);
//-------------- 쿼리 입니다. ------------------------------------------------//
//---- 쿼리결과 속도가 훨씬 더걸립니다. T.T ; 결과를 못보고 스톱시킬만큼... -----//
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'));
//---------------- explain analyze 결과 입니다. ---------------------------------------//
//---- 이게 맞나요? DataOutput 과 History가 있던데, DataOutput 부분입니다. --------------//
"Nested Loop Left Join (cost=0.00..34019360.05 rows=39 width=143) (actual time=2539.396..558452.883 rows=1079 loops=1)"
" -> Seq Scan on t_sugangsave_gita a (cost=0.00..34005313.80 rows=39 width=129) (actual time=2536.402..550262.881 rows=1079 loops=1)"
" 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=904.94..904.95 rows=1 width=6) (actual time=17.955..17.956 rows=1 loops=14718)"
" -> Index Scan using t_sugangsave_pkey on t_sugangsave s3 (cost=0.00..904.93 rows=1 width=6) (actual time=17.927..17.943 rows=0 loops=14718)"
" 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=904.94..904.95 rows=1 width=6) (actual time=17.987..17.988 rows=1 loops=15767)"
" -> Index Scan using t_sugangsave_pkey on t_sugangsave s3 (cost=0.00..904.93 rows=1 width=6) (actual time=17.361..17.977 rows=0 loops=15767)"
" 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) (actual time=0.023..0.024 rows=1 loops=1471)"
" -> Index Scan using t_sugangsave_pkey on t_sugangsave b (cost=0.00..4.33 rows=1 width=12) (actual time=0.013..0.016 rows=2 loops=1471)"
" 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) (actual time=0.023..0.024 rows=1 loops=4203)"
" -> Index Scan using t_sugangsave_pkey on t_sugangsave b (cost=0.00..4.33 rows=1 width=12) (actual time=0.013..0.017 rows=2 loops=4203)"
" 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) (actual time=0.026..0.027 rows=1 loops=14408)"
" -> Index Scan using t_sugangsave_pkey on t_sugangsave b (cost=0.00..4.33 rows=1 width=12) (actual time=0.013..0.017 rows=3 loops=14408)"
" 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) (actual time=0.049..0.049 rows=1 loops=18560)"
" -> Index Scan using t_sugangsave_pkey on t_sugangsave b (cost=0.00..4.33 rows=1 width=12) (actual time=0.030..0.036 rows=3 loops=18560)"
" 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) (actual time=5.820..7.451 rows=1 loops=1079)"
" 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) (actual time=0.026..0.026 rows=1 loops=1079)"
" -> Index Scan using t_sugangsave_pkey on t_sugangsave b (cost=0.00..4.33 rows=1 width=12) (actual time=0.013..0.017 rows=2 loops=1079)"
" 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) (actual time=0.051..0.051 rows=1 loops=1079)"
" -> Index Scan using t_sugangsave_pkey on t_sugangsave b (cost=0.00..4.33 rows=1 width=12) (actual time=0.030..0.036 rows=2 loops=1079)"
" Index Cond: (((mid)::text = ($0)::text) AND (stu_c = $1) AND ((yb)::text = ($2)::text))"
"Total runtime: 558455.855 ms"
//---------------- History 입니다. -----------------------------//
-- Executing query:
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'));
ERROR: canceling statement due to user request
-- Executing query:
EXPLAIN ANALYZE 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'));
Total query runtime: 558578 ms.
Data retrieval runtime: 16 ms.
34 rows retrieved.
|