【问题标题】:SQL query is running for very long timeSQL 查询运行了很长时间
【发布时间】:2018-02-15 13:28:39
【问题描述】:

帮我优化下面的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 是一个临时表。

【问题讨论】:

  • 您能否详细说明您的查询的预期结果?最终目标是什么?

标签: sql join query-optimization sap-ase


【解决方案1】:

你能不能试试这个:

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))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多