SQL查询运行很长时间

时间:2018-02-15 13:28:39

标签: sql join query-optimization sybase-ase

帮我优化下面的sql,运行很多个小时 数据库:sybase

select
    too.toID,too.toName,frm.fromID,frm.fromName<br>
from
    entityClientTempTable frm, entityClientTempTable too
where
    frm.fromServerId = too.toServerId 
and
    frm.fromID < too.toID 
and 
    lower(substring(frm.fromName, 0, CHARINDEX(''------'',frm.fromName))) like lower(too.toName))

entityClientTempTable中的记录数:约五十万 entityClientTempTable表上没有索引 entityClientTempTable是一个临时表。

1 个答案:

答案 0 :(得分:0)

请你试试这个:

select too.toID,too.toName,frm.fromID,frm.fromName
from entityClientTempTable frm
inner join entityClientTempTable too on frm.fromServerId = too.toServerId 
       and frm.fromID < too.toID
where lower(substring(frm.fromName, 0, CHARINDEX(''------'',frm.fromName))) like lower(too.toName))