1

Fist of all, let me clarify that I'm brand new to this whole DBA world so I apologize in advance.

One of the databases I'm (since a couple of days ago) in charge of is throwing an 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."

This particular instance is running SQL Server 2014 SP2.

How do I find which query is causing this? I've been having a hard time finding documentation on this.

Thanks!

1 Answer 1

4

You can use Extended Events to capture failing queries. Here is a link to a detailed howto article. https://www.brentozar.com/archive/2013/08/what-queries-are-failing-in-my-sql-server/

TSQL to create xevents and start:

CREATE EVENT SESSION what_queries_are_failing
ON SERVER
ADD EVENT sqlserver.error_reported
(
ACTION (sqlserver.sql_text, sqlserver.tsql_stack, sqlserver.database_id, sqlserver.username)
WHERE ([severity]> 15)
)
ADD TARGET package0.asynchronous_file_target
(set filename = 'C:\XEventSessions\what_queries_are_failing.xel' ,
metadatafile = 'C:\XEventSessions\what_queries_are_failing.xem',
max_file_size = 5,
max_rollover_files = 5)
WITH (MAX_DISPATCH_LATENCY = 5SECONDS)
GO

-- Start the session
ALTER EVENT SESSION what_queries_are_failing
ON SERVER STATE = START
GO

-- Trigger Level 16 error
select * from Person.Person where ModifiedDate='20aaa'; 

--Query the logfile
;with events_cte as(
select
DATEADD(mi,DATEDIFF(mi, GETUTCDATE(), CURRENT_TIMESTAMP),
xevents.event_data.value('(event/@timestamp)[1]', 'datetime2')) AS [err_timestamp],
xevents.event_data.value('(event/data[@name="severity"]/value)[1]', 'bigint') AS [err_severity],
xevents.event_data.value('(event/data[@name="error_number"]/value)[1]', 'bigint') AS [err_number],
xevents.event_data.value('(event/data[@name="message"]/value)[1]', 'nvarchar(512)') AS [err_message],
xevents.event_data.value('(event/action[@name="sql_text"]/value)[1]', 'nvarchar(max)') AS [sql_text],
xevents.event_data
from sys.fn_xe_file_target_read_file
('C:\XEventSessions\what_queries_are_failing*.xel',
'C:\XEventSessions\what_queries_are_failing*.xem',null, null)
cross apply (select CAST(event_data as XML) as event_data) as xevents
)
SELECT *
from events_cte
order by err_timestamp;
1
  • Is there a way to get parameters from query in sql_text?
    – lear1
    Commented Jan 15 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.