Warning: Constant WP_TEMP_DIR already defined in /var/www/html/blogs/joe/wp-config.php on line 93
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902
{"id":1073,"date":"2013-11-16T09:54:31","date_gmt":"2013-11-16T17:54:31","guid":{"rendered":"http:\/\/3.209.169.194\/blogs\/joe\/?p=1073"},"modified":"2013-12-29T19:12:03","modified_gmt":"2013-12-30T03:12:03","slug":"a-first-look-at-the-query_optimizer_estimate_cardinality-xe-event","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/joe\/a-first-look-at-the-query_optimizer_estimate_cardinality-xe-event\/","title":{"rendered":"A first look at the query_optimizer_estimate_cardinality XE event"},"content":{"rendered":"
This weekend I set up a Windows Azure virtual machine running SQL Server 2014 CTP2 (12.0.1524).\u00a0 I had a local copy of SQL Server 2014 CTP2 in VMware as well, but thought it would be more fun to explore it on Windows Azure (kill two explorations with one stone).\u00a0 On a side note, I\u2019m really digging having the azure credits to play with each month.\u00a0 If you have an MSDN subscription, be sure to take advantage of this benefit.<\/em><\/p>\n
In this post I\u2019m just sharing my initial exploration steps regarding the query_optimizer_estimate_cardinality XE event.\u00a0 I\u2019m not entirely sure how well this event will be documented, but I\u2019m definitely interested in learning more about it.<\/p>\n
For my test scenario, I attached a version of AdventureWorksLT2012, set it to compatibility level 120 and then created the following session:<\/p>\n
If you\u2019re looking for the query_optimizer_estimate_cardinality in the GUI, keep in mind that it is in the Debug channel (so you\u2019ll need to select this in order to see it).\u00a0 This also implies that there is likely nontrivial overhead to enabling this event, so while there isn\u2019t an explicit warning for this event like other more invasive ones, I would still use it with caution.<\/p>\n
As for the description of this event in the GUI, it is as follows:<\/p>\n
\u201cOccurs when the query optimizer estimates cardinality on a relational expression.\u201d<\/p><\/blockquote>\n
Okay \u2013 no big deal, right?\u00a0 Why care?<\/p>\n
So in keeping things simple, I executed the following query against a single table (using the RECOMPILE so I can get the event each time I tested it out):<\/p>\n
The actual query execution plan had a Clustered Index Seek with an estimate of 1 row.\u00a0 And gathering the query_optimizer_estimate_cardinality event I saw two events surfaced.<\/p>\n
The first event had the following information:<\/p>\n
So there is a lot here to dig through, but I highlighted a couple of values that stood out. And I know that AddressID happens to be my clustered, unique, primary key column for this table.<\/p>\n
What happens if I reference a non-unique key value that is covered by an index (such as StateProvince)?<\/p>\n
Also \u2013 for a scenario where I didn\u2019t have stats \u2013 and disabled them from being auto-created (to simulate a wild guess scenario), I saw the following calculator list:<\/p>\n
This query plan just had a Clustered Index Scan, but spawned five query_optimizer_estimate_cardinality events associated with it (and I tested this a few times to see if the 5-event output was consistent):<\/p>\n
Lots of scenarios to mull over and dig through as time permits.<\/p>\n
Why care?<\/p>\n
Many query performance issues (and associated query plan quality issues) are due to cardinality estimate skews.\u00a0\u00a0\u00a0 It would be great to have a way to more efficiently point to how <\/em>the various estimates are being calculated and why<\/em> the estimates are off.<\/p>\n
I\u2019m not sure how in-depth this event and associated calculators will be documented by Microsoft, and my assumption is that we\u2019ll need to figure it out via collective reverse-engineering.\u00a0 But in the meantime this new XE event might prove to be quite useful for troubleshooting the more mysterious cardinality estimates.<\/p>\n","protected":false},"excerpt":{"rendered":"
This weekend I set up a Windows Azure virtual machine running SQL Server 2014 CTP2 (12.0.1524).\u00a0 I had a local copy of SQL Server 2014 CTP2 in VMware as well, but thought it would be more fun to explore it on Windows Azure (kill two explorations with one stone).\u00a0 On a side note, I\u2019m really […]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42,24,28],"tags":[],"class_list":["post-1073","post","type-post","status-publish","format-standard","hentry","category-cardinality-estimation","category-indexing","category-performance"],"yoast_head":"\n
A first look at the query_optimizer_estimate_cardinality XE event - Joe Sack<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n