How to fix 'query processor ran out of internal resources' in SQL Server

SQL-Server

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

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 8623 Severity 16

That is a beautiful error. The message is replete with information and gives you everything needed to fix the problem, right? More than a handful of DBAs have been frustrated by this error. It's not just DBAs that this message seems to bother. I have seen plenty of clients grumble about it too.

The obvious problem is that we have no real information as to what query caused the error to appear. The frustrating part is that the error may not be a persistent or consistent issue.

Thanks to the super powers of XE (extended events), we can trap that information fairly easily now. The bonus is that trapping that information is pretty lightweight as far as resource requirements go.

Without further ado, here is a quick XE session that could be set up to help trap this bugger.