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
운영게시판
최근게시물
MS-SQL Q&A 2098 게시물 읽기
No. 2098
이 쿼리문 퍼포먼스 향상좀 시켜주세요
작성자
연금이
작성일
2005-07-13 10:48
조회수
3,152

select a.item_cd, b.item_nm, b.basic_unit, b.item_acct,
(select isnull(sum(case when a2.debit_credit_flag = 'D' then a2.qty End),0) -
isnull(sum(case when a2.debit_credit_flag = 'C' then a2.qty End),0)
from i_goods_movement_header as a1, i_goods_movement_detail as a2
where a1.item_document_no = a2.item_document_no
and a2.delete_flag = 'N'
and a2.plant_cd = '2907'
and a2.item_cd = a.item_cd
and convert(char(10), a1.document_dt, 126) < '2005-07-01') as Stock,
(select isnull(sum(b2.qty), 0)
from i_goods_movement_header as b1(nolock), i_goods_movement_detail as b2(nolock)
where b1.item_document_no = b2.item_document_no
and b2.delete_flag = 'N'
and b2.item_cd = a.item_cd
and b2.debit_credit_flag = 'D'
and b2.plant_cd = '2907'
and convert(char(10), b1.document_dt,126) >= '2005-07-01'
and convert(char(10), b1.document_dt, 126) <= '2005-07-12') as In_Qty, (select isnull(sum(c2.qty), 0)
from i_goods_movement_header as c1(nolock), i_goods_movement_detail as c2(nolock)
where c1.item_document_no = c2.item_document_no
and c2.delete_flag = 'N'
and c2.item_cd = a.item_cd
and c2.debit_credit_flag = 'C'
and c2.plant_cd = '2907'
and convert(char(10), c1.document_dt,126) >= '2005-07-01'
and convert(char(10), c1.document_dt, 126) <= '2005-07-12') as Out_Qty,
isnull(from_factor ,1) as UNIT, (select top 1 isnull(item_price,1)
from s_item_sales_price w
here item_cd = a.item_cd
and sales_unit = 'BOX'
and valid_from_dt <= '2005-07-12' order by valid_from_dt desc) as BOX,
(select top 1 isnull(item_price,1)
from s_item_sales_price where item_cd = a.item_cd
and sales_unit = 'EA'
and valid_from_dt <= '2005-07-12' order by valid_from_dt desc) as EA
from b_item_by_plant as a(nolock), b_item as b(nolock), b_translation_of_unit_for_item as c(nolock)
where a.item_cd = b.item_cd
and a.item_cd *= c.item_cd
and c.from_unit = 'EA'
and c.To_unit = 'Box
' and a.valid_flg = 'Y'
and plant_cd = '2907'
and (b.item_acct = '10' or b.item_acct = '50') order by a.item_cd

꽤 길죠? 이것을 돌리면 2-30분 정도 걸립니다.

최대한 빨리 처리할려구 하는데 어떻게 하면 속도향상을 얻을수 있을까요?

많은 조언 부탁드립니다.

 

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

테이블의 스키마와 샘플데이터 그리고 출력물의 형태를 볼 수 있을까요?

 

쿼리문 하나로 퍼포먼스 까지 고려하는 건 무척 힘이 드는 걸요 ^^

여리님이 2005-07-13 11:16에 작성한 댓글입니다. Edit

테이블 스키마, Primary key, Index, 전체 데이터 수를 알려주시면 Tuning이 가능하지 않을까요?

 

그럼.. 전 좀 있다가 맥주마시러.. ^^*

길가는 나그네..님이 2005-07-13 18:08에 작성한 댓글입니다. Edit

실행 결과를 아래 과정으로 나온 출력을 올려 주세요...

 

 먼저 sql analyzer 를 여시고....

 

 set statistics profile on

 

 하시고 해당 sql 을 실행하시면.. 실행계획을 txt 형식으로

볼수 있습니다.

 

 이 출력물을 올려 주시면... 제가 힘이 닿는데 까지 튜닝 해 드리겠습니다.

 

 참고로 오라클에서는 모든 sql 튜닝시 실행계획을 참조하게 됩니다.

물론 mssql 처럼 어설픈 그래픽환경의 gui 는 업지만요..

 

 gui 형식의 어설픈 실행계획은 정말 어설 프더군요..

