-3

Not sure what's going on with the below statement. It's taking upwards of 5 minutes to run - it only started to show a real slowdown when I wrapped the main statement in a select and aliased it as temp, but doing that has never slowed down any of my other SQL. Any ideas? I'm on MySQL.

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" <> ' '
4

2 回答 2

0

快速查看您的查询:

  • 子查询太多,用连接替换它们
  • 缺少 field_key 和 term_date 的索引
  • 不需要临时子查询,将 where 移到主查询中(联接中的数据更少)
于 2013-09-25T09:16:48.353 回答
0

通过连接替换子查询,并确保表有索引

于 2013-09-25T09:23:50.047 回答