我有一些从 sharePoint 表中选择的视图,因此我无法控制索引。它只有 3000 行,所以没什么大不了的。我需要能够选择与特定用户具有相同部门的所有行。我创建了一个函数,但是如果放在 where 子句中太慢了。我是否还有其他选项,例如连接、嵌套选择或存储过程?
这非常慢:
select *
from apt_files_detailed
where apt_department = [dbo].[APT_GetDept]('mydomain\jdoe')
然而这些都不是:
select * from apt_files_detailed
和
select [dbo].[APT_GetDept]('domain\user')
我需要能够在没有代码隐藏访问权限的 ASP.NET 页面内选择内联。除非我可以直接在控件中从中选择,否则不要使用存储过程。还必须传入用户参数。
另外,在 ASP.NET 中我可以这样做:
SelectCommand = "SELECT * FROM [APT_Files_Detailed] where [apt_department] = [dbo].[apt_Getdept](@context)"
WebPartPages:DataFormParameter ParameterKey="LOGON_USER" PropertyName="ParameterValues" Name="context"
只是不确定它是否应该是(@context)
或者('@context')
.. idk 是否有语法问题,因为页面无论如何都会超时。
也许我可以使用嵌套选择、加入或存储过程来代替函数?
谢谢。
计划:
select * from apt_files_detailed where apt_department = [dbo].[APT_GetDept]('domain\jdoe')
|--Hash Match(Inner Join, HASH:([WSS_Content_apt].[dbo].[AllUserData].[nvarchar1])=([WSS_Content_apt].[dbo].[AllUserData].[nvarchar1]), RESIDUAL:([WSS_Content_apt].[dbo].[AllUserData].[nvarchar1]=[WSS_Content_apt].[dbo].[AllUserData].[nvarchar1]))
|--Merge Join(Inner Join, MANY-TO-MANY MERGE:([WSS_Content_apt].[dbo].[AllUserData].[int1])=([WSS_Content_apt].[dbo].[AllUserData].[tp_ID]), RESIDUAL:([WSS_Content_apt].[dbo].[AllUserData].[int1]=[WSS_Content_apt].[dbo].[AllUserData].[tp_ID]))
| |--Sort(ORDER BY:([WSS_Content_apt].[dbo].[AllUserData].[int1] ASC))
| | |--Nested Loops(Inner Join, OUTER REFERENCES:([WSS_Content_apt].[dbo].[AllUserData].[tp_SiteId], [WSS_Content_apt].[dbo].[AllUserData].[tp_RowOrdinal], [WSS_Content_apt].[dbo].[AllUserData].[tp_DirName], [WSS_Content_apt].[dbo].[AllUserData].[tp_LeafName], [WSS_Content_apt].[dbo].[AllUserData].[tp_DeleteTransactionId], [WSS_Content_apt].[dbo].[AllUserData].[tp_Level], [WSS_Content_apt].[dbo].[AllUserData].[tp_IsCurrentVersion], [WSS_Content_apt].[dbo].[AllUserData].[tp_CalculatedVersion], [Expr1010]) WITH UNORDERED PREFETCH)
| | |--Index Scan(OBJECT:([WSS_Content_apt].[dbo].[AllUserData].[AllUserData_PK]), WHERE:([WSS_Content_apt].[dbo].[AllUserData].[tp_IsCurrentVersion]=(1) AND [WSS_Content_apt].[dbo].[AllUserData].[tp_CalculatedVersion]=(0) AND [WSS_Content_apt].[dbo].[AllUserData].[tp_DeleteTransactionId]=0x AND [WSS_Content_apt].[dbo].[AllUserData].[tp_DirName]=N'sites/apt/Process'))
| | |--Clustered Index Seek(OBJECT:([WSS_Content_apt].[dbo].[AllUserData].[AllUserData_Url]), SEEK:([WSS_Content_apt].[dbo].[AllUserData].[tp_SiteId]=[WSS_Content_apt].[dbo].[AllUserData].[tp_SiteId] AND [WSS_Content_apt].[dbo].[AllUserData].[tp_DeleteTransactionId]=[WSS_Content_apt].[dbo].[AllUserData].[tp_DeleteTransactionId] AND [WSS_Content_apt].[dbo].[AllUserData].[tp_IsCurrentVersion]=[WSS_Content_apt].[dbo].[AllUserData].[tp_IsCurrentVersion] AND [WSS_Content_apt].[dbo].[AllUserData].[tp_DirName]=[WSS_Content_apt].[dbo].[AllUserData].[tp_DirName] AND [WSS_Content_apt].[dbo].[AllUserData].[tp_LeafName]=[WSS_Content_apt].[dbo].[AllUserData].[tp_LeafName] AND [WSS_Content_apt].[dbo].[AllUserData].[tp_CalculatedVersion]=[WSS_Content_apt].[dbo].[AllUserData].[tp_CalculatedVersion] AND [WSS_Content_apt].[dbo].[AllUserData].[tp_Level]=[WSS_Content_apt].[dbo].[AllUserData].[tp_Level] AND [WSS_Content_apt].[dbo].[AllUserData].[tp_RowOrdinal]=[WSS_Content_apt].[dbo].[AllUserData].[tp_RowOrdinal]) LOOKUP ORDERED FORWARD)
| |--Sort(ORDER BY:([WSS_Content_apt].[dbo].[AllUserData].[tp_ID] ASC))
| |--Filter(WHERE:([WSS_Content_apt].[dbo].[AllUserData].[nvarchar7]=CONVERT_IMPLICIT(nvarchar(100),[SharePoint_UM_Custom].[dbo].[APT_GetDept]('domain\jdoe'),0)))
| |--Clustered Index Scan(OBJECT:([WSS_Content_apt].[dbo].[AllUserData].[AllUserData_Url]), WHERE:([WSS_Content_apt].[dbo].[AllUserData].[tp_IsCurrentVersion]=(1) AND [WSS_Content_apt].[dbo].[AllUserData].[tp_CalculatedVersion]=(0) AND [WSS_Content_apt].[dbo].[AllUserData].[tp_DeleteTransactionId]=0x AND [WSS_Content_apt].[dbo].[AllUserData].[tp_DirName]=N'sites/apt/Lists/APT'))
|--Compute Scalar(DEFINE:([Expr1009]=N'domain\'+[WSS_Content_apt].[dbo].[AllUserData].[nvarchar3]))
|--Clustered Index Scan(OBJECT:([WSS_Content_apt].[dbo].[AllUserData].[AllUserData_Url]), WHERE:([WSS_Content_apt].[dbo].[AllUserData].[tp_IsCurrentVersion]=(1) AND [WSS_Content_apt].[dbo].[AllUserData].[tp_CalculatedVersion]=(0) AND [WSS_Content_apt].[dbo].[AllUserData].[tp_DeleteTransactionId]=0x AND [WSS_Content_apt].[dbo].[AllUserData].[tp_DirName]=N'sites/apt/Lists/Cnum2CaneID'))
UDF: [SharePoint_UM_Custom].[dbo].[APT_GetDept]
CREATE FUNCTION APT_GetDept
(
@user varchar(100)
)
RETURNS varchar(100)
AS
BEGIN
DECLARE @Dept varchar(100)
SET @Dept = (SELECT TOP 1 apt_department FROM apt_faculty WHERE lookup_caneid = @user)
|--Compute Scalar(DEFINE:([Expr1008]=CONVERT_IMPLICIT(varchar(100),[WSS_Content_apt].[dbo].[AllUserData].[nvarchar7],0)))
|--Nested Loops(Left Outer Join)
|--Constant Scan
|--Top(TOP EXPRESSION:((1)))
|--Nested Loops(Inner Join, WHERE:([WSS_Content_apt].[dbo].[AllUserData].[nvarchar1]=[WSS_Content_apt].[dbo].[AllUserData].[nvarchar1]))
|--Clustered Index Scan(OBJECT:([WSS_Content_apt].[dbo].[AllUserData].[AllUserData_Url]), WHERE:([WSS_Content_apt].[dbo].[AllUserData].[tp_IsCurrentVersion]=(1) AND [WSS_Content_apt].[dbo].[AllUserData].[tp_CalculatedVersion]=(0) AND [WSS_Content_apt].[dbo].[AllUserData].[tp_DeleteTransactionId]=0x AND [WSS_Content_apt].[dbo].[AllUserData].[tp_DirName]=N'sites/apt/Lists/Cnum2CaneID' AND (N'domain\'+[WSS_Content_apt].[dbo].[AllUserData].[nvarchar3])=CONVERT_IMPLICIT(nvarchar(100),[@user],0)))
|--Clustered Index Scan(OBJECT:([WSS_Content_apt].[dbo].[AllUserData].[AllUserData_Url]), WHERE:([WSS_Content_apt].[dbo].[AllUserData].[tp_IsCurrentVersion]=(1) AND [WSS_Content_apt].[dbo].[AllUserData].[tp_CalculatedVersion]=(0) AND [WSS_Content_apt].[dbo].[AllUserData].[tp_DeleteTransactionId]=0x AND [WSS_Content_apt].[dbo].[AllUserData].[tp_DirName]=N'sites/apt/Lists/APT'))
RETURN @Dept