8623错误:The query processor ran out of internal resources and could not pro
admin
2023-06-05 18:41:37
0

8623错误:The query processor ran out of internal resources and could not produce a query plan

 

问题描述:


配置了SQL Server安全性16的告警,发送邮件通知,如下:

8623错误:The query processor ran out of internal resources and could not pro


收到如下告警信息:

8623错误:The query processor ran out of internal resources and could not pro


查看错误日志:

8623错误:The query processor ran out of internal resources and could not pro

Error: 8623, Severity: 16, State: 1.    
The query processor ran out of internal resources and could not produce a query plan.

 

原因:


这是一个突发事件,预料中只会发生在极其复杂的查询,或者参照了非常大量的表或者分区的查询。比如,使用IN从句(多于10000个条目)SELECT记录。

 

解决方法:


如果是SQL Server 2008 R2及之前版本,使用Server Side Trace;如果是SQL Server 2012及之后版本,使用Extended Event。首先,跟踪到具体导致8623错误的查询。然后对查询进行优化,可以尝试将部分查询结果放到临时表中,然后再去根据条件关联。


对于IN从句,我们可以来看看BOL上的附注部分:

Explicitly including an extremely large number of values (many thousands of values separated by commas) within the parentheses, in an IN clause can consume resources and return errors 8623 or 8632. To work around this problem, store the items in the IN list in a table, and use a SELECT subquery within an IN clause.

Error 8623:

The query processor ran out of internal resources and could not produce a query plan. This is a rare event and only expected for extremely complex queries or queries that reference a very large number of tables or partitions. Please simplify the query. If you believe you have received this message in error, contact Customer Support Services for more information.

Error 8632:

Internal error: An expression services limit has been reached. Please look for potentially complex expressions in your query, and try to simplify them.


其他方法:


可以尝试运行带有使用了提示option(force order)、option(hash join)、option(merge join)、option(querytraceon 4102)的计划向导的查询。通过启用跟踪标志4102,将行为转为SQL Server 2000的半连接处理。启用跟踪标志4118、4122(或者涵盖的4199)也可以避免你看到的问题。查看文档确定你的情况下的具体原因:

Microsoft Knowledge Base article for TF 4122

Microsoft Knowledge Base article for TF 4102, 4118

Microsoft Knowledge Base article for TF 4199


打相关Hotfix补丁包,或者直接升级到对应版本最新的SP包。相关KB 982376文章:

FIX: A non-yielding scheduler error or an error 8623 occurs when you run a query that contains a large IN clause in SQL Server 2005, SQL Server 2008, or SQL Server 2008 R2

 

使用扩展事件识别8623错误:

 

在SQL Server 2012及后续版本运行以下TSQL脚本:

CREATE EVENT SESSION
overly_complex_queries
ON SERVER
ADD EVENT sqlserver.error_reported
(
ACTION (sqlserver.sql_text, sqlserver.tsql_stack, sqlserver.database_id, sqlserver.username)
WHERE ([severity] = 16
AND [error_number] = 8623)
)
ADD TARGET package0.asynchronous_file_target
(set filename = 'E:\SQL-DATA\XE\overly_complex_queries.xel' ,
metadatafile = 'E:\SQL-DATA\XE\overly_complex_queries.xem',
max_file_size = 10,
max_rollover_files = 5)
WITH (MAX_DISPATCH_LATENCY = 5SECONDS)
GO
-- Start the session
ALTER EVENT SESSION overly_complex_queries
ON SERVER STATE = START
GO


该创建语句若在SQL Server 2008 R2中运行,会报如下错误:

Msg 25706, Level 16, State 8, Line 1

The event attribute or predicate source, "error_number", could not be found.

 

参考:

https://blogs.technet.microsoft.com/mdegre/2012/03/13/8623-the-query-processor-ran-out-of-internal-resources-and-could-not-produce-a-query-plan/

http://dba.stackexchange.com/questions/28945/query-processor-ran-out-of-internal-resources-and-could-not-produce-a-query-plan

https://mssqlwiki.com/2012/10/07/optimizer-timeout-or-optimizer-memory-abort/

http://blog.rdx.com/blog/dba_tips/2014/05/using-server-trace-to-identify-8623-errors

http://jasonbrimhall.info/2014/01/02/day-9-queries-going-boom/


相关内容

热门资讯

真实感,AI时代写作的生命力所... AI时代,对于许多人来说,因为有了各种智能工具的加持,写作似乎变得容易了。通过提出命题、投喂内容,无...
一个以科技为名的节日,在一座深... 5月23日,2026年上海科技节在上海科技馆正式开幕,同日还将举办第五届上海科技传播大会,并见证上海...
原创 靠... 谁能想到,一笔眼看能让90后创始人躺赚140亿的AI公司收购案,会被商务部一记重拳紧急喊停。 江西小...
特朗普称美伊协议基本谈成 美东时间23日下午,美国总统特朗普在社交媒体发文,称美国与伊朗已经基本谈成一份协议。(央视记者 刘骁...
以媒:美伊协议或“非常不利”,... 新华社耶路撒冷5月23日电(记者陈君清 庞昕熠)以色列媒体23日报道,以总理内塔尼亚胡当晚召集执政联...
独属于AI时代的故事|新华走笔 来源:5月22日《新华每日电讯》 作者:孙正好 AI浪潮激荡,总会在那些平凡而普通的个体生命中,惊起...
原创 i... 2026年5月20日,iQOO带来了全新旗舰机型iQOO 15T,同时一口气上新iQOO Pad6 ...
巴基斯坦消息人士:美伊接近达成... 新华社伊斯兰堡5月23日电(记者杨恺)巴基斯坦官方消息人士23日告诉新华社记者,美国与伊朗接近达成一...
特朗普又说美伊“越来越接近”达... 新华社华盛顿5月23日电(记者黄强 徐剑梅)美国总统特朗普23日说,美国与伊朗的谈判“越来越接近”达...