从SQL Server 2008 R2获取粗略的7Mb数据到客户端需要大约5秒钟。该机相对强大的AMD 12 Core,64Gb RAM,Windows Server 2008,2个10Gbit卡。 在服务器上运行select甚至更慢,然后从客户端运行。将7Mb文件从该服务器复制到本地工作站大约需要500毫秒。
这是一个小型的复制品:
--create test table for reproducer
CREATE TABLE [dbo].[Test_Speed](
[ED] [datetime] NULL
) ON [PRIMARY]
--fill test table with data, insert took 3:51 mins
declare @r int
set @r = 1
while (@r < 830000)
begin
insert into [CDB_ODS].[dbo].[Test_Speed] select getdate()
set @r = @r+1
end
--select all records, roughly 7Mb. 4 secs if run on the client, 5 secs on the server (1.4Mb sec)
select ed from [dbo].[Test_Speed]
/*
SELECT on CLIENT
SQL Server parse and compile time:
CPU time = 0 ms, elapsed time = 0 ms.
Table 'Test_Speed'. Scan count 1, logical reads 1833, physical reads 0, read-ahead reads 0,
lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 281 ms, elapsed time = 4020 ms.
SQL Server parse and compile time:
CPU time = 0 ms, elapsed time = 0 ms.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
--- SELECT on SERVER
SQL Server parse and compile time:
CPU time = 0 ms, elapsed time = 0 ms.
(829999 row(s) affected)
Table 'Test_Speed'. Scan count 1, logical reads 1833, physical reads 0, read-ahead reads 0,
lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 328 ms, elapsed time = 5369 ms.
SQL Server parse and compile time:
CPU time = 0 ms, elapsed time = 0 ms.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
*/
答案 0 :(得分:0)
是的,这对我来说似乎相对正常。 7Mbytes是相当数量的数据。
性能在很大程度上取决于客户。当然,像网络速度这样的事情会产生影响。更大的影响是沿途各个点的缓冲区大小。为了获得最快的性能,您希望SQL Server一次性发送大批量的结果,然后快速将其放入应用程序中。
其他选项也有很大影响。在Excel / VBA中,有不同的数据输入方法。如果使用游标,则需要只读的前向游标。其他任何东西都可以更快,更慢。例如,一种游标将一次读取一行数据 - 因此延迟成为性能而非带宽的主导因素(我认为这是可更新的游标,但我不是正面的。)
您需要详细说明您的客户以及它如何访问数据。这很可能是客户端问题,而不是数据库问题。
答案 1 :(得分:0)
主键,索引搜索,索引扫描,执行计划,这些都是你的朋友。索引主题Check this link。这个forum post也可以帮助理解主键和外键。关于执行计划分析和理解,请查看this link
在我工作的数据库上工作并且已经工作检索了相似数量的信息,数千行,只需不到一秒钟。考虑到你的数据库设计以及后来通过测试不同的方法来调整查询的性能非常重要,并不总是抛出更多的CPU / RAM功率是最好的方法
EDITED
我对你的评论感到讽刺,希望不是你的目标。是我的客人使用我刚刚完成的以下测试(以前不可能做到,现在我已经下班了)。在我的情况下插入大约20-30s,因为我使用更好的方法(CTE)插入近100万行。比较时间您将看到使用主键比不使用主键快一点多。同样在服务器上通常快1秒。
CREATE TABLE [dbo].[Test_Speed]([ED] [DATETIME2] NULL) ON [PRIMARY]
CREATE UNIQUE CLUSTERED INDEX Idx1 ON Test_Speed(ED);
DECLARE @firstdate DATETIME2='00010101 00:00:00',
@lastdate DATETIME2= '25001231 00:00:00'
;WITH CTE_DatesTable
AS
(
SELECT @FirstDate AS auxDate
UNION ALL
SELECT DATEADD(dd, 1, auxDate)
FROM CTE_DatesTable
WHERE DATEADD(dd, 1, auxDate) <= @LastDate
)
INSERT INTO [dbo].[Test_Speed]
SELECT auxDate FROM CTE_DatesTable
OPTION (MAXRECURSION 0);
SET STATISTICS TIME ON;
SET STATISTICS IO ON;
SELECT ED FROM [dbo].[Test_Speed]
SET STATISTICS TIME OFF;
SET STATISTICS IO OFF;
/*
Select on Client with primary key , insertion 21s
(913106 row(s) affected)
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
(913106 row(s) affected)
Table 'Test_Speed'. Scan count 1, logical reads 1919, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 375 ms, elapsed time = 7790 ms
Select on Client without primary key , insertion 31s
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
(913106 row(s) affected)
Table 'Test_Speed'. Scan count 1, logical reads 1931, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
(1 row(s) affected)
SQL Server Execution Times:
CPU time = 405 ms, elapsed time = 8049 ms.
------------------
Select on Server with Primary key, insertion 19s
(913106 row(s) affected)
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
(913106 row(s) affected)
Table 'Test_Speed'. Scan count 1, logical reads 1931, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 187 ms, elapsed time = 6164 ms.
Select on Server without Primary key, insertion 25s
(913106 row(s) affected)
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
(913106 row(s) affected)
Table 'Test_Speed'. Scan count 1, logical reads 1919, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 343 ms, elapsed time = 7407 ms.
*/