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 6940 게시물 읽기
No. 6940
아래 재고쿼리관련 실행 계획 결과내용입니다.
작성자
이기자
작성일
2006-12-05 16:00
조회수
3,901

"Sort  (cost=815671.03..815672.95 rows=767 width=320) (actual time=44452.152..44452.845 rows=2120 loops=1)"

"  Sort Key: sutacc, jobday, mcode, serial, settime"

"  ->  Subquery Scan lp  (cost=1051.69..815634.28 rows=767 width=320) (actual time=125.025..44433.888 rows=2120 loops=1)"

"        Filter: (settime >= (subplan))"

"        ->  Unique  (cost=1051.69..1137.98 rows=2301 width=424) (actual time=85.100..105.088 rows=4533 loops=1)"

"              ->  Sort  (cost=1051.69..1057.44 rows=2301 width=424) (actual time=85.098..93.585 rows=4533 loops=1)"

"                    Sort Key: idx, settime, jobday, sutacc, ssutacc, jcode, mcode, serial, cc, price, instatus, commant, statusc, setuid"

"                    ->  Append  (cost=517.61..661.98 rows=2301 width=424) (actual time=42.414..65.807 rows=4533 loops=1)"

"                          ->  Result  (cost=517.61..603.82 rows=2299 width=424) (actual time=42.412..60.574 rows=4531 loops=1)"

"                                ->  Unique  (cost=517.61..603.82 rows=2299 width=424) (actual time=42.392..52.735 rows=4531 loops=1)"

"                                      ->  Sort  (cost=517.61..523.36 rows=2299 width=424) (actual time=42.390..45.495 rows=4531 loops=1)"

"                                            Sort Key: idx, settime, jobday, sutacc, ssutacc, jcode, mcode, serial, cc, price, instatus, commant, statusc, setuid"

"                                            ->  Append  (cost=0.00..389.25 rows=2299 width=424) (actual time=0.179..22.901 rows=4531 loops=1)"

"                                                  ->  Subquery Scan "*SELECT* 1"  (cost=0.00..191.94 rows=71 width=83) (actual time=0.178..11.507 rows=2579 loops=1)"

"                                                        ->  Seq Scan on t_in  (cost=0.00..191.23 rows=71 width=83) (actual time=0.176..8.336 rows=2579 loops=1)"

"                                                              Filter: (((COALESCE(debenture_debt, \'\'::character varying))::text <> \'M\'::text) AND ((setmid)::text = \'metro\'::text) AND ((tno)::text = \'1\'::text) AND (jobday <= \'2006-12-04\'::date) AND (((CASE  (..)"

"                                                  ->  Subquery Scan "*SELECT* 2"  (cost=0.00..137.52 rows=2224 width=297) (actual time=0.081..7.733 rows=1947 loops=1)"

"                                                        ->  Seq Scan on t_out ssel  (cost=0.00..115.28 rows=2224 width=297) (actual time=0.078..5.528 rows=1947 loops=1)"

"                                                              Filter: (((setmid)::text = \'metro\'::text) AND ((tno)::text = \'1\'::text) AND (jobday <= \'2006-12-04\'::date) AND (((status)::text = \'1\'::text) OR ((status)::text = \'2\'::text) OR ((status)::text =  (..)"

"                                                  ->  Subquery Scan "*SELECT* 3"  (cost=0.00..14.89 rows=1 width=384) (actual time=0.015..0.034 rows=5 loops=1)"

"                                                        ->  Seq Scan on t_bi ssel  (cost=0.00..14.88 rows=1 width=384) (actual time=0.013..0.026 rows=5 loops=1)"

"                                                              Filter: (((setmid)::text = \'metro\'::text) AND ((tno)::text = \'1\'::text) AND (jobday <= \'2006-12-04\'::date) AND (((status)::text = \'1\'::text) OR ((status)::text = \'2\'::text) OR ((status)::text =  (..)"

"                                                  ->  Subquery Scan "*SELECT* 4"  (cost=0.00..14.89 rows=1 width=424) (actual time=0.017..0.017 rows=0 loops=1)"

"                                                        ->  Seq Scan on t_bp ssel  (cost=0.00..14.88 rows=1 width=424) (actual time=0.016..0.016 rows=0 loops=1)"

"                                                              Filter: (((setmid)::text = \'metro\'::text) AND ((tno)::text = \'1\'::text) AND (jobday <= \'2006-12-04\'::date) AND (((status)::text = \'1\'::text) OR ((status)::text = \'2\'::text) OR ((status)::text =  (..)"

"                                                  ->  Subquery Scan "*SELECT* 5"  (cost=0.00..15.14 rows=1 width=83) (actual time=0.575..0.575 rows=0 loops=1)"

"                                                        ->  Seq Scan on t_gp ssel  (cost=0.00..15.13 rows=1 width=83) (actual time=0.574..0.574 rows=0 loops=1)"

