我有一些从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