Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql “存储过程疑难解答”;有时";慢动作_Sql_Sql Server 2012 - Fatal编程技术网

Sql “存储过程疑难解答”;有时";慢动作

Sql “存储过程疑难解答”;有时";慢动作,sql,sql-server-2012,Sql,Sql Server 2012,我有一些性能差异很大的存储过程。我不知道为什么 例如,存储过程1通常需要不到1秒的时间,但有时可能需要28秒!我们看到的是相同的SQL Server 2012企业版、相同的存储过程、相同的数据库和相同数量的数据。我弄不清楚到底发生了什么 如有任何意见或建议,将不胜感激。事先非常感谢 巨大差距: min_physical_reads max_physical_reads 518 6833 min_worker_time max_worker_time 93011 310917 min_l

我有一些性能差异很大的存储过程。我不知道为什么

例如,存储过程1通常需要不到1秒的时间,但有时可能需要28秒!我们看到的是相同的SQL Server 2012企业版、相同的存储过程、相同的数据库和相同数量的数据。我弄不清楚到底发生了什么

如有任何意见或建议,将不胜感激。事先非常感谢

巨大差距:

min_physical_reads  max_physical_reads
518 6833

min_worker_time max_worker_time
93011   310917

min_logical_writes  max_logical_writes
0   173

min_elapsed_time    max_elapsed_time
158005  27479580
以下是DMV的统计数据

cached_time
2014-09-11 19:00:03.267
cached_time last_execution_time execution_count total_worker_time   last_worker_time    min_worker_time max_worker_time total_physical_reads    last_physical_reads min_physical_reads  max_physical_reads  total_logical_writes    last_logical_writes min_logical_writes  max_logical_writes  total_logical_reads last_logical_reads  min_logical_reads   max_logical_reads   total_elapsed_time  last_elapsed_time   min_elapsed_time    max_elapsed_time
2014-09-11 19:00:03.267 2014-09-12 13:04:13.097 18  2194087 113974  93011   310917  20715   518 518 6833    2439    169 0

    173 863985  47981   47981   48145   65239761    237022  158005  27479580
狂欢

