我需要帮助找出某些索引或某些不同的结构来加速我的查询,我先尝试分组,然后根据以下内容选择分组CTE的结果... http://codeidol.com/sql/sql-performance-tuning/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)
答案 0 :(得分:0)
如果您经常运行查询,则将按部分预先计算为帮助程序表
此外,您可以使用ISNULL([fldDDT], [fldDDT2])