2013-09-25 3 views
-3

아래 진술로 어떤 일이 벌어지는 지 잘 모르겠습니다. 실행에 5 분 이상이 소요되었습니다. 기본 명령문을 선택하여 별칭으로 임시로 감쌀 때 실제 감속을 나타 내기 시작했지만, 그렇게하면 다른 SQL이 느려지지 않습니다. 어떤 아이디어? 나는 MySQL을 사용 중이다.SQL 문 실행 속도가 느립니다 - 어떤 아이디어입니까?

select * 

from (
    select emp.company 
    , emp.employee 
    , emp.last_name "Last Name" 
    , emp.first_name "First Name" 
    , emp.middle_init "Middle Initial" 
    , trim(last_name) || ', ' || trim(first_name) || 
     decode(trim(middle_init),'','',' '|| trim(middle_init)|| '.') "Full Name" 
    , emp.emp_status 
    , emp.work_country "Country" 
    , (select 
    (Case pgs.group_name 
     when 'HREMEA' then 'EMEA' 
     when 'HRNAMER' then 'NA' 
     when 'HRLAMER' then 'LA' 
     when 'HRAPAC' then'APAC' 
     end) 
     from lawson.pgselect pgs 
     where pgs.begin_value = emp.work_country 
     and pgs.company = 1 
     and pgs.group_name in ('HREMEA','HRNAMER','HRLAMER','HRAPAC')) "Region" 
    , emp.department "Department" 
    , (select trim(r_name) 
     from lawson.deptcode dpt 
     where company = emp.company 
     and trim(process_level) = trim(emp.process_level) 
     and trim(department) = trim(emp.department)) "Department Description" 
    , emp.job_code "Job Code" 
    , (select description 
     from lawson.jobcode jbc 
     where company = emp.company 
     and job_code = emp.job_code) "Job Title" 
    , emp.supervisor 
    , (select trim(last_name) || ', ' || trim(first_name) || 
     decode(trim(middle_init),'','',' '|| trim(middle_init)|| '.') 
     from lawson.employee supv 
     where supv.company = 1 
      and supv.position = emp.supervisor 
      and term_date = '01-JAN-1700') "Supervisor Name" 
    , (select a_field 
     from lawson.hrempusf 
     where company = emp.company and employee = emp.employee 
     and field_key = '99') "Alt Mgr" 
    , (select a_field 
     from lawson.hrempusf 
     where company = emp.company and employee = emp.employee 
     and field_key = '79') "TE Proxy Approver" 
    , (select a_field 
     from lawson.hrempusf 
     where company = emp.company and employee = emp.employee 
     and field_key = '76') "Time Entry Proxy 1" 
    , (select a_field 
     from lawson.hrempusf 
     where company = emp.company and employee = emp.employee 
     and field_key = '77') "Time Entry Proxy 2" 
    from lawson.employee emp 
    where term_date = '01-JAN-1700' 
) temp 

where temp."TE Proxy Approver" <> ' ' 
    or temp."Time Entry Proxy 1" <> ' ' 
    or temp."Time Entry Proxy 2" <> ' ' 
+1

같은 테이블에서 subselecting하는 대신에'JOIN'을 사용하는 것이 여러 번 속도가 빨라집니다. 데이터의 양에 따라 .. "느린"은 상대적입니다. 쿼리가 몇 시간마다 실행되면 5 분이 오래 걸리지 않습니다. – DanFromGermany

답변

0

쿼리의 빠른 검토 :

  • 너무 많은 서브 쿼리하는 field_key에 인덱스 및 term_date
  • 임시 서브 쿼리에 대한 필요가 없습니다 누락 조인
  • 으로 교체 , 귀하의 기본 쿼리 (귀하의 조인에 적은 데이터)
+0

내 기본 쿼리에 위치를 이동하면 별칭이기 때문에 "TE 프록시 승인자"등을 지정할 수 없습니다 ... 또는 뭔가 빠졌습니까? –

+0

하위 쿼리 대신 내부 조인을 수행하고 조인 조건에서 조건을 지정해야합니다. – Peter

0

조인에 의해 대체 어디로 테이블을 이동 인덱스가 있습니다

+0

해당 작업을 수행 할 것입니다. 감사. –

관련 문제