0

XML PATH 関数で 5 つのフィールド (ID フィールドではない) が使用されているビューがあります。ビューは、ID がクラスター化された主キーであるテーブルから値を取り込みます。ビューは膨大な実行時間を要し、混乱を引き起こしています。誰でも助けることができますか。

これは私が操作しているビューです

SELECT t1.ID,
hcp = REPLACE((SELECT t2.hcp AS [data()]--,t2.imstime AS [data()],t2.medtime AS [data()],t2.slntime AS [data()]
                        FROM dbo.STG_HCP_ATTESTTATION_ADDRESS_ATLAS t2
                        WHERE t2.ID = t1.ID
                        ORDER BY t2.hcp--,t2.imstime,t2.medtime,t2.slntime
                        FOR XML PATH('')),
                       ' ', ','),
       convert(Datetime,REPLACE((SELECT t2.hcptime AS [data()]--,t2.imstime AS [data()],t2.medtime AS [data()],t2.slntime AS [data()]
                        FROM dbo.STG_HCP_ATTESTTATION_ADDRESS_ATLAS t2
                        WHERE t2.ID = t1.ID and datalength(t2.hcptime)>0
                        ORDER BY t2.hcptime --,t2.imstime,t2.medtime,t2.slntime
                        FOR XML PATH('')),
                       ' ', ','),127) as hcptime,
      ims = REPLACE((SELECT t2.ims AS [data()]--,t2.imstime AS [data()],t2.medtime AS [data()],t2.slntime AS [data()]
                        FROM dbo.STG_HCP_ATTESTTATION_ADDRESS_ATLAS t2
                        WHERE t2.ID = t1.ID
                        ORDER BY t2.ims--,t2.imstime,t2.medtime,t2.slntime
                        FOR XML PATH('')),
                       ' ', ','),
        convert(Datetime,REPLACE((SELECT t2.imstime AS [data()]
                         FROM dbo.STG_HCP_ATTESTTATION_ADDRESS_ATLAS t2
                        WHERE t2.ID = t1.ID and datalength(t2.imstime)>0
                        ORDER BY t2.imstime--,t2.imstime,t2.medtime,t2.slntime
                        FOR XML PATH('')),
                       ' ', ','),127) as imstime,
         med = REPLACE((SELECT t2.med AS [data()]--,t2.imstime AS [data()],t2.medtime AS [data()],t2.slntime AS [data()]
                        FROM dbo.STG_HCP_ATTESTTATION_ADDRESS_ATLAS t2
                        WHERE t2.ID = t1.ID
                        ORDER BY t2.med--,t2.imstime,t2.medtime,t2.slntime
                        FOR XML PATH('')),
                       ' ', ','),

        convert(Datetime,REPLACE((SELECT t2.medtime AS [data()]
                         FROM dbo.STG_HCP_ATTESTTATION_ADDRESS_ATLAS t2
                        WHERE t2.ID = t1.ID and datalength(t2.medtime)>0
                        ORDER BY t2.medtime--,t2.imstime,t2.medtime,t2.slntime
                        FOR XML PATH('')),
                       ' ', ','),127) as medtime,

         sln = REPLACE((SELECT t2.sln AS [data()]--,t2.imstime AS [data()],t2.medtime AS [data()],t2.slntime AS [data()]
                        FROM dbo.STG_HCP_ATTESTTATION_ADDRESS_ATLAS t2
                        WHERE t2.ID = t1.ID
                        ORDER BY t2.sln--,t2.imstime,t2.medtime,t2.slntime
                        FOR XML PATH('')),
                       ' ', ','),

        convert(Datetime,REPLACE((SELECT t2.slntime AS [data()]
                         FROM dbo.STG_HCP_ATTESTTATION_ADDRESS_ATLAS t2
                        WHERE t2.ID = t1.ID and datalength(t2.slntime)>0
                        ORDER BY t2.slntime--,t2.imstime,t2.medtime,t2.slntime
                        FOR XML PATH('')),
                       ' ', ','),127) as slntime

       FROM dbo.STG_HCP_ATTESTTATION_ADDRESS_ATLAS t1
       GROUP BY ID,med,sln,ims,hcp

12K レコードを処理して 10K に削減するには、1 時間かかります。'dbo.STG_HCP_ATTESTTATION_ADDRESS_ATLAS' ビューが操作されている元のテーブルの ID 列にインデックスがあります。

4

0 に答える 0