我需要帮助找出某些索引或一些不同的结构来加快我的查询,我先尝试分组,然后根据以下内容从分组的 CTE 中选择结果...... http://codeidol.com/sql/sql-性能调整/GROUP-BY/Optimal-GROUP-BY-Clauses/
然而,我最终只是擦除了它,以下是基本查询,需要 2 分钟,查询 730,000 条记录,排序成本为 91%,我假设它主要用于分组。我真的需要这个至少缩短到 1 分钟。
询问:
SELECT
tblFLS.fldFN,
tblFLS.fldRN,
tblFC.fldFC,
tblFC.fldCity,
tblFC.fldState,
tblFLS.fldIN,
tblUL.fldPRK,
tblUL.fldLN,
tblUA.fldANA,
tblUA.fldMTH,
(CASE
WHEN (ISNULL([fldDTT], '') = '') THEN [fldDTT2]
ELSE [fldDTT]
END) AS fldDate,
tblUA.fldPG
FROM tblUA
INNER JOIN tblUL ON tblUA.fldULKey = tblUL.fldULID
INNER JOIN tblFLS ON tblUL.fldFileKey = tblFLS.fldFileID
INNER JOIN tblFC ON tblFLS.fldFacKey = tblFC.fldFacID
GROUP BY
tblFLS.fldFN,
tblFLS.fldRN,
tblFC.fldFC,
tblFC.fldCity,
tblFC.fldState,
tblFLS.fldIN,
tblUL.fldPRK tblUL.fldLN,
tblUA.fldANA,
tblUA.fldMTH,
(CASE
WHEN (ISNULL([fldDDT], '') = '') THEN [fldDDT2]
ELSE [fldDDT]
END),
tblUA.fldPG
表结构:
tblUA -- 850,000 rows, clustered Index on fldUAID
fldULK... INT
fldUAID... INT
fldALY... NVARCHAR(10)
fldAK... INT
fldMTH... NVARCHAR(15)
fldMK... INT
fldMMK... TINYINT
fldUNI... NVARCHAR(10)
fld7... INT
fld8... TINYINT
fld9...TINYINT
fld10...TINYINT
tblUL -- 200,000 rows, clustered Index on fldULID
fldULID... INT
fldFK... INT
fldPRK... INT
fld2... INT
fld3... INT
fldLN... NVARCHAR(15)
fldDTT... DATETIME
fldDTT2... DATETIME
tblFLS -- 70,000 rows, clustered Index on Primary Key, Non-Unique Non-Clustered On: fldDV, fldFK, fldIN, fldMK
fldFN... NVARCHAR(255)
fldRN... NVARCHAR(255)
fldIN... NVARCHAR(100)
fldDV... NVARCHAR(5)
fldM... NVARCHAR(100)
fldMK... INT
fldINC... NVARCHAR(10)
fldIDN... NVARCHAR(30)
fldDTA... NVARCHAR(50)
tblFC -- 10,000 records, clustered Index on Primary Key, Non-Unique Non-Clustered on fldFCID
fldFCID... INT
fldFC..NVARCHAR(100)
fldADDR... NVARCHAR(50)
fldADDR2... NVARCHAR(50)
fldCity... NVARCHAR(50)
fldState... NVARCHAR(10)