Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/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 server 我是否需要重新优化视图&;更改服务器核心数后的过程_Sql Server_Sql Server 2005 - Fatal编程技术网

Sql server 我是否需要重新优化视图&;更改服务器核心数后的过程

Sql server 我是否需要重新优化视图&;更改服务器核心数后的过程,sql-server,sql-server-2005,Sql Server,Sql Server 2005,运行SQL server 2005的服务器已转换为虚拟机。原始服务器有16个逻辑核心。新的虚拟服务器只有4个核心,但速度应该更快 某些存储过程(可能调用视图或UDF)的运行时间更长。这可能是因为并行性较差。但是,查询计划是否仍然可以针对16个核心进行优化,还是在硬件更改后自动重新优化 如果我需要强制重新计算所有计划,最好的方法是什么?还有别的想法吗 您可以使用以下方法清除计划缓存: DBCC FREEPROCCACHE; 但是,对于某些“较慢”的查询,我会首先检查您的一些计划,看看它们是否有任

运行SQL server 2005的服务器已转换为虚拟机。原始服务器有16个逻辑核心。新的虚拟服务器只有4个核心,但速度应该更快

某些存储过程(可能调用视图或UDF)的运行时间更长。这可能是因为并行性较差。但是,查询计划是否仍然可以针对16个核心进行优化,还是在硬件更改后自动重新优化


如果我需要强制重新计算所有计划,最好的方法是什么?还有别的想法吗

您可以使用以下方法清除计划缓存:

DBCC FREEPROCCACHE;
但是,对于某些“较慢”的查询,我会首先检查您的一些计划,看看它们是否有任何并行操作。

显示保存的查询计划允许并行处理,但没有专门绑定特定数量的线程

可能还有其他原因需要定期编译新的查询计划,例如在更新统计数据之后。可以安排存储过程来标记所有要重新编译的存储过程。我在以下方面取得了一些成功:

create procedure [dbo].[INUpdateStatistics]
as
  set nocount on

  create table #Tables ( Table_Qualifier sysname, Table_Owner sysname, Table_Name sysname, Table_Type VarChar(32), Remarks VarChar(254) )

  declare CTable cursor local for select Table_Name, Table_Owner, Table_Type from #Tables order by Table_Name
  declare @TableName as sysname
  declare @TableOwner as sysname
  declare @TableType as sysname

  -- Get the list of tables in the database.
  insert into #Tables exec sp_tables
  open CTable
  fetch next from CTable into @TableName, @TableOwner, @TableType
  -- For each table ... .
  while @@Fetch_Status = 0
    begin
    if @TableOwner = 'dbo' and @TableType = 'TABLE'
      begin
      -- Update statistics for all user tables.
      execute( 'update statistics [' + @TableName + '] with fullscan, all' )
      -- Recompile all stored procedures and triggers when they are next executed.
      exec sp_recompile @objname = @TableName
      -- Throttle the loop.
      waitfor delay '00:00:01'
      end
    fetch next from CTable into @TableName, @TableOwner, @TableType
    end

  -- Houseclean.
  close CTable
  deallocate CTable
  drop table #Tables

当统计数据被更新时,计划将在下次执行查询时自动得到基于优化的重新编译。@MartinSmith-的确如此!看起来我的旧SP崩溃为大约
SP\u updatestats
。多亏了你们两位。我要更新过期的统计数据@如果可以的话,我会给你一个+1。