The extended Execution Plan Analysis support is the most significant improvement in the latest SQL Enlight release 18.104.22.1685. It allows execution plans analysis to be automated and applied not only on separate statements or batches but on all stored procedures and views in a given database.
The execution plan analysis is implemented in the new analysis rule ‘EX0018: Analyze execution plan and check for high-cost operations’. The rule uses the XSLT extension method execute-query-plan which now extended with the support for generating XML execution plans for CREATE PROCEDURE and CREATE VIEW statements for which SQL Server otherwise does not produce execution plans.
The XML Execution Plan is generated using the execute-show-plan XSLT extension method which generates the execution plan XML by executing the provided T-SQL script with SHOWPLAN_XML ON option set. Internally, if necessary the method does some additional work in order to rewrite the CREATE PROCEDURE and CREATE VIEW statements in a way that is to be possible for an execution plan XML to be generated. The rewriting basically extracts the statement body (e.g. the SELECT statement from CREATE VIEW or the stored procedure body from CREATE PROCEDURE) and uses it to get the XML plan.
For example, the stored procedure statement on the left cannot generate execution plan XML, but after being rewritten by SQL Enlight, the resulting an expanded script (the one on the right) will be able to have an execution plan generated.
After having execution plan XML, the analysis rule EX0018 checks for several operations that could have in some cases a negative impact over query performance.
The rule checks the XML plan and returns information for missing indexes that have a high impact on the analyzed query, and also checks several operations for having higher than allowed(set in the rule parameters) estimated operator cost. The currently supported operators are Bookmark Lookups(Key Lookup, RID Lookup), Table Scan, Index Scan, Sort, and Hash Match.
The analysis results are output in the SQL Enlight Error List allow navigation to the statement that produces the given rule violation.
Showplan Schema – http://schemas.microsoft.com/sqlserver/2004/07/showplan/
Logical and Physical Operators Reference – http://msdn.microsoft.com/en-us/library/ms191158.aspx
Transact-SQL Statements That Produce Showplans – http://msdn.microsoft.com/en-us/library/ms187886.aspx