This is my first blog for Year 2024!
Recently I have the opportunity to go through "Query Optimizer Deep Drive" article series by Paul White.
It was one of the very good and soundly technical series on Query Optimization. However, thing got my most attention was Query Optimizer's input tree and how we can get it output on SSMS output window.
On SQL Server's Optimizer Pipe line, first component is "Input Tree" (Bound Logical Tree). Input Tree make it easier for optimizer to understand the query better. For example, different developers can write same query in different way. But if we can get it break down to logical steps and standardize it will be muck easier for next phases in Optimizer.
By reading and understanding the Input tree or logical steps, we can also understand how query will going to perform on SQL server and hence help to optimize the query.
So how do we make it appear on output?
As per above mentioned article we can use undocumented trace flag 8605 for this. If you want tree output to appear on SSMS output window use the trace flag 3604.
Here is my query to test this. It is a simple contact table with First name and Surname.
SELECT c.CONTACT_FirstNames, c.CONTACT_Surname FROM CONTACT c
OPTION
(
RECOMPILE,
QUERYTRACEON 3604,
QUERYTRACEON 8605
);
And then you can see the following output on the SSMS output window.
*** Converted Tree: ***
LogOp_Project QCOL: [c].CONTACT_FirstNames QCOL: [c].CONTACT_Surname
LogOp_Get TBL: CONTACT(alias TBL: c) CONTACT TableID=1668825653 TableReferenceID=0 IsRow: COL: IsBaseRow1000
AncOp_PrjList
*******************
(52624 rows affected)
Completion time: 2024-01-15T09:27:30.1054801+00:00
No comments:
Post a Comment