运行SQL server 2005的服务器已转换为虚拟机。原始服务器有16个逻辑核心。新的虚拟服务器只有4个核心,但应该更快。
一些存储过程(可能调用视图或UDF)运行时间较长。这可能是因为并行度较低。但是,查询计划是否仍然可以针对16核进行优化,或者它们会在硬件更改后自动重新优化吗?
如果我需要强制重新计算所有计划,最好的方法是什么?其他想法?
发布于 2012-06-09 02:23:28
Parallel Query Processing表明,保存的查询计划允许并行处理,但并没有特别绑定特定数量的线程。
可能还有其他原因需要周期性地编译新的查询计划,例如在更新统计数据之后。可以安排存储过程将所有存储过程标记为重新编译。我在以下方面取得了一些成功:
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发布于 2012-06-09 02:21:39
您可以使用以下命令清除计划缓存:
DBCC FREEPROCCACHE;然而,我会首先检查您的一些计划,对于一些“较慢”的查询,看看它们是否有任何并行操作放在首位。
https://stackoverflow.com/questions/10953729
复制相似问题