"                                                              Filter: (((setmid)::text = \'metro\'::text) AND ((tno)::text = \'1\'::text) AND (jobday <= \'2006-12-04\'::date) AND (((status)::text = \'1\'::text) OR ((status)::text = \'2\'::text) OR ((status)::text =  (..)"

"                                                  ->  Subquery Scan "*SELECT* 6"  (cost=0.00..14.89 rows=1 width=424) (actual time=0.120..0.120 rows=0 loops=1)"

"                                                        ->  Seq Scan on t_gong ssel  (cost=0.00..14.88 rows=1 width=424) (actual time=0.119..0.119 rows=0 loops=1)"

"                                                              Filter: (((setmid)::text = \'metro\'::text) AND ((tno)::text = \'1\'::text) AND (jobday <= \'2006-12-04\'::date) AND (((status)::text = \'1\'::text) OR ((status)::text = \'2\'::text) OR ((status)::text =  (..)"

"                          ->  Subquery Scan "*SELECT* 7"  (cost=0.00..58.16 rows=2 width=90) (actual time=1.653..2.390 rows=2 loops=1)"

"                                ->  Seq Scan on t_sale ssel  (cost=0.00..58.14 rows=2 width=90) (actual time=1.648..2.384 rows=2 loops=1)"

"                                      Filter: (((setmid)::text = \'metro\'::text) AND ((tno)::text = \'1\'::text) AND (saledate <= \'2006-12-04\'::date) AND (((status)::text = \'1\'::text) OR ((status)::text = \'2\'::text) OR ((status)::text = \'3\'::text) OR ((status (..)"

"        SubPlan"

"          ->  Aggregate  (cost=353.95..353.96 rows=1 width=8) (actual time=9.771..9.771 rows=1 loops=4533)"

"                ->  Unique  (cost=353.74..353.86 rows=7 width=134) (actual time=9.761..9.765 rows=2 loops=4533)"

"                      ->  Sort  (cost=353.74..353.75 rows=7 width=134) (actual time=9.758..9.759 rows=2 loops=4533)"

"                            Sort Key: settime, jcode, mcode, serial, setmid, tno"

"                            ->  Append  (cost=0.00..353.64 rows=7 width=134) (actual time=1.879..9.741 rows=2 loops=4533)"

"                                  ->  Seq Scan on t_in  (cost=0.00..136.58 rows=1 width=45) (actual time=1.873..4.270 rows=1 loops=4533)"

"                                        Filter: ((jobday <= \'2006-12-04\'::date) AND ((setmid)::text = \'metro\'::text) AND ((tno)::text = \'1\'::text) AND (($0)::text = (mcode)::text) AND (($1)::text = (serial)::text) AND ((setmid)::text = \'metro\'::text) AND ( (..)"

"                                  ->  Seq Scan on t_out  (cost=0.00..104.16 rows=1 width=45) (actual time=1.702..3.171 rows=1 loops=4533)"

"                                        Filter: ((jobday <= \'2006-12-04\'::date) AND ((setmid)::text = \'metro\'::text) AND ((tno)::text = \'1\'::text) AND (($0)::text = (mcode)::text) AND (($1)::text = (serial)::text) AND ((setmid)::text = \'metro\'::text) AND ( (..)"

"                                  ->  Seq Scan on t_bi  (cost=0.00..14.13 rows=1 width=134) (actual time=0.009..0.009 rows=0 loops=4533)"

"                                        Filter: ((jobday <= \'2006-12-04\'::date) AND ((setmid)::text = \'metro\'::text) AND ((tno)::text = \'1\'::text) AND (($0)::text = (mcode)::text) AND (($1)::text = (serial)::text) AND ((setmid)::text = \'metro\'::text) AND ( (..)"

"                                  ->  Seq Scan on t_bp  (cost=0.00..14.13 rows=1 width=134) (actual time=0.005..0.005 rows=0 loops=4533)"

"                                        Filter: ((jobday <= \'2006-12-04\'::date) AND ((setmid)::text = \'metro\'::text) AND ((tno)::text = \'1\'::text) AND (($0)::text = (mcode)::text) AND (($1)::text = (serial)::text) AND ((setmid)::text = \'metro\'::text) AND ( (..)"

"                                  ->  Seq Scan on t_gp  (cost=0.00..14.49 rows=1 width=45) (actual time=0.437..0.439 rows=0 loops=4533)"

"                                        Filter: ((jobday <= \'2006-12-04\'::date) AND ((setmid)::text = \'metro\'::text) AND ((tno)::text = \'1\'::text) AND (($0)::text = (mcode)::text) AND (($1)::text = (serial)::text) AND ((setmid)::text = \'metro\'::text) AND ( (..)"

