欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

SQL Server 更新统计信息出现严重错误,应放弃任何可能产生的结果

程序员文章站 2022-05-18 14:21:26
一台SQL Server 2008 R2版本(具体版本如下所示)的数据库,最近几天更新统计信息的作业出错,错误如下所示: Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64) Jun 28 2012 08:36:30 Copyright (c... ......

 

一台sql server 2008 r2版本(具体版本如下所示)的数据库,最近几天更新统计信息的作业出错,错误如下所示:

 

microsoft sql server 2008 r2 (sp2) - 10.50.4000.0 (x64)

    jun 28 2012 08:36:30

    copyright (c) microsoft corporation

    standard edition (64-bit) on windows nt 6.1 <x64> (build 7601: service pack 1) (hypervisor)

 

 

第一次碰到这么奇葩的问题。查看错误日志,就会发现更新统计信息时出现异常,生成了dump文件。

 

 

对表做dbcc checktable发现正常,未有一致性错误。

 

dbcc checktable('tbusretail')

 

 

 

 

 

后面查了一下资料,在官方文档看到有个bug会导致这个问题,官方文档为:fix: an access violation may occur when you update the statistics of a table after you enable and then disable conflict detection on a table in in sql server 2008 or in sql server 2008 r2。刚好我们这个环境的版本也在其中。具体参考下面:

 

 

 

 

cause

 

 

this issue occurs because the database engine is trying to load dangling statistics. when p2p conflict detection is enabled, an mdcolumnidp2pcdid system column is added to the base index rowset of the table. replication-related queries may create statistics on the system column automatically. when p2p conflict detection is disabled, the system column is removed from the table. however, the corresponding statistics remain. therefore, updating statistics causes the access violation exception to occur because the statistics cannot be added to the table.

 

 

sql server 2008 service pack 2

the fix for this issue was first released in cumulative update 3 for sql server 2008 service pack 2. for more information about this cumulative update package, click the following article number to view the article in the microsoft knowledge base:

2498535 cumulative update package 3 for sql server 2008 service pack 2

note because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous sql server 2008 fix release. microsoft recommends that you consider applying the most recent fix release that contains this hotfix. for more information, click the following article number to view the article in the microsoft knowledge base:

2402659 the sql server 2008 builds that were released after sql server 2008 service pack 2 was released

microsoft sql server 2008 hotfixes are created for specific sql server service packs. you must apply a sql server 2008 service pack 2 hotfix to an installation of sql server 2008 service pack 2. by default, any hotfix that is provided in a sql server service pack is included in the next sql server service pack.

 

 

the fix for this issue was first released in cumulative update package 6 for sql server 2008 r2. for more information about how to obtain this cumulative update package, click the following article number to view the article in the microsoft knowledge base:

2489376 cumulative update package 6 for sql server 2008 r2

note because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous sql server 2008 r2 fix release. we recommend that you consider applying the most recent fix release that contains this hotfix. for more information, click the following article number to view the article in the microsoft knowledge base:

981356 the sql server 2008 r2 builds that were released after sql server 2008 r2 was released

 

 

但是等我打上补丁后,测试发现问题依然存在,也只有这个表存在这个问题。后面仔细检查,发现这个表有不少计算列(computed column),刚好以前也遇到过由于计算列导致统计信息更新出现错误的情况,一检查,发现这表有大量的统计信息,遂生成删除统计信息的脚本后执行删除(排除了相关索引的统计信息)。然后再更新统计信息,ok,问题解决了。看来又是神奇的计算列computed column导致的统计信息更新异常!

 

 

select  'drop statistics dbo.tbusretail.' + quotename(name) + ';'

from    sys.stats

where   object_id = object_id('dbo.tbusretail')

 

 

drop statistics dbo.tbusretail.[pk_tbusretail];  --排除这个统计信息

drop statistics dbo.tbusretail.[idxrefnoopdate]; --排除这个统计信息

drop statistics dbo.tbusretail.[_wa_sys_00000016_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_00000015_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_00000003_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_payway_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_opr_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_charger_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_refno_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_ticketamount_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_chargedate_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_ticketfamount_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_payamount_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_accepted_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_opdate_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_checked_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_checkdate_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_hangup_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_tpayamount_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_remark_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_retailtype_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_acceptdate_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_ifnetretail_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_dismodified_58bcecdb]

drop statistics dbo.tbusretail.[_wa_sys_dealed_58bcecdb]

drop

上一篇: 别骗吃骗喝

下一篇: 我妈四十八岁