위에서 말씀드린 txt형식의 실행계획을 올려 주시면..

튜닝 해 보겟씁니다.

 답답하기겟지만.. 올려 주세요... 그래야 가능합니다.

sqler님이 2005-07-14 10:12에 작성한 댓글입니다. Edit

환경에 대한 제시가 없기에 일반적인 정도의 문장밖에 나올 수 없을 것입니다.  인덱스나 데이터분포도, 실행계획 같은 것을 안다면 더 좋은 방향이 나올텐데 제가 한 일은 중복읽기만 제거한 것입니다.

물론 경우에 따라선 중복읽기가 아닐 수도 있지만..

 

b_translation_of_unit_for_item 이 테이블과의 연결은 아우터조인을 하곤 아래쪽에 조건을 주어서 어떤 의도인지 몰라 제외하였습니다.

 

select a.item_cd
      ,a.item_nm
      ,a.basic_unit
      ,a.item_acct
      ,a.BOX
      ,a.EA
      ,Cast(Substring(a.stock_val, 2, 9) as decimal(9))
     - Cast(Substring(a.stock_val, 12, 9) as decimal(9))  Stock
      ,Cast(Substring(a.stock_val, 22, 9) as decimal(9))  In_Qty
      ,Cast(Substring(a.stock_val, 32, 9) as decimal(9))  Out_Qty
from (
     select a.item_cd
           ,b.item_nm
           ,b.basic_unit
           ,b.item_acct
          ,(select Cast(isnull(sum(case when a1.document_dt <= Cast('2005-07-01' as datetime)
                                         and a2.debit_credit_flag = 'D' then a2.qty End),0) + 1000000000 as char(10))
                 + Cast(isnull(sum(case when a1.document_dt <= Cast('2005-07-01' as datetime)
                                         and a2.debit_credit_flag = 'C' then a2.qty End),0) + 1000000000 as char(10))
                 + Cast(isnull(sum(case when a1.document_dt > Cast('2005-07-01' as datetime)
                                         and a2.debit_credit_flag = 'D' then a2.qty End),0) + 1000000000 as char(10))
                 + Cast(isnull(sum(case when a1.document_dt > Cast('2005-07-01' as datetime)
                                         and a2.debit_credit_flag = 'C' then a2.qty End),0) + 1000000000 as char(10))
           from i_goods_movement_header as a1,
                i_goods_movement_detail as a2
           where a1.item_document_no = a2.item_document_no
           and a2.delete_flag = 'N'
           and a2.plant_cd = a.plant_cd
           and a2.item_cd  = a.item_cd
           and a1.document_dt <= Cast('2005-07-12' as datetime)
           )               stock_val
         ,(select top 1 isnull(item_price,1)
           from s_item_sales_price
           where item_cd = a.item_cd
           and sales_unit = 'BOX'
           and valid_from_dt <= '2005-07-12'
           order by valid_from_dt desc) as BOX
         ,(select top 1 isnull(item_price,1)
           from s_item_sales_price
           where item_cd = a.item_cd
           and sales_unit = 'EA'
           and valid_from_dt <= '2005-07-12'
           order by valid_from_dt desc) as EA
     from b_item_by_plant as a,
          b_item as b
     where a.item_cd = b.item_cd
     and a.valid_flg = 'Y'
     and a.plant_cd  = '2907'
     and b.item_acct IN ('10', '50')
     ) a

m님이 2005-07-14 11:23에 작성한 댓글입니다. Edit
[Top]
No.
제목
작성자
작성일
조회
2101instance 복제에 대해 질문입니다. [4]
석이
2005-07-13
2403
2100[쿼리 질문]고수님들의 가르침 부탁드립니다. [3]
봉달이
2005-07-13
2415
2099테이블 생성하려는데요. [1]
커너
2005-07-13
1965
2098이 쿼리문 퍼포먼스 향상좀 시켜주세요 [4]
연금이
2005-07-13
3152
2097replication에 대한 초보적인 질문있습니다.
김지훈
2005-07-13
1801
2096특정테이블에서 특정칼럼의 데이터가 Null 인것만 추출할수 있습니까? [3]
지승용
2005-07-12
2904
2095답답한마음에 여기에도 올려봅니다..ㅠ_ㅠ [3]
임종석
2005-07-12
2694
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.016초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다