我有大型表的大型数据库,而从多个表中检索数据(查询大约包含 10 个内部连接)从数据库中获取数据需要很长时间(在某些情况下需要 10-20 秒或分钟)。该查询需要大多数表中的几乎所有列和其余表中的近一半列。
我的问题是在我的案例中使用 SQL Server 2012 列存储架构有多大帮助。目前我正在使用 SQL Server 2008。欢迎任何其他时间优化建议,因为我非常需要优化此类查询
SELECT Seq.SeqId,Seq.ThreadId, Seq.Subject,LastAccessed, Seq.State, Seq.AlarmSent,Prop.RegionCode ,Seq.Rating , Seq.ClassId, Seq.SeqMedium,
Seq.SeqPriority, Seq.StatusDate , Seq.SeqCreateDt, Seq.StartDate, Seq.LastModified, Seq.Resolved, Seq.SeqSrcId, Seq.StatusReason , SeqDocument.DocId,
SeqDocument.IsCheckedOut, SeqDocument.CheckedOutById , SeqDocument.Remarks, Prop.PahLName ,OC.ClassID,OC.ClassName,OC.ClassShortName,OC.Description ,
OC.ParentID,OC2.ClassName AS ParentClassName,OC.OrgID ,CM.DeptID,CM.Severity,CM.Nature ,ST.TargetClsId,ST.TargetSubClsId,ST.TargetId, ST.ResponderActive,
ST.TargetType, ST.SentDate ,SF.FlowId, SF.InwardNo, SF.OutwardNo,SF.InwardDate,SF.OutwardDate ,SF.FlowOrder,SF.OriginatorState,SF.ResponderState,SF.PrevFlowId ,
SF.SeqFlowSrcClsId,SF.SeqFlowSrcId, OrgP.Name, SF.FlowStatus ,
CASE Prop.BCPNO WHEN '' THEN Prop.TempNo ELSE Prop.BCPNO END AS FileNo, Prop.DeveloperName ,PROP.BCPNO,PROP.CaseType, Prop.OwnerFName,
PROP.InwardDate as ProposalInwardDate, PROP.CaseTrack ,PROP.TempNo, PROP.FastTrackNo ,Prop.RevNo ,PROP.CTSNo as CTSNo, PROP.FinalPlotNo as FinalPlotNo,
SeqDocument.CurrentSequence,IsNull(PROP.ProposalID,0) as ProposalID,IsNull(PROP.PlotRegion,0) as PlotRegion,
IsNull(Prop.ReservationID,0) as ReservationID, Prop.ADRunKey,IsNull(Prop.ApplicantName, '') as ApplicantName, Prop.CaseSubType,
IsNull(Prop.OwnerPeth,'') as OwnerPeth, Prop.ProposedProject, P.Name as ConsultantName, Prop.CURRENTSTAGEID, Seq.SequenceMode, Seq.Sequencebody,
Seq.Phaseid, PROP.RegionCode, Seq.SequenceNo, Seq.Validity, Seq.BillDate, Seq.BillNo, Seq.TransactionRegion
FROM Sequence Seq
INNER JOIN Sequence$Document SeqDocument ON Seq.SeqId = SeqDocument.DocId
LEFT OUTER JOIN ClassMapping CM ON Seq.ClassId = CM.ClassID
LEFT OUTER JOIN ObjectClass OC ON CM.ClassID = OC.ClassID
LEFT OUTER JOIN ObjectClass OC2 ON OC.ParentID = OC2.ClassID
LEFT OUTER JOIN Sequence_Flow SF ON Seq.SeqID = SF.SeqID
LEFT OUTER JOIN OrgPeople OrgP ON Seq.SeqSrcId = OrgP.Id And Seq.SeqSrcClsId = OrgP.ClsId
LEFT OUTER JOIN TemplateProposals PROP ON Seq.SeqID = PROP.DocId
LEFT OUTER JOIN Sequence_Flow_Target ST ON SF.FlowId = ST.FlowId
LEFT OUTER JOIN People P ON P.PeopleId = PROP.ArchitectId
WHERE SeqClsId = 6 AND SeqSubClsId = 1 AND Seq.SeqTypId = 3
AND Seq.SeqSubTypId = 0 AND Seq.State IN (1,2,3,5) AND ST.ResponderActive IN ('1', '2')
AND ST.TARGETPOSTID IN (132,1333,135,136 )
Order By ProposalInwardDate DESC
此查询在 Intel (i5 3.00GHz) 8GB RAM 上需要 50 秒(大约),结果为 5676 行。
Sequence 176232行38列,Sequence$Document 132776行8列,ClassMapping 6行10列,ObjectClass 6行11列,Sequence_Flow 4847730行22列,OrgPeople 4656行11列,TemplateProposals 90889行64列,Sequence_Flow_Target 521621行9列,人 4655 行 67 列。
所有属性数据类型都在(数字、字符串、日期)