此查询的替代方法是什么?

时间:2016-01-13 09:41:52

标签: sql-server sql-optimization

以下是我的查询。在sql server中运行需要4分钟,通过.net代码需要1个多小时。请为此查询建议备用解决方案。

SELECT DISTINCT
    REPLACE(REPLACE(
        CASE
            WHEN (CHARINDEX('/', REVERSE(URL), 1) = 1)
                THEN LEFT(URL, LEN(URL) - 1)
            ELSE URL
        END, 'http://', ''), 'www.', '') AS URL,
    NULL AS [source],
    REPLACE(REPLACE(
        CASE
            WHEN (CHARINDEX('/', REVERSE(TargetURL), 1) = 1)
                THEN LEFT(TargetURL, LEN(TargetURL) - 1)
            ELSE TargetURL
        END, 'http://', ''), 'www.', '') AS TargetURL,
    NULL AS [target],
    PageAuthority AS Authority,
    1 AS [isInternal]
FROM [Internal](nolock)
WHERE Domain_ID = 2
    AND NoofDomainsLinkingtothisPage > 1
    AND REPLACE(REPLACE(
        CASE
            WHEN (CHARINDEX('/', REVERSE(URL), 1) = 1)
                THEN LEFT(URL, LEN(URL) - 1)
            ELSE URL
        END, 'http://', ''), 'www.', '')
            IN (SELECT DISTINCT URL FROM #tempCalAuthTable11(NOLOCK))--864

    AND REPLACE(REPLACE(
        CASE
            WHEN (CHARINDEX('/', REVERSE(TargetURL), 1) = 1)
                THEN LEFT(TargetURL, LEN(TargetURL) - 1)
            ELSE TargetURL
        END, 'http://', ''), 'www.', '')
            IN (SELECT DISTINCT URL FROM #tempCalAuthTable11(NOLOCK))

以下是执行计划详情。

enter image description here

0 个答案:

没有答案