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 pop. 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. Bonus is that to trap that information, it is pretty lightweight as far as resource requirements go.
Without further ado, here is a quick XE session that could be setup to help trap this bugger.
And now for the caveats. This session will only work on SQL 2012. The second caveat is that there are two file paths defined in this session that must be changed to match your naming and directory structure for the output files etc.