このクエリの実行には 30 ~ 40 秒かかるため、高速化する必要があります。どんな助けでも大歓迎です。以下のビュー スクリプトで更新します。.NET 環境の Microsoft SQL Server 2008 で実行されています。小さいデータベースでは 3 ~ 4 秒かかりますが、私が使用しているデータベースははるかに大きく、SQL タイムアウトの境界にあります。
WITH TEMP As
(SELECT *
FROM (SELECT lease_number AS 'lease_number',
facility AS 'facility',
Lease_Name AS 'Lease_Name',
lease_start_date AS 'lease_start_date',
lease_end_date AS 'lease_end_date',
slschedule_id AS 'slschedule_id',
type_id AS 'type_id',
lease_id AS 'lease_id',
property_id AS 'property_id',
VW_FND_LA_PORT_SL.row_id AS 'row_id',
ROW_NUMBER() OVER (ORDER BY VW_FND_LA_PORT_SL.row_id ASC) ROW_NBR
FROM VW_FND_LA_PORT_SL
WHERE ( classfication = 1
AND slschedule_id = 1
AND is_dirty = 0
AND is_new = 1 )) AS ROWNUM_APPENDED),
countfinder AS (SELECT Count(*) AS [rowcount] FROM TEMP)
SELECT *,
(SELECT [rowcount] FROM countfinder) [totalrowcount]
FROM TEMP
WHERE ROW_NBR >= ( 1 - ( 1 - 1 )%10 )
AND ROW_NBR < ( 1 - ( 1 - 1 )%10 + 10 )
ビューは次のとおりです。
CREATE VIEW [dbo].[vw_FND_LA_PORT_SL]
AS
SELECT DISTINCT( L.lease_id ),
L.lease_number,
L.name AS Lease_Name,
L.lease_start_date,
L.lease_end_date,
F.name AS facility,
L.row_id,
L.property_id,
L.heldby_id,
EC.slschedule_id,
S.type_id,
CASE
WHEN dbo.Udf_isleaseoperational(L.lease_id) = '1' THEN 1
ELSE 2
END AS classfication,
CASE
WHEN (SELECT dirty_flag
FROM la_tbl_slschedule_calc_detail AS D
WHERE D.lease_id = L.lease_id
AND D.slschedule_id = S.slschedule_id
AND isdeleted = 0) = 1 THEN 1
ELSE 0
END AS is_dirty,
CASE
WHEN ( CASE
WHEN dbo.Udf_isleaseoperational(L.lease_id) = '1' THEN
(SELECT Count(*)
FROM
la_tbl_slschedule_calculation AS O
WHERE
O.lease_id = L.lease_id
AND O.slschedule_id = S.slschedule_id
AND isdeleted = 0)
ELSE (SELECT Count(*)
FROM la_tbl_slcapitalschedule_calc AS C
WHERE C.lease_id = L.lease_id
AND C.slschedule_id = S.slschedule_id
AND isdeleted = 0)
END ) > 0 THEN 0
ELSE 1
END AS is_new
FROM dbo.la_tbl_lease AS L
INNER JOIN dbo.vw_fnd_tlu_facility AS F
ON L.property_id = F.facilitypk
INNER JOIN la_tbl_expense AS E
ON L.lease_id = E.lease_id
INNER JOIN la_tbl_slschedule_expcategory AS EC
ON E.expense_category_id = EC.expense_category_id
INNER JOIN la_tbl_slschedule AS S
ON S.slschedule_id = EC.slschedule_id
INNER JOIN la_tlu_held_by AS H
ON L.heldby_id = H.heldby_id
WHERE L.isdeleted = 0
AND E.isdeleted = 0
AND EC.isdeleted = 0
AND S.isdeleted = 0
AND ( dbo.Udf_getnumberofleaseterms(L.lease_id) > 0 )
AND H.system_type <> '3'
GO