0

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

関数の代わりに、ネストされた選択、結合、またはストアド プロシージャを使用できますか?

ありがとう。

プラン:

    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
4

0 に答える 0