下面是我的sql 请问还可以怎么优化
select t.tuid,
s.jobName,
g.groupName,
g.groupType,
e.typeName,
t.logMessage,
t.logTime,
c.descripTion,
c.code,
c.codeType,
c.description logdetail,
clogtype.description logtype,
caction.description action
from schedule_log t left join schedule s
on (t.jobid = s.tuid) left join schedule_group g
on (t.jobgroupid = g.tuid) left join schedule_group_type e
on (e.tuid = g.grouptype) left join schedule_log_code caction
on (t.action = caction.code and caction.codetype = 1) left join schedule_log_code clogtype
on (t.logtype = clogtype.code and clogtype.codetype = 2) left join schedule_log_code c
on (t.logdetail = c.code and c.codetype = 3)
select t.tuid,
s.jobName,
g.groupName,
g.groupType,
e.typeName,
t.logMessage,
t.logTime,
c.descripTion,
c.code,
c.codeType,
c.description logdetail,
clogtype.description logtype,
caction.description action
from schedule_log t left join schedule s
on (t.jobid = s.tuid) left join schedule_group g
on (t.jobgroupid = g.tuid) left join schedule_group_type e
on (e.tuid = g.grouptype) left join schedule_log_code caction
on (t.action = caction.code and caction.codetype = 1) left join schedule_log_code clogtype
on (t.logtype = clogtype.code and clogtype.codetype = 2) left join schedule_log_code c
on (t.logdetail = c.code and c.codetype = 3)
至于优化的话,这种基本的查询,我也想看看大神的方案。。
select t.tuid,
s.jobName,
g.groupName,
g.groupType,
e.typeName,
t.logMessage,
t.logTime,
c.descripTion,
c.code,
c.codeType,
c.description logdetail,
clogtype.description logtype,
caction.description action
from schedule_log t left join schedule s
on t.jobid = s.tuid left join schedule_group g
on t.jobgroupid = g.tuid left join schedule_group_type e
on e.tuid = g.grouptype left join schedule_log_code caction
on t.action = caction.code left join schedule_log_code clogtype
on t.logtype = clogtype.code left join schedule_log_code c
on t.logdetail = c.code
where c.codetype = 3 and clogtype.codetype = 2 and caction.codetype = 1
select t.tuid,
s.jobName,
g.groupName,
g.groupType,
e.typeName,
t.logMessage,
t.logTime,
c.descripTion,
c.code,
c.codeType,
c.description logdetail,
clogtype.description logtype,
caction.description action
from schedule_log t left join schedule s
on t.jobid = s.tuid left join schedule_group g
on t.jobgroupid = g.tuid left join schedule_group_type e
on e.tuid = g.grouptype left join schedule_log_code caction
on t.action = caction.code left join schedule_log_code clogtype
on t.logtype = clogtype.code left join schedule_log_code c
on t.logdetail = c.code
where c.codetype = 3 and clogtype.codetype = 2 and caction.codetype = 1
感觉好像更慢了