Question: In the SQL Server Error Logs I saw the following message:
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
Is there a way to find the query ? I know I can use something like Extended Events – which would allow me to trap the sql text , but what about finding a query that has executed and triggered this error
Answer: If you don’t have the query , you can use some DMVs to extract large queries .The limitation is that the data from DMVs is refreshed after every SQL Server restart.
Here are some example queries utilitising DMVs which could assist you to track down the query .
Look for queries with long IN lists, an unusually large number of UNIONS & nested sub queries. In my experience these have contributed a large percentage of the reason for these error messages.
On occasion , the root cause may be fixed by a the service pack upgrade.