DMV统计数据(今天有2行,缓存时间不同

SCHEMA_NAME OBJECT_NAME database_id object_id   type    type_desc   sql_handle  plan_handle cached_time last_execution_time execution_count total_worker_time   last_worker_time    min_worker_time max_worker_time total_physical_reads    last_physical_reads min_physical_reads  max_physical_reads  total_logical_writes    last_logical_writes min_logical_writes  max_logical_writes  total_logical_reads last_logical_reads  min_logical_reads   max_logical_reads   total_elapsed_time  last_elapsed_time   min_elapsed_time    max_elapsed_time
dbo GetFormularyProducts    8   187355932   P   SQL_STORED_PROCEDURE    0x030008001CD32A0B70F43801A3A3000001000000000000000000000000000000000000000000000000000000  0x050008001CD32A0B307FD9320200000001000000000000000000000000000000000000000000000000000000  2014-09-12 17:43:09.833 2014-09-12 17:43:09.970 1   119014  119014  119014  119014  518 518 518 518 170 170 170 170 48190   48190   48190   48190   588034  588034  588034  588034
dbo GetFormularyProducts    8   187355932   P   SQL_STORED_PROCEDURE    0x030008001CD32A0B70F43801A3A3000001000000000000000000000000000000000000000000000000000000  0x050008001CD32A0BC07C00D00100000001000000000000000000000000000000000000000000000000000000  2014-09-11 19:00:03.267 2014-09-12 15:59:33.387 63  7253123 111992  93011   310917  44046   518 518 6833    8362    159 0   181 3024242 47980   47968   48193   367605152   3551205 158005  27479580
2014-09-12 17:43:09.970——存储过程缓存时间,存储过程日志记录为 LogDate EndDate ProcName参数列表
2014-09-12 17:43:09.973 2014-09-12 17:43:10.557 GetFormularyProducts@FormularyType=2@PracticeID=NULL@Filter=2@PageSize=-1感谢所有看过我的问题的人。我已经更改了存储过程以使用局部变量禁用参数嗅探。我将在下周进行监控,看看问题是否得到解决


非常感谢。

存储过程是什么样子的?一些代码会有帮助。你传递参数了吗?没有更多的细节我们会猜测。听起来像参数嗅探,但是……你需要提供更多的细节。当列标题不对齐时,表是不可读的。请考虑设置结果。发送文本并重新运行查询或使用可能也是服务器资源…这是在测试服务器上,还是您在任何给定时间都有很多其他事务在运行?我1000%同意@BlueFoots。这听起来像是参数嗅探。看看这里,确保您看到了第2部分和第3部分。而您(不可避免地)在编辑问题时,请发布列的实际查询计划(链接到dropbox/gist.github/answers.sqlperformance.com)、ddl、dbcc show_statistics的输出你正在筛选的,你正在使用的值-更好的是…发布两个查询!否则,我们不知道。鉴于手头的信息,我很想把它归咎于最近的x级太阳耀斑。
ElapsedTime logdate                 enddate                 Paramlist
0           2014-09-11 19:00:03.300 2014-09-11 19:00:03.920  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
28          2014-09-11 19:01:49.957 2014-09-11 19:02:17.430  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
1           2014-09-11 19:02:48.793 2014-09-11 19:02:49.843  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
0           2014-09-11 19:11:43.190 2014-09-11 19:11:43.530  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
1           2014-09-11 19:11:48.907 2014-09-11 19:11:49.257  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
0           2014-09-11 19:11:56.210 2014-09-11 19:11:56.483  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
0           2014-09-11 19:12:20.190 2014-09-11 19:12:20.523  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
0           2014-09-11 19:12:34.580 2014-09-11 19:12:34.920  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
0           2014-09-11 19:12:41.063 2014-09-11 19:12:41.323  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
0           2014-09-11 19:54:56.287 2014-09-11 19:54:56.490  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
0           2014-09-11 19:55:04.347 2014-09-11 19:55:04.520  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
0           2014-09-11 19:55:12.013 2014-09-11 19:55:12.170  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
22          2014-09-12 12:02:12.933 2014-09-12 12:02:34.363  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
2           2014-09-12 12:28:15.720 2014-09-12 12:28:17.903  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
3           2014-09-12 12:39:35.203 2014-09-12 12:39:38.130  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
4           2014-09-12 12:40:33.877 2014-09-12 12:40:37.103  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
3           2014-09-12 12:42:20.060 2014-09-12 12:42:23.690  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
0           2014-09-12 13:04:13.097 2014-09-12 13:04:13.333  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
0           2014-09-12 13:47:34.050 2014-09-12 13:47:34.270  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
7           2014-09-12 14:37:43.483 2014-09-12 14:37:50.527  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
3           2014-09-12 14:47:34.297 2014-09-12 14:47:37.153  @FormularyType = 2 @PracticeID = NULL @Filter = 2 @PageSize = -1
SCHEMA_NAME OBJECT_NAME database_id object_id   type    type_desc   sql_handle  plan_handle cached_time last_execution_time execution_count total_worker_time   last_worker_time    min_worker_time max_worker_time total_physical_reads    last_physical_reads min_physical_reads  max_physical_reads  total_logical_writes    last_logical_writes min_logical_writes  max_logical_writes  total_logical_reads last_logical_reads  min_logical_reads   max_logical_reads   total_elapsed_time  last_elapsed_time   min_elapsed_time    max_elapsed_time
dbo GetFormularyProducts    8   187355932   P   SQL_STORED_PROCEDURE    0x030008001CD32A0B70F43801A3A3000001000000000000000000000000000000000000000000000000000000  0x050008001CD32A0B307FD9320200000001000000000000000000000000000000000000000000000000000000  2014-09-12 17:43:09.833 2014-09-12 17:43:09.970 1   119014  119014  119014  119014  518 518 518 518 170 170 170 170 48190   48190   48190   48190   588034  588034  588034  588034
dbo GetFormularyProducts    8   187355932   P   SQL_STORED_PROCEDURE    0x030008001CD32A0B70F43801A3A3000001000000000000000000000000000000000000000000000000000000  0x050008001CD32A0BC07C00D00100000001000000000000000000000000000000000000000000000000000000  2014-09-11 19:00:03.267 2014-09-12 15:59:33.387 63  7253123 111992  93011   310917  44046   518 518 6833    8362    159 0   181 3024242 47980   47968   48193   367605152   3551205 158005  27479580