"                                  ->  Seq Scan on t_gong  (cost=0.00..14.13 rows=1 width=134) (actual time=0.104..0.104 rows=0 loops=4533)"

"                                        Filter: ((jobday <= \'2006-12-04\'::date) AND ((setmid)::text = \'metro\'::text) AND ((tno)::text = \'1\'::text) AND (($0)::text = (mcode)::text) AND (($1)::text = (serial)::text) AND ((setmid)::text = \'metro\'::text) AND ( (..)"

"                                  ->  Seq Scan on t_sale  (cost=0.00..55.96 rows=1 width=43) (actual time=1.605..1.704 rows=0 loops=4533)"

"                                        Filter: ((saledate <= \'2006-12-04\'::date) AND ((setmid)::text = \'metro\'::text) AND ((tno)::text = \'1\'::text) AND (($0)::text = (mcode)::text) AND (($1)::text = (serial)::text) AND ((setmid)::text = \'metro\'::text) AND (..)"

"Total runtime: 44455.151 ms"



이렇게 나오던데,

잘좀 해결됐음 좋겠습니다.

딴쪽은 문제 없는데, 재고쪽이 문제가 되어서 곤혹스럽습니다.

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

에.. 보시면 1번째, 3번째 라인에서 cost가 보이는데요.

예상에는 1번째 라인인 sort에서 가장 많은 시간이 걸릴줄 알았는데 실제로는 3번째 라인인 subquery scan에서 가장 많이 걸리고 있습니다..

 

work_mem 을 조정해 보세요. postgresql.conf 파일을 찾아서 work_mem 부분의 주석을 풀어주고 8~16메가 정도로 조정하고 postgresql을 재시작 해보시면 됩니다.

 

아니면 쿼리를 튜닝하거나 특정 부분을 함수로 만든 후에 인덱스를 만드는 것도 도움이 됩니다.

실행계획으로 볼 때 데이터 량이 얼마나 되는지 몰라도 인덱스만 잘 걸어주거나 구조를 바꾸면 5초는 커녕 0.5초 안에도 결과가 나올수도 있습니다

 

신기배(소타)님이 2006-12-05 16:13에 작성한 댓글입니다.

데이터를 일괄로 넣었다면, 

먼저 실재 서비스를 하기 전에, vacuum analyze 작업을 한번 해 주셔야합니다.

실행계획의 모습이 아마도 이 analyze 작업을 안해서 생긴 결과 같아보입니다. \"\"

김상기(ioseph)님이 2006-12-05 16:17에 작성한 댓글입니다.

답변 감사합니다.

일단 work_mem 부분 문제는 아닌거 같습니가.

16메가로 올리고 재실행하고 해봐도 걸리는 시간은 같고,

vacuum analyze 하고 해봐도 같습니다.

인덱스를 한번 사용해 봐야겠군요.

이기자님이 2006-12-05 17:25에 작성한 댓글입니다. Edit

몇일간 고민해보고 수정해봐도 별로 발전이 없군요. T.T;

프로그램은 이미 납품되어서 사용중인데 속도때문에 난리들이고...

처음에 테스트는 너무 간단한 적은 데이타로 해서 못느꼈던 부분에서 문제가 생기는군요.

너무 급한 문제고 무료 디비라 선택했었는데, 처음 사용하는거라 뭘 어찌해야할지를 모르겠네요.

사실 디비쪽은 많이 약한 초보 수준이었기도하고요.

염치없는 부탁인데, 신기배(소타)님이 좀 도와주시면 안될까요.

이메일로 SQL문을 보내드릴테니 인덱스쪽하고 구조좀 손좀 봐주시면 정말 감사하겠는데...

딴쪽은 그럭저럭 할만한데, 재고쪽만 너무 느린 문제가 발생이 되네요.

바쁘시겠지만 부탁좀 드릴께요.

제 이메일은 k3i2@nate.com 입니다.

이기자(k3i2)님이 2006-12-06 09:31에 작성한 댓글입니다.

네이트온 추가했습니다 ㅋㅋ

신기배(소타)님이 2006-12-06 11:43에 작성한 댓글입니다.
[Top]
No.
제목
작성자
작성일
조회
6944psql 스키마접속.. [2]
백수환
2006-12-07
4910
6943소트방법 좀 알려주세요..
나그네
2006-12-06
4080
6941파티션 테이블 정렬 인덱스 문제 [2]
박난하
2006-12-05
4614
6940아래 재고쿼리관련 실행 계획 결과내용입니다. [5]
이기자
2006-12-05
3901
6939구원요청 DB가 자꾸 죽어요
dba
2006-12-05
3428
6928재고조회 쿼리인데, ms-sql에 비해 시간이 너무 오래 걸립니다. [5]
이기자
2006-12-05
4531
6927아랫분 아스키... 댓글이 안돼서 새글로... [1]
이기자
2006-12-05
3392
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.017초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다