如何提高SQL Server中大数据的获取速度

时间:2018-12-05 06:04:07

标签: sql sql-server sql-server-2008

以下是我的查询,需要2:26分钟才能从SQL Server 2008 R2数据库中提取9'619'516记录

查询:

SELECT 
    SERVERID, MSGID, BPID, FLOWID, FSID, FSSTEP, 
    MESSAGETYPEID, MESSAGESTRING, USERBLOB, USERCODE, 
    CREATEDATE, CREATETIME, OBJECTLEVEL, CATEGORY, 
    USERKEY1, USERKEY2, VERSIONKEY, STATUSCODE, SEVERITY, 
    EXTENSION, PROJECTKEY, BLOBEXISTS, ROOTFSID, 
    FLOWREQUESTID, FILELOCATION, RUNID, 
    TEMP_MGXPI4_1.DateTimeObject, TEMP_MGXPI4_1.TEMP_ROW_NUM 
FROM
    (SELECT 
         SERVERID, MSGID, BPID, FLOWID, FSID, FSSTEP, 
         MESSAGETYPEID, MESSAGESTRING, USERBLOB, USERCODE, 
         CREATEDATE, CREATETIME, OBJECTLEVEL, CATEGORY, 
         USERKEY1, USERKEY2, VERSIONKEY, STATUSCODE, 
         SEVERITY, EXTENSION, PROJECTKEY, BLOBEXISTS, ROOTFSID, 
         FLOWREQUESTID, FILELOCATION, RUNID,
         REPLACE(CONVERT(NVARCHAR(10),CREATEDATE, 126),'-','') + CONVERT(NVARCHAR(50),CREATETIME) AS DateTimeObject,
         ROW_NUMBER() OVER(ORDER BY CREATEDATE DESC, CREATETIME DESC, MSGID DESC) AS TEMP_ROW_NUM 
     FROM 
         IFS_ACTLOG 
     WHERE 
         PROJECTKEY = 'Project1' AND ROOTFSID = 1) AS TEMP_MGXPI4_1

查询的SQL Server执行计划:

Execution plan of query

1 个答案:

答案 0 :(得分:1)

很可能,您的性能取决于移动大量数据。

但是,从性能角度来看,您的查询是:

SELECT . . .,
   ROW_NUMBER() OVER (ORDER BY CREATEDATE DESC, CREATETIME DESC, MSGID DESC) AS TEMP_ROW_NUM 
 FROM  IFS_ACTLOG 
 WHERE PROJECTKEY = 'Project1' AND ROOTFSID = 1

此查询建议在(PROJECTKEY, ROOTFSID, CREATEDATE DESC, CREATETIME DESC, MSGID)上建立索引。

也就是说,即使查询运行得更快,被移出数据库的数据量仍然需要花费时间来处理。