在加入 CTE 的 link 服务器 table 上进行性能调整
Performance tuning on link server table joining with CTE
想要通过执行 JOIN
操作减少 OPENQUERY
上 SELECT
的数量来调整性能。
我的查询是这样的。
查询:
;WITH CTE AS
(
SELECT
[EmployeeFirstName], [EmployeeMiddleName],
[EmployeeLastName], [EmployeeAddress]
FROM
Employee
WHERE
[EmployeeSalary] >= 200000
)
SELECT
[First Name], [Fathers Husband Name], [Last Name], [Department Name]
FROM
OPENQUERY ([Depart], 'SELECT [First Name], [Fathers Name], [Last Name],[Department Name]
FROM Department
INNER JOIN CTE C1 ON PATINDEX(''[First Name]'',''C1.[EmployeeFirstName]'') > 0');
错误:
Invalid object name 'CTE'
尝试以下方法
;WITH CTE AS
(
SELECT
[EmployeeFirstName], [EmployeeMiddleName],
[EmployeeLastName], [EmployeeAddress]
FROM
LocalServer.Database.Schema.Employee
WHERE
[EmployeeSalary] >= 200000
)
SELECT
[First Name], [Fathers Husband Name], [Last Name], [Department Name]
--It's better to specify the table eg: C1.ColumnName
FROM
(
SELECT [First Name], [Fathers Name], [Last Name],[Department Name]
FROM LinkedServer.Database.Schema.Department
INNER JOIN CTE C1
ON PATINDEX([First Name],C1.[EmployeeFirstName]) > 0
) TBL;
想要通过执行 JOIN
操作减少 OPENQUERY
上 SELECT
的数量来调整性能。
我的查询是这样的。
查询:
;WITH CTE AS
(
SELECT
[EmployeeFirstName], [EmployeeMiddleName],
[EmployeeLastName], [EmployeeAddress]
FROM
Employee
WHERE
[EmployeeSalary] >= 200000
)
SELECT
[First Name], [Fathers Husband Name], [Last Name], [Department Name]
FROM
OPENQUERY ([Depart], 'SELECT [First Name], [Fathers Name], [Last Name],[Department Name]
FROM Department
INNER JOIN CTE C1 ON PATINDEX(''[First Name]'',''C1.[EmployeeFirstName]'') > 0');
错误:
Invalid object name 'CTE'
尝试以下方法
;WITH CTE AS
(
SELECT
[EmployeeFirstName], [EmployeeMiddleName],
[EmployeeLastName], [EmployeeAddress]
FROM
LocalServer.Database.Schema.Employee
WHERE
[EmployeeSalary] >= 200000
)
SELECT
[First Name], [Fathers Husband Name], [Last Name], [Department Name]
--It's better to specify the table eg: C1.ColumnName
FROM
(
SELECT [First Name], [Fathers Name], [Last Name],[Department Name]
FROM LinkedServer.Database.Schema.Department
INNER JOIN CTE C1
ON PATINDEX([First Name],C1.[EmployeeFirstName]) > 0
) TBL;