{"id":3589,"date":"2014-05-25T17:40:00","date_gmt":"2014-05-25T15:40:00","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/"},"modified":"2014-05-25T17:40:00","modified_gmt":"2014-05-25T15:40:00","slug":"tempdb-enhancements-with-sql-server-2014","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/","title":{"rendered":"Tempdb enhancements with SQL Server 2014"},"content":{"rendered":"<p><img decoding=\"async\" class=\"blog-image aligncenter\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014.jpg\" alt=\"\" \/><\/p>\n<p>SQL Server 2014 is definitively designed for performance and I will try to demonstrate it during this blog post. I like to talk about hidden performance features because generally it does not require any changes for applications unlike in-memory tables for instance (aka hekaton tables).<\/p>\n<p>Since SQL Server 2005 version some improvements have been made for tempdb. Tempdb caching is one of them and allows to reduce the page allocation contention. Basically to create a table SQL Server must first build the system catalog entries related to system pages. Then, SQL Server has to allocate an IAM page and find a mixed extent in an SGAM page to store data and mark it in the PFS page (as a reminder, by default mixed extent is chosen unless to force uniform extent by using the traceflag 1118). Finally the allocation process must be recorded to system pages. When a table is dropped SQL Server has to revert all it have done for creating the table. It implies some normal locks and latches during all the allocation process, same ones used for creating and dropping a temporary table. However in tempdb tables are created and dropped very quickly and it can generate page allocation contention especially for PFS, SGAM and GAM system pages (the famous PAGELATCH_UP wait type against the concerned pages). The bottom line is that SQL Server can cache some of the metadata and page allocations from temporary objects for easier and faster reuse with less contention.<\/p>\n<p>In addition, to allow a temporary table to be cached it must be first used into a stored procedure but some situations can prevent this caching like:<\/p>\n<ul>\n<li>Using named constraints<\/li>\n<li>Using DDL after the temporary table creation<\/li>\n<li>Create a table in a different scope<\/li>\n<li>Using a stored procedure with recompile option<\/li>\n<\/ul>\n<p>By executing the following T-SQL script with SQLQueryStress we can easily show that temporary tables are not reused by SQL Server.<\/p>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">use<span style=\"font-size: 9.5pt;font-family: Consolas\"> [AdventureWorks2012]<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">go<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">create<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">table #test<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">(<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 TransactionID <span style=\"color: blue\">bigint<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ProductID\u00a0\u00a0\u00a0 <span style=\"color: blue\">int<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 TransactionDate\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">datetime<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Quantity\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">int<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ActualCost\u00a0\u00a0 <span style=\"color: blue\">money<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">)<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">insert<span style=\"font-size: 9.5pt;font-family: Consolas\"> #test<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">select<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">top 10000 <span style=\"color: gray\">*<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">from<span style=\"font-size: 9.5pt;font-family: Consolas\"> AdventureWorks2012<span style=\"color: gray\">.dbo<span style=\"color: gray\">.bigTransactionHistory<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">select<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ProductID<span style=\"color: gray\">,<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: fuchsia\">sum<span style=\"color: gray\">(Quantity <span style=\"color: gray\">* ActualCost<span style=\"color: gray\">) <span style=\"color: blue\">as total_cost<\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">from<span style=\"font-size: 9.5pt;font-family: Consolas\"> #test<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">where<span style=\"font-size: 9.5pt;font-family: Consolas\"> ProductID <span style=\"color: gray\">= <span style=\"color: red\">&#8216;16004&#8217;<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">group<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">by ProductID<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">drop<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">table #test<span style=\"color: gray\">;<\/span><\/span><\/span><\/span><\/div>\n<p>I used 8 concurrent threads with 100 iterations during this test.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/Blog_9_-sqlstress_test1.jpg\" alt=\"Blog_9_-sqlstress_test1\" width=\"525\" height=\"357\" \/><\/p>\n<p>In the same time, I enabled the following perfmon counters:<\/p>\n<table style=\"width: 472px;border-collapse: collapse\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border: 1pt solid #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong>Counter name<\/strong><\/p>\n<\/td>\n<td style=\"width: 65.55pt;border-width: 1pt 1pt 1pt medium;border-style: solid solid solid none;border-color: #bfbfbf #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"87\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong>Min value<\/strong><\/p>\n<\/td>\n<td style=\"width: 63.8pt;border-width: 1pt 1pt 1pt medium;border-style: solid solid solid none;border-color: #bfbfbf #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"85\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong>avg value<\/strong><\/p>\n<\/td>\n<td style=\"width: 63.65pt;border-width: 1pt 1pt 1pt medium;border-style: solid solid solid none;border-color: #bfbfbf #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"85\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong>Max value<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: black\">Average latch wait time (ms)<\/span><\/p>\n<\/td>\n<td style=\"width: 65.55pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"87\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">1,043<\/span><\/p>\n<\/td>\n<td style=\"width: 63.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"85\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">3,327<\/span><\/p>\n<\/td>\n<td style=\"width: 63.65pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"85\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">7,493<\/span><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: black\">Latch wait \/ sec<\/span><\/p>\n<\/td>\n<td style=\"width: 65.55pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"87\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">110,014<\/span><\/p>\n<\/td>\n<td style=\"width: 63.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"85\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">242,468<\/span><\/p>\n<\/td>\n<td style=\"width: 63.65pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"85\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">965,508<\/span><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: red\">Temp tables creation rate \/ sec<\/span><\/p>\n<\/td>\n<td style=\"width: 65.55pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"87\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: red\">4,001<\/span><\/p>\n<\/td>\n<td style=\"width: 63.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"85\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: red\">16<\/span><\/p>\n<\/td>\n<td style=\"width: 63.65pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"85\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: red\">21,146<\/span><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: red\">Cache objects in Use<\/span><\/p>\n<\/td>\n<td style=\"width: 65.55pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"87\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: red\">0<\/span><\/p>\n<\/td>\n<td style=\"width: 63.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"85\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: red\">0<\/span><\/p>\n<\/td>\n<td style=\"width: 63.65pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"85\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: red\">0<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Now if I rewrite the same ad-hoc T-SQL statement into a stored procedure and then I perform the same test we can notice some speed improvements:<\/p>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">use<span style=\"font-size: 9.5pt;font-family: Consolas\"> [AdventureWorks2012]<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">go<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">create<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">procedure [dbo]<span style=\"color: gray\">.[sp_test_tempdb]<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">as<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">create<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">table #test<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">(<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 TransactionID <span style=\"color: blue\">bigint<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ProductID\u00a0\u00a0\u00a0 <span style=\"color: blue\">int<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 TransactionDate\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">datetime<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Quantity\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">int<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ActualCost\u00a0\u00a0 <span style=\"color: blue\">money<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">)<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">insert<span style=\"font-size: 9.5pt;font-family: Consolas\"> #test<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">select<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">top 10000 <span style=\"color: gray\">*<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">from<span style=\"font-size: 9.5pt;font-family: Consolas\"> AdventureWorks2012<span style=\"color: gray\">.dbo<span style=\"color: gray\">.bigTransactionHistory<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">select<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ProductID<span style=\"color: gray\">,<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: fuchsia\">sum<span style=\"color: gray\">(Quantity <span style=\"color: gray\">* ActualCost<span style=\"color: gray\">) <span style=\"color: blue\">as total_cost<\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">from<span style=\"font-size: 9.5pt;font-family: Consolas\"> #test<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">where<span style=\"font-size: 9.5pt;font-family: Consolas\"> ProductID <span style=\"color: gray\">= <span style=\"color: red\">&#8216;16004&#8217;<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">group<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">by ProductID<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">drop<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">table #test<span style=\"color: gray\">;<\/span><\/span><\/span><\/span><\/div>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/blog_9_-_sqlstress_test2.jpg\" alt=\"blog_9_-_sqlstress_test2\" width=\"509\" height=\"366\" \/><\/p>\n<p>&nbsp;<\/p>\n<table style=\"width: 484px;border-collapse: collapse\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border: 1pt solid #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong><span style=\"color: black\">counter name<\/span><\/strong><\/p>\n<\/td>\n<td style=\"width: 65.55pt;border-width: 1pt 1pt 1pt medium;border-style: solid solid solid none;border-color: #bfbfbf #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"87\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong><span style=\"color: black\">min value<\/span><\/strong><\/p>\n<\/td>\n<td style=\"width: 63.8pt;border-width: 1pt 1pt 1pt medium;border-style: solid solid solid none;border-color: #bfbfbf #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"85\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong><span style=\"color: black\">avg value<\/span><\/strong><\/p>\n<\/td>\n<td style=\"width: 72.85pt;border-width: 1pt 1pt 1pt medium;border-style: solid solid solid none;border-color: #bfbfbf #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"97\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong><span style=\"color: black\">Max value<\/span><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: black\">Average latch wait time (ms)<\/span><\/p>\n<\/td>\n<td style=\"width: 65.55pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"87\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">0<\/span><\/p>\n<\/td>\n<td style=\"width: 63.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"85\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">0,855<\/span><\/p>\n<\/td>\n<td style=\"width: 72.85pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"97\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">1,295<\/span><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: black\">Latch wait \/ sec<\/span><\/p>\n<\/td>\n<td style=\"width: 65.55pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"87\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">0<\/span><\/p>\n<\/td>\n<td style=\"width: 63.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"85\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">4405,145<\/span><\/p>\n<\/td>\n<td style=\"width: 72.85pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"97\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">5910,304<\/span><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: black\">Temp tables creation rate \/ sec<\/span><\/p>\n<\/td>\n<td style=\"width: 65.55pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"87\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: red\">0<\/span><\/p>\n<\/td>\n<td style=\"width: 63.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"85\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: red\">0<\/span><\/p>\n<\/td>\n<td style=\"width: 72.85pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"97\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: red\">0<\/span><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: black\">Cache objects in Use<\/span><\/p>\n<\/td>\n<td style=\"width: 65.55pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"87\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: red\">0<\/span><\/p>\n<\/td>\n<td style=\"width: 63.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"85\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: red\">7,048<\/span><\/p>\n<\/td>\n<td style=\"width: 72.85pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"97\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: red\">8<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>As expected, this improvement is due to the tempdb caching mechanism. We can notice here that SQL Server reuses caching objects (\u201cCache objects in Use\u201d counter &gt; 0) that are in fact the temporary table into the stored procedure. Using caching objects decrease drastically the temporary table creation rate (Temp Tables creation rate \/ sec is equal to 0 here).<\/p>\n<p>The cached objects themselves are visible by using the system table sys.tables in the tempdb context. For example during the first test we can easily observe that SQL Server does not deallocate completely a temporary table used into a stored procedure. The relationship can be made with the object id column value with a negative number. When SQL Server uses a temporary table the name of table is #test and when SQL Server doesn\u2019t use it without deallocating the associated pages the name is composed of a 8-character hexadecimal string that maps in fact to the object id value. #AF42A2AE is the hexadecimal representation of the #test temporary table with the object id equal to -1354587474.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/blog_9_-_tempdb_caching.jpg\" alt=\"blog_9_-_tempdb_caching\" width=\"615\" height=\"69\" \/><\/p>\n<p>&#8230;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/blog_9_-_tempdb_caching_2.jpg\" alt=\"blog_9_-_tempdb_caching_2\" width=\"612\" height=\"70\" \/><\/p>\n<p>Furthermore we can notice several records in the above results because I used SQLQueryStress with 8 concurrent threads that imply concurrent executions of the stored procedure with separate cached objects in tempdb. We can see 4 records (I didn\u2019t show completely the entire result here) but in fact we retrieved 8 records.<\/p>\n<p>As I said earlier, DDL statements after the creation of the temporary table inhibits the ability to cache the temporary objects by SQL Server and can decrease the global performance of the stored procedure (we can ask here what is a DDL statement .. because DROP TABLE #table is apparently not considered as such because tempdb caching mechanism is not impacted). In my sample, SQL Server proposes to create the following index on the ProductID column to improve the query statement:<\/p>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">create<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">nonclustered <span style=\"color: blue\">index idx_test_transaction_product_id<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">on<span style=\"font-size: 9.5pt;font-family: Consolas\"> #test<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">(<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ProductID<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">)<\/span><\/div>\n<p style=\"background: none repeat scroll 0% 0% white\"><span style=\"color: #333333\">\u00a0<\/span><\/p>\n<p>Go ahead, we trust SQL Server and we will add the creation of the index after the creation of the temporary table into the stored procedure:<\/p>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">use<span style=\"font-size: 9.5pt;font-family: Consolas\"> [AdventureWorks2012]<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">go<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">create<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">procedure [dbo]<span style=\"color: gray\">.[sp_test_tempdb]<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">as<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">create<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">table #test<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">(<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 TransactionID <span style=\"color: blue\">bigint<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ProductID\u00a0\u00a0\u00a0 <span style=\"color: blue\">int<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 TransactionDate\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">datetime<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Quantity\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">int<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ActualCost\u00a0\u00a0 <span style=\"color: blue\">money<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">)<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: green\">&#8211;create index for ProductID predicate<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">create<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">nonclustered <span style=\"color: blue\">index idx_test_transaction_product_id<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">on<span style=\"font-size: 9.5pt;font-family: Consolas\"> #test<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">(<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ProductID<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">)<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">insert<span style=\"font-size: 9.5pt;font-family: Consolas\"> #test<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">select<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">top 10000 <span style=\"color: gray\">*<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">from<span style=\"font-size: 9.5pt;font-family: Consolas\"> AdventureWorks2012<span style=\"color: gray\">.dbo<span style=\"color: gray\">.bigTransactionHistory<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">select<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ProductID<span style=\"color: gray\">,<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: fuchsia\">sum<span style=\"color: gray\">(Quantity <span style=\"color: gray\">* ActualCost<span style=\"color: gray\">) <span style=\"color: blue\">as total_cost<\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">from<span style=\"font-size: 9.5pt;font-family: Consolas\"> #test<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">where<span style=\"font-size: 9.5pt;font-family: Consolas\"> ProductID <span style=\"color: gray\">= <span style=\"color: red\">&#8216;16004&#8217;<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">group<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">by ProductID<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">drop<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">table #test<span style=\"color: gray\">;<\/span><\/span><\/span><\/span><\/div>\n<p>However, the result is not as good as we would expect &#8230;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/blog_9_-_sqlstress_test3.jpg\" alt=\"blog_9_-_sqlstress_test3\" width=\"500\" height=\"354\" \/><\/p>\n<p>If we take a look at the perfmon counters values:<\/p>\n<table style=\"width: 472px;border-collapse: collapse\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border: 1pt solid #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong><span style=\"color: black\">Counter name <\/span><\/strong><\/p>\n<\/td>\n<td style=\"width: 58.5pt;border-width: 1pt 1pt 1pt medium;border-style: solid solid solid none;border-color: #bfbfbf #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"78\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong><span style=\"color: black\">min value<\/span><\/strong><\/p>\n<\/td>\n<td style=\"width: 2cm;border-width: 1pt 1pt 1pt medium;border-style: solid solid solid none;border-color: #bfbfbf #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"76\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong><span style=\"color: black\">avg value<\/span><\/strong><\/p>\n<\/td>\n<td style=\"width: 77.8pt;border-width: 1pt 1pt 1pt medium;border-style: solid solid solid none;border-color: #bfbfbf #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong><span style=\"color: black\">Max value<\/span><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: black\">Average latch wait time (ms)<\/span><\/p>\n<\/td>\n<td style=\"width: 58.5pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"78\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">0,259<\/span><\/p>\n<\/td>\n<td style=\"width: 2cm;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"76\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">0,567<\/span><\/p>\n<\/td>\n<td style=\"width: 77.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">0,821<\/span><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: black\">Latch wait \/ sec<\/span><\/p>\n<\/td>\n<td style=\"width: 58.5pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"78\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">0<\/span><\/p>\n<\/td>\n<td style=\"width: 2cm;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"76\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">2900<\/span><\/p>\n<\/td>\n<td style=\"width: 77.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">4342<\/span><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: black\">Temp tables creation rate \/ sec<\/span><\/p>\n<\/td>\n<td style=\"width: 58.5pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"78\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">3,969<\/span><\/p>\n<\/td>\n<td style=\"width: 2cm;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"76\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">5,09<\/span><\/p>\n<\/td>\n<td style=\"width: 77.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">8,063<\/span><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong><span style=\"color: red\">temp tables for destruction<\/span><\/strong><\/p>\n<\/td>\n<td style=\"width: 58.5pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"78\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><strong><span style=\"color: red\">0<\/span><\/strong><\/p>\n<\/td>\n<td style=\"width: 2cm;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"76\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><strong><span style=\"color: red\">27,02<\/span><\/strong><\/p>\n<\/td>\n<td style=\"width: 77.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><strong><span style=\"color: red\">58<\/span><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: black\">Cache objects in Use<\/span><\/p>\n<\/td>\n<td style=\"width: 58.5pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"78\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">6<\/span><\/p>\n<\/td>\n<td style=\"width: 2cm;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"76\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">7,9<\/span><\/p>\n<\/td>\n<td style=\"width: 77.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">8<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"color: #333333\">\u00a0<\/span><\/p>\n<p>For this test I added a new perfmon counter: temp tables for destruction that indicates clearly that the temporary tables will be destroyed by SQL Server because they cannot be used in this case: the index creation DDL prevents the tempdb caching mechanism.<\/p>\n<p>Here comes a new SQL Server 2014 feature that introduces a new way for declaring nonclustered indexes directly into the table creation DDL which can be a good workaround to the preceding test.<\/p>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">alter<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">procedure [dbo]<span style=\"color: gray\">.[sp_test_tempdb]<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">as<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">create<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">table #test<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">(<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 TransactionID <span style=\"color: blue\">bigint<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ProductID <span style=\"color: blue\">int <span style=\"color: blue\">index idx_test_transaction_product_id<span style=\"color: gray\">, <span style=\"color: green\">&#8211;&lt; index created &#8220;on the fly&#8221;<\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 TransactionDate\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">datetime<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Quantity\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">int<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ActualCost\u00a0\u00a0 <span style=\"color: blue\">money<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">)<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">insert<span style=\"font-size: 9.5pt;font-family: Consolas\"> #test<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">select<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">top 1000000 <span style=\"color: gray\">*<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">from<span style=\"font-size: 9.5pt;font-family: Consolas\"> AdventureWorks2012<span style=\"color: gray\">.dbo<span style=\"color: gray\">.bigTransactionHistory<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">select<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ProductID<span style=\"color: gray\">,<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: fuchsia\">sum<span style=\"color: gray\">(Quantity <span style=\"color: gray\">* ActualCost<span style=\"color: gray\">) <span style=\"color: blue\">as total_cost<\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">from<span style=\"font-size: 9.5pt;font-family: Consolas\"> #test<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">where<span style=\"font-size: 9.5pt;font-family: Consolas\"> ProductID <span style=\"color: gray\">= <span style=\"color: red\">&#8216;16004&#8217;<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">group<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">by ProductID<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">drop<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">table #test<span style=\"color: gray\">;<\/span><\/span><\/span><\/span><\/div>\n<p>After running the test we can notice that the temp tables creation rate and temp tables for destruction counters value are again equal to zero. SQL Server used the temporary table during the testing as showing the &#8220;Cache objects in User&#8221; counter.<\/p>\n<table style=\"width: 472px;border-collapse: collapse\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border: 1pt solid #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong><span style=\"color: black\">Counter name <\/span><\/strong><\/p>\n<\/td>\n<td style=\"width: 58.5pt;border-width: 1pt 1pt 1pt medium;border-style: solid solid solid none;border-color: #bfbfbf #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"78\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong><span style=\"color: black\">min value<\/span><\/strong><\/p>\n<\/td>\n<td style=\"width: 2cm;border-width: 1pt 1pt 1pt medium;border-style: solid solid solid none;border-color: #bfbfbf #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"76\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong><span style=\"color: black\">avg value<\/span><\/strong><\/p>\n<\/td>\n<td style=\"width: 77.8pt;border-width: 1pt 1pt 1pt medium;border-style: solid solid solid none;border-color: #bfbfbf #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong><span style=\"color: black\">Max value<\/span><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: black\">Average latch wait time (ms)<\/span><\/p>\n<\/td>\n<td style=\"width: 58.5pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"78\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">0<\/span><\/p>\n<\/td>\n<td style=\"width: 2cm;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"76\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">0,262<\/span><\/p>\n<\/td>\n<td style=\"width: 77.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">0,568<\/span><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: black\">Latch wait \/ sec<\/span><\/p>\n<\/td>\n<td style=\"width: 58.5pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"78\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">0<\/span><\/p>\n<\/td>\n<td style=\"width: 2cm;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"76\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">1369<\/span><\/p>\n<\/td>\n<td style=\"width: 77.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">3489<\/span><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: black\">Temp tables creation rate \/ sec<\/span><\/p>\n<\/td>\n<td style=\"width: 58.5pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"78\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">0<\/span><\/p>\n<\/td>\n<td style=\"width: 2cm;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"76\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">5,09<\/span><\/p>\n<\/td>\n<td style=\"width: 77.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">8,063<\/span><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\">temp tables for destruction<\/p>\n<\/td>\n<td style=\"width: 58.5pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"78\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\">0<\/p>\n<\/td>\n<td style=\"width: 2cm;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"76\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\">0<\/p>\n<\/td>\n<td style=\"width: 77.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\">0<\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 161pt;border-right: 1pt solid #bfbfbf;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color #bfbfbf #bfbfbf;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"215\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: black\">Cache objects in Use<\/span><\/p>\n<\/td>\n<td style=\"width: 58.5pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"78\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">6<\/span><\/p>\n<\/td>\n<td style=\"width: 2cm;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"76\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">7,9<\/span><\/p>\n<\/td>\n<td style=\"width: 77.8pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color #bfbfbf #bfbfbf -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;text-align: right;line-height: normal\" align=\"right\"><span style=\"color: black\">8<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>However if we can still use the tempdb caching mechanism with SQL Server 2014 and this new tips the above result is contrasted with the total duration of execution as showed by the following picture:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/blog_9_-_sqlstress_test5.jpg\" alt=\"blog_9_-_sqlstress_test5\" width=\"490\" height=\"334\" \/><\/p>\n<p>The global execution time is larger than the test first with the stored procedure, the temporary table without any nonclustered index (02:44 vs 00:21) in my case. This is because inserting data into a table with a nonclustered index can take more time than a table without any indexes but in a real production environment we will probably encounter situations where the cost for inserting data into a table with an index would be substantial compared to the gain made for the following readings. If you have some examples please feel free to share with us\u00a0\ud83d\ude00<\/p>\n<p>Another interesting feature since many versions is the concept of eager writes that prevent flooding the buffer pool with pages that are newly created, from bulk activities, and need to be written to disk. Eager write is another background process that helps to reduce the pressure of the well-known lazy writes and checkpoint background processes as well as increasing the IO performance by gathering pages before writing to disk. Basically, SQL Server tracks these pages into a circular list in memory. When the list is full old entries are removed by writing them to disk if still dirty.<\/p>\n<p>Let me show you with the following T-SQL script on the SQL Server 2012 instance. I used the traceflag 3917 to show eager writes activity (thanks to Bod Dorr for this tip).<\/p>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">use<span style=\"font-size: 9.5pt;font-family: Consolas\"> AdventureWorks2012<span style=\"color: gray\">;<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">go<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: green\">&#8212; create procedure sp_test_tempdb_2<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: green\">&#8212; bulk activity by using select into #table <\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">CREATE<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">procedure sp_test_tempdb_2<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">as<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">select<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 bth<span style=\"color: gray\">.*,<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 p<span style=\"color: gray\">.Name <span style=\"color: blue\">AS ProductName<span style=\"color: gray\">,<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 p<span style=\"color: gray\">.Color<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">into<span style=\"font-size: 9.5pt;font-family: Consolas\"> #test<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">from<span style=\"font-size: 9.5pt;font-family: Consolas\"> AdventureWorks2012<span style=\"color: gray\">.dbo<span style=\"color: gray\">.bigTransactionHistory <span style=\"color: blue\">as bth<\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: gray\">join AdventureWorks2012<span style=\"color: gray\">.dbo<span style=\"color: gray\">.bigProduct <span style=\"color: blue\">as p<\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">on<span style=\"font-size: 9.5pt;font-family: Consolas\"> bth<span style=\"color: gray\">.ProductID <span style=\"color: gray\">= p<span style=\"color: gray\">.ProductID<\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">where<span style=\"font-size: 9.5pt;font-family: Consolas\"> p<span style=\"color: gray\">.Color <span style=\"color: gray\">in<span style=\"color: gray\">(<span style=\"color: red\">&#8216;White&#8217;<span style=\"color: gray\">)<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: gray\">and p<span style=\"color: gray\">.Size <span style=\"color: gray\">= <span style=\"color: red\">&#8216;M&#8217;<\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">option <span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">(<span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">maxdop<span style=\"font-size: 9.5pt;font-family: Consolas\"> 1<span style=\"color: gray\">);<\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">select<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 TransactionDate<span style=\"color: gray\">,<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ProductID<span style=\"color: gray\">,<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ProductName<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Quantity<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: green\">&#8211;Quantity * ActualCost AS total_individual_sale<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">from <span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">(<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">select <\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: fuchsia\">ROW_NUMBER<span style=\"color: gray\">() <span style=\"color: blue\">OVER <span style=\"color: gray\">(<span style=\"color: blue\">PARTITION <span style=\"color: blue\">BY TransactionDate <span style=\"color: blue\">ORDER <span style=\"color: blue\">BY Quantity <span style=\"color: blue\">DESC<span style=\"color: gray\">) <span style=\"color: blue\">AS num<span style=\"color: gray\">,<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: gray\">*<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">from #test<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">)<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">transaction_production_sales_top_ten<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">where<span style=\"font-size: 9.5pt;font-family: Consolas\"> num <\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">option <span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">(<span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">maxdop<span style=\"font-size: 9.5pt;font-family: Consolas\"> 1<span style=\"color: gray\">);<\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">drop<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: blue\">table #test<\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">go<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: green\">&#8212; using of traceflag 3917 to show eager write activity (be carefull the ouput may be verbose)<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">dbcc<span style=\"font-size: 9.5pt;font-family: Consolas\"> traceon<span style=\"color: gray\">(3917<span style=\"color: gray\">);<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">dbcc<span style=\"font-size: 9.5pt;font-family: Consolas\"> traceon<span style=\"color: gray\">(3605<span style=\"color: gray\">);<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">go<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: green\">&#8212; cycle errorlog for next easy read<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">exec<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: maroon\">sp_cycle_errorlog<span style=\"color: gray\">;<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">go<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: green\">&#8212; execution of the stored procedure dbo.sp_test_tempdb_2;<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">exec<span style=\"font-size: 9.5pt;font-family: Consolas\"> dbo<span style=\"color: gray\">.sp_test_tempdb_2<span style=\"color: gray\">;<\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">go<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: green\">&#8212; Reading the error log file <\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">exec<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: maroon\">xp_readerrorlog<span style=\"color: gray\">;<\/span><\/span><\/span><\/span><\/div>\n<p><span style=\"font-family: Wingdings\">\u00a0<\/span><\/p>\n<p>Below a sample of the SQL Server error log:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/blog_9_-_sql12_eager_writes.jpg\" alt=\"blog_9_-_sql12_eager_writes\" width=\"572\" height=\"188\" \/><\/p>\n<p>We can notice that SQL Server writes up contiguous 32 dirty pages to disk in my test.<\/p>\n<p>Even if this process is optimized to write pages efficiently to disk, we have still IO activity. SQL Server 2014 enhances this process by relaxing the need to flush these pages to disk as quickly as the older versions. SQL Server recognizes the bulk activity and the concerned pages are loaded, queried and released without any flushing disk activity.<\/p>\n<p>The same test performed on the SQL Server 2014 environment gives the following result:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/blog_9_-_test_select_into_eager_write_sql14.jpg\" alt=\"blog_9_-_test_select_into_eager_write_sql14\" width=\"597\" height=\"127\" \/><\/p>\n<p>The eager write process was not triggered this time. So let\u2019s compare with a simulating workload by using ostress this time. Ostress is a stress tool provided by the <a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=4511\">RML utilities<\/a>. This time I used ostress with 4 threads and 1000 iterations each. SQLQueryStress generated a bunch of ASYNC_IO_NETWORK during my tests which potentially distorts the final result.<\/p>\n<p>So, I used the following script for the both environment (SQL Server 2012 and SQL Server 2014):<\/p>\n<p style=\"margin-bottom: 0.0001pt;background: none repeat scroll 0% 0% #d9d9d9\">&#8220;C:Program FilesMicrosoft CorporationRMLUtilsostress.exe&#8221; -Slocalhost -dAdventureWorks2012 -Q&#8221;exec dbo.sp_test_tempdb_2&#8243; -n4 -r1000 -N \u2013q<\/p>\n<p>&nbsp;<\/p>\n<h4>SQL Server 2012<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/blog_9_-_ostress_sql12.jpg\" alt=\"blog_9_-_ostress_sql12\" width=\"614\" height=\"133\" \/><\/p>\n<p>\u2026 the corresponding io file stats:<\/p>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">SELECT<\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 d<span style=\"color: gray\">.name <span style=\"color: blue\">AS database_name<span style=\"color: gray\">, <\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 f<span style=\"color: gray\">.name <span style=\"color: blue\">AS [file_name]<span style=\"color: gray\">, <\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 f<span style=\"color: gray\">.physical_name<span style=\"color: gray\">, <\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 f<span style=\"color: gray\">.type_desc<span style=\"color: gray\">, <\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 vf<span style=\"color: gray\">.num_of_reads<span style=\"color: gray\">, <\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 vf<span style=\"color: gray\">.num_of_writes<\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">FROM<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: green\">sys<span style=\"color: gray\">.<span style=\"color: green\">dm_io_virtual_file_stats<span style=\"color: gray\">(NULL, <span style=\"color: gray\">NULL) <span style=\"color: blue\">AS vf <\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">INNER<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: gray\">JOIN <span style=\"color: green\">sys<span style=\"color: gray\">.<span style=\"color: green\">databases <span style=\"color: blue\">AS d <\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">ON<span style=\"font-size: 9.5pt;font-family: Consolas\"> d<span style=\"color: gray\">.database_id <span style=\"color: gray\">= vf<span style=\"color: gray\">.database_id <\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: gray\">INNER<span style=\"font-size: 9.5pt;font-family: Consolas\"> <span style=\"color: gray\">JOIN <span style=\"color: green\">sys<span style=\"color: gray\">.<span style=\"color: green\">master_files <span style=\"color: blue\">AS f <\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">ON<span style=\"font-size: 9.5pt;font-family: Consolas\"> f<span style=\"color: gray\">.<span style=\"color: fuchsia\">file_id <span style=\"color: gray\">= vf<span style=\"color: gray\">.<span style=\"color: fuchsia\">file_id <\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas\">\u00a0\u00a0 <span style=\"color: gray\">AND f<span style=\"color: gray\">.database_id <span style=\"color: gray\">= vf<span style=\"color: gray\">.database_id <\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"margin-bottom: 0.0001pt;line-height: normal;background: none repeat scroll 0% 0% #d9d9d9\"><span style=\"font-size: 9.5pt;font-family: Consolas;color: blue\">where<span style=\"font-size: 9.5pt;font-family: Consolas\"> f<span style=\"color: gray\">.database_id <span style=\"color: gray\">= <span style=\"color: fuchsia\">db_id<span style=\"color: gray\">(<span style=\"color: red\">&#8216;tempdb&#8217;<span style=\"color: gray\">)<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/blog_9_-_ostress_sql12_tempdb_io.jpg\" alt=\"blog_9_-_ostress_sql12_tempdb_io\" width=\"615\" height=\"55\" \/><\/p>\n<p>\u2026 and the corresponding wait types:<\/p>\n<table style=\"border-collapse: collapse\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr style=\"height: 15pt\">\n<td style=\"width: 176.95pt;border: 1pt solid windowtext;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"236\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong>Wait type<\/strong><\/p>\n<\/td>\n<td style=\"width: 70.9pt;border-width: 1pt 1pt 1pt medium;border-style: solid solid solid none;border-color: windowtext windowtext windowtext -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"95\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong>Total wait<\/strong><\/p>\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong>ms<\/strong><\/p>\n<\/td>\n<td style=\"width: 92.1pt;border-width: 1pt 1pt 1pt medium;border-style: solid solid solid none;border-color: windowtext windowtext windowtext -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"123\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong>Total wait count<\/strong><\/p>\n<\/td>\n<td style=\"width: 78pt;border-width: 1pt 1pt 1pt medium;border-style: solid solid solid none;border-color: windowtext windowtext windowtext -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong>Avg wait time <\/strong><\/p>\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><strong>ms<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 176.95pt;border-right: 1pt solid windowtext;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color windowtext windowtext;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"236\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: red\">PAGEIOLATCH_UP<\/span><\/p>\n<\/td>\n<td style=\"width: 70.9pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"95\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: red\">452737834<\/span><\/p>\n<\/td>\n<td style=\"width: 92.1pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"123\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: red\">3333841<\/span><\/p>\n<\/td>\n<td style=\"width: 78pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: red\">135<\/span><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 176.95pt;border-right: 1pt solid windowtext;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color windowtext windowtext;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"236\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: red\">PAGEIOLATCH_EX<\/span><\/p>\n<\/td>\n<td style=\"width: 70.9pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"95\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: red\">343071451<\/span><\/p>\n<\/td>\n<td style=\"width: 92.1pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"123\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: red\">4696853<\/span><\/p>\n<\/td>\n<td style=\"width: 78pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\"><span style=\"color: red\">73<\/span><\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 176.95pt;border-right: 1pt solid windowtext;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color windowtext windowtext;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"236\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\">PREEMPTIVE_OS_ENCRYPTMESSAGE<\/p>\n<\/td>\n<td style=\"width: 70.9pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"95\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\">929<\/p>\n<\/td>\n<td style=\"width: 92.1pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"123\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\">29527<\/p>\n<\/td>\n<td style=\"width: 78pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\">0<\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 15pt\">\n<td style=\"width: 176.95pt;border-right: 1pt solid windowtext;border-width: medium 1pt 1pt;border-style: none solid solid;border-color: -moz-use-text-color windowtext windowtext;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"236\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\">PAGELATCH_SH<\/p>\n<\/td>\n<td style=\"width: 70.9pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"95\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\">603<\/p>\n<\/td>\n<td style=\"width: 92.1pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"123\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\">201<\/p>\n<\/td>\n<td style=\"width: 78pt;border-width: medium 1pt 1pt medium;border-style: none solid solid none;border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color;padding: 0cm 5.4pt;height: 15pt\" valign=\"top\" nowrap=\"nowrap\" width=\"104\">\n<p style=\"margin-bottom: 0.0001pt;line-height: normal\">3<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h4>SQL Server 2014<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/blog_9_-_ostress_sql14.jpg\" alt=\"blog_9_-_ostress_sql14\" width=\"612\" height=\"138\" \/><\/p>\n<p>&#8230;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/blog_9_-_ostress_sql14_tempdb_io.jpg\" alt=\"blog_9_-_ostress_sql14_tempdb_io\" width=\"606\" height=\"52\" \/><\/p>\n<p>&#8230;<\/p>\n<p><strong>Wait type<br \/>\nTotal wait<br \/>\nms<br \/>\nTotal wait count<\/strong><\/p>\n<p><span style=\"float: none;background-color: #ffffff;color: #333333;cursor: text;font-family: Georgia,'Times New Roman','Bitstream Charter',Times,serif;font-size: 16px;font-style: normal;font-variant: normal;font-weight: 400;letter-spacing: normal;text-align: left;text-decoration: none;text-indent: 0px;text-transform: none\">By David Barbarin<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL Server 2014 is definitively designed for performance and I will try to demonstrate it during this blog post. I like to talk about hidden performance features because generally it does not require any changes for applications unlike in-memory tables for instance (aka hekaton tables). Since SQL Server 2005 version some improvements have been made [&hellip;]<\/p>\n","protected":false},"author":26,"featured_media":3590,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[67,52,430],"type_dbi":[],"class_list":["post-3589","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-application-integration-middleware","tag-performance","tag-sql-server-2014","tag-tempdb"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Tempdb enhancements with SQL Server 2014 - dbi Blog<\/title>\n<meta name=\"description\" content=\"Tempdb enhancements with SQL Server 2014\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tempdb enhancements with SQL Server 2014\" \/>\n<meta property=\"og:description\" content=\"Tempdb enhancements with SQL Server 2014\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2014-05-25T15:40:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"245\" \/>\n\t<meta property=\"og:image:height\" content=\"149\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Microsoft Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Microsoft Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/\"},\"author\":{\"name\":\"Microsoft Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4\"},\"headline\":\"Tempdb enhancements with SQL Server 2014\",\"datePublished\":\"2014-05-25T15:40:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/\"},\"wordCount\":1903,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014.jpg\",\"keywords\":[\"Performance\",\"SQL Server 2014\",\"tempdb\"],\"articleSection\":[\"Application integration &amp; Middleware\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/\",\"name\":\"Tempdb enhancements with SQL Server 2014 - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014.jpg\",\"datePublished\":\"2014-05-25T15:40:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4\"},\"description\":\"Tempdb enhancements with SQL Server 2014\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#primaryimage\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014.jpg\",\"contentUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014.jpg\",\"width\":245,\"height\":149},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tempdb enhancements with SQL Server 2014\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4\",\"name\":\"Microsoft Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g\",\"caption\":\"Microsoft Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/microsoft-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Tempdb enhancements with SQL Server 2014 - dbi Blog","description":"Tempdb enhancements with SQL Server 2014","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/","og_locale":"en_US","og_type":"article","og_title":"Tempdb enhancements with SQL Server 2014","og_description":"Tempdb enhancements with SQL Server 2014","og_url":"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/","og_site_name":"dbi Blog","article_published_time":"2014-05-25T15:40:00+00:00","og_image":[{"width":245,"height":149,"url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014.jpg","type":"image\/jpeg"}],"author":"Microsoft Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Microsoft Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/"},"author":{"name":"Microsoft Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4"},"headline":"Tempdb enhancements with SQL Server 2014","datePublished":"2014-05-25T15:40:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/"},"wordCount":1903,"commentCount":0,"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014.jpg","keywords":["Performance","SQL Server 2014","tempdb"],"articleSection":["Application integration &amp; Middleware"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/","url":"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/","name":"Tempdb enhancements with SQL Server 2014 - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014.jpg","datePublished":"2014-05-25T15:40:00+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4"},"description":"Tempdb enhancements with SQL Server 2014","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#primaryimage","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014.jpg","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014.jpg","width":245,"height":149},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/tempdb-enhancements-with-sql-server-2014\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Tempdb enhancements with SQL Server 2014"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4","name":"Microsoft Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g","caption":"Microsoft Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/microsoft-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/3589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=3589"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/3589\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media\/3590"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=3589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=3589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=3589"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=3589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}