Sql-server – Filter not working on Showplan XML in SQL Server trace

sql serversql server 2014trace

I have setup a SQL Server trace to capture long running queries on my SQL Server 2014 box and added Showplan XML event to capture the execution plan of the queries. The trace was created with duration filter. During the testing, I found that Showplan XML didn't take duration filter into account and was showing execution plan for all queries. I was expecting only the queries with my duration filter and their execution plans in the trace. However, this was not the case. It was showing duration filter queries correctly but the execution plan was getting logged for all the queries.

Does anyone know how to get around this problem in SQL Server trace?

Best Answer

SHOWPLAN XML event does not have a column with cpu duration so you cannot filter by duration. You can only filter by columns mentioned in this article.

https://docs.microsoft.com/en-us/sql/relational-databases/event-classes/showplan-xml-event-class

Few alternatives:

  • use filter by other allowed columns.

  • capture everything for as minimum time as practical, load in table and filter. Be careful about load generated by this process, especially on production server.

  • Trace for long running queries. Use that list to filter SHOWPLAN XML event.