아래 진술로 어떤 일이 벌어지는 지 잘 모르겠습니다. 실행에 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" <> ' '
같은 테이블에서 subselecting하는 대신에'JOIN'을 사용하는 것이 여러 번 속도가 빨라집니다. 데이터의 양에 따라 .. "느린"은 상대적입니다. 쿼리가 몇 시간마다 실행되면 5 분이 오래 걸리지 않습니다. – DanFromGermany