tag:blogger.com,1999:blog-2131314766460217082024-03-13T00:59:26.539+01:00SQL Server OnlineHolger Schmeling about SQL ServerHolger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.comBlogger22125tag:blogger.com,1999:blog-213131476646021708.post-86709754244016407902011-11-01T12:36:00.001+01:002011-11-01T12:36:18.136+01:00Configuring a server side trace<p>When I’m after SQL Server performance  problems, SQL Server Profiler is still my number one tool. Allthough I know that extended events provide a mor lightweight solution, those are still a bit cumbersome to use (but I’ve seen that we can expect some improvements with SQL Server 2012).</p> <p>When I’m using profiler to isolate performance issues, I try to configure server side traces, whenever possible. Fortunately, SQL Server Profiler will help you creating a script for a server side trace (File/Export/Script Trace Definition), so you don’t have to figure out all the event- and column-codes. Very good!</p> <p>As I was doing the same configuration again and again, I decided to separate the TSQL code for the configuration inside a stored procedure.</p> <p>And here comes dbo.configureServerSideTrace:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0" width="1315"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="1313"> <p style="line-height: normal; margin: 6pt 0in" class="MsoNormal"><span style="font-family: ; color: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff" face="Lucida Console"><font style="font-size: 10pt">if</font></font></span><font style="font-size: 10pt"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font face="Lucida Console"><font color="#000000"> </font><span style="color: "><font color="#ff00ff">object_id</font></span><span style="color: "><font color="#808080">(</font></span><span style="color: "><font color="#ff0000">'dbo.configureServerSideTrace'</font></span><span style="color: "><font color="#808080">,</font></span><font color="#000000"> </font><span style="color: "><font color="#ff0000">'P'</font></span><span style="color: "><font color="#808080">)</font></span><font color="#000000"> </font><span style="color: "><font color="#808080">is</font></span><font color="#000000"> </font><span style="color: "><font color="#808080">not</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span style="color: "><font color="#808080">null</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">  </font></span><span style="color: "><font color="#0000ff">drop</font></span><font color="#000000"> </font><span style="color: "><font color="#0000ff">procedure</font></span><font color="#000000"> dbo</font><span style="color: "><font color="#808080">.</font></span><font color="#000000">configureServerSideTrace</font> <br /></font><span style="color: "><font face="Lucida Console"><font color="#0000ff">go</font> <br /> <br /></font></span><font face="Lucida Console"><span style="color: "><font color="#008000">-- Example for: <br />-- Start Trace <br />--<span style="mso-spacerun: yes">   </span>declare @traceID int <br />--<span style="mso-spacerun: yes">   </span>exec dbo.configureServerSideTrace @traceStatus = 1 <br />--<span style="mso-spacerun: yes">                                    </span>,@traceID = @traceID output <br />--<span style="mso-spacerun: yes">                                    </span>,@maxFileSize = 10000 <br />--<span style="mso-spacerun: yes">               </span><span style="mso-spacerun: yes">                     </span>,@traceFileName = N'e:\VMITrace\Undo' <br />--<span style="mso-spacerun: yes">                                    </span>,@spId = @@spid <br />-- <br />-- End Trace <br />--<span style="mso-spacerun: yes">   </span>exec dbo.configureServerSideTrace @traceStatus = 0, @traceID = @traceID</font> <br /> <br /> <br /></span><span style="color: "><font color="#0000ff">create</font></span><font color="#000000"> </font><span style="color: "><font color="#0000ff">procedure</font></span><font color="#000000"> dbo</font><span style="color: "><font color="#808080">.</font></span><font color="#000000">configureServerSideTrace</font> <br /><span style="color: "><span style="mso-spacerun: yes"><font color="#0000ff">                                 </font></span></span><span style="color: "><font color="#808080">(</font></span><font color="#000000">@traceStatus<span style="mso-spacerun: yes">   </span></font><span style="color: "><font color="#0000ff">bit</font></span><span style="mso-spacerun: yes"><font color="#000000">                  </font></span></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- 1 => Start Trace</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                                                                      </font></span></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- 0 => Stop Trace</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                                 </font></span><span style="color: "><font color="#808080">,</font></span><font color="#000000">@traceID<span style="mso-spacerun: yes">       </span></font><span style="color: "><font color="#0000ff">int</font></span><font color="#000000"> </font><span style="color: "><font color="#0000ff">output</font></span><span style="mso-spacerun: yes"><font color="#000000">           </font></span></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- If the Trace is started, this param will return the TraceID</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                                                                      </font></span></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- For stopping the trace, the param has to be provided</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                                 </font></span><span style="color: "><font color="#808080">,</font></span><font color="#000000">@spId<span style="mso-spacerun: yes">          </span></font><span style="color: "><font color="#0000ff">int</font></span><span style="mso-spacerun: yes"><font color="#000000">           </font></span><span style="color: "><font color="#808080">=</font></span><font color="#000000"> </font><span style="color: "><font color="#808080">null</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- provide the @@spid, if you want to filter only events for this conection</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                                                                      </font></span></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Optional. If not provided => no filter. Not needed for stopping the trace</font> <br /></span><font color="#000000"><span style="mso-spacerun: yes">                              </span><span style="mso-spacerun: yes">   </span></font><span style="color: "><font color="#808080">,</font></span><font color="#000000">@maxFileSize<span style="mso-spacerun: yes">   </span></font><span style="color: "><font color="#0000ff">bigint</font></span><span style="mso-spacerun: yes"><font color="#000000">        </font></span><span style="color: "><font color="#808080">=</font></span><font color="#000000"> 5000 </font></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Maximum Trace File Size in Megabyte. Trace will be stopped, if the filesize is reached.</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                                 </font></span><span style="color: "><font color="#808080">,</font></span><font color="#000000">@traceFileName </font><span style="color: "><font color="#0000ff">nvarchar</font></span><span style="color: "><font color="#808080">(</font></span><font color="#000000">200</font><span style="color: "><font color="#808080">)</font></span><font color="#000000"> </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> </font><span style="color: "><font color="#808080">null</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Name of the trace file (server side!)</font> <br /></span><font color="#000000"><span style="mso-spacerun: yes">              </span><span style="mso-spacerun: yes">                                                        </span></font></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Optional. Not neded for stoping the trace</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                                                                      </font></span></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Attention! If the file already exists, the SP will yield an error</font> <br /></span><font color="#000000"><span style="mso-spacerun: yes">                </span><span style="mso-spacerun: yes">                                                      </span></font></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- and no trace is started.</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                                 </font></span><span style="color: "><font color="#808080">)</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span style="color: "><font color="#0000ff">as <br />begin <br /> <br />if </font></span><span style="color: "><font color="#808080">(</font></span><font color="#000000">@traceStatus </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> 0</font></font><span style="color: "><font face="Lucida Console"><font color="#808080">)</font> <br /></font></span><font face="Lucida Console"><span style="color: "><font color="#0000ff">begin</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">   </font></span><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setstatus</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span></font><font face="Lucida Console"><font color="#000000"> 0 <br /><span style="mso-spacerun: yes">   </span></font><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setstatus</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span></font><font face="Lucida Console"><font color="#000000"> 2 <br /><span style="mso-spacerun: yes">   </span></font><span style="color: "><font color="#0000ff">return</font></span></font><span style="color: "><font face="Lucida Console"><font color="#808080">;</font> <br /></font></span><span style="color: "><font face="Lucida Console"><font color="#0000ff">end</font> <br /> <br /></font></span><font face="Lucida Console"><span style="color: "><font color="#008000">-- Create a Queue</font> <br /></span><span style="color: "><font color="#0000ff">declare</font></span><font color="#000000"> @rc </font></font><font face="Lucida Console"><span style="color: "><font color="#0000ff">int <br /> <br />exec</font></span><font color="#000000"> @rc </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_create</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID </font><span style="color: "><font color="#0000ff">output</font></span><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 0</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @traceFileName</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @maxfilesize</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> </font><span style="color: "><font color="#808080">NULL</font></span><font color="#000000"> </font> <br /><span style="color: "><font color="#0000ff">if </font></span><span style="color: "><font color="#808080">(</font></span><font color="#000000">@rc </font><span style="color: "><font color="#808080">!=</font></span><font color="#000000"> 0</font><span style="color: "><font color="#808080">)</font></span><font color="#000000"> </font><span style="color: "><font color="#0000ff">goto</font></span><font color="#000000"> error</font> <br /> <br /></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Set the events</font> <br /></span><span style="color: "><font color="#0000ff">declare</font></span><font color="#000000"> @on </font></font><font face="Lucida Console"><span style="color: "><font color="#0000ff">bit <br />set</font></span><font color="#000000"> @on </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> 1</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 15</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 48</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 1</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 34</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 35</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 51</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 4</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 12</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 13</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 14</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 22</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 1</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 14</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 22</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 34</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 35</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 51</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 4</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 12</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 16</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 48</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 1</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 17</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 18</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 34</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 35</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 51</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 4</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 12</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 13</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 14</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 22</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 15</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- XML Statistics Profile</font> <br /></span><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 146</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 1</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 146</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 51</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 146</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 4</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 146</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 12</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font> <br /> <br /></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Filter: Log only events for the provided @@spid</font> <br /></span><span style="color: "><font color="#0000ff">if</font></span><font color="#000000"> @spId </font><span style="color: "><font color="#808080">is</font></span><font color="#000000"> </font><span style="color: "><font color="#808080">not</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span style="color: "><font color="#808080">null</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">  </font></span><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setfilter</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 12</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 0</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 0</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @spID</font> <br /> <br /></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Set the trace status to start</font> <br /></span><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setstatus</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 1</font> <br /> <br /><span style="color: "><font color="#0000ff">goto</font></span><font color="#000000"> finish</font> <br /> <br /><span style="color: "><font color="#0000ff">error:</font></span><font color="#000000"> </font> <br /><span style="color: "><font color="#0000ff">select</font></span><font color="#000000"> ErrorCode</font><span style="color: "><font color="#808080">=</font></span><font color="#000000">@rc</font> <br /> <br /></font></span><span style="font-family: ; color: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><font color="#0000ff" face="Lucida Console">finish: <br />end</font></span></font><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><font face="Lucida Console"><font style="font-size: 10pt"><font color="#000000"> </font> <br /></font><span style="color: "><font style="font-size: 10pt" color="#0000ff">go</font></span></font></span><span style="mso-ansi-language: en-us" lang="EN-US"></span></p> </td> </tr> </tbody></table> <p>Some annotations:</p> <ul> <li>For the parameters, see the comments.</li> <li>Don’t specify a filename extension for the trace file. .TRC will be added automatically.</li> <li>Ensure that the output file does not already exist. Otherwise you’ll get an error.</li> <li>Very often I replace the code for starting and stopping the trace inside “interesting code” inside a stored procedure. That is, I’m wrapping some more or less awkward code by starting and stopping a trace like this:</li> </ul> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in" class="MsoNormal"><span style="font-family: ; color: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff" face="Lucida Console"><font style="font-size: 10pt">declare</font></font></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font style="font-size: 10pt"><font color="#000000" face="Lucida Console"> @traceID </font><font face="Lucida Console"><span style="color: "><font color="#0000ff">int <br />exec</font></span><font color="#000000"> dbo</font><span style="color: "><font color="#808080">.</font></span><font color="#000000">configureServerSideTrace</font><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@traceStatus </font><span style="color: "><font color="#808080">=</font></span></font><font face="Lucida Console"><font color="#000000"> 1 <br /><span style="mso-spacerun: yes">                                 </span></font><span style="color: "><font color="#808080">,</font></span><font color="#000000">@traceID </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> @traceID </font></font><font face="Lucida Console"><span style="color: "><font color="#0000ff">output</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                                 </font></span><span style="color: "><font color="#808080">,</font></span><font color="#000000">@maxFileSize </font><span style="color: "><font color="#808080">=</font></span></font><font face="Lucida Console"><font color="#000000"> 10000 <br /><span style="mso-spacerun: yes">                                 </span></font><span style="color: "><font color="#808080">,</font></span><font color="#000000">@traceFileName </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span style="color: "><font color="#ff0000">N'e:\MyTrace\Test'</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                                 </font></span><span style="color: "><font color="#808080">,</font></span><font color="#000000">@spId </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> </font></font><span style="color: "><font face="Lucida Console"><font color="#ff00ff">@@spid</font> <br /> <br /></font></span></font><font face="Lucida Console"><font style="font-size: 10pt"><span style="color: "><font color="#008000">-- <br />-- Code of interest <br />--</font> <br /> <br /></span><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> dbo</font><span style="color: "><font color="#808080">.</font></span><font color="#000000">configureServerSideTrace</font><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@traceStatus </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> 0</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @traceID </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> @traceID</font></font></font></span><span style="mso-ansi-language: en-us" lang="EN-US"></span></p> </td> </tr> </tbody></table> <p>Cheers.</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com1tag:blogger.com,1999:blog-213131476646021708.post-80593280937303556332011-02-27T15:57:00.001+01:002011-02-27T15:57:45.773+01:00Calculating SQL Server Data Compression Savings<p>SQL Server 2008 Enterprise edition comes with an opportunity for storing table or index data in a compressed format which may save huge amount of storage space and – much more important – IO requests and buffer pool utilization. There’s two different options for data compression, namely Row and Page level compression. This blog post is not concerned with how these two work internally and will also not explain the differences between the two. If you like to know more about this, you find much of useful information on the internet - including links to further articles (e.g. <a href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2007/11/12/types-of-data-compression-in-sql-server-2008.aspx">here</a>, <a href="http://www.sqlskills.com/blogs/kimberly/post/SQL-Server-2005-and-2008-Compression.aspx">here</a>, and <a href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2009/08/16/update-on-data-compression-in-sql-server-2008-rtm.aspx">here</a>).</p> <p>Whether compression is worth or not isn’t an easy question to answer. One aspect that has to be taken into account is certainly the amount of storage that may be saved by storing a distinct table or index in any of the two compressed formats. SSMS offers a Data Compression Wizard than can provide storage-saving estimates for row or page level compression. From the context menu for a table or index just open Storage/Manage Compression… In the Combo box at the top select the compression type (Row or Page) and press the Calculate Button at the bottom. Here’s a sample of a calculated saving for an index:</p> <p><a href="http://lh4.ggpht.com/_-C4uSahz1Gg/TWpmOodfgrI/AAAAAAAACaE/R9aWOMZQijo/s1600-h/image7.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_-C4uSahz1Gg/TWpmPXdPkmI/AAAAAAAACaI/oA-_xyFyq0Y/image_thumb3.png?imgmax=800" width="600" height="501" /></a></p> <p>Unfortunately, SSMS does not offer an option for calculating estimated savings for more than one table or index at once. If you, let’s say, would like to know the estimated storage savings of page level compression for you largest 10 tables, there’s no GUI support in SSMS that will assist you in finding an answer. This is, where the stored procedure <em>sp_estimate_data_compression_savings</em> comes in handy. This procedure – as you may have guessed from its name – provides estimated savings for row or page level compression for any table or index. You have to provide the table or index as a parameter to the procedure. In other words: The procedure will only calculate the estimations for one table or index at a time. If you want to retrieve the calculations of more than one table or index as a result set, there’s some more work to do, since the procedure has to be invoked multiple times. Here’s a script that calculates the estimated savings of page level compression for the database in context.</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"><font face="Lucida Console"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#008000"><font style="font-size: 11pt">-- Determine the estimated impact of compression <br />-- NOTE: This script is only for SQL Server Enterprise and Developer edition.</font></font><font style="font-size: 11pt"> <br /></font></span><font style="font-size: 11pt"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff">set</font></span></font></font><font style="font-size: 11pt"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font face="Lucida Console"><font color="#000000"> </font><span><font color="#0000ff">nocount</font></span><font color="#000000"> </font></font><span><font face="Lucida Console"><font color="#0000ff">on</font> <br /> <br /></font></span><font face="Lucida Console"><span><font color="#008000">-- We create a temp table for the result</font> <br /></span><span><font color="#0000ff">if </font></span><span><font color="#808080">(</font></span><span><font color="#ff00ff">object_id</font></span><span><font color="#808080">(</font></span><span><font color="#ff0000">'tempdb..#comp'</font></span><span><font color="#808080">,</font></span><font color="#000000"> </font><span><font color="#ff0000">'U'</font></span><span><font color="#808080">)</font></span><font color="#000000"> </font><span><font color="#808080">is</font></span><font color="#000000"> </font><span><font color="#808080">not</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span><font color="#808080">null)</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">  </font></span><span><font color="#0000ff">drop</font></span><font color="#000000"> </font><span><font color="#0000ff">table</font></span><font color="#000000"> #comp</font> <br /><span><font color="#0000ff">go</font></span><span style="mso-spacerun: yes"><font color="#000000">  </font></span> <br /><span><font color="#0000ff">create</font></span><font color="#000000"> </font><span><font color="#0000ff">table</font></span><font color="#000000"> #comp</font> <br /></font><font face="Lucida Console"><span><font color="#808080">(</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">  </font></span><span><font color="#ff00ff">object_name</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span><font color="#0000ff">sysname</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000"> </font></span><span><font color="#808080">,</font></span><span><font color="#ff00ff">schema_name</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span><font color="#0000ff">sysname</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000"> </font></span><span><font color="#808080">,</font></span><font color="#000000">index_id </font></font><font face="Lucida Console"><span><font color="#0000ff">int</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000"> </font></span><span><font color="#808080">,</font></span><font color="#000000">partition_number </font></font><font face="Lucida Console"><span><font color="#0000ff">int</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000"> </font></span><span><font color="#808080">,</font></span><font color="#000000">[size_with_current_compression_setting (KB)] </font></font><font face="Lucida Console"><span><font color="#0000ff">bigint</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000"> </font></span><span><font color="#808080">,</font></span><font color="#000000">[size_with_requested_compression_setting (KB)] </font><span><font color="#0000ff">bigint</font></span></font><font face="Lucida Console"><font color="#000000"> <br /><span style="mso-spacerun: yes"> </span></font><span><font color="#808080">,</font></span><font color="#000000">[sample_size_with_current_compression_setting (KB)] </font><span><font color="#0000ff">bigint</font></span></font><font face="Lucida Console"><font color="#000000"> <br /><span style="mso-spacerun: yes"> </span></font><span><font color="#808080">,</font></span><font color="#000000">[sample_size_with_requested_compression_setting (KB)] </font></font><span><font face="Lucida Console"><font color="#0000ff">bigint</font> <br /></font></span><span><font face="Lucida Console"><font color="#808080">)</font> <br /></font></span><span><font face="Lucida Console"><font color="#0000ff">go</font> <br /> <br /></font></span><font face="Lucida Console"><span><font color="#008000">-- Calculate estimated impact of page level compression for all <br />-- user-tables and indexes in all schemas. <br />-- NOTE: <br />--<span style="mso-spacerun: yes">  </span>1) To get the estimated impact of row level compression change the last parameter <br />--<span style="mso-spacerun: yes">     </span>of sp_estimate_data_compression_savings to 'row' instead. <br />--<span style="mso-spacerun: yes">  </span>2) We don't care about partitioning here. If this is important for you, <br />--<span style="mso-spacerun: yes">     </span>you have to modify forth parameter of sp_estimate_data_compression_savings. <br />--<span style="mso-spacerun: yes">     </span>Please refer to BOL.</font> <br /></span><span><font color="#0000ff">declare</font></span><font color="#000000"> @cmd </font><span><font color="#0000ff">nvarchar</font></span><span><font color="#808080">(</font></span><span><font color="#ff00ff">max</font></span></font><font face="Lucida Console"><span><font color="#808080">)</font> <br /></span><span><font color="#0000ff">set</font></span><font color="#000000"> @cmd </font><span><font color="#808080">=</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span><font color="#ff0000">''</font> <br /></span><span><font color="#0000ff">select</font></span><font color="#000000"> @cmd </font><span><font color="#808080">=</font></span></font><font face="Lucida Console"><font color="#000000"> @cmd <br /><span style="mso-spacerun: yes">    </span></font><span><font color="#808080">+</font></span></font><font face="Lucida Console"><span><font color="#ff0000">';insert #comp exec sp_estimate_data_compression_savings '''</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">    </font></span></font></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><font color="#808080" face="Lucida Console">+</font></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><font face="Lucida Console"><font color="#000000"> </font><span><font color="#ff00ff">schema_name</font></span><span><font color="#808080">(</font></span><span><font color="#ff00ff">schema_id</font></span><span><font color="#808080">)+</font></span></font><font face="Lucida Console"><span><font color="#ff0000">''','''</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">    </font></span></font></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#808080" face="Lucida Console">+</font></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font face="Lucida Console"><font color="#000000"> name </font><span><font color="#808080">+</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span><font color="#ff0000">''',null, null, ''page'''</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">  </font></span><span><font color="#0000ff">from</font></span><font color="#000000"> </font><span><font color="#008000">sys</font></span><span><font color="#808080">.</font></span></font><font face="Lucida Console"><span><font color="#008000">tables</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000"> </font></span><span><font color="#0000ff">where</font></span><font color="#000000"> </font><span><font color="#ff00ff">objectproperty</font></span><span><font color="#808080">(</font></span><span><font color="#ff00ff">object_id</font></span><span><font color="#808080">,</font></span><font color="#000000"> </font><span><font color="#ff0000">'IsUserTable'</font></span><span><font color="#808080">)</font></span><font color="#000000"> </font><span><font color="#808080">=</font></span><font color="#000000"> 1</font> <br /></font></span><font face="Lucida Console"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><font color="#0000ff">exec </font></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><font color="#808080">(</font></span></font><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><font color="#000000" face="Lucida Console">@cmd</font><span><font color="#808080" face="Lucida Console">) <br /> <br /></font></span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font face="Lucida Console"><font color="#808080">;</font> <br /></font></span><font face="Lucida Console"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#008000">-- Do some further calculations for a more meaningful result</font> <br /></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff">with</font></span></font><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#000000" face="Lucida Console"> compressionSavings </font><span><font face="Lucida Console"><font color="#0000ff">as</font> <br /></font></span><font face="Lucida Console"><span><font color="#808080">(</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">  </font></span><span><font color="#0000ff">select</font></span><font color="#000000"> </font><span><font color="#ff00ff">quotename</font></span><span><font color="#808080">(</font></span><span><font color="#ff00ff">schema_name</font></span><span><font color="#808080">)</font></span><font color="#000000"> </font><span><font color="#808080">+</font></span><font color="#000000"> </font><span><font color="#ff0000">'.'</font></span><font color="#000000"> </font><span><font color="#808080">+</font></span><font color="#000000"> </font><span><font color="#ff00ff">quotename</font></span><span><font color="#808080">(</font></span><span><font color="#ff00ff">object_name</font></span><span><font color="#808080">)</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span></font><font face="Lucida Console"><font color="#000000"> table_name <br /><span style="mso-spacerun: yes">        </span></font><span><font color="#808080">,</font></span></font><font face="Lucida Console"><font color="#000000">index_id <br /><span style="mso-spacerun: yes">        </span></font><span><font color="#808080">,</font></span></font><font face="Lucida Console"><font color="#000000">[size_with_current_compression_setting (KB)] <br /><span style="mso-spacerun: yes">        </span></font><span><font color="#808080">,</font></span></font><font face="Lucida Console"><font color="#000000">[size_with_requested_compression_setting (KB)] <br /><span style="mso-spacerun: yes">        </span></font><span><font color="#808080">,</font></span><span><font color="#ff00ff">cast</font></span><span><font color="#808080">(</font></span></font><font face="Lucida Console"><span><font color="#0000ff">case</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                </font></span><span><font color="#0000ff">when</font></span><font color="#000000"> [size_with_current_compression_setting (KB)] </font><span><font color="#808080">=</font></span><font color="#000000"> 0 </font><span><font color="#0000ff">then</font></span></font><font face="Lucida Console"><font color="#000000"> 0 <br /><span style="mso-spacerun: yes">                </span></font><span><font color="#0000ff">else</font></span><font color="#000000"> 100.0</font><span><font color="#808080">*(</font></span><font color="#000000">1.0</font><span><font color="#808080">-</font></span></font><font face="Lucida Console"><font color="#000000">1.0 <br /><span style="mso-spacerun: yes">                       </span></font><span><font color="#808080">*</font></span></font><font face="Lucida Console"><font color="#000000">[size_with_requested_compression_setting (KB)] <br /><span style="mso-spacerun: yes">                       </span></font><span><font color="#808080">/</font></span><font color="#000000">[size_with_current_compression_setting (KB)]</font></font><font face="Lucida Console"><span><font color="#808080">)</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">              </font></span><span><font color="#0000ff">end</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span><font color="#000000"> </font><span><font color="#0000ff">decimal</font></span><span><font color="#808080">(</font></span><font color="#000000">6</font><span><font color="#808080">,</font></span><font color="#000000">2</font><span><font color="#808080">))</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span></font><font face="Lucida Console"><font color="#000000"> [Estimated Savings (%)] <br /><span style="mso-spacerun: yes">  </span></font><span><font color="#0000ff">from</font></span><font color="#000000"> #comp</font> <br /></font><font face="Lucida Console"><span><font color="#808080">)</font> <br /></span><span><font color="#0000ff">select</font></span><font color="#000000"> cs</font><span><font color="#808080">.</font></span></font><font face="Lucida Console"><font color="#000000">table_name <br /><span style="mso-spacerun: yes">       </span></font><span><font color="#808080">,</font></span><span><font color="#ff00ff">isnull</font></span><span><font color="#808080">(</font></span><font color="#000000">i</font><span><font color="#808080">.</font></span><font color="#000000">name</font><span><font color="#808080">,</font></span><font color="#000000"> i</font><span><font color="#808080">.</font></span><font color="#000000">type_desc</font><span><font color="#808080">)</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span></font><font face="Lucida Console"><font color="#000000"> index_name <br /><span style="mso-spacerun: yes">       </span></font><span><font color="#808080">,</font></span><font color="#000000">cs</font><span><font color="#808080">.</font></span></font><font face="Lucida Console"><font color="#000000">[size_with_current_compression_setting (KB)] <br /><span style="mso-spacerun: yes">       </span></font><span><font color="#808080">,</font></span><font color="#000000">cs</font><span><font color="#808080">.</font></span></font><font face="Lucida Console"><font color="#000000">[size_with_requested_compression_setting (KB)] <br /><span style="mso-spacerun: yes">       </span></font><span><font color="#808080">,</font></span><font color="#000000">cs</font><span><font color="#808080">.</font></span><font color="#000000">[Estimated Savings (%)]</font></font><font face="Lucida Console"><span> <br /></span><span style="mso-spacerun: yes"><font color="#000000">   </font></span><span><font color="#0000ff">from</font></span><font color="#000000"> compressionSavings </font><span><font color="#0000ff">as</font></span></font><font face="Lucida Console"><font color="#000000"> cs <br /><span style="mso-spacerun: yes">        </span></font><span><font color="#808080">left</font></span><font color="#000000"> </font><span><font color="#808080">outer</font></span><font color="#000000"> </font><span><font color="#808080">join</font></span><font color="#000000"> </font><span><font color="#008000">sys</font></span><span><font color="#808080">.</font></span><span><font color="#008000">indexes</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span></font><font face="Lucida Console"><font color="#000000"> i <br /><span style="mso-spacerun: yes">                     </span></font><span><font color="#0000ff">on</font></span><font color="#000000"> i</font><span><font color="#808080">.</font></span><font color="#000000">index_id </font><span><font color="#808080">=</font></span><font color="#000000"> cs</font><span><font color="#808080">.</font></span></font><font face="Lucida Console"><font color="#000000">index_id <br /><span style="mso-spacerun: yes">                    </span></font><span><font color="#808080">and</font></span><font color="#000000"> i</font><span><font color="#808080">.</font></span><span><font color="#ff00ff">object_id</font></span><font color="#000000"> </font><span><font color="#808080">=</font></span><font color="#000000"> </font><span><font color="#ff00ff">object_id</font></span><span><font color="#808080">(</font></span><font color="#000000">cs</font><span><font color="#808080">.</font></span><font color="#000000">table_name</font><span><font color="#808080">,</font></span><font color="#000000"> </font><span><font color="#ff0000">'U'</font></span></font><font face="Lucida Console"><span><font color="#808080">)</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">  </font></span><span><font color="#0000ff">order</font></span><font color="#000000"> </font><span><font color="#0000ff">by</font></span><font color="#000000"> cs</font><span><font color="#808080">.</font></span><font color="#000000">[Estimated Savings (%)] </font></font><span><font face="Lucida Console"><font color="#0000ff">desc</font> <br /> <br /></font></span><span><font face="Lucida Console"><font color="#008000">-- Get rid of the temp table</font> <br /></font></span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><font color="#0000ff" face="Lucida Console">drop</font></span></font><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><font face="Lucida Console"><font style="font-size: 11pt"><font color="#000000"> </font><span><font color="#0000ff">table</font></span><font color="#000000"> #comp</font> <br /></font><span><font style="font-size: 11pt" color="#0000ff">go</font></span></font></span></p> </td> </tr> </tbody></table> <p>The script calculates the impact of Page level compression but may easily be adapted to consider Row level compression instead. Please read the comments inside the script. Also, please notice that the script will only run on SQL Server Enterprise and Developer edition. All other editions don’t provide the opportunity for data compression.</p> <p>Here’s a partial result retrieved from running the script against the <em>AdventureWorksDW2008R2</em> database.</p> <p><a href="http://lh6.ggpht.com/_-C4uSahz1Gg/TWpmQCU7pKI/AAAAAAAACaM/MYcGk-5wquA/s1600-h/image3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_-C4uSahz1Gg/TWpmQ1NNDKI/AAAAAAAACaQ/xobVVXc1lJM/image_thumb1.png?imgmax=800" width="955" height="186" /></a></p> <p>If you execute the script, please be aware that it may produce some extensive I/O. Running the script against your production database at business hours wouldn’t be a very good idea therefore.</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com3tag:blogger.com,1999:blog-213131476646021708.post-24962453606092012012011-02-22T08:08:00.001+01:002011-02-22T08:08:53.752+01:00SQL Server Start Time<p>Have you tried finding out the time, your SQL Server instance has been started? There are some sophisticated solutions, like the one from Tracy Hamlin (<a href="http://twitter.com/tracyhhamlin">twitter</a>), which takes advantage of the fact that tempdb is re-created every time, SQL Server starts. Her solution goes like this:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff" face="Lucida Console"><font style="font-size: 11pt">select</font></font></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font face="Lucida Console"><font style="font-size: 11pt"><font color="#000000"> create_date <br /><span style="mso-spacerun: yes">  </span></font><span><font color="#0000ff">from</font></span><font color="#000000"> </font><span><font color="#008000">sys</font></span><span><font color="#808080">.</font></span><span><font color="#008000">databases</font></span><font color="#000000"> </font><span><font color="#0000ff">where</font></span><font color="#000000"> database_id</font><span><font color="#808080">=</font></span><font color="#000000">2</font></font><span></span></font></span></p> </td> </tr> </tbody></table> <p>Another answer to the question, I’ve seen sometimes on the internet queries the login time for any of the system processes:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff" face="Lucida Console"><font style="font-size: 11pt">select</font></font></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font face="Lucida Console"><font style="font-size: 11pt"><font color="#000000"> login_time <br /><span style="mso-spacerun: yes">  </span></font><span><font color="#0000ff">from</font></span><font color="#000000"> </font><span><font color="#008000">sys</font></span><span><font color="#808080">.</font></span><span><font color="#008000">dm_exec_sessions</font></span><font color="#000000"> </font><span><font color="#0000ff">where</font></span><font color="#000000"> session_id</font><span><font color="#808080">=</font></span><font color="#000000">1</font></font><span></span></font></span></p> </td> </tr> </tbody></table> <p>This was my preferred way – until yesterday, when I discovered the following simple method:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff" face="Lucida Console"><font style="font-size: 11pt">select</font></font></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font face="Lucida Console"><font style="font-size: 11pt"><font color="#000000"> sqlserver_start_time <br /><span style="mso-spacerun: yes">  </span></font><span><font color="#0000ff">from</font></span><font color="#000000"> </font><span><font color="#008000">sys</font></span><span><font color="#808080">.</font></span></font><span><font style="font-size: 11pt" color="#008000">dm_os_sys_info</font></span></font><span></span></span></p> </td> </tr> </tbody></table> <p>Easy, isn’t it? Interestingly though, every of the above three queries yields a different result. Here’s a query with a sample output:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"><font face="Lucida Console"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff"><font style="font-size: 11pt">select </font></font></span><font style="font-size: 11pt"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#808080">(</font></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff">select</font></span></font></font><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font style="font-size: 11pt"><font face="Lucida Console"><font color="#000000"> sqlserver_start_time <br /><span style="mso-spacerun: yes">          </span></font><span><font color="#0000ff">from</font></span><font color="#000000"> </font><span><font color="#008000">sys</font></span><span><font color="#808080">.</font></span><span><font color="#008000">dm_os_sys_info</font></span><span><font color="#808080">)</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span></font><font face="Lucida Console"><font color="#000000"> sql_server_start_time <br /><span style="mso-spacerun: yes">      </span></font><span><font color="#808080">,(</font></span><span><font color="#0000ff">select</font></span></font><font face="Lucida Console"><font color="#000000"> create_date <br /><span style="mso-spacerun: yes">          </span></font><span><font color="#0000ff">from</font></span><font color="#000000"> </font><span><font color="#008000">sys</font></span><span><font color="#808080">.</font></span><span><font color="#008000">databases</font></span><font color="#000000"> </font><span><font color="#0000ff">where</font></span><font color="#000000"> database_id</font><span><font color="#808080">=</font></span><font color="#000000">2</font><span><font color="#808080">)</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span></font><font face="Lucida Console"><font color="#000000"> tempdb_creation_time <br /><span style="mso-spacerun: yes">      </span></font><span><font color="#808080">,(</font></span><span><font color="#0000ff">select</font></span></font></font><font face="Lucida Console"><font style="font-size: 11pt"><font color="#000000"> login_time <br /><span style="mso-spacerun: yes">          </span></font><span><font color="#0000ff">from</font></span><font color="#000000"> </font><span><font color="#008000">sys</font></span><span><font color="#808080">.</font></span><span><font color="#008000">dm_exec_sessions</font></span><font color="#000000"> </font><span><font color="#0000ff">where</font></span><font color="#000000"> session_id</font><span><font color="#808080">=</font></span><font color="#000000">1</font><span><font color="#808080">)</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span><font color="#000000"> sysprocess_login_time</font></font></font></span></p> </td> </tr> </tbody></table> <p>Result:</p> <p><a href="http://lh3.ggpht.com/_-C4uSahz1Gg/TWNg4xLA61I/AAAAAAAACZo/UVypZwjDgvM/s1600-h/image%5B4%5D.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_-C4uSahz1Gg/TWNg5SX04TI/AAAAAAAACZs/W7ZBNUqKu4Y/image_thumb%5B2%5D.png?imgmax=800" width="671" height="49" /></a></p> <p>It seems the SQL Server service must be started first. Only after the service is running, tempdb is created followed by a subsequent start of all sysprocesses. I can’t imagine that the diverse three times make any difference in practice, e.g. if you try finding out for how many hours your SQL Server instance is running. But out there may be existing applications that have to be aware of the difference. </p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com2tag:blogger.com,1999:blog-213131476646021708.post-22613144686826005042011-01-16T08:27:00.001+01:002011-01-16T08:27:20.464+01:00Exploring SQL Server Blockings and Timeouts<p>Last Thursday I was giving a presentation about information collection and evaluation of SQL Server Blockings and Timeouts at the regional PASS chapter meeting in Munich.</p> <p>You may download the presentation as well as the corresponding scripts <a href="http://sqlserver-presentations.com/Presentations/SQL Server Blockings and Timeouts.zip">here</a> (German only).</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com0tag:blogger.com,1999:blog-213131476646021708.post-4022731394867128492010-12-09T19:48:00.001+01:002010-12-09T19:48:19.885+01:00How useful is your backup?<p><em>A backup is worth nothing, if you can’t utilize it for restore.</em></p> <p>You probably agree with this well known word of wisdom, don’t you?</p> <p>This week I had to learn another aspect - the hard way: There are many cases that may require a restore. Only one of those cases is recovering a database from a state of failure. Another situation may require access to legacy data of a meanwhile deactivated database, a database that doesn’t exist anymore. In this case only a successful restore from an older backup, although necessary, may not be sufficient. Here’s the story, why.</p> <p>I was called by a customer who requested me to pull out two documents from a legacy (SQL Server 2000) database. We found an 8 year old backup we could rely on and restore worked well. Great! But then we discovered the documents had been stored in an IMAGE column and nobody had an idea how it had been encoded at the time it was stored. We soon recognized that we need the original application to get access to the documents, only to recognize that nobody had an idea where to find the installation package. Eventually I could find an 8 year old backup which included the old VB6 code. I could have used this code to rebuild the application and also an installation package only with considerable difficulties, because:</p> <ul> <li>The application uses some ActiveX components that I may not be able to find anymore.</li> <li>The original application run on Windows NT, so I may have to install this OS first, including the required service pack. Even if I find the installation CDs; I doubt, I will be able to find the appropriate device drivers but maybe, I can set up a virtual machine.</li> <li>I had to install Visual Studio 6, including the latest service pack and I had no idea where to find the installation CDs.</li> <li>The application may rely on deprecated SQL Server 2000 features. So I have to have a SQL Server 2000 installation on which the existing backup has to be restored. If it gets worse, I might even have to install the appropriate service pack to make the application working. I have no idea which service pack this would be, so there’s a chance I have to experiment.</li> </ul> <p>I recognized that all those steps require a big effort and will take some days to accomplish. If only we had built a virtual machine of at least one legacy client system before replacing all client PCs by newer machines…</p> <p>So, I’d modify the introductory statement like this:</p> <p><strong><em>A backup is worth nothing, if you can’t utilize the data that is contained inside this backup.</em></strong></p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com0tag:blogger.com,1999:blog-213131476646021708.post-74599932512512135902010-11-04T19:04:00.001+01:002010-11-04T19:04:56.026+01:00Multiple statistics sharing the same leading column<p>SQL Server will not prevent you from creating identical indexes or statistics. You may think that everything is under your control, but have you ever added a missing index that has been reported by the query optimizer, or the DTA? If so, you will certainly have created duplicate statistics. Have a look at the following example:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"><font face="Lucida Console"><font size="2"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#008000">-- create test table with 3 columns <br />-- filler is only nedded to widen the row</font> <br /></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff">create</font></span></font></font><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font face="Lucida Console"><font size="2"><font color="#000000"> </font><span><font color="#0000ff">table</font></span><font color="#000000"> T1</font> <br /><span><span style="mso-spacerun: yes"><font color="#0000ff"> </font></span></span><span><font color="#808080">(</font></span></font></font><font face="Lucida Console"><font size="2"><font color="#000000"> <br /><span style="mso-spacerun: yes">  </span>c1 </font><span><font color="#0000ff">int</font></span><font color="#000000"> </font><span><font color="#808080">not</font></span><font color="#000000"> </font><span><font color="#808080">null</font></span><font color="#000000"> </font><span><font color="#0000ff">identity</font></span><span><font color="#808080">(</font></span><font color="#000000">1</font><span><font color="#808080">,</font></span><font color="#000000">1</font><span><font color="#808080">)</font></span><font color="#000000"> </font><span><font color="#0000ff">primary</font></span><font color="#000000"> </font></font></font><font face="Lucida Console"><font size="2"><span><font color="#0000ff">key</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000"> </font></span><span><font color="#808080">,</font></span><font color="#000000">c2 </font><span><font color="#0000ff">int</font></span><font color="#000000"> </font><span><font color="#808080">not</font></span><font color="#000000"> </font></font></font><font face="Lucida Console"><font size="2"><span><font color="#808080">null</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000"> </font></span><span><font color="#808080">,</font></span><font color="#000000">filler </font><span><font color="#0000ff">nchar</font></span><span><font color="#808080">(</font></span><font color="#000000">200</font><span><font color="#808080">)</font></span><font color="#000000"> </font><span><font color="#808080">not</font></span><font color="#000000"> </font><span><font color="#808080">null</font></span><font color="#000000"> </font><span><font color="#0000ff">default</font></span><font color="#000000"> </font></font></font><font face="Lucida Console"><font size="2"><span><font color="#ff0000">'#'</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000"> </font></span></font></font><span><font face="Lucida Console"><font size="2"><font color="#808080">)</font> <br /></font></font></span><span><font face="Lucida Console"><font size="2"><font color="#0000ff">go</font> <br /> <br /></font></font></span><font face="Lucida Console"><font size="2"><span><font color="#008000">-- insert 500000 rows with random <br />-- values between 0 and 49999 for c2</font> <br /></span><span><font color="#0000ff">insert</font></span><font color="#000000"> T1</font><span><font color="#808080">(</font></span><font color="#000000">c2</font></font></font><font face="Lucida Console"><font size="2"><span><font color="#808080">)</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">  </font></span><span><font color="#0000ff">select</font></span><font color="#000000"> </font><span><font color="#0000ff">top</font></span><span><font color="#808080">(</font></span><font color="#000000">500000</font><span><font color="#808080">)</font></span><font color="#000000"> </font><span><font color="#ff00ff">abs</font></span><span><font color="#808080">(</font></span><span><font color="#ff00ff">checksum</font></span><span><font color="#808080">(</font></span><span><font color="#ff00ff">newid</font></span><span><font color="#808080">()))</font></span><font color="#000000"> </font><span><font color="#808080">%</font></span></font></font><font face="Lucida Console"><font size="2"><font color="#000000"> 50000 <br /><span style="mso-spacerun: yes">    </span></font><span><font color="#0000ff">from</font></span><font color="#000000"> </font><span><font color="#008000">sys</font></span><span><font color="#808080">.</font></span><font color="#000000">fulltext_system_stopwords </font><span><font color="#0000ff">as</font></span></font></font><font face="Lucida Console"><font size="2"><font color="#000000"> a <br /><span style="mso-spacerun: yes">        </span></font><span><font color="#808080">,</font></span><span><font color="#008000">sys</font></span><span><font color="#808080">.</font></span><font color="#000000">fulltext_system_stopwords </font><span><font color="#0000ff">as</font></span><font color="#000000"> b</font></font></font></span></p> </td> </tr> </tbody></table> <p>Before invoking the following SELECT command, allow the actual execution plan being displayed (Strg-M or selecting Query/Include Actual Execution Plan from the menu).</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"><font face="Lucida Console"><font size="2"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#008000">-- get some data</font> <br /></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff">select</font></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#000000"> </font><span><font color="#808080">*</font></span><font color="#000000"> </font><span><font color="#0000ff">from</font></span><font color="#000000"> </font><span><font color="#008080">T1</font></span><font color="#000000"> </font><span><font color="#0000ff">where</font></span><font color="#000000"> </font><span><font color="#008080">c2</font></span><font color="#000000"> </font><span><font color="#808080">=</font></span><font color="#000000"> 100</font></span></font></font></p> </td> </tr> </tbody></table> <p>If you look at the execution plan, you see that the optimizer complains about a missing index on column c2. The prognosticated improvement is about 99%, so adding the index it’s certainly a good idea. Let’s do it:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 0in 0in 0pt" class="MsoNormal"><font size="2"><font face="Lucida Console"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#008000">-- add missing index</font> <br /></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff">create</font></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#000000"> </font><span><font color="#0000ff">nonclustered</font></span><font color="#000000"> </font><span><font color="#0000ff">index</font></span><font color="#000000"> </font><span><font color="#008080">ix_1</font></span><font color="#000000"> </font><span><font color="#0000ff">on</font></span><font color="#000000"> </font><span><font color="#008080">t1</font></span><span><font color="#808080">(</font></span><span><font color="#008080">c2</font></span><span><font color="#808080">)</font></span></span></font><span style="mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"></span></font></p> </td> </tr> </tbody></table> <p>Perfect! The query runs much faster now and needs a lot fewer resources. But have a look at the table’s statistics:</p> <p><a href="http://lh5.ggpht.com/_-C4uSahz1Gg/TNL1wTm1LLI/AAAAAAAACY8/jUZHBPTVmKE/s1600-h/image3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_-C4uSahz1Gg/TNL1w3BqUfI/AAAAAAAACZA/lwQOfSbhtKQ/image_thumb1.png?imgmax=800" width="261" height="220" /></a></p> <p>You see three statistics, one for the primary key, a second one for our created index ix_1, and a third one that was automatically created during execution plan generation for the first SELECT statement. This is the statistics, named <em>_WA_Sys…</em>. If the AUTO CREATE STATISTICS option is set to ON, the optimizer will add missing statistics automatically. In our little experiment, the optimizer had to generate this column statistics on column c2 in order to make some assumptions about the number of rows that had to be processed.</p> <p>And here’s the problem: When creating the index on column c2, a statistics on this column is also created, since every index has a corresponding linked statistics. That’s just the way it works. At the time the index was added, the column statistics on c2 (that <em>_WA_Sys…</em> statistics) already existed. If you don’t remove it manually, this statistics will remain there forever, although it is needless now. All it’s good for is to increase maintenance efforts during statistics updates. You can safely remove this statistics by executing:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 0in 0in 0pt" class="MsoNormal"><font size="2"><font face="Lucida Console"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff">drop</font></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#000000"> </font><span><font color="#0000ff">statistics</font></span><font color="#000000"> </font><span><font color="#008080">t1</font></span><span><font color="#808080">.</font></span><span><font color="#008080">_WA_Sys_...</font></span></span></font><span style="mso-ansi-language: en-us" lang="EN-US"></span></font></p> </td> </tr> </tbody></table> <p>If you didn’t think about this before, there’s a chance that you’ll find some of those superfluous statistics duplicates inside your database(s). Here’s a query that finds index-related and column-statistics that match on the first column. Looking for matches on the first column is sufficient here, since the optimizer only automatically adds missing <em>single-column</em> statistics.</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 0in 0in 0pt" class="MsoNormal"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff" size="2" face="Lucida Console">with</font></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font face="Lucida Console"><font size="2"><font color="#000000"> </font><span><font color="#008080">all_stats</font></span><font color="#000000"> </font></font></font><span><font color="#0000ff"><font face="Lucida Console"><font size="2">as <br /><span style="mso-spacerun: yes"> </span></font></font></font></span><font face="Lucida Console"><font size="2"><span><font color="#808080">(</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">  </font></span><span><font color="#0000ff">select</font></span><font color="#000000"> </font><span><font color="#008080">s</font></span><span><font color="#808080">.</font></span><span><font color="#ff00ff">object_id</font></span><span><font color="#808080">,</font></span><font color="#000000"> </font><span><font color="#008080">s</font></span><span><font color="#808080">.</font></span><span><font color="#008080">name</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span><font color="#000000"> </font><span><font color="#008080">stats_name</font></span><span><font color="#808080">,</font></span><font color="#000000"> </font><span><font color="#008080">s</font></span><span><font color="#808080">.</font></span><span><font color="#008080">stats_id</font></span><span><font color="#808080">,</font></span><font color="#000000"> </font><span><font color="#008080">s</font></span><span><font color="#808080">.</font></span></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">has_filter</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">        </font></span><span><font color="#808080">,</font></span><span><font color="#008080">s</font></span><span><font color="#808080">.</font></span><span><font color="#008080">auto_created</font></span><span><font color="#808080">,</font></span><font color="#000000"> </font><span><font color="#008080">sc</font></span><span><font color="#808080">.</font></span></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">stats_column_id</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">        </font></span><span><font color="#808080">,</font></span><span><font color="#008080">sc</font></span><span><font color="#808080">.</font></span><span><font color="#008080">column_id</font></span><span><font color="#808080">,</font></span><font color="#000000"> </font><span><font color="#008080">c</font></span><span><font color="#808080">.</font></span><span><font color="#008080">name</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span><font color="#000000"> </font></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">column_name</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">    </font></span><span><font color="#0000ff">from</font></span><font color="#000000"> </font><span><font color="#3e4118">sys</font></span><span><font color="#808080">.</font></span><span><font color="#3e4118">stats</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span><font color="#000000"> </font></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">s</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">         </font></span><span><font color="#808080">inner</font></span><font color="#000000"> </font><span><font color="#808080">join</font></span><font color="#000000"> </font><span><font color="#3e4118">sys</font></span><span><font color="#808080">.</font></span><span><font color="#3e4118">stats_columns</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span><font color="#000000"> </font></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">sc</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                 </font></span><span><font color="#0000ff">on</font></span><font color="#000000"> </font><span><font color="#008080">s</font></span><span><font color="#808080">.</font></span><span><font color="#008080">stats_id</font></span><font color="#000000"> </font><span><font color="#808080">=</font></span><font color="#000000"> </font><span><font color="#008080">sc</font></span><span><font color="#808080">.</font></span></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">stats_id</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                </font></span><span><font color="#808080">and</font></span><font color="#000000"> </font><span><font color="#008080">s</font></span><span><font color="#808080">.</font></span><span><font color="#ff00ff">object_id</font></span><font color="#000000"> </font><span><font color="#808080">=</font></span><font color="#000000"> </font><span><font color="#008080">sc</font></span><span><font color="#808080">.</font></span></font></font><font face="Lucida Console"><font size="2"><span><font color="#ff00ff">object_id</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                </font></span><span><font color="#808080">and</font></span><font color="#000000"> </font><span><font color="#008080">sc</font></span><span><font color="#808080">.</font></span><span><font color="#008080">stats_column_id</font></span><font color="#000000"> </font><span><font color="#808080">=</font></span></font></font><font face="Lucida Console"><font size="2"><font color="#000000"> 1 <br /><span style="mso-spacerun: yes">         </span></font><span><font color="#808080">inner</font></span><font color="#000000"> </font><span><font color="#808080">join</font></span><font color="#000000"> </font><span><font color="#3e4118">sys</font></span><span><font color="#808080">.</font></span><span><font color="#3e4118">columns</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span><font color="#000000"> </font></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">c</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                 </font></span><span><font color="#0000ff">on</font></span><font color="#000000"> </font><span><font color="#008080">c</font></span><span><font color="#808080">.</font></span><span><font color="#ff00ff">object_id</font></span><font color="#000000"> </font><span><font color="#808080">=</font></span><font color="#000000"> </font><span><font color="#008080">s</font></span><span><font color="#808080">.</font></span></font></font><font face="Lucida Console"><font size="2"><span><font color="#ff00ff">object_id</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                </font></span><span><font color="#808080">and</font></span><font color="#000000"> </font><span><font color="#008080">c</font></span><span><font color="#808080">.</font></span><span><font color="#ff00ff">object_id</font></span><font color="#000000"> </font><span><font color="#808080">=</font></span><font color="#000000"> </font><span><font color="#008080">sc</font></span><span><font color="#808080">.</font></span></font></font><font face="Lucida Console"><font size="2"><span><font color="#ff00ff">object_id</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">                </font></span><span><font color="#808080">and</font></span><font color="#000000"> </font><span><font color="#008080">c</font></span><span><font color="#808080">.</font></span><span><font color="#008080">column_id</font></span><font color="#000000"> </font><span><font color="#808080">=</font></span><font color="#000000"> </font><span><font color="#008080">sc</font></span><span><font color="#808080">.</font></span></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">column_id</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">   </font></span><span><font color="#0000ff">where</font></span><font color="#000000"> </font><span><font color="#ff00ff">objectproperty</font></span><span><font color="#808080">(</font></span><span><font color="#008080">s</font></span><span><font color="#808080">.</font></span><span><font color="#ff00ff">object_id</font></span><span><font color="#808080">,</font></span><font color="#000000"> </font><span><font color="#ff0000">'IsUserTable'</font></span><span><font color="#808080">)</font></span><font color="#000000"> </font><span><font color="#808080">=</font></span><font color="#000000"> 1</font> <br /></font></font><font face="Lucida Console"><font size="2"><span><font color="#808080">)</font> <br /></span><span><font color="#0000ff">select</font></span><font color="#000000"> </font><span><font color="#ff00ff">row_number</font></span><span><font color="#808080">()</font></span><font color="#000000"> </font><span><font color="#0000ff">over</font></span><span><font color="#808080">(</font></span><span><font color="#0000ff">partition</font></span><font color="#000000"> </font><span><font color="#0000ff">by</font></span><font color="#000000"> </font><span><font color="#008080">s1</font></span><span><font color="#808080">.</font></span><span><font color="#ff00ff">object_id</font></span><span><font color="#808080">,</font></span><font color="#000000"> </font><span><font color="#008080">s1</font></span><span><font color="#808080">.</font></span><span><font color="#008080">column_name</font></span><font color="#000000"> </font><span><font color="#0000ff">order</font></span><font color="#000000"> </font><span><font color="#0000ff">by</font></span><font color="#000000"> </font><span><font color="#008080">s1</font></span><span><font color="#808080">.</font></span><span><font color="#008080">column_name</font></span><span><font color="#808080">)</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span><font color="#000000"> </font></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">stats_no</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">      </font></span><span><font color="#808080">,</font></span><span><font color="#ff00ff">object_name</font></span><span><font color="#808080">(</font></span><span><font color="#008080">s1</font></span><span><font color="#808080">.</font></span><span><font color="#ff00ff">object_id</font></span><span><font color="#808080">)</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span><font color="#000000"> </font></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">table_name</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">      </font></span><span><font color="#808080">,</font></span><span><font color="#008080">s1</font></span><span><font color="#808080">.</font></span><span><font color="#008080">stats_name</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span><font color="#000000"> </font></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">stats_name</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">      </font></span><span><font color="#808080">,</font></span><span><font color="#008080">s2</font></span><span><font color="#808080">.</font></span><span><font color="#008080">stats_name</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span><font color="#000000"> </font></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">identical_stats_name</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">      </font></span><span><font color="#808080">,</font></span><span><font color="#008080">s2</font></span><span><font color="#808080">.</font></span></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">column_name</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">  </font></span><span><font color="#0000ff">from</font></span><font color="#000000"> </font><span><font color="#008080">all_stats</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span><font color="#000000"> </font></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">s1</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">       </font></span><span><font color="#808080">inner</font></span><font color="#000000"> </font><span><font color="#808080">join</font></span><font color="#000000"> </font><span><font color="#008080">all_stats</font></span><font color="#000000"> </font><span><font color="#0000ff">as</font></span><font color="#000000"> </font></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">s2</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">               </font></span><span><font color="#0000ff">on</font></span><font color="#000000"> </font><span><font color="#008080">s1</font></span><span><font color="#808080">.</font></span><span><font color="#ff00ff">object_id</font></span><font color="#000000"> </font><span><font color="#808080">=</font></span><font color="#000000"> </font><span><font color="#008080">s2</font></span><span><font color="#808080">.</font></span></font></font><font face="Lucida Console"><font size="2"><span><font color="#ff00ff">object_id</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">              </font></span><span><font color="#808080">and</font></span><font color="#000000"> </font><span><font color="#008080">s1</font></span><span><font color="#808080">.</font></span><span><font color="#008080">stats_id</font></span><font color="#000000"> </font><span><font color="#808080">!=</font></span><font color="#000000"> </font><span><font color="#008080">s2</font></span><span><font color="#808080">.</font></span></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">stats_id</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">              </font></span><span><font color="#808080">and</font></span><font color="#000000"> </font><span><font color="#008080">s1</font></span><span><font color="#808080">.</font></span><span><font color="#008080">stats_column_id</font></span><font color="#000000"> </font><span><font color="#808080">=</font></span><font color="#000000"> </font><span><font color="#008080">s2</font></span><span><font color="#808080">.</font></span></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">stats_column_id</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">              </font></span><span><font color="#808080">and</font></span><font color="#000000"> </font><span><font color="#008080">s1</font></span><span><font color="#808080">.</font></span><span><font color="#008080">column_id</font></span><font color="#000000"> </font><span><font color="#808080">=</font></span><font color="#000000"> </font><span><font color="#008080">s2</font></span><span><font color="#808080">.</font></span></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">column_id</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">              </font></span><span><font color="#808080">and</font></span><font color="#000000"> </font><span><font color="#008080">s1</font></span><span><font color="#808080">.</font></span><span><font color="#008080">has_filter</font></span><font color="#000000"> </font><span><font color="#808080">=</font></span><font color="#000000"> </font><span><font color="#008080">s2</font></span><span><font color="#808080">.</font></span></font></font><font face="Lucida Console"><font size="2"><span><font color="#008080">has_filter</font> <br /></span><span style="mso-spacerun: yes"><font color="#000000">              </font></span><span><font color="#808080">and</font></span><font color="#000000"> </font><span><font color="#008080">s1</font></span><span><font color="#808080">.</font></span><span><font color="#008080">auto_created</font></span><font color="#000000"> </font><span><font color="#808080">!=</font></span><font color="#000000"> </font><span><font color="#008080">s2</font></span><span><font color="#808080">.</font></span><span><font color="#008080">auto_created</font></span></font></font></span><span style="mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"></span></p> </td> </tr> </tbody></table> <p>With that query at hand, you may easily find redundant statistics. Here’s a sample output:</p> <p><a href="http://lh5.ggpht.com/_-C4uSahz1Gg/TNL1xWNFZJI/AAAAAAAACZE/Mink9Juv8qw/s1600-h/image%5B4%5D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_-C4uSahz1Gg/TNL1xmQYutI/AAAAAAAACZI/rkwpHfet_7g/image_thumb%5B1%5D.png?imgmax=800" width="790" height="66" /></a></p> <p>If you’d like to find out more about SQL Server statistics, you may want to check out my series of two articles, published recently on the <a href="http://www.simple-talk.com">Simple-Talk</a> platform.</p> <p>Part 1: <a href="http://www.simple-talk.com/sql/performance/queries,-damned-queries-and-statistics/">Queries, Damned Queries and Statistics</a> <br />Part 2: <a href="http://www.simple-talk.com/sql/performance/sql-server-statistics-problems-and-solutions/">SQL Server Statistics: Problems and Solutions</a></p> <p>It’s free, so you might want to give it a try. Feel free to vote, if you like it!</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com10tag:blogger.com,1999:blog-213131476646021708.post-50333083376492068502010-11-01T14:33:00.001+01:002010-11-02T18:50:46.415+01:00No automatically created or updated statistics for read-only databases<p>Ok, that’s not really the latest news and also well documented. But keep in mind that <em>database snapshots</em> also fall into the category of read-only databases, so you won’t see automatically maintained statistics for these as well.</p> <p>I’ve seen the advice of taking a snapshot from a mirrored database for reporting purposes many times. Even books online contains a chapter <a href="http://msdn.microsoft.com/en-us/library/ms175511.aspx" target="_blank">Database Mirroring and Database Snapshots</a>, where the scenario is explained. </p> <p>The intention is to decouple your resource intensive reporting queries from the OLTP system which is generally a good idea. But keep in mind that:</p> <ol> <li>Reporting queries are highly unpredictable, and </li> <li>Reporting queries differ from OLTP queries. </li> </ol> <p>So there’s more than only a slightly a chance that query performance will suffer from missing statistics in your reporting snapshot, since the underlying OLTP database simply does not contain all statistics (or indexes) that your reporting applications could take advantage of. These missing statistics can’t be added in the snapshot, because it’s a read-only database. Additionally, you won’t experience any automatic updates of stale statistics in the snapshot. And moreover, any added or updated statistics in the source database are not transferred into the snapshot, of course. This can affect your query performance significantly!</p> <p>Have a look at the following example:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">use</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> <span style="color: blue">master <br />go <br /> <br /></span><span style="color: green">-- Create test database <br /></span><span style="color: blue">create</span> <span style="color: blue">database</span> ssBase <br /><span style="color: blue">go <br />use</span> ssBase <br /><span style="color: blue">go <br /></span><span style="color: green">-- create test table and insert 10000 rows <br /></span><span style="color: blue">create</span> <span style="color: blue">table</span> t1 <br /><span style="color: blue"><span style="mso-spacerun: yes"> </span></span><span style="color: gray">( <br /></span><span style="mso-spacerun: yes">  </span>c1 <span style="color: blue">int</span> <span style="color: gray">not</span> <span style="color: gray">null</span> <span style="color: blue">primary</span> <span style="color: blue">key <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span>c2 <span style="color: blue">int</span> <span style="color: gray">not</span> <span style="color: gray">null <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">) <br /></span><span style="color: blue">go <br />go <br />insert</span> t1<span style="color: gray">(</span>c1<span style="color: gray">,</span>c2<span style="color: gray">) <br /></span><span style="mso-spacerun: yes"> </span><span style="color: blue">select</span> <span style="color: blue">top</span> 10000 <br /><span style="mso-spacerun: yes">        </span><span style="color: fuchsia">row_number</span><span style="color: gray">()</span> <span style="color: blue">over</span><span style="color: gray">(</span><span style="color: blue">order</span> <span style="color: blue">by</span> <span style="color: fuchsia">current_timestamp</span><span style="color: gray">) <br /></span><span style="mso-spacerun: yes">       </span><span style="color: gray">,</span><span style="color: fuchsia">checksum</span><span style="color: gray">(</span><span style="color: fuchsia">newid</span><span style="color: gray">()) <br /></span><span style="mso-spacerun: yes">   </span><span style="color: blue">from</span> <span style="color: green">sys</span><span style="color: gray">.</span>fulltext_system_stopwords <br /><span style="color: blue">go</span><span style="mso-spacerun: yes">   </span> <br /> <br /><span style="color: green">-- create snapshot of test database <br />-- NOTE: the filename has to be adjusted <br />-- for your own experimenting <br /></span><span style="color: blue">create</span> <span style="color: blue">database</span> ssBase_SS <span style="color: blue">on <br /><span style="mso-spacerun: yes">  </span></span><span style="color: gray">( <br /></span><span style="mso-spacerun: yes">   </span>name <span style="color: gray">=</span> ssBase <br /><span style="mso-spacerun: yes">  </span><span style="color: gray">,</span><span style="color: blue">filename</span> <span style="color: gray">=</span> <span style="color: red">'e:\SqlTestData\ssBase_SS.ss' <br /></span><span style="mso-spacerun: yes">  </span></span><span style="font-family: "Lucida Console"; color: gray; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">) <br /></span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><span style="color: blue"> as</span> <span style="color: blue">snapshot</span> <span style="color: blue">of</span> ssBase<span style="color: gray">; <br /></span><span style="color: blue">go</span></span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> </span></p> </td> </tr> </tbody></table> <p>The script above creates a test database with one table and adds some rows to the table before creating a snapshot of this database. As we have never used column c2 in any query (besides the INSERT), there won’t be any statistics for column t1.c2.</p> <p>Now let’s query the snapshot and have a look at the actual execution plan. Here’s the query:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: green; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">-- Be sure to show the actual execution plan <br />-- for the following query <br /></span><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">use</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> ssBase_SS <br /><span style="color: blue"> <br />select</span> <span style="color: gray">*</span> <span style="color: blue">from</span> t1 <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">where</span> c2 <span style="color: gray">=</span> 10 </span></p> </td> </tr> </tbody></table> <p>Here’s the actual execution plan:</p> <p><a href="http://lh6.ggpht.com/_-C4uSahz1Gg/TM7Bqqlhy2I/AAAAAAAACYc/MmwSj2ouHsU/s1600-h/image3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_-C4uSahz1Gg/TM7BrBqJ-lI/AAAAAAAACYg/r9_WKrYR4V4/image_thumb1.png?imgmax=800" width="630" height="500" /></a> </p> <p>Clearly evident that the optimizer detects a missing statistics, although the options AUTO CREATE STATISTICS and AUTO UPDATE STATISTICS have both been set to ON. The plan reveals a noticeable difference between the actual and estimated number of rows and also a warning regarding the missing statistics.</p> <p>So, keep that in mind when using snapshots for reporting applications.</p> <p>If you’d like to find out more about SQL Server statistics, you may want to check out my series of two articles, published recently on the <a href="http://www.simple-talk.com" target="_blank">Simple-Talk</a> platform.</p> <p>Part 1: <a href="http://www.simple-talk.com/sql/performance/queries,-damned-queries-and-statistics/" target="_blank">Queries, Damned Queries and Statistics</a> <br />Part 2: <a href="http://www.simple-talk.com/sql/performance/sql-server-statistics-problems-and-solutions/" target="_blank">SQL Server Statistics: Problems and Solutions</a></p> <p>It’s free, so you might want to give it a try. Feel free to vote, if you like it!</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com2tag:blogger.com,1999:blog-213131476646021708.post-20014091933048255302010-10-29T08:22:00.001+02:002010-10-29T08:22:08.467+02:00Blog Mirror on InsideSQL.org<p>Two weeks ago <a href="http://www.insidesql.org" target="_blank">Frank Kalis</a> invited me to syndicate my blog on the <a href="http://www.insidesql.org" target="_blank">InsideSql platform</a> that he’s driving for some years now. I gratefully accepted, since I find myself in very good company there.</p> <p>I will also keep this blog active and just mirror my posts to <a title="http://www.insidesql.org/blogs/holgerschmeling/" href="http://www.insidesql.org/blogs/holgerschmeling/">http://www.insidesql.org/blogs/holgerschmeling/</a>. You may want to check out blog entries on <a title="http://www.insidesql.org/blogs/" href="http://www.insidesql.org/blogs/">http://www.insidesql.org/blogs/</a>. Some interesting stuff going on there. The majority of people uses German for their blog posts, so you should be somewhat familiar with that language. I decided to stick to English. From now on you will find duplicates of my blog posts <a href="http://sqlserver-online.blogspot.com/" target="_blank">here</a> and <a href="http://www.insidesql.org/blogs/holgerschmeling" target="_blank">there</a>.</p> <p>Cheers, <br />Holger</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com0tag:blogger.com,1999:blog-213131476646021708.post-86858228862250926402010-10-29T07:43:00.001+02:002010-10-29T07:45:05.449+02:00How to treat your MDF and LDF files<p>Have you ever set a database to read only? If so, you probably did this by using SQL Server Management Studio or by by executing the regarding ALTER DATABASE command. </p> <p>Here’s another method that I had to investigate recently: I colleague of mine with some limited knowledge of SQL Server didn’t discover the ALTER DATABASE statement so far. But he knew how to detach and attach a database, because this is what he does all the time in order to copy databases from one computer to another. One day, when he wanted to prevent modifications to one of his databases, he decided to protect the MDF- and LDF- files of these database. Very straightforward he detached the database, set the MDF- and LDF-file to read only mode (by using Windows Explorer) and attached the database after completing this. Voila: SQL Server does not complain at all (I was very surprised about this) and as he expected, the database was displayed as read only in the Object Explorer of SSMS.</p> <p>As I said: I was very surprised, since I didn’t expect this method would work. Smart SQL Server! But then the trouble began…</p> <p>Very shortly, after a system reboot, SQL Server started showing the database in question as “suspect”. What happened? I don’t know, but I was able to reproduce the behavior with SQL Server 2008 on Windows Server 2008 R2 every time I repeated the following steps:</p> <ul> <li>Create a database </li> <li>Detach the database </li> <li>Set the MDF- and LDF-file to read only </li> <li>Attach the database again </li> <li>Restart the computer </li> </ul> <p>So, I think you should be careful with <em>any</em> modifications to MDF- and LDF-files outside SQL Server. This not only seems to be true for data itself but also for these files’ attributes. You should always treat MDF- and LDF files as kind of SQL Server’s exclusive property and never touch them!</p> <p>Just another point to add here: If you try setting a database with read only MDF- or LDF files to read write again by executing ALTER DATABASE, you’ll get an error like this:</p> <p><span style="font-family: "Courier New"; color: red; font-size: 8pt; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">Msg 5120, Level 16, State 101, Line 1 <br />Unable to open the physical file "C:\SqlData\User\db2.mdf". Operating system error 5: "5(Access is denied.)". <br />Msg 5120, Level 16, State 101, Line 1 <br />Unable to open the physical file "C:\SqlData\User\db2_log.LDF". Operating system error 5: "5(Access is denied.)". <br />Msg 945, Level 14, State 2, Line 1 <br />Database 'db2' cannot be opened due to inaccessible files or insufficient memory or disk space.<span style="mso-spacerun: yes">  </span>See the SQL Server errorlog for details. <br />Msg 5069, Level 16, State 1, Line 1 <br />ALTER DATABASE statement failed. </span></p> <p>But that’s as expected, I’d say.</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com0tag:blogger.com,1999:blog-213131476646021708.post-43450453043428757212010-06-22T19:46:00.001+02:002010-06-22T19:46:29.276+02:00Renaming a stored procedure may lead to inconsistent system catalogs<p>I came across this behavior a while ago and decided to write about it, so it may prevent you from falling into the same trap. </p> <p>It’s very straight to reproduce. First, let’s create a simple stored procedure:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes">use</span><span style="font-family: "Lucida Console"; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes"> tempdb <br /><span style="color: blue">go <br />create</span> <span style="color: blue">procedure</span> SP1 <span style="color: blue">as</span> <span style="color: blue">select</span> 1 <span style="color: blue">as</span> x <br /><span style="color: blue">go</span><span style="color: gray"> </span></span></p> </td> </tr> </tbody></table> <p>This procedure doesn’t do anything useful but that’s not the point here. Let’s rename the procedure by utilizing the system stored procedure sp_rename like this:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes">exec</span><span style="font-family: "Lucida Console"; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes"> <span style="color: maroon">sp_rename</span><span style="color: blue"> </span><span style="color: red">'SP1'</span><span style="color: gray">,</span><span style="color: red">'SP2' </span></span></p> </td> </tr> </tbody></table> <p>After invoking the statement above, our procedure SP1 will have been renamed to SP2. You may check this by calling the procedure.</p> <p>Now, let’s see what sp_helptext returns for SP2:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes">exec</span><span style="font-family: "Lucida Console"; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes"> <span style="color: maroon">sp_helptext</span><span style="color: blue"> </span><span style="color: red">'SP2' </span></span></p> </td> </tr> </tbody></table> <p>Here’s the result:</p> <p><a href="http://lh5.ggpht.com/_-C4uSahz1Gg/TCD266vZopI/AAAAAAAACLc/82Tzo0yG7uU/s1600-h/image3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_-C4uSahz1Gg/TCD27BKABoI/AAAAAAAACLg/eABAzLRQsTs/image_thumb1.png?imgmax=800" width="349" height="47" /></a> </p> <p>Oops. Wrong (old) name in the CREATE PROCEDURE statement.</p> <p>So, how about querying sys.sql_modules then:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes">select</span><span style="font-family: "Lucida Console"; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes"> <span style="color: fuchsia">object_name</span><span style="color: gray">(</span><span style="color: fuchsia">object_id</span><span style="color: gray">)</span> <span style="color: blue">as</span> sp_name<span style="color: gray">,</span> <span style="color: blue">definition <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">sql_modules</span> <span style="color: blue">where</span> <span style="color: fuchsia">object_id</span><span style="color: gray">=</span><span style="color: fuchsia">object_id</span><span style="color: gray">(</span><span style="color: red">'SP2'</span><span style="color: gray">) </span></span></p> </td> </tr> </tbody></table> <p>This query will return the following result:</p> <p><a href="http://lh6.ggpht.com/_-C4uSahz1Gg/TCD27hZbFsI/AAAAAAAACLk/tjrRkmT-oM0/s1600-h/image7.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_-C4uSahz1Gg/TCD28abYJaI/AAAAAAAACLo/7Y6W3J-5sgc/image_thumb3.png?imgmax=800" width="430" height="47" /></a> </p> <p>Also not the correct CREATE PROCEDURE statement.</p> <p>I was right about adding an item on Microsoft’s connect platform for reporting this behavior as a bug, when I discovered this warning in books online regarding sp_rename:</p> <p><a href="http://lh6.ggpht.com/_-C4uSahz1Gg/TCD28sjv4QI/AAAAAAAACLs/lye0mHPs3SA/s1600-h/image11.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_-C4uSahz1Gg/TCD29Nzxh5I/AAAAAAAACLw/bvDq8mXqkGQ/image_thumb5.png?imgmax=800" width="902" height="68" /></a> </p> <p>So, the behavior seems to be as expected. Be careful with sp_rename – not only when renaming stored procedures but also triggers, functions and views!</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com1tag:blogger.com,1999:blog-213131476646021708.post-69234113535006374542010-06-16T19:50:00.001+02:002010-06-16T19:50:30.789+02:00Backup and Restore of the SQL Server buffer pool<p>Have you ever missed this feature? Whenever you install the latest security update, it is very likely that your server requires a restart, leading also to a restart of SQL Server. If this ever happens, SQL Server needs to start from scratch, having nothing in the plan cache and also no data pages in the pool.I have many customers that complain about applications performing poorly after a server restart – for whatever reason that may have been necessary.</p> <p>So finally, in the current project, we ended up developing a method for warming up the cache on our own after SQL Server has been started. Obviously not an easy task, but we had a smart guy who implemented this. The final solution is by no means perfect but almost sufficient according to our requirements.</p> <p>When discussing about how we should implement this feature and also the pros and cons, we had the idea that we did nothing more than SQL Server itself should be capable of. Wouldn’t it be nice, if we could just perform a backup of the buffer pool and later restore it? Or even better, how about just sending SQL Server to hibernate mode (like Windows) and wake it up later? Clearly this won’t work under every circumstance, since some updates or patches may require a "cold" restart. But in those cases where it’s technically possible, I’d like to have this opportunity.</p> <p>I like the idea so much that I’ve added a regarding change request on Microsoft’s connect platform (item# 561951). If you agree, you can vote for it <a href="http://connect.microsoft.com/SQLServer/feedback/details/561951/backup-restore-of-buffer-pool-state">here</a>.</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com0tag:blogger.com,1999:blog-213131476646021708.post-51714519399354443632010-06-14T19:50:00.001+02:002010-06-14T19:50:25.606+02:00Do you rebuild your indexes periodically?<p>Most of you will – hopefully – have some index maintenance strategy. That is, you need some criteria, when to rebuild or reorganize an index. I will not repeat every advice that you may find elsewhere on the internet, e.g. <a href="http://ola.hallengren.com/">here</a>, or <a href="http://msdn.microsoft.com/en-us/library/ms188917.aspx">here</a>.</p> <p>In almost all given advices the dynamic management view sys.dm_db_index_physical_stats plays a central role, since it can easily be used to detect the degree of fragmentation of an index and the course of action to perform. Generally spoken, if index fragmentation exceeds a distinct value (let’s say 40%), you should perform a complete rebuild of the index. By doing so, the whole index tree is built from scratch and also the index related statistics is rebuilt. If the fragmentation is noticeable, but not too high (somewhere between 10% and 40%), an index reorganize may be sufficient. By performing a reorganize only the index pages in the leaf level are rearranged which is less cost (I/O) intensive than a complete index rebuild.</p> <p>Unfortunately, sys.dm_db_index_physical_stats can create huge I/O stress, as you can check inside <a href="http://www.sqlskills.com/BLOGS/PAUL/post/Inside-sysdm_db_index_physical_stats.aspx">this</a> blog post of Paul Randal (yes, the <a href="http://www.sqlskills.com/AboutPaulSRandal.asp">guru</a>). There is, of course, an opportunity to affect the I/O load created, by specifying the last parameter of the sys.dm_db_index_physical_stats DMF. IF you use LIMITED here, the I/O load is as minimal as possible. DETAILED, on the other hand, may create very noticeable physical I/O, especially for larger indexes, although it should reveal very detailed and realistic.</p> <p>But be aware that querying the fragmentation by the use of sys.dm_db_index_physical_stats, as also suggested in Books Online (see <a href="http://msdn.microsoft.com/en-us/library/ms188917.aspx">here</a>), may not be sufficient to detect candidates for necessary rebuilds.</p> <p>Look at the following example.</p> <p>We start by creating a simple table and inserting 400,000 rows:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes">create</span><span style="font-family: "Lucida Console"; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes"> <span style="color: blue">table</span> t1 <br /><span style="color: gray">( <br /></span><span style="mso-spacerun: yes">  </span>c1 <span style="color: blue">uniqueidentifier</span> <span style="color: gray">not</span> <span style="color: gray">null</span> <span style="color: blue">default</span> <span style="color: fuchsia">newsequentialid</span><span style="color: gray">()</span> <span style="color: blue">primary</span> <span style="color: blue">key <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span>c2 <span style="color: blue">nchar</span><span style="color: gray">(</span>513<span style="color: gray">)</span> <span style="color: gray">not</span> <span style="color: gray">null</span> <span style="color: blue">default</span> <span style="color: red">'#' <br /></span><span style="color: gray">) <br /></span><span style="color: blue">go <br /></span><span style="color: green">-- Insert 400,000 rows <br /></span><span style="color: blue">insert</span> t1<span style="color: gray">(</span>c2<span style="color: gray">)</span> <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">select</span> <span style="color: blue">top</span> 400000 <span style="color: red">'?'</span> <span style="color: blue">from</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">trace_event_bindings</span> c1<span style="color: gray">,</span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">trace_event_bindings</span> <span style="color: blue">as</span> c2 <br /><span style="color: blue">go</span><span style="color: gray"> </span></span></p> </td> </tr> </tbody></table> <p>Now, let’s see the fragmentation of the primary key (which is also the clustered key in our case). Oh, btw.: I know very well that a clustered index on a GUID column is less than optimal, but I see this practice all the time. It’s just tat developers love the idea of creating objects (table rows) that are unique throughout the whole universe. But that’s not the point here, so let’s see how the fragmentation as well as the space used values look like. First, we use the LIMITED mode:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes">select</span><span style="font-family: "Lucida Console"; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes"> index_level<span style="color: gray">,</span> avg_fragmentation_in_percent<span style="color: gray">,</span> avg_page_space_used_in_percent <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">dm_db_index_physical_stats</span><span style="color: gray">(</span><span style="color: fuchsia">db_id</span><span style="color: gray">(),</span><span style="color: fuchsia">object_id</span><span style="color: gray">(</span><span style="color: red">'t1'</span><span style="color: gray">),null,null,</span><span style="color: red">'limited'</span><span style="color: gray">) </span></span></p> </td> </tr> </tbody></table> <p>Here’s the result:</p> <p><a href="http://lh3.ggpht.com/_-C4uSahz1Gg/TBZr0sDWHGI/AAAAAAAACLE/mut_8L713Fk/s1600-h/image%5B3%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_-C4uSahz1Gg/TBZr1V9FeSI/AAAAAAAACLI/WTPJRzlFAsQ/image_thumb%5B1%5D.png?imgmax=800" width="672" height="46" /></a> </p> <p>Looks pretty good, he? 0.7% fragmentation, so no need for any actions, right? (avg_space_used_in_percent is not shown in LIMITED mode.) Well, let’s see what sys.dm_db_index_physical_stats returns when running in DETAILED mode:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes">select</span><span style="font-family: "Lucida Console"; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes"> index_level<span style="color: gray">,</span> avg_fragmentation_in_percent<span style="color: gray">,</span> avg_page_space_used_in_percent <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">dm_db_index_physical_stats</span><span style="color: gray">(</span><span style="color: fuchsia">db_id</span><span style="color: gray">(),</span><span style="color: fuchsia">object_id</span><span style="color: gray">(</span><span style="color: red">'t1'</span><span style="color: gray">),null,null,</span><span style="color: red">'detailed'</span><span style="color: gray">) </span></span></p> </td> </tr> </tbody></table> <p>Here’s the result:</p> <p><a href="http://lh4.ggpht.com/_-C4uSahz1Gg/TBZr1-vWhCI/AAAAAAAACLM/s6Jd7FB6mIs/s1600-h/image%5B7%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_-C4uSahz1Gg/TBZr2mD_MHI/AAAAAAAACLQ/woDCITuUwjE/image_thumb%5B3%5D.png?imgmax=800" width="670" height="112" /></a> </p> <p>Also nothing to worry about, right? Almost no fragmentation. But wait! Why has the index tree a depth of 4? That seems too deep! So let’s see, if an index rebuild will shrink the depth:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes">alter</span><span style="font-family: "Lucida Console"; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes"> <span style="color: blue">index</span> <span style="color: gray">all</span> <span style="color: blue">on</span> t1 <span style="color: blue">rebuild <br />go <br />select</span> index_level<span style="color: gray">,</span> avg_fragmentation_in_percent<span style="color: gray">,</span> avg_page_space_used_in_percent<span style="color: gray">,</span> <span style="color: red">'' <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">dm_db_index_physical_stats</span><span style="color: gray">(</span><span style="color: fuchsia">db_id</span><span style="color: gray">(),</span><span style="color: fuchsia">object_id</span><span style="color: gray">(</span><span style="color: red">'t1'</span><span style="color: gray">),null,null,</span><span style="color: red">'detailed'</span><span style="color: gray">) </span></span></p> </td> </tr> </tbody></table> <p>Now the index looks like that:</p> <p><a href="http://lh5.ggpht.com/_-C4uSahz1Gg/TBZr3VYl5dI/AAAAAAAACLU/1xP0a_kMfTY/s1600-h/image%5B11%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_-C4uSahz1Gg/TBZr35H37BI/AAAAAAAACLY/BshaTjwkWA0/image_thumb%5B5%5D.png?imgmax=800" width="668" height="88" /></a> </p> <p></p> <p></p> <p>So, the index three has one level less than before! Therefore, every index seek has to perform one read less – that’s 25% less!</p> <p>If you look at the avg_space_used_in_percent column, you see why.The non-leaf levels of the index are more packed with data and don’t contain as much space after the rebuild as before.</p> <p>So be aware, when following the best practices guides in <a href="http://msdn.microsoft.com/en-us/library/ms188917.aspx">BOL</a> or the internet. Those guidelines are definitely very good and helpful, but may not be sufficient under all circumstances.</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com0tag:blogger.com,1999:blog-213131476646021708.post-56626738650635672742010-06-03T13:02:00.001+02:002010-06-03T13:02:41.200+02:00Non Clustered Indexes may prevent dead locks<p>If a table is very tiny, so that all table’s data fit into one single data page e.g., will any index be helpful when accessing/modifying the table’s data? You may think no, since for reading the data, the one and only data page has to be touched anyway, so a table (or clustered index) scan will get by with a single page read, and that’s the most efficient method for reading the data. So, there’s no need for an index, right?</p> <p>Well, as the <a href="http://www.sqlskills.com/AboutPaulSRandal.asp">guru</a> always says: It depends.</p> <p>Have a look at the following table:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes">create</span><span style="font-family: "Lucida Console"; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes"> <span style="color: blue">table</span> t1 <br /><span style="color: blue"><span style="mso-spacerun: yes"> </span></span><span style="color: gray">( <br /></span><span style="mso-spacerun: yes">   </span>c1 <span style="color: blue">int</span> <span style="color: gray">not</span> <span style="color: gray">null</span> <span style="color: blue">primary</span> <span style="color: blue">key</span> <span style="color: blue">clustered <br /></span><span style="mso-spacerun: yes">  </span><span style="color: gray">,</span>c2 <span style="color: blue">int</span> <span style="color: gray">not</span> <span style="color: gray">null <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">)</span></span><span style="font-family: "Lucida Console"; color: red; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes"> <p></p> </span></p> </td> </tr> </tbody></table> <p>Now, lets say we modify some data simultaneously from two different connections. Try the following scripts from two separate connections: </p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: green; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes">-- Connection 1 <br /></span><span style="font-family: "Lucida Console"; color: blue; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes">begin</span><span style="font-family: "Lucida Console"; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes"> <span style="color: blue">tran <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">insert</span> t1<span style="color: gray">(</span>c1<span style="color: gray">,</span> c2<span style="color: gray">)</span> <span style="color: blue">values </span><span style="color: gray">(</span>1<span style="color: gray">,</span> 1111<span style="color: gray">) <br /></span><span style="mso-spacerun: yes">  </span> <br /><span style="mso-spacerun: yes">  </span><span style="color: green">-- pretend, we do something here <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">waitfor</span> <span style="color: blue">delay</span> <span style="color: red">'00:00:10' <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">delete</span> t1 <span style="color: blue">where</span> c2 <span style="color: gray">=</span> 1111 <br /><span style="color: blue">commit</span></span><span style="font-family: "Lucida Console"; color: red; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes"> <p></p> </span></p> </td> </tr> </tbody></table> <p> </p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: green; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes">-- Connection 2 <br /></span><span style="font-family: "Lucida Console"; color: blue; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes">begin</span><span style="font-family: "Lucida Console"; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes"> <span style="color: blue">tran <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">insert</span> t1<span style="color: gray">(</span>c1<span style="color: gray">,</span> c2<span style="color: gray">)</span> <span style="color: blue">values </span><span style="color: gray">(</span>2<span style="color: gray">,</span> 2222<span style="color: gray">) <br /></span><span style="mso-spacerun: yes">  </span> <br /><span style="mso-spacerun: yes">  </span><span style="color: green">-- pretend, we do something here <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">waitfor</span> <span style="color: blue">delay</span> <span style="color: red">'00:00:10' <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">delete</span> t1 <span style="color: blue">where</span> c2 <span style="color: gray">=</span> 2222 <br /><span style="color: blue">commit</span></span><span style="font-family: "Lucida Console"; color: red; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes"> <p></p> </span></p> </td> </tr> </tbody></table> <p>After a few seconds you will see an abortion one of the two transactions with a deadlock error like this:</p> <p><span style="font-family: "Courier New"; color: red; font-size: 8pt; mso-ansi-language: en-us; mso-no-proof: yes">Msg 1205, Level 13, State 51, Line 7 <br />Transaction (Process ID 52) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.</span><span style="color: red; mso-ansi-language: en-us"> <p></p> </span></p> <p>Now, let’s create a nonclustered index on column c2.</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes">create</span><span style="font-family: "Lucida Console"; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes"> <span style="color: blue">nonclustered</span> <span style="color: blue">index</span> ix1 <span style="color: blue">on</span> t1<span style="color: gray">(</span>c2<span style="color: gray">) <p></p> </span></span></p> </td> </tr> </tbody></table> <p>You may think, this index isn’t any useful, since our table only contains two rows and the optimizer will never decide for an index seek therefore. But if you repeat the above experiment, no deadlock shows up this time. So the index is good, helpful and may be even necessary.</p> <p>Ok, let’s see what happened here. We start with the first case, without the nonclustered index. Our focus should be on the DELETE statement, since this is the cause for the problem. The execution plan (without the nonclustered index) looks like this:</p> <p><a href="http://lh5.ggpht.com/_-C4uSahz1Gg/TAeLynLPWLI/AAAAAAAACK0/ErwE60TxwRw/s1600-h/image%5B3%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_-C4uSahz1Gg/TAeLzMxMYDI/AAAAAAAACK4/33qb9HIkBk8/image_thumb%5B1%5D.png?imgmax=800" width="711" height="90" /></a> </p> <p>In order to find the row that has to be deleted, a clustered index scan must be performed.</p> <p>A call of sp_lock during the execution of the two statements reveals a situation like this:</p> <table style="width: 343.05pt; border-collapse: collapse; margin-left: 4.65pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt" class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="457"><tbody> <tr style="height: 15pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 58pt; padding-right: 5.4pt; background: #f2f2f2; height: 15pt; border-top: windowtext 1pt solid; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-alt: solid windowtext .5pt" valign="bottom" width="77" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">spid <p></p> </span></b></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #f2f2f2; height: 15pt; border-top: windowtext 1pt solid; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-top-alt: solid windowtext .5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">IndId <p></p> </span></b></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #f2f2f2; height: 15pt; border-top: windowtext 1pt solid; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-top-alt: solid windowtext .5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">Type <p></p> </span></b></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 85.25pt; padding-right: 5.4pt; background: #f2f2f2; height: 15pt; border-top: windowtext 1pt solid; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-top-alt: solid windowtext .5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="114" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">Resource <p></p> </span></b></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 55.8pt; padding-right: 5.4pt; background: #f2f2f2; height: 15pt; border-top: windowtext 1pt solid; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-top-alt: solid windowtext .5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">Mode <p></p> </span></b></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #f2f2f2; height: 15pt; border-top: windowtext 1pt solid; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-top-alt: solid windowtext .5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="72" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">Status <p></p> </span></b></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 1"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 58pt; padding-right: 5.4pt; background: #e6b8b7; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="bottom" width="77" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">52 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #e6b8b7; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #e6b8b7; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">KEY <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 85.25pt; padding-right: 5.4pt; background: #e6b8b7; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="114" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">(8194443284a0)</span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 55.8pt; padding-right: 5.4pt; background: #e6b8b7; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">U <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #e6b8b7; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="72" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">WAIT <p></p> </span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 2"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 58pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="bottom" width="77" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">52 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">PAG <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 85.25pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="114" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1:115 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 55.8pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">IX <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="72" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 3"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 58pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="bottom" width="77" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">52 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">0 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">TAB <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 85.25pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="114" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 55.8pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">IX <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="72" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 4"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 58pt; padding-right: 5.4pt; background: #d8e4bc; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="bottom" width="77" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">52 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #d8e4bc; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #d8e4bc; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">KEY <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 85.25pt; padding-right: 5.4pt; background: #d8e4bc; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="114" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">(61a06abd401c)</span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 55.8pt; padding-right: 5.4pt; background: #d8e4bc; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">X <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #d8e4bc; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="72" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 5"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 58pt; padding-right: 5.4pt; background: #d8e4bc; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="bottom" width="77" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">54 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #d8e4bc; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #d8e4bc; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">KEY <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 85.25pt; padding-right: 5.4pt; background: #d8e4bc; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="114" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">(8194443284a0)</span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 55.8pt; padding-right: 5.4pt; background: #d8e4bc; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">X <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #d8e4bc; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="72" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 6"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 58pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="bottom" width="77" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">54 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">0 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">TAB <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 85.25pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="114" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 55.8pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">IX <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="72" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 7"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 58pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="bottom" width="77" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">54 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">PAG <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 85.25pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="114" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1:115 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 55.8pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">IX <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="72" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 8; mso-yfti-lastrow: yes"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 58pt; padding-right: 5.4pt; background: #e6b8b7; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="bottom" width="77" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">54 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #e6b8b7; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #e6b8b7; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">KEY <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 85.25pt; padding-right: 5.4pt; background: #e6b8b7; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="114" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">(61a06abd401c)</span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 55.8pt; padding-right: 5.4pt; background: #e6b8b7; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">U <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #e6b8b7; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="72" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">WAIT <p></p> </span></p> </td> </tr> </tbody></table> <p>We see two connections (SPIDs) holding or waiting for locks. I’ve highlighted the rows of interest, where I used a green background for granted locks and a red background for waits. The resource column of the highlighted rows is related to a table (clustered index) row. You may investigate this on your own by using the undocumented %%lockres%% column. (See <a href="http://consultingblogs.emc.com/jamesrowlandjones/archive/2009/05/28/the-curious-case-of-the-dubious-deadlock-and-the-not-so-logical-lock.aspx">this</a> blog post by James Rowland-Jones)  It is very obvious that the two connections are waiting on each other to release a lock on a row which is locked by the other connection, while – at the same time - holding a lock on the row the other connection is waiting for. Classical deadlock situation.</p> <p>Now, let’s see how this changes with the nonclustered index in place. Here’s the execution plan for the delete:</p> <p><a href="http://lh4.ggpht.com/_-C4uSahz1Gg/TAeLzaSXK9I/AAAAAAAACK8/helIntaasRw/s1600-h/image%5B7%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_-C4uSahz1Gg/TAeLzhIhfBI/AAAAAAAACLA/wl6G7fGyROs/image_thumb%5B3%5D.png?imgmax=800" width="603" height="89" /></a> </p> <p>Ok, the index is used for looking up the row that has to be deleted. Very good. The optimizer is aware of the fact that an index seek will be more appropriate for determining the row, since this will lead to fewer resource locks. </p> <p>Here’s what sp_lock reveals if the two scripts are executed with an existing nonclustered index:</p> <table style="width: 328pt; border-collapse: collapse; margin-left: 4.65pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt" class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="437"><tbody> <tr style="height: 15pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #f2f2f2; height: 15pt; border-top: windowtext 1pt solid; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-top-alt: 1.0pt; mso-border-bottom-alt: .5pt; mso-border-right-alt: .5pt; mso-border-left-alt: 1.0pt; mso-border-color-alt: windowtext; mso-border-style-alt: solid" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">spid <p></p> </span></b></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #f2f2f2; height: 15pt; border-top: windowtext 1pt solid; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-top-alt: solid windowtext 1.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">IndId <p></p> </span></b></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #f2f2f2; height: 15pt; border-top: windowtext 1pt solid; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-top-alt: solid windowtext 1.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">Type <p></p> </span></b></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 88pt; padding-right: 5.4pt; background: #f2f2f2; height: 15pt; border-top: windowtext 1pt solid; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-top-alt: solid windowtext 1.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="117" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">Resource <p></p> </span></b></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #f2f2f2; height: 15pt; border-top: windowtext 1pt solid; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-top-alt: solid windowtext 1.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">Mode <p></p> </span></b></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; background: #f2f2f2; height: 15pt; border-top: windowtext 1pt solid; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-top-alt: solid windowtext 1.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">Status <p></p> </span></b></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 1"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">52 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">3 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">PAG <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 88pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="117" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1:126 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">IX <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 2"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">52 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">PAG <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 88pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="117" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1:120 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">IX <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 3"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">52 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">3 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">KEY <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 88pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="117" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">(0fcd4e06ed44)</span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">X <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 4"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">52 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">0 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">TAB <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 88pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="117" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">IX <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 5"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">52 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">KEY <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 88pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="117" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">(61a06abd401c)</span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">X <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 6"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">54 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">KEY <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 88pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="117" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">(8194443284a0)</span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">X <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 7"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">54 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">PAG <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 88pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="117" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1:120 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">IX <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 8"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">54 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">3 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">PAG <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 88pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="117" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">1:126 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">IX <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 9"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">54 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">0 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">TAB <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 88pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="117" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">IX <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> <tr style="height: 15.75pt; mso-yfti-irow: 10; mso-yfti-lastrow: yes"> <td style="border-bottom: windowtext 1pt solid; border-left: windowtext 1pt solid; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15.75pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">54 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15.75pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">3 <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15.75pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">KEY <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 88pt; padding-right: 5.4pt; height: 15.75pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="117" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">(917735e52a83)</span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15.75pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">X <p></p> </span></p> </td> <td style="border-bottom: windowtext 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 5.4pt; width: 48pt; padding-right: 5.4pt; height: 15.75pt; border-top: medium none; border-right: windowtext 1pt solid; padding-top: 0in" valign="bottom" width="64" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-ansi-language: en-us; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri">GRANT <p></p> </span></p> </td> </tr> </tbody></table> <p>Very good! Only granted locks this time, no waits.</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com2tag:blogger.com,1999:blog-213131476646021708.post-45937546519470354442010-04-01T19:47:00.001+02:002010-04-01T19:47:55.452+02:00Boost the performance of your SQL Server<p>Today I discovered a fascinating, although also weird thing regarding SQL Server Standard Edition. We all know that SQL Server has many of undocumented commands. DBCC makes no difference here. You probably know it as the DBA’s all purpose tool, but what I found by coincidence really puzzled me when I came across it this afternoon.</p> <p>So here’s the story. A customer of mine runs some SQL Server Standard Editions which – as you may know – has some limitations in comparison to the Enterprise Edition. Those limitations also include some features of the optimizer, e.g. regarding the use of Bitmap Filters, or Indexed Views. Today, just for fun, I entered and ran the following DBCC command:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">DBCC</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> SQLPERF<span style="color: gray">(</span><span style="color: blue">ON</span><span style="color: gray">)</span></span><span style="font-family: "Lucida Console"; color: red; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> </span></p> </td> </tr> </tbody></table> <p>And, believe it or not, all the limitations of the SQL Server Standard Edition went away instantly. It really behaves like it was the Enterprise Edition now. Amazing!</p> <p>Of course, I can’t give any explanation what’s behind this. But hey, all that counts is, it finally works, right? So why not giving it a try? But be prepared that the command is undocumented and maybe not work as expected on all systems. But for me – it did! At least today…</p> <p>Have fun!</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com2tag:blogger.com,1999:blog-213131476646021708.post-47401704985329503082010-03-27T16:59:00.001+01:002010-03-27T17:01:31.445+01:00Bad index usage within stored procedure<p>I came across this problem last week. Here’s a table containing contact data:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">create</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> <span style="color: blue">table</span> contact <br /><span style="color: blue"><span style="mso-spacerun: yes"> </span></span><span style="color: gray">( <br /></span><span style="mso-spacerun: yes">  </span>last_name <span style="color: blue">nvarchar</span><span style="color: gray">(</span>200<span style="color: gray">) <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span>city <span style="color: blue">nvarchar</span><span style="color: gray">(</span>200<span style="color: gray">) <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span>filler <span style="color: blue">nchar</span><span style="color: gray">(</span>200<span style="color: gray">) <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">) <br /></span><span style="color: blue">go <br />insert</span> contact<span style="color: blue"> </span><span style="color: gray">(</span>last_name<span style="color: gray">,</span>City<span style="color: gray">)</span> <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">select</span> LastName<span style="color: gray">,</span> City <br /><span style="mso-spacerun: yes">    </span><span style="color: blue">from</span> AdventureWorks2008R2<span style="color: gray">.</span>Sales<span style="color: gray">.</span>vIndividualCustomer </span></p> </td> </tr> </tbody></table> <p>Yes, I’m already using SQL Server 2008 R2 but I was able to reproduce the behavior described below also with SQL Server 2008. The script above will insert 18,508 rows into our table.</p> <p>Let’s create a clustered index on the last_name column and a nonclustered index on the city column:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">create</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> <span style="color: blue">clustered</span> <span style="color: blue">index</span> ix_t1_last_name <span style="color: blue">on</span> contact<span style="color: gray">(</span>last_name<span style="color: gray">) <br /></span><span style="color: blue">go <br />create</span> <span style="color: blue">nonclustered</span> <span style="color: blue">index</span> ix_t1_city <span style="color: blue">on</span> contact<span style="color: gray">(</span>city<span style="color: gray">) </span></span></p> </td> </tr> </tbody></table> <p>Given this table, what do you think about index utilization of the following ad hoc statement:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">select</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> <span style="color: gray">* <br /></span><span style="mso-spacerun: yes">    </span><span style="color: blue">from</span> contact <br /><span style="mso-spacerun: yes">   </span><span style="color: blue">where</span> last_name <span style="color: gray">like</span> <span style="color: red">'%nobody%' <br /></span><span style="mso-spacerun: yes">     </span><span style="color: gray">and</span> city <span style="color: gray">like</span> <span style="color: red">'nowhere%'</span><span style="color: gray"> </span></span></p> </td> </tr> </tbody></table> <p>The SELECT statement returns 0 rows and the optimizer is able to find out this by using the nonclustered index on the city column. The execution plan proves it:</p> <p><a href="http://lh5.ggpht.com/_-C4uSahz1Gg/S64rdc7t7DI/AAAAAAAABe8/62OfHBVv0Dk/s1600-h/image%5B3%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_-C4uSahz1Gg/S64rdnaXDtI/AAAAAAAABfA/Vi_VSrR2qAQ/image_thumb%5B1%5D.png?imgmax=800" width="442" height="168" /></a> </p> <p>As the index contains two levels, two logical reads are necessary to obtain the empty result set.</p> <p>Ok, now let’s create the following stored procedure:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">create</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> <span style="color: blue">procedure</span> getNames<span style="color: gray">(</span>@name <span style="color: blue">nvarchar</span><span style="color: gray">(</span>50<span style="color: gray">),</span> @city <span style="color: blue">nvarchar</span><span style="color: gray">(</span>50<span style="color: gray">))</span> <span style="color: blue">with</span> <span style="color: blue">recompile</span> <span style="color: blue">as <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">select</span> <span style="color: gray">* <br /></span><span style="mso-spacerun: yes">    </span><span style="color: blue">from</span> contact <br /><span style="mso-spacerun: yes">   </span><span style="color: blue">where</span> city <span style="color: gray">like</span> @city <br /><span style="mso-spacerun: yes">     </span><span style="color: gray">and</span> last_name <span style="color: gray">like</span> @name <span style="color: blue">go</span><span style="color: gray"> </span> <p></p> </span></p> <p></p> </td> </tr> </tbody></table> <p>Inside the SP the same statement as before is executed. Also, the procedure is created with the RECOMPILE option, to ensure a fresh execution plan is generated for every execution of the SP. Let’s say, we like it to be this way, since we expect very different parameter values will be provided which in turn will create result sets of very different cardinality. </p> <p>If we call the procedure like this:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">exec</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> getNames<span style="color: blue"> </span>@name <span style="color: gray">=</span> <span style="color: red">'%nobody%'</span><span style="color: gray">,</span> @city <span style="color: gray">=</span> <span style="color: red">'nowhere%'</span><span style="color: gray"> </span></span></p> </td> </tr> </tbody></table> <p>What will the execution plan look like? Inside the procedure the same statement is executed as the ad hoc statement above, so I’d expected to see the same execution plan as before.</p> <p>But surprisingly, the execution plan reveals a clustered index seek this time which is far from optimal! Look at this:</p> <p><a href="http://lh5.ggpht.com/_-C4uSahz1Gg/S64reH161YI/AAAAAAAABfE/cHQLNBZNV0A/s1600-h/image%5B7%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_-C4uSahz1Gg/S64rek1z6VI/AAAAAAAABfI/egVJaBIEVDM/image_thumb%5B3%5D.png?imgmax=800" width="555" height="169" /></a> </p> <p>Although the plan shows a Clustered Index Seek, this seek actually is a scan, because of the provided search argument “%nobody%”. (See <a href="http://sqlserver-online.blogspot.com/2010/02/when-index-seek-actually-is-scan.html" target="_blank">here</a> for more information.) Therefore, all leaf level pages of the clustered index have to be scanned, and this takes 1,065 reads. That’s about than 300 times more then it was with the ad hoc query!</p> <p>I did some more experiments, where I left out the clustered index, e.g. and created both indexes nonclustered. Same result. If executing the procedure, always the suboptimal index is chosen, with one exception: If I create the clustered index on the city column, both queries will take advantage of the clustered index.</p> <p>Strange. I wasn’t expecting this. Due to parameter sniffing, the procedure’s plan should be adjusted to the parameter values provided. This statement should be even more valid, since the procedure was created by specifying the RECOMPILE option. But parameter sniffing seems not to work in this case. As I don’t know why, and I also consider this behavior totally unexpected and kind of wrong, I’ve created a bug for this on MSFT’s connect platform. You can vote for it <a href="https://connect.microsoft.com/SQLServer/feedback/details/545088/suboptimal-index-usage-within-stored-procedure" target="_blank">here</a>.</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com0tag:blogger.com,1999:blog-213131476646021708.post-10128772011950752502010-03-21T12:55:00.001+01:002010-03-21T12:55:26.763+01:00Making a column value in all rows identical<p>Assume we have the following table:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">create</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> <span style="color: blue">table</span> t1 <br /><span style="color: blue"><span style="mso-spacerun: yes"> </span></span><span style="color: gray">( <br /></span><span style="mso-spacerun: yes">  </span>id <span style="color: blue">int</span> <span style="color: gray">not</span> <span style="color: gray">null</span> <span style="color: blue">identity </span><span style="color: gray">(</span>1<span style="color: gray">,</span>1<span style="color: gray">)</span> <span style="color: blue">primary</span> <span style="color: blue">key</span> <br /><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span><span style="color: blue">status</span> <span style="color: blue">tinyint</span> <span style="color: gray">not</span> <span style="color: gray">null</span> <span style="color: blue">default</span> 0 <br /><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span>filler <span style="color: blue">nchar</span><span style="color: gray">(</span>4000<span style="color: gray">)</span> <span style="color: gray">not</span> <span style="color: gray">null</span> <span style="color: blue">default</span> <span style="color: red">'#'</span> <br /><span style="mso-spacerun: yes"> </span><span style="color: gray">) <br /></span><span style="color: blue">go <br />insert</span> t1<span style="color: gray">(</span><span style="color: blue">status</span><span style="color: gray">) <br /></span><span style="mso-spacerun: yes"> </span><span style="color: blue">select</span> <span style="color: blue">top</span> 10000 1 <br /><span style="mso-spacerun: yes">   </span><span style="color: blue">from</span> <span style="color: green">sys</span><span style="color: gray">.</span>fulltext_system_stopwords <span style="color: blue">as</span> a <br /><span style="mso-spacerun: yes">       </span><span style="color: gray">,</span><span style="color: green">sys</span><span style="color: gray">.</span>fulltext_system_stopwords <span style="color: blue">as</span> b <br /><span style="color: blue">go <br />update</span> <span style="color: blue">top</span><span style="color: gray">(</span>100<span style="color: gray">)</span> t1 <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">set</span> <span style="color: blue">status</span> <span style="color: gray">=</span> 0 </span></p> </td> </tr> </tbody></table> <p>Table t1 has 10,000 rows and also 10,000 pages at the leaf level of the clustered index (one row per page, since I’ve added the filler column which is 8,000 bytes wide). I’ve decided creating the test table like this (one row per page), since it eases further calculations.</p> <p>I was using a table similar to this, when collecting data during the day that had to be processed in a nightly batch job. To distinguish between new arrived rows and already processed ones, the status column is used. Let’s just say, we use a status value of 1 to mark rows that have been processed and that a value of 0 is flagging all rows that are ready to be processed. So, at the moment there are 10,000 rows in total, where 100 rows (with status=0) are waiting to be handled.</p> <p>For all rows that could be successfully handled, the nightly batch will set the value of the status column to 1 at the end. Usually, if all rows could be properly processed, all values of the status column will be at 1 after the nightly batch has accomplished its work.</p> <p>So let’s say, all rows could be handled successfully and no new rows will be arriving during the nightly batch. What’s the difference than between the following two statements:</p> <h5>Statement 1:</h5> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">update</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> t1 <span style="color: blue">set</span> <span style="color: blue">status</span> <span style="color: gray">=</span> 1 <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">where</span> <span style="color: blue">status</span> <span style="color: gray">!=</span> </span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">1 </span></p> </td> </tr> </tbody></table> <h5>Statement 2:</h5> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: 'Lucida Console'; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">update</span><span style="font-family: 'Lucida Console'; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> t1 <span style="color: blue">set</span> <span style="color: blue">status</span> <span style="color: gray">=</span> 1 </span></p> </td> </tr> </tbody></table> <p>Logically, there’s no difference. Both statements will set the value of the status column to 1 for all existing rows. But we have only 100 rows with status != 1 in place, so will there be any noticeable difference in the number of writes and the amount of dirty pages in the buffer cache after executing each of the two UPDATE statements? Is SQL Server smart enough to detect that only 100 rows are affected (that is also 100 pages in our case) for both queries, or is the update without a predicate really touching all rows/pages?</p> <p>Well, let’ see. For each of the following experiments I have repeated the creation of the test table before executing one of the two UPDATE statements. Additionally, I have performed the following script right before starting the UPDATE:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">checkpoint</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> 10 <br /><span style="color: blue">go <br />dbcc</span> dropcleanbuffers <br /><span style="color: blue">dbcc</span> freeproccache </span></p> </td> </tr> </tbody></table> <p>This is to make sure that all modified pages have been written to disk before examining the number of dirty pages that our UPDATE will create.</p> <p>For examining the performed number of writes, I queried the column last_logical_writes of the DMV sys.dm_exec_query_stats. The number of dirty pages after each UPDATE was simply obtained by utilizing the DBA’s all purpose tool DBCC. DBCC MEMORYSTATUS reveals a regarding section (almost at the end) containing buffer pool information which looks like this:</p> <p><a href="http://lh3.ggpht.com/_-C4uSahz1Gg/S6YJKxJdTgI/AAAAAAAABe0/vNYOpIXjJy0/s1600-h/image3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_-C4uSahz1Gg/S6YJLcO8DSI/AAAAAAAABe4/8qR7T8VR6Os/image_thumb1.png?imgmax=800" width="338" height="364" /></a> </p> <p>We start with the first statement, containing the predicate WHERE status != 1. I expect to see only 100 pages been written (100 logical writes) and almost the same amount of dirty pages (may be some more, since the value obtained by DBCC MEMORYSTATUS is server-wide).</p> <p>Ok, the numbers are as expected. My experiment shows 100 logical writes and 115 dirty pages. Nor surprise here. </p> <p>My second experiment uses statement 2 (that one without a predicate). This time, the result<em> is</em> surprising. Again the UPDATE shows 100 logical writes and a similar amount of dirty pages (135). That’s really amazing, isn’t it? SQL Server is smart enough to write only modified data and not touches unchanged rows, even if we, let’s say, forget the predicate. I didn’t expect this result.</p> <h3>Including the OUTPUT clause</h3> <p>What will happen if we incorporate an OUTPUT clause into our UPDATE statements? Via the OUTPUT clause I do have access to all modified data by using the virtual DELETED and INSERTED tables. Actually, two questions arise, when not specifying the predicate WHERE status != 1:</p> <ol> <li>Will we see all rows in the OUTPUT? Technically, only 100 rows are affected, but logically we have specified that all rows have to be modified. So, how many rows are returned by OUTPUT inserted.*? </li> <li>If OUTPUT inserted.* returns all rows, how many writes and dirty pages can be seen this time? </li> </ol> <p>Here come the answers:</p> <ol> <li>If no predicate is specified, the OUTPUT clause returns all rows, regardless of the fact that, technically, only 100 rows are affected by the UPDATE. </li> <li>Incorporating the OUTPUT clause does have no effect on the number or necessary writes and also no impact on the quantum of dirty pages. </li> </ol> <p>I’d say, this is as expected.</p> <h3>Introducing an Update Trigger</h3> <p>For the next experiments, I’ve also created an UPDATE TRIGGER like this: </p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">create</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> <span style="color: blue">trigger</span> tr_t1 <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">on</span> t1 <span style="color: blue">for</span> <span style="color: blue">update</span> <span style="color: blue">as <br /></span><span style="mso-spacerun: yes"> </span><span style="color: blue">begin <br /></span><span style="mso-spacerun: yes">   </span><span style="color: green">-- do nothing <br /></span><span style="mso-spacerun: yes">   </span><span style="color: blue">declare</span> @x <span style="color: blue">int <br /></span><span style="mso-spacerun: yes"> </span><span style="color: blue">end</span><span style="mso-spacerun: yes">  </span> <br /><span style="color: blue">go</span></span></p> </td> </tr> </tbody></table> <p>The trigger doesn’t do anything particularly useful, but let’s see if its only existence changes something. </p> <p>It does!</p> <p>With the trigger in place, the number of writes and also the amount of dirty pages increase dramatically, if no predicate is specified (so all rows are affected by the UPDATE). In this case I’ve observed number of writes as well as the total of dirty pages are both around 40,000! That’s about 400 times higher than without a trigger. So, the next CHECKPOINT has to write out about 40,000 pages this time, instead of only around 100 before. Big change!</p> <p>I think, the reason for this specific behavior lies in the pure existence of the virtual tables INSERTED and DELETED inside the trigger. The trigger is fired <em>after</em> the update has been performed, and these two virtual tables have to contain all tables’ rows, when no predicate is specified. It seems, SQL Server has to modify rows in order to have them included in INSERTED and DELETED tables.</p> <p>I could also observe reads from tempdb, when the trigger is present. That’s as expected, since INSERTED and DELETED tables are hosted inside tempdb.</p> <p>Somewhat strange, since the behavior for the OUTPUT clause is different, although both cases (OUTPUT and TRIGGER) are pretty similar.</p> <p>So, despite the trigger does nothing, it is affecting query performance and resource utilization! Not because of the trigger’s code, but simply because of its pure existence. Just one more reason to be careful with triggers!</p> <h3>Wrapping up</h3> <p>The following table contains all measured results. </p> <table style="width: 296pt; border-collapse: collapse; margin-left: 2.75pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 3.5pt 0in 3.5pt" class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="395"><tbody> <tr style="height: 15pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes"> <td style="border-bottom: medium none; border-left: #366092 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 70pt; padding-right: 3.5pt; background: #f2f2f2; height: 15pt; border-top: #366092 1pt solid; border-right: #366092 1pt solid; padding-top: 0in; mso-border-top-alt: solid #366092 .5pt; mso-border-left-alt: solid #366092 .5pt; mso-border-right-alt: solid #366092 .5pt" valign="bottom" width="93" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Trigger </span></b></p> </td> <td style="border-bottom: medium none; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 93pt; padding-right: 3.5pt; background: #f2f2f2; height: 15pt; border-top: #366092 1pt solid; border-right: #366092 1pt solid; padding-top: 0in; mso-border-top-alt: solid #366092 .5pt; mso-border-right-alt: solid #366092 .5pt" valign="bottom" width="124" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Predicate </span></b></p> </td> <td style="border-bottom: medium none; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 73pt; padding-right: 3.5pt; background: #f2f2f2; height: 15pt; border-top: #366092 1pt solid; border-right: #366092 1pt solid; padding-top: 0in; mso-border-top-alt: solid #366092 .5pt; mso-border-right-alt: solid #366092 .5pt" valign="bottom" width="97" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><b><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Logical Writes </span></b></p> </td> <td style="border-bottom: medium none; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 60pt; padding-right: 3.5pt; background: #f2f2f2; height: 15pt; border-top: #366092 1pt solid; border-right: #366092 1pt solid; padding-top: 0in; mso-border-top-alt: solid #366092 .5pt; mso-border-right-alt: solid #366092 .5pt" valign="bottom" width="80" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><b><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Dirty Pages </span></b></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 1"> <td style="border-bottom: #366092 1pt solid; border-left: #366092 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 70pt; padding-right: 3.5pt; background: #f2f2f2; height: 15pt; border-top: #366092 1pt solid; border-right: #366092 1pt solid; padding-top: 0in; mso-border-alt: solid #366092 .5pt" rowspan="2" width="93" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">No Trigger</span></p> </td> <td style="border-bottom: #366092 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 93pt; padding-right: 3.5pt; height: 15pt; border-top: #366092 1pt solid; border-right: #366092 1pt solid; padding-top: 0in; mso-border-top-alt: solid #366092 .5pt; mso-border-right-alt: solid #366092 .5pt; mso-border-bottom-alt: solid #366092 .5pt" valign="bottom" width="124" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">No Predicate </span></p> </td> <td style="border-bottom: #366092 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 73pt; padding-right: 3.5pt; height: 15pt; border-top: #366092 1pt solid; border-right: #366092 1pt solid; padding-top: 0in; mso-border-top-alt: solid #366092 .5pt; mso-border-right-alt: solid #366092 .5pt; mso-border-bottom-alt: solid #366092 .5pt" valign="bottom" width="97" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">100</span></p> </td> <td style="border-bottom: #366092 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 60pt; padding-right: 3.5pt; height: 15pt; border-top: #366092 1pt solid; border-right: #366092 1pt solid; padding-top: 0in; mso-border-top-alt: solid #366092 .5pt; mso-border-right-alt: solid #366092 .5pt; mso-border-bottom-alt: solid #366092 .5pt" valign="bottom" width="80" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">135</span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 2"> <td style="border-bottom: #366092 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 93pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #366092 1pt solid; padding-top: 0in; mso-border-right-alt: solid #366092 .5pt; mso-border-bottom-alt: solid #366092 .5pt" valign="bottom" width="124" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">WHERE status!=1</span></p> </td> <td style="border-bottom: #366092 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 73pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #366092 1pt solid; padding-top: 0in; mso-border-right-alt: solid #366092 .5pt; mso-border-bottom-alt: solid #366092 .5pt" valign="bottom" width="97" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">100</span></p> </td> <td style="border-bottom: #366092 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 60pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #366092 1pt solid; padding-top: 0in; mso-border-right-alt: solid #366092 .5pt; mso-border-bottom-alt: solid #366092 .5pt" valign="bottom" width="80" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">115</span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 3"> <td style="border-bottom: #366092 1pt solid; border-left: #366092 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 70pt; padding-right: 3.5pt; background: #f2f2f2; height: 15pt; border-top: medium none; border-right: #366092 1pt solid; padding-top: 0in; mso-border-left-alt: solid #366092 .5pt; mso-border-right-alt: solid #366092 .5pt; mso-border-bottom-alt: solid #366092 .5pt" rowspan="2" width="93" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">FOR UPDATE </span></p> </td> <td style="border-bottom: #366092 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 93pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #366092 1pt solid; padding-top: 0in; mso-border-right-alt: solid #366092 .5pt; mso-border-bottom-alt: solid #366092 .5pt" valign="bottom" width="124" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">No Predicate </span></p> </td> <td style="border-bottom: #366092 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 73pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #366092 1pt solid; padding-top: 0in; mso-border-right-alt: solid #366092 .5pt; mso-border-bottom-alt: solid #366092 .5pt" valign="bottom" width="97" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de"><font color="#a60000">40,101</font></span></p> </td> <td style="border-bottom: #366092 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 60pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #366092 1pt solid; padding-top: 0in; mso-border-right-alt: solid #366092 .5pt; mso-border-bottom-alt: solid #366092 .5pt" valign="bottom" width="80" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de"><font color="#a60000">40,107</font></span></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 4; mso-yfti-lastrow: yes"> <td style="border-bottom: #366092 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 93pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #366092 1pt solid; padding-top: 0in; mso-border-right-alt: solid #366092 .5pt; mso-border-bottom-alt: solid #366092 .5pt" valign="bottom" width="124" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">WHERE status!=1</span></p> </td> <td style="border-bottom: #366092 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 73pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #366092 1pt solid; padding-top: 0in; mso-border-right-alt: solid #366092 .5pt; mso-border-bottom-alt: solid #366092 .5pt" valign="bottom" width="97" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">501</span></p> </td> <td style="border-bottom: #366092 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 60pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #366092 1pt solid; padding-top: 0in; mso-border-right-alt: solid #366092 .5pt; mso-border-bottom-alt: solid #366092 .5pt" valign="bottom" width="80" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #0f243e; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">556</span></p> </td> </tr> </tbody></table> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com0tag:blogger.com,1999:blog-213131476646021708.post-24687165618258595632010-03-14T10:42:00.001+01:002010-03-14T10:43:35.273+01:00Implicit type conversation and the plan cache<p>You probably read already something about caveats and catches when relying on implicit type conversation. Here’s another one regarding the plan cache.</p> <p>Whenever an execution plan is compiled, SQL Server will try to store this plan in the plan cache. That’s because plan compilations are quite expensive in respect of CPU usage and therefore should be minimized. But sometimes this process doesn’t work as expected. Have a look at the following example.</p> <h3>Problem</h3> <p>First, we clear the plan cache</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">dbcc</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> freeproccache</span><span style="font-family: "Lucida Console"; color: red; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> </span></p> </td> </tr> </tbody></table> <p>Now let’s execute the following query: </p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">select</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> <span style="color: gray">*</span> <span style="color: blue">from</span> msdb<span style="color: gray">.</span>dbo<span style="color: gray">.</span>backupfile <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">where</span> backup_set_id<span style="color: gray">=</span>100000</span></p> </td> </tr> </tbody></table> <p>and see what’s in the plan cache by invoking this query:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">select</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> qt<span style="color: gray">.</span><span style="color: blue">text <br /></span><span style="mso-spacerun: yes">      </span><span style="color: gray">,</span>qs<span style="color: gray">.</span>execution_count <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">dm_exec_query_stats</span> <span style="color: blue">as</span> qs <br /><span style="mso-spacerun: yes">       </span><span style="color: gray">cross</span> <span style="color: gray">apply</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">dm_exec_sql_text</span><span style="color: gray">(</span>qs<span style="color: gray">.</span><span style="color: blue">sql_handle</span><span style="color: gray">)</span> <span style="color: blue">as</span> qt</span></p> </td> </tr> </tbody></table> <p>Here’s the result:</p> <p><a href="http://lh4.ggpht.com/_-C4uSahz1Gg/S5yvgJaD9zI/AAAAAAAABec/NXpnAXS5AEU/s1600-h/image%5B3%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_-C4uSahz1Gg/S5yvglOfqzI/AAAAAAAABeg/cMhHcM5gkNk/image_thumb%5B1%5D.png?imgmax=800" width="989" height="50" /></a>  </p> <p>Ok, no surprise. There’s a cached plan with a usage count of 1. This is as expected.</p> <p>Now, let’s execute a second query like this:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: 'Lucida Console'; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">select</span><span style="font-family: 'Lucida Console'; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> <span style="color: gray">*</span> <span style="color: blue">from</span> msdb<span style="color: gray">.</span>dbo<span style="color: gray">.</span>backupfile <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">where</span> backup_set_id<span style="color: gray">=</span>1000</span></p> </td> </tr> </tbody></table> <p>I expected the cached plan was reused. But surprisingly not! Let’s see what the plan cache reveals now. It looks like this: </p> <p><a href="http://lh3.ggpht.com/_-C4uSahz1Gg/S5yvhB1aVmI/AAAAAAAABek/JxH8K-5GH6g/s1600-h/image%5B7%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_-C4uSahz1Gg/S5yvhtWLzYI/AAAAAAAABeo/4jLNGfSh0H8/image_thumb%5B3%5D.png?imgmax=800" width="1051" height="78" /></a> </p> <p>As we asked for backup_set_id=1000 this time, our parameter is implicitly converted into a SMALLINT, since SMALLINT is the smallest possible data type a value of 1000 fits into. Consequently a new plan is generated and cached.</p> <p>We can repeat our experiment with a predicate of WHERE backup_set_id=10 and see another plan is going into the plan cache:</p> <p><a href="http://lh4.ggpht.com/_-C4uSahz1Gg/S5yviHI7IiI/AAAAAAAABes/w30ADSX2j50/s1600-h/image%5B11%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_-C4uSahz1Gg/S5yviYvKYjI/AAAAAAAABew/VMhjhOKBezE/image_thumb%5B5%5D.png?imgmax=800" width="1045" height="98" /></a> </p> <p>So, we have three plans now, all with an execution count of 1! </p> <p>As for me, I think this behavior is somewhat strange. The column backupset_id is of type INT, so why not just create one plan with INT as parameter type and stick to this plan?</p> <h3>Solutions</h3> <p>Since implicit type conversation is the root of our problem, we may solve it by avoiding this implicit conversation and cast explicit. We can re-write our queries like this:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">select</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> <span style="color: gray">*</span> <span style="color: blue">from</span> msdb<span style="color: gray">.</span>dbo<span style="color: gray">.</span>backupfile <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">where</span> backup_set_id<span style="color: gray">=</span><span style="color: fuchsia">cast</span><span style="color: gray">(</span>100000 <span style="color: blue">as</span> <span style="color: blue">int</span><span style="color: gray">) <br /></span><span style="mso-spacerun: yes"> </span> <br /><span style="color: blue">select</span> <span style="color: gray">*</span> <span style="color: blue">from</span> msdb<span style="color: gray">.</span>dbo<span style="color: gray">.</span>backupfile <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">where</span> backup_set_id<span style="color: gray">=</span><span style="color: fuchsia">cast</span><span style="color: gray">(</span>1000 <span style="color: blue">as</span> <span style="color: blue">int</span><span style="color: gray">) <br /> <br /></span><span style="color: blue">select</span> <span style="color: gray">*</span> <span style="color: blue">from</span> msdb<span style="color: gray">.</span>dbo<span style="color: gray">.</span>backupfile <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">where</span> backup_set_id<span style="color: gray">=</span><span style="color: fuchsia">cast</span><span style="color: gray">(</span>10 <span style="color: blue">as</span> <span style="color: blue">int</span><span style="color: gray">) </span></span></p> </td> </tr> </tbody></table> <p>After doing so, there’s only one plan in the cache. But I suppose, you wouldn’t want to introduce those explicit casts to all of your queries. It’s not very readable and looks like bad programming style, doesn’t it?</p> <p>Another solution comes through sp_executesql:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">exec</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> <span style="color: maroon">sp_executesql</span><span style="color: blue"> </span><span style="color: red">N'select * from msdb.dbo.backupfile <br /><span style="mso-spacerun: yes">                      </span>where backup_set_id=@id' <br /></span><span style="mso-spacerun: yes">                  </span><span style="color: gray">,</span><span style="color: red">N'@id int' <br /></span><span style="mso-spacerun: yes">                  </span><span style="color: gray">,</span>@id <span style="color: gray">=</span> 100000 <br /><span style="mso-spacerun: yes"> </span> <br /><span style="color: blue">exec</span> <span style="color: maroon">sp_executesql</span><span style="color: blue"> </span><span style="color: red">N'select * from msdb.dbo.backupfile <br /><span style="mso-spacerun: yes">                      </span>where backup_set_id=@id' <br /></span><span style="mso-spacerun: yes">                  </span><span style="color: gray">,</span><span style="color: red">N'@id int' <br /></span><span style="mso-spacerun: yes">                  </span><span style="color: gray">,</span>@id <span style="color: gray">=</span> 1000 <br /> <br /><span style="color: blue">exec</span> <span style="color: maroon">sp_executesql</span><span style="color: blue"> </span><span style="color: red">N'select * from msdb.dbo.backupfile <br /><span style="mso-spacerun: yes">                      </span>where backup_set_id=@id' <br /></span><span style="mso-spacerun: yes">                  </span><span style="color: gray">,</span><span style="color: red">N'@id int' <br /></span><span style="mso-spacerun: yes">                </span><span style="mso-spacerun: yes">  </span></span><span style="font-family: "Lucida Console"; color: gray; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">,</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">@id <span style="color: gray">=</span> 10 </span></p> </td> </tr> </tbody></table> <p>sp_executesql expects parameter declarations and, therefore, no implicit type conversation is involved this time. We see only one cached plan with an execution count of 3, when all of the above three queries have been executed.</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com0tag:blogger.com,1999:blog-213131476646021708.post-167788858660034412010-03-06T11:18:00.000+01:002010-03-06T11:19:10.028+01:00String comparison and collation<p>You probably already know that string comparison is dependent on the collation. But sometimes this dependency is slightly strange…</p> <p>I have installed an SQL Server with LATIN1_GENERAL_CI_AS as default collation (like is also the default setting during installation). Some weeks ago I came across a specific behavior in combination of this collation and the German language.</p> <p>German is a beautiful language! Really. You may know that we Germans have some special vowels (the “Umlaut”: ä, ö, and ü) and also that extra ß which is often (but not always) simply interchangeable with “ss”. Look at this query that uses the default collation for comparison:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">select</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> <span style="color: blue">case <br /></span><span style="mso-spacerun: yes">         </span><span style="color: blue">when</span> <span style="color: red">'ss'</span> <span style="color: blue">collate</span> latin1_general_ci_as <br /><span style="mso-spacerun: yes">             </span><span style="color: gray">=</span> <span style="color: red">'ß'</span> <span style="color: blue">collate</span> latin1_general_ci_as <br /><span style="mso-spacerun: yes">              </span><span style="color: blue">then</span> <span style="color: red">'Yes' <br /></span><span style="mso-spacerun: yes">         </span><span style="color: blue">else</span> <span style="color: red">'No' <br /></span><span style="mso-spacerun: yes">       </span><span style="color: blue">end</span> [ss=ß?]</span></p> </td> </tr> </tbody></table> <p>Considering that LATIN1_GENERAL_CI_AS is the default collation, the query above is identical to the following query:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">select</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> <span style="color: blue">case <br /></span><span style="mso-spacerun: yes">         </span><span style="color: blue">when</span> <span style="color: red">'ss'</span><span style="mso-spacerun: yes"> </span><span style="color: gray">=</span> <span style="color: red">'ß'</span><span style="mso-spacerun: yes"> </span><span style="color: blue">then</span> <span style="color: red">'Yes' <br /></span><span style="mso-spacerun: yes">         </span><span style="color: blue">else</span> <span style="color: red">'No' <br /></span><span style="mso-spacerun: yes">       </span><span style="color: blue">end</span> [ss=ß?] </span></p> </td> </tr> </tbody></table> <p>In both cases the result is <em>Yes</em>, so “ß” is considered as to be identical to “ss” when using the LATIN1_GENERAL_CI_AS collation.</p> <p>Hmm. Now look at this query:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">select</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> <span style="color: blue">case <br /></span><span style="mso-spacerun: yes">         </span><span style="color: blue">when</span> <span style="color: red">'ä'</span> <span style="color: gray">=</span> <span style="color: red">'ae'</span> <span style="color: blue">then</span> <span style="color: red">'Yes' <br /></span><span style="mso-spacerun: yes">         </span><span style="color: blue">else</span> <span style="color: red">'No' <br /></span><span style="mso-spacerun: yes">       </span><span style="color: blue">end</span> [ä=ae?] </span></p> </td> </tr> </tbody></table> <p>This time the answer is <em>No</em> which is somewhat surprising, since one could consider the overall behavior inconsistent. In German, “ä” and “ae” (and also “ö” and “oe” as well as “ü” and “ue”) are just as interchangeable as “ß” and “ss”.</p> <p>When this happened to me, I started browsing books online. There’s a hint, where you are advised setting the default collation to LATIN1_GENERAL_BIN for new installations. I didn’t know this so far, but ok: let’s retry our experiment:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">select</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> <span style="color: blue">case <br /></span><span style="mso-spacerun: yes">         </span><span style="color: blue">when</span> <span style="color: red">'ss'</span> <span style="color: blue">collate</span> latin1_general_bin <br /><span style="mso-spacerun: yes">             </span><span style="color: gray">=</span> <span style="color: red">'ß'</span> <span style="color: blue">collate</span> latin1_general_bin <br /><span style="mso-spacerun: yes">              </span><span style="color: blue">then</span> <span style="color: red">'Yes' <br /></span><span style="mso-spacerun: yes">         </span><span style="color: blue">else</span> <span style="color: red">'No' <br /></span><span style="mso-spacerun: yes">       </span><span style="color: blue">end</span> [ss=ß?] </span></p> </td> </tr> </tbody></table> <p>Now the answer is <em>No.</em></p> <p>But considering the fact that most newer installations use LATIN1_GENERAL_CI_AS, simply because that’s the default during installation, I can’t just change the collation to LATIN1_GENERAL_BIN, since this will certainly create other problems with queries spanning multiple databases with different collations. Not taking into account that changing the collation for an existing server and all of its databases/columns is a cumbersome and also very risky task on its own…</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com0tag:blogger.com,1999:blog-213131476646021708.post-63612946579948209912010-02-27T12:17:00.001+01:002010-02-27T12:17:47.584+01:00Are you a SQL Server Guru?<p>At the moment I have one contract as a SQL Server consultant for a company that develops software, and – guess what – uses SQL Server 2008 as their DBMS. About one month ago lead of development asked me to conduct one part of an interview with an applicant, to find out his real SQL Server skills. When looking at the application I was truly amazed, because the candidate designated himself the title of a <em>SQL Server Guru</em>. I know some people who are experts regarding SQL Server, even I know something more than only the fundamentals, but I seriously think there’s <em><a title="The only SQL Server Guru" href="http://www.sqlskills.com/aboutpaulsrandal.asp" target="_blank">only one SQL Server Guru alive</a></em> :). (You know, who I’m talking about without following the link, don’t you?) I was very excited about how the interview would go. As it turned out, it went somewhat surprising, and so I developed the idea for this blog post.</p> <p>But before I start repeating parts of the interview, I’d like to provide some background information about the company’s business model, just to get you a little more in context. The corporation not only builds software, but delivers complete systems to smaller stores, consisting of hardware and software, where the hardware usually encompasses one server and some client computers that are primarily used as checkout-counters. Of course the sales price has to be as low as possible, so there’s a very limited budget for building the system. Due to this limit, also the server hardware is quite imperfect, and SQL Server operates on the edge every so often, making performance and optimization a big issue. Actually I spend the majority of my time with performance optimization.</p> <p>Ok, here are some excerpts from the interview. I’ve included my thoughts and annotations <em>(written in italic and embedded in brackets)</em>.</p> <h3>The interview</h3> <p><strong>Q:</strong> This is the first time, I have the opportunity to interview a SQL Server Guru. So, what kind of guru are you actually? Is it more Development or Administration? Are you familiar with MSFT’s BI stack?</p> <p><strong>A:</strong> I’m very good in TSQL and optimization and I also know Reporting Services.</p> <p><strong>Q:</strong> Very good, you know something about optimization! We really need reinforcement in that area. So, what’s your general approach to optimization? Do you follow a method or framework here?</p> <p><strong>A: </strong>In most cases I optimize TSQL. <br /><em>(I loved to hear that. Really, I did. Tuning the database design, TSQL, and application requests is the most promising approach. The majority of people I’ve asked the same question so far were instantly telling me something about simply adding more indexes.)</em></p> <p><strong>Q:</strong> Very good! I really like that. How do you usually optimize TSQL? Is there a general approach, you follow?</p> <p><strong>A:</strong> I use query hints. <br /><em>(Ugh! How surprising. Query hints as general optimizing approach! I had to find out more.)</em></p> <p><strong>Q:</strong> Query hints? Why is that?</p> <p><strong>A:</strong> Because the optimizer is very stupid and generates wrong plans most of the time. <br /><em>(Hmm. About 20 years or so of development effort to make the optimizer perfect, all wasted. Does he really believe this?)</em></p> <p><strong>Q:</strong> That’s amazing. I didn’t know about that so far! Can you provide an example please?</p> <p><strong>A:</strong> Yes, for instance, the optimizer very often decides for using merge joins, and merge joins are always slow, particularly slower than nested loop joins. I have to force the optimizer using nested loop joins instead. <br /><em>(If merge joins are always slow and outperformed by nested loop joins, why do we have those? Has he never thought about that?)</em></p> <p><strong>Q:</strong> So, that’s your approach to optimization? Query hints?</p> <p><strong>A:</strong> Yes, whenever I write a query, I develop the execution plan in my head, because I can do better than the optimizer. And then I provide as many query hints as required to force the optimizer in the direction of using this plan, my plan. <br /><em>(I confess that I was tempted to ask for the company’s name where he implemented this, since I had a strong feeling this company would need some support. But at the moment I was fully booked and so I resisted. I recognized, this discussion would need to nowhere and decided it was time for a topic change.)</em></p> <p><strong>Q:</strong> Ok, thank you. So what did the guru do last week?</p> <p><strong>A:</strong> I used clustered indexes because this minimized locks. <br /><em>(Hmm. Another interesting statement. Let’s see, if he can tell me more about this.)</em></p> <p><strong>Q:</strong> Clustered index? What is that? Can you explain it, please?</p> <p><strong>A:</strong> When a query uses a clustered index, the query is very fast.</p> <p><strong>Q:</strong> So, a clustered index is kind of magic? How come, a query is always fast, when a clustered index is used? Can you tell me some more about a clustered index please? How is it constructed, or structured.</p> <p><strong>A:</strong> A clustered index is ordered. <br /><em>(Wow! The guru enlightened me with that perception!)</em></p> <p><strong>Q:</strong> So does this mean, a non-clustered index is non-ordered?</p> <p><strong>A:</strong> No no, a non-clustered index is also ordered.</p> <p><strong>Q:</strong> Ok, but what’s the difference then between a clustered index and a non-clustered index? What exactly is a clustered index? <br /><em>(I was about loosing my patience at this point!)</em></p> <p><strong>A:</strong> A clustered index minimizes blocking.</p> <p><strong>Q:</strong> Really? How is this possible? How is a clustered index structured? Can you explain, please?</p> <p><strong>A:</strong> You know, I use clustered indexes every day. I’m so deeply involved with clustered indexes that I can’t explain it anymore. <br /><em>(That was the moment, when I decided to send him back to where he came from. But unfortunately everybody else, including my interview pals were sitting in a strategic planning meeting, so I was the only one available and had to continue. I started getting angry, since he did nothing more than stealing my time.)</em></p> <p><strong>Q:</strong> Can you explain how a non-clustered index seek on a table works, if also a clustered index is existing?</p> <p>I just asked this question to tease him a little. Of course he couldn’t explain this. How could he, if he not even doesn’t know what is clustered index is at all?</p> <p>After a while our chief architect appeared, took over, and rescued me. Another 30 minutes later the candidate was sent home.</p> <h3>Ok, so what is this blog post all about?</h3> <p>About one year ago, <a href="http://www.brentozar.com/" target="_blank">Brent Ozar</a> has written a very informative and entertaining series of blog posts, containing some interview tips which you may find <a href="http://www.brentozar.com/archive/2009/01/interview-tip-dont-stress-out/" target="_blank">here</a>. I’d add another simple tip to his advices: Be honest. Only include those skills in your CV, you really can cope with. Know what you know but, more important, also know what you don’t know! While tuning your SQL Server is a good thing to do, tuning your CV too much is not! Be sure, someone will find out and you’d be pegged as being dishonest. You’ll be out of the game immediately when this happens.</p> <p>But how come, people consider themselves as being SQL Server experts or even gurus? I think that’s because MSFT did a great job in making SQL Server an easy to use product. After you managed to install your server and client tools, you can start using the relational engine instantly. It’s very easy staring at zero and improving your skill to, lets say, 30% in a short period. So, should we blame MSFT for making SQL Server that simple to use in taking the first steps? Of course not. But it’s just reality that many people using SQL Server don’t know much more than only some fundamentals. That’s not a bad thing at all, because SQL Server will do the job, even if it’s not operated at its optimal configuration, and non ideal queries are fired at it. To be honest, I personally like this, since it gives me the opportunity of being called for rescue, when things go worse.</p> <p>As with many things, also the term <em>expert</em> is relative. You can be that 30% expert in a particular environment, where you know only something about SQL Server, but everybody else knows almost nothing, making you the one-eyed amongst all the other blind persons.</p> <p>I remember a presentation <a href="http://www.sqlserverinternals.com/" target="_blank">Kalen Delaney</a> was holding in my hometown on the occasion of SQL Server 2005 inauguration, where she very frankly confessed that she has to face the fact, her SQL Server knowledge will decrease with every new release of SQL Server, simply because the product has an ever increasing complexity, and her knowledge will not able of keeping pace with this complexity<em> in all fields</em>. Therefore, she decided to focus on some things, and to be an expert on these.</p> <p>You may compare this to the disappearance of Middle Ages’ universal scholars. Also universal SQL Server experts are certainly rare, or even non-existent. I’m pretty sure, even <a href="http://www.sqlskills.com/aboutpaulsrandal.asp" target="_blank">the guru himself</a> would be somewhat conservative calling himself a guru.</p> <p>What do you think?</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com2tag:blogger.com,1999:blog-213131476646021708.post-72948874654791224852010-02-21T17:17:00.001+01:002010-02-24T21:21:15.212+01:00When an Index Seek actually is a Scan<p>I came across this issue recently when we discovered some very resource and time consuming seeks in some of our lately rolled out user databases. The users were querying articles from an article table by name.</p> <p>Here’s the simplified table that I’m talking about:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">use</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> tempdb <br /><span style="color: blue">go <br /> <br />if </span><span style="color: gray">(</span><span style="color: fuchsia">object_id</span><span style="color: gray">(</span><span style="color: red">'article'</span><span style="color: gray">,</span> <span style="color: red">'U'</span><span style="color: gray">)</span> <span style="color: gray">is</span> <span style="color: gray">not</span> <span style="color: gray">null) <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">drop</span> <span style="color: blue">table</span> article <br /><span style="color: blue">go <br />create</span> <span style="color: blue">table</span> article <br /><span style="color: blue"><span style="mso-spacerun: yes"> </span></span><span style="color: gray">( <br /></span><span style="mso-spacerun: yes">  </span>article_id <span style="color: blue">int</span> <span style="color: blue">identity</span><span style="color: gray">(</span>1<span style="color: gray">,</span>1<span style="color: gray">)</span> <span style="color: blue">primary</span> <span style="color: blue">key</span> <span style="color: gray">not</span> <span style="color: gray">null <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span>catalog_name <span style="color: blue">nvarchar</span><span style="color: gray">(</span>80<span style="color: gray">)</span> <span style="color: gray">not</span> <span style="color: gray">null <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span>filler <span style="color: blue">nchar</span><span style="color: gray">(</span>250<span style="color: gray">)</span> <span style="color: gray">not</span> <span style="color: gray">null</span> <span style="color: blue">default</span> <span style="color: red">'#' <br /></span><span style="mso-spacerun: yes"> </span></span><span style="font-family: "Lucida Console"; color: gray; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">) <br /></span><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">go </span></p> </td> </tr> </tbody></table> <p>Let’s pretend there are 400000 distinct articles (that’s approximately the real number, we have). The following scrip will insert 400000 rows:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: green; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">-- Insert 400000 rows. <br />-- We simulate random article names. <br /></span><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">insert</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> article<span style="color: gray">(</span>catalog_name<span style="color: gray">) <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">select</span> <span style="color: blue">top</span><span style="color: gray">(</span>400000<span style="color: gray">)</span> <span style="color: fuchsia">newid</span><span style="color: gray">() <br /></span><span style="mso-spacerun: yes">   </span><span style="color: blue">from</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">trace_event_bindings</span> <span style="color: blue">as</span> b1 <br /><span style="mso-spacerun: yes">       </span><span style="color: gray">,</span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">trace_event_bindings</span> <span style="color: blue">as</span> b2 <br /></span><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">go </span></p> </td> </tr> </tbody></table> <p>Now finally, we do some re-indexing just to make sure nothing like fragmented indexes or stale statistics will hamper our experiment’s results:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: green; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">-- Rebuild/create index will also generate <br />-- brand new statistics with full scan <br /></span><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">alter</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> <span style="color: blue">index</span> <span style="color: gray">all</span> <span style="color: blue">on</span> article <span style="color: blue">rebuild <br />go <br />create</span> <span style="color: blue">nonclustered</span> <span style="color: blue">index</span> ix_covering <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">on</span> article<span style="color: gray">(</span>catalog_name<span style="color: gray">)</span> include<span style="color: blue"> </span><span style="color: gray">(</span>filler<span style="color: gray">)</span> <br /><span style="color: blue">go </span></span></p> </td> </tr> </tbody></table> <p>I’ve created a covering index, including all of the table’s columns. Usually not a good idea but we can afford this, since the the table’s data never get modified by OLTP operations. Articles are rolled out from a master data source every two weeks, so we can have plenty of indexes simply for speeding up article searches. (We do bulk loads and index rebuilds.) Of course, you may object that I could have created the clustered index on the catalog_name column. Yes, may be a good idea. I come back to this later.</p> <p>Let’s switch on statistics io and statistics time counters to get an idea of how many reads and how much time every of the following queries need:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">set</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> <span style="color: blue">statistics</span> <span style="color: blue">io</span> <span style="color: blue">on <br />set</span> <span style="color: blue">statistics</span> <span style="color: blue">time</span> <span style="color: blue">on</span><span style="color: red"> </span></span></p> </td> </tr> </tbody></table> <p>Ok, everything is set now. Since we’ve just performed an index rebuild, we should also be sure that all of our data- and index pages reside in the buffer pool. We’re ready to perform some searches and look at execution plans and the required number of reads. Here’s the first query:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">select</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> catalog_name<span style="color: gray">,</span> filler <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> article <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">where</span> catalog_name <span style="color: gray">like</span> <span style="color: red">'abac%' </span></span></p> </td> </tr> </tbody></table> <p>Nothing special here. The number of reads is 6 and as expected, the covering index is utilized. This is also, what the execution plan reveals:</p> <p><a href="http://lh4.ggpht.com/_-C4uSahz1Gg/S4FcjKU6QuI/AAAAAAAABdY/_T3eHwzDyQs/s1600-h/image16.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_-C4uSahz1Gg/S4FcjWOpvwI/AAAAAAAABdc/mrao8-J0Aik/image_thumb12.png?imgmax=800" width="289" height="82" /></a> </p> <p>Very good! That’s the best plan we can get for the invoked query. The execution time is hardly measurable. It’s about 1ms on my machine, where CPU utilization does not even appear. (It says 0ms, so I suppose it’s simply somewhat lost in the general noise floor.)</p> <p>The operator information for the Index Seek exposes a slightly little detail:</p> <p><a href="http://lh3.ggpht.com/_-C4uSahz1Gg/S4FckG7lqoI/AAAAAAAABdg/WO8gTtwXvbQ/s1600-h/image%5B19%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_-C4uSahz1Gg/S4Fckj8yXaI/AAAAAAAABdk/bqGZqm2WVbk/image_thumb%5B9%5D.png?imgmax=800" width="328" height="536" /></a> </p> <p>The seek actually is a range scan, so the Index Seek <em>scans</em> a range of rows from the index. That is, the seek starts at a particular minimum value and then subsequently scans all leaf level rows in an ordered sequence until the predicate’s condition isn’t complied any more. To determine which rows will fulfill the predicate, a maximum value for the range scan is determined. The actual minimum and maximum values are calculated by examining the provided literal for the LIKE operator which is “abac%” in our experiment. That’s an important trifle which we’ll get back to a little later on.</p> <p>Unfortunately we discovered users would execute somewhat different requests. There’s a clear pattern we saw, and sadly most of the provided search strings started (and also ended) with wildcards (“%”). So, instead of looking for articles, <em>starting with</em> “abac”, more often than not users are looking for articles, <em>containing</em> “abac”. That’d be a query like this one:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">select</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> catalog_name<span style="color: gray">,</span> filler <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> article <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">where</span> catalog_name <span style="color: gray">like</span> <span style="color: red">'%abac%' </span></span></p> </td> </tr> </tbody></table> <p>Of course that’s a complete different query! We see a lot more reads (35313) and the execution plan reveals a parallel index scan this time:</p> <p><a href="http://lh6.ggpht.com/_-C4uSahz1Gg/S4Fckw3JANI/AAAAAAAABdo/MiOjjbn5GWY/s1600-h/image%5B3%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_-C4uSahz1Gg/S4FclRKiXbI/AAAAAAAABds/NCBYga105yk/image_thumb%5B1%5D.png?imgmax=800" width="456" height="82" /></a> </p> <p>The execution time is 1122 ms and the CPU utilization (with two cores) is 1997 ms, a big raise in both!</p> <p>Apparently an index seek can’t be performed here, because we’re using a wildcard at the first position of the filter condition, or can it?</p> <p>Let’s create a stored procedure for the search:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">if </span><span style="font-family: "Lucida Console"; color: gray; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">(</span><span style="font-family: "Lucida Console"; color: fuchsia; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">object_id</span><span style="font-family: "Lucida Console"; color: gray; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">(</span><span style="font-family: "Lucida Console"; color: red; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">'search_articles'</span><span style="font-family: "Lucida Console"; color: gray; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">,</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> <span style="color: red">'P'</span><span style="color: gray">)</span> <span style="color: gray">is</span> <span style="color: gray">not</span> <span style="color: gray">null) <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">drop</span> <span style="color: blue">procedure</span> search_articles <br /><span style="color: blue">go</span><span style="mso-spacerun: yes">  </span> <br /><span style="color: blue">create</span> <span style="color: blue">procedure</span> search_articles<span style="color: gray">(</span>@p1 <span style="color: blue">nvarchar</span><span style="color: gray">(</span>80<span style="color: gray">))</span> <span style="color: blue">with</span> <span style="color: blue">recompile <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">as <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">select</span> catalog_name<span style="color: gray">,</span> filler <br /><span style="mso-spacerun: yes">    </span><span style="color: blue">from</span> article <br /><span style="mso-spacerun: yes">   </span></span><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">where</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> catalog_name <span style="color: gray">like</span> @p1 <br /><span style="color: blue">go</span></span><span style="font-family: "Lucida Console"; color: red; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> </span></p> </td> </tr> </tbody></table> <p>Because we expect to see varying search arguments, leading to very different row count estimations and execution plans, the procedure is created by specifying the WITH RECOMPILE hint, so an execution plan is never cached, but will always be generated when the procedure gets called.</p> <p>Ok, let’s try the procedure. First we invoke a simple search, where we expect an index seek as the optimal operator:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">exec</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> search_articles<span style="color: blue"> </span><span style="color: red">'abac%' </span></span></p> </td> </tr> </tbody></table> <p>The execution plan looks pretty much the same as above, where the index seek on the existing covering index has been utilized:</p> <p><a href="http://lh4.ggpht.com/_-C4uSahz1Gg/S4Fclj24jVI/AAAAAAAABdw/KsWJoJPuaU4/s1600-h/image%5B7%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_-C4uSahz1Gg/S4FclyOcnPI/AAAAAAAABd0/55092nV9P6g/image_thumb%5B3%5D.png?imgmax=800" width="537" height="168" /></a> </p> <p>We see 6 reads and again, the execution time is only about 1 ms (and another 1-2 ms for stored procedure compilation). The execution plan looks pretty much the same as before, with the exception of the now existent Constant Scan and the Compute Scalar operators. These two operators calculate minimal and maximal values for the Index Seek (or the Index Range Scan, if you like) from the provided parameter.</p> <p>Let’s invoke the procedure with a wildcard as the first character for the search argument:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">exec</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> search_articles<span style="color: blue"> </span><span style="color: red">'%abac%' </span></span></p> </td> </tr> </tbody></table> <p>Surprisingly, the execution plan doesn’t reveal an Index Scan this time. Although the query is the same as in our second example, where an Ad Hoc query with an identical search argument was executed, the procedure’s plan sticks to an Index Seek:</p> <p><a href="http://lh5.ggpht.com/_-C4uSahz1Gg/S4FcmIjD6dI/AAAAAAAABd4/DqYp-TtgMZo/s1600-h/image%5B23%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_-C4uSahz1Gg/S4FcmkxZxyI/AAAAAAAABd8/2bK8iZb9XZg/image_thumb%5B11%5D.png?imgmax=800" width="538" height="168" /></a> </p> <p>Additionally, we don’t see any parallel execution. That’s probably since an Index Seek (or Index Range Scan) has to be done sequentially, so parallel execution is simply not possible. The query took 31120 reads, 1810 ms CPU time, and 1841 ms in total. That’s a lot of reads for only 128 rows in the result set. So, is there anything we can do to lower the number of reads resp. the execution time?</p> <p>May be, we can! Think about the reason for the huge number of reads. It’s because all leaf level rows of the index have to be investigated to determine, whether a particular row matches the search condition or not. Therefore the navigation through our covering index looks like this:</p> <p><a href="http://lh5.ggpht.com/_-C4uSahz1Gg/S4Fcm7psN0I/AAAAAAAABeA/WTV7Dou6Vho/s1600-h/image%5B27%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_-C4uSahz1Gg/S4FcnO4JSjI/AAAAAAAABeE/-k1_5kmMCnQ/image_thumb%5B13%5D.png?imgmax=800" width="285" height="160" /></a> </p> <p>That’s a <em>scan of the whole covering index</em>, although the plan exposes an Index Seek here! See where this leads to? We can probably lower the number number of necessary reads by creating a non covering index with catalog_name as the only column in it. In that case the Index Range Scan had to read fewer pages to find our 128 keys for an additional clustered index Key Lookup.</p> <p>Let’s try this out. First, we create the non covering index:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">create</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> <span style="color: blue">index</span> ix_noncovering <span style="color: blue">on</span> article<span style="color: gray">(</span>catalog_name<span style="color: gray">) </span></span></p> </td> </tr> </tbody></table> <p>And now, we invoke the Ad Hoc query again:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">select</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> catalog_name<span style="color: gray">,</span> filler <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> article <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">where</span> catalog_name <span style="color: gray">like</span> <span style="color: red">'%abac%'</span><span style="color: gray"> </span></span></p> </td> </tr> </tbody></table> <p>As expected, the plan exposes an Index Seek on the non covering index to find all rows matching the predicate, and additional Key Lookups for retrieval of the missing column data:</p> <p><a href="http://lh3.ggpht.com/_-C4uSahz1Gg/S4Fcnem0dGI/AAAAAAAABeI/Z1mLQxqOKdI/s1600-h/image%5B31%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_-C4uSahz1Gg/S4Fcn7aDw1I/AAAAAAAABeM/JdIoq1CgOBE/image_thumb%5B15%5D.png?imgmax=800" width="514" height="172" /></a> </p> <p>This query took 4559 reads, about 7 times fewer than before! Unfortunately, on my machine, execution times haven’s changed much. The query still took 1830 ms with a CPU utilization of 1763 ms. But fewer reads means fewer resource usage, and also fewer blockings (latches in particular), so the result isn’t too bad at all. And this is the moment, where I’d like to mention the clustered index again. Some people would advice to create the clustered index on the catalog_name column. This is generally a good idea, when the clustered index can be utilized for <em>seeks</em>. When Clustered Index Scans (or Range Scans) come into play, the clustered index (since it is covering) may not be an optimal choice.</p> <p>Let’s now see, how our stored procedure behaves with the new non covering index in place:</p> <p>This is the call:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">exec</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> search_articles<span style="color: blue"> </span><span style="color: red">'%abac%'</span><span style="color: gray"> </span></span></p> </td> </tr> </tbody></table> <p>And here’s the execution plan:</p> <p><a href="http://lh4.ggpht.com/_-C4uSahz1Gg/S4FcoHbiJmI/AAAAAAAABeQ/KT-vHxfCL_M/s1600-h/image%5B35%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_-C4uSahz1Gg/S4FcoYMOQFI/AAAAAAAABeU/P7fbAXvLdDg/image_thumb%5B17%5D.png?imgmax=800" width="541" height="167" /></a> </p> <p>Surprisingly the plan has not changed! The non covering index isn’t utilized, although the number of reads would have been 7 times lower! So, the query still needs 31120 reads, 1905 ms total execution time, and 1872 ms of CPU utilization. When invoking the stored procedure, the covering index is always used! </p> <p>Is the optimizer wrong? I don’t think so, because the optimizer uses a strategy that doesn’t care much about resource utilization – with three exceptions: time, time, and time. Minimizing the execution time is the only thing that counts for the optimizer. The optimizer is very aggressive when trying to reach the goal of minimizing execution time and thus, a query may eat up all CPU cycles, do a vastly number of reads, or burden the environment with even more greenhouse gas emission, and further increase global warming. All this topics will not be taken into account by the optimizer.</p> <p>The Ad Hoc query is, by the way, more “sensitive” here. The following query:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">select</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> catalog_name<span style="color: gray">,</span> filler <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> article <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">where</span> catalog_name <span style="color: gray">like</span> <span style="color: red">'abac%'</span><span style="color: gray"> </span></span></p> </td> </tr> </tbody></table> <p>will perform an Index Seek on the covering index, since this takes only 6 reads and is very fast.</p> <p>So finally, let’s remove the covering index to see, how this affects or queries:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">drop</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> <span style="color: blue">index</span> ix_covering <span style="color: blue">on</span> article </span></p> </td> </tr> </tbody></table> <p>Now the stored procedure can’t perform an Index Seek on the covering index any more. It has to use the non covering index instead. We’ll see some additional Key Lookups as a consequence. As long as a query returns only a handful of rows, this will need fewer reads, however. With a larger number of rows in the result set, dropping the covering index will affect the query performance negatively. So, deciding which index(es) to create is not an easy task! </p> <p>The following tables summarizes all measured results:</p> <table style="width: 497.1pt; border-collapse: collapse; margin-left: 2.75pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 3.5pt 0in 3.5pt" class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="663"><tbody> <tr style="height: 15pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes"> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 173pt; padding-right: 3.5pt; background: #f2f2f2; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="231" colspan="2" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #16365c; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Search argument: "%abac%" </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 324.1pt; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="432" colspan="6" nowrap="nowrap"> <p style="text-align: center; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="center"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Query </span></b> <p></p> </p> <p></p> <p></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 1"> <td style="border-bottom: medium none; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 173pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: medium none; border-right: medium none; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-left-alt: solid #1f497d .5pt" valign="bottom" width="231" colspan="2" nowrap="nowrap"> <p style="text-align: center; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="center"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Existing Indexes </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 162.05pt; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: medium none; border-right: medium none; padding-top: 0in; mso-border-left-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt" valign="bottom" width="216" colspan="3" nowrap="nowrap"> <p style="text-align: center; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="center"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Ad Hoc </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 162.05pt; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-alt: solid #1f497d .5pt; mso-border-top-alt: solid #1f497d .5pt" valign="bottom" width="216" colspan="3" nowrap="nowrap"> <p style="text-align: center; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="center"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Stored Procedure </span></b> <p></p> </p> <p></p> <p></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 2"> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 74.9pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-alt: solid #1f497d .5pt" valign="bottom" width="100" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Covering Index </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 98.1pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="131" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Non Covering Index </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: medium none; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 34.95pt; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="47" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Reads </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: medium none; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 77.65pt; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="104" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Execution Time </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="padding-bottom: 0in; padding-left: 3.5pt; width: 49.45pt; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; padding-top: 0in" valign="bottom" width="66" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">CPU Time </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: medium none; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 34.95pt; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-left-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="47" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Reads </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: medium none; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 77.65pt; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="104" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Execution Time </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: medium none; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 49.45pt; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">CPU Time </span></b> <p></p> </p> <p></p> <p></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 3"> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 74.9pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-left-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="100" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Yes </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 98.1pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="131" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">No </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: medium none; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 34.95pt; padding-right: 3.5pt; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="47" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">35,313 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 77.65pt; padding-right: 3.5pt; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="104" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">1,122 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 49.45pt; padding-right: 3.5pt; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">1,997 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 34.95pt; padding-right: 3.5pt; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="47" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">31,120 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 77.65pt; padding-right: 3.5pt; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="104" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">1,841 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 49.45pt; padding-right: 3.5pt; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">1,810 </span></p> <p></p> <p></p> <p></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 4"> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 74.9pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-left-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="100" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Yes </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 98.1pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="131" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Yes </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 34.95pt; padding-right: 3.5pt; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="47" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">4,559 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 77.65pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="104" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">1,830 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 49.45pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: medium none; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">1,763 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 34.95pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-left-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="47" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">31,120 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 77.65pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="104" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">1,905 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 49.45pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">1,872 </span></p> <p></p> <p></p> <p></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 5; mso-yfti-lastrow: yes"> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 74.9pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-left-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="100" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">No </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 98.1pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="131" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Yes </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 34.95pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="47" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">4,576 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 77.65pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="104" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">1,806 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 49.45pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: medium none; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">1,747 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 34.95pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-left-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="47" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">4,576 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 77.65pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="104" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">2,092 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 49.45pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="66" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">2,074 </span></p> <p></p> <p></p> <p></p> </td> </tr> </tbody></table> <p> </p> <table style="width: 497pt; border-collapse: collapse; margin-left: 2.75pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 3.5pt 0in 3.5pt" class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="663"><tbody> <tr style="height: 15pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes"> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 173pt; padding-right: 3.5pt; background: #f2f2f2; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="231" colspan="2" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #16365c; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Search argument: "abac%" </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 4.5in; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="432" colspan="6" nowrap="nowrap"> <p style="text-align: center; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="center"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Query </span></b> <p></p> </p> <p></p> <p></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 1"> <td style="border-bottom: medium none; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 173pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: medium none; border-right: medium none; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-left-alt: solid #1f497d .5pt" valign="bottom" width="231" colspan="2" nowrap="nowrap"> <p style="text-align: center; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="center"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Existing Indexes </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 2.25in; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: medium none; border-right: medium none; padding-top: 0in; mso-border-left-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt" valign="bottom" width="216" colspan="3" nowrap="nowrap"> <p style="text-align: center; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="center"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Ad Hoc </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 2.25in; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-alt: solid #1f497d .5pt; mso-border-top-alt: solid #1f497d .5pt" valign="bottom" width="216" colspan="3" nowrap="nowrap"> <p style="text-align: center; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="center"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Stored Procedure </span></b> <p></p> </p> <p></p> <p></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 2"> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 74.9pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-alt: solid #1f497d .5pt" valign="bottom" width="100" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Covering Index </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 98.1pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="131" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Non Covering Index </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: medium none; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 32.2pt; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="43" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Reads </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: medium none; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 79.3pt; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="106" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Execution Time </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="padding-bottom: 0in; padding-left: 3.5pt; width: 50.5pt; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; padding-top: 0in" valign="bottom" width="67" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">CPU Time </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: medium none; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 32.2pt; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-left-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="43" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Reads </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: medium none; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 79.3pt; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="106" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Execution Time </span></b> <p></p> </p> <p></p> <p></p> </td> <td style="border-bottom: medium none; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 50.5pt; padding-right: 3.5pt; background: #e9e9f3; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="67" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><b><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">CPU Time </span></b> <p></p> </p> <p></p> <p></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 3"> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 74.9pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-left-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="100" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Yes </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 98.1pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="131" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">No </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: medium none; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 32.2pt; padding-right: 3.5pt; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="43" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">5 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 79.3pt; padding-right: 3.5pt; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="106" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">1 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 50.5pt; padding-right: 3.5pt; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="67" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">0 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 32.2pt; padding-right: 3.5pt; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="43" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">5 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 79.3pt; padding-right: 3.5pt; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="106" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">2 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 50.5pt; padding-right: 3.5pt; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="67" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">0 </span></p> <p></p> <p></p> <p></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 4"> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 74.9pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-left-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="100" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Yes </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 98.1pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="131" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Yes </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 32.2pt; padding-right: 3.5pt; height: 15pt; border-top: #1f497d 1pt solid; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-top-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="43" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">5 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 79.3pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="106" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">1 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 50.5pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: medium none; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt" valign="bottom" width="67" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">0 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 32.2pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-left-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="43" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">5 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 79.3pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="106" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">3 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 50.5pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="67" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">0 </span></p> <p></p> <p></p> <p></p> </td> </tr> <tr style="height: 15pt; mso-yfti-irow: 5; mso-yfti-lastrow: yes"> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 74.9pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-left-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="100" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">No </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 98.1pt; padding-right: 3.5pt; background: #cbe6eb; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="131" nowrap="nowrap"> <p style="line-height: normal; margin-bottom: 0pt" class="MsoNormal"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">Yes </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 32.2pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="43" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">18 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 79.3pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="106" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">1 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 50.5pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: medium none; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt" valign="bottom" width="67" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">0 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: #1f497d 1pt solid; padding-bottom: 0in; padding-left: 3.5pt; width: 32.2pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-left-alt: solid #1f497d .5pt; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="43" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">18 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 79.3pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="106" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">2 </span></p> <p></p> <p></p> <p></p> </td> <td style="border-bottom: #1f497d 1pt solid; border-left: medium none; padding-bottom: 0in; padding-left: 3.5pt; width: 50.5pt; padding-right: 3.5pt; height: 15pt; border-top: medium none; border-right: #1f497d 1pt solid; padding-top: 0in; mso-border-bottom-alt: solid #1f497d .5pt; mso-border-right-alt: solid #1f497d .5pt" valign="bottom" width="67" nowrap="nowrap"> <p style="text-align: right; line-height: normal; margin-bottom: 0pt" class="MsoNormal" align="right"><span style="color: #366092; mso-bidi-font-family: calibri; mso-ascii-font-family: calibri; mso-fareast-font-family: 'Times New Roman'; mso-hansi-font-family: calibri; mso-fareast-language: de">0 </span></p> <p></p> <p></p> <p></p> </td> </tr> </tbody></table> <p>I’ve executed every experiment a few times and averaged obtained results, to ensure side effects are minimized.</p> <p>Note: If you start your own experiments by using the scripts provided here, your results may vary, since the scripts operate with random values.</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com1tag:blogger.com,1999:blog-213131476646021708.post-17059593211317407522010-02-18T17:50:00.001+01:002010-02-18T17:56:14.375+01:00Did you know: Aggregate functions on floats may be non-deterministic<p>One day some of the report-users mentioned that, every time they run a report, they get different results. My first idea was that there were some undergoing data changes, probably from a different connection/user, so this would explain it. But it turned out that no modifications were made. Even setting the database to read only did not help. Numbers in reports differed by about 20% with every execution.</p> <p>Delving into it, I could isolate the problem. It was a single SELECT statement that, when invoked, returned different results. The numbers differed by up to 20% in value without any data changes being performed!</p> <p>Have a look at the following sample. We create a test table to demonstrate what I’m talking about:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">use</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> tempdb <br /><span style="color: blue">go <br /> <br />if </span><span style="color: gray">(</span><span style="color: fuchsia">object_id</span><span style="color: gray">(</span><span style="color: red">'SumTest'</span><span style="color: gray">,</span> <span style="color: red">'U'</span><span style="color: gray">)</span> <span style="color: gray">is</span> <span style="color: gray">not</span> <span style="color: gray">null) <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">drop</span> <span style="color: blue">table</span> SumTest <br /><span style="color: blue">go</span><span style="mso-spacerun: yes">  </span> <br /><span style="color: blue">create</span> <span style="color: blue">table</span> SumTest <br /><span style="color: blue"><span style="mso-spacerun: yes"> </span></span><span style="color: gray">( <br /></span><span style="mso-spacerun: yes">  </span>floatVal <span style="color: blue">float</span> <span style="color: gray">not</span> <span style="color: gray">null <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span>decimalVal <span style="color: blue">decimal</span><span style="color: gray">(</span>20<span style="color: gray">,</span>4<span style="color: gray">)</span> <span style="color: gray">not</span> <span style="color: gray">null <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span>filler <span style="color: blue">nchar</span><span style="color: gray">(</span>300<span style="color: gray">)</span> <span style="color: gray">not</span> <span style="color: gray">null</span> <span style="color: blue">default</span> <span style="color: red">'#' <br /></span><span style="mso-spacerun: yes"> </span></span><span style="font-family: "Lucida Console"; color: gray; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">) <br /></span><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">go</span><span style="mso-ansi-language: en-us" lang="EN-US"> </span></p> </td> </tr> </tbody></table> <p>The table has three columns, where the third column only serves the purpose of filling up the row, so the table contains more data pages.</p> <p>Let’s now insert 600000 rows into our table:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">declare</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> @x <span style="color: blue">float <br />set</span> @x <span style="color: gray">=</span> 1000000000000000.9999<span style="mso-spacerun: yes">       </span> <br /> <br /><span style="color: green">-- Insert 300000 identical rows <br /></span><span style="color: blue">insert</span> SumTest<span style="color: gray">(</span>floatVal<span style="color: gray">,</span> decimalVal<span style="color: gray">) <br /></span><span style="mso-spacerun: yes"> </span><span style="color: blue">select</span> <span style="color: blue">top</span><span style="color: gray">(</span>300000<span style="color: gray">)</span> @x<span style="color: gray">,</span> @x <br /><span style="mso-spacerun: yes">   </span><span style="color: blue">from</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">trace_event_bindings</span> <span style="color: blue">as</span> b1 <br /><span style="mso-spacerun: yes">       </span><span style="color: gray">,</span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">trace_event_bindings</span> <span style="color: blue">as</span> b2 <br /><span style="mso-spacerun: yes">       </span> <br /><span style="color: green">-- Again insert 300000 rows. <br />-- This time with negative sign <br /></span><span style="color: blue">insert</span> SumTest<span style="color: gray">(</span>floatVal<span style="color: gray">,</span> decimalVal<span style="color: gray">) <br /></span><span style="mso-spacerun: yes"> </span><span style="color: blue">select</span> <span style="color: blue">top</span><span style="color: gray">(</span>300000<span style="color: gray">)</span> <span style="color: gray">-</span>@x<span style="color: gray">,</span> <span style="color: gray">-</span>@x <br /><span style="mso-spacerun: yes">   </span><span style="color: blue">from</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">trace_event_bindings</span> <span style="color: blue">as</span> b1 <br /><span style="mso-spacerun: yes">       </span><span style="color: gray">,</span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">trace_event_bindings</span> <span style="color: blue">as</span> b2</span></p> </td> </tr> </tbody></table> <p>The first INSERT statement adds 300000 rows with positive values for the two columns floatVal and decimalVal. After that, we insert another 300000 rows, this time with inverse signs. So in total, values for each of the two columns should add up to zero. Let’s check this by invoking the summation over all rows a few times:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">select</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal <br /><span style="mso-spacerun: yes">      </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> SumTest <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal <br /><span style="mso-spacerun: yes">      </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> SumTest <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal <br /><span style="mso-spacerun: yes">      </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> SumTest <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal <br /><span style="mso-spacerun: yes">      </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> SumTest <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal <br /><span style="mso-spacerun: yes">      </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> SumTest <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal <br /><span style="mso-spacerun: yes">      </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> SumTest <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal <br /><span style="mso-spacerun: yes">      </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> SumTest <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal <br /><span style="mso-spacerun: yes">      </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> SumTest <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal <br /><span style="mso-spacerun: yes">      </span></span><span style="font-family: "Lucida Console"; color: gray; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">,</span><span style="font-family: "Lucida Console"; color: fuchsia; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">sum</span><span style="font-family: "Lucida Console"; color: gray; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">(</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> SumTest</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> </span></p> </td> </tr> </tbody></table> <p>And here’s the result:</p> <p><a href="http://lh5.ggpht.com/_-C4uSahz1Gg/S31vxEDbZqI/AAAAAAAABcg/y5viS3JM5as/s1600-h/image%5B7%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_-C4uSahz1Gg/S31vxlxQ7BI/AAAAAAAABck/RMH3Br1F6lg/image_thumb%5B7%5D.png?imgmax=800" width="295" height="172" /></a> </p> <p>As for the DECIMAL column, the outcome is as expected. But look at the totals for the FLOAT column. It’s perfectly understandable, the sum will reveal some rounding errors. What really puzzled me is the difference between the numbers. Why isn’t the rounding error the same for all executions?</p> <p>I was pretty sure that I discovered a bug in SQL Server and posted a regarding item on MSFT’s connect platform (see <a href="https://connect.microsoft.com/SQLServer/feedback/details/465147/select-sum-is-non-deterministic-when-adding-the-column-values-of-datatype-float" target="_blank">here</a>).</p> <p>Unfortunately nobody cared about my problem, and so I took the opportunity of talking to some fellows of the SQL Server CAT team on the occasion of the 2009 PASS Summit. After a while, I received an explanation which I’d like to repeat here.</p> <p>The query is executed in parallel, as the plan reveals:</p> <p><a href="http://lh3.ggpht.com/_-C4uSahz1Gg/S31vyk37WKI/AAAAAAAABco/F0U8x6VjF-w/s1600-h/image1%5B1%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_-C4uSahz1Gg/S31vz8UvHoI/AAAAAAAABcs/IBL6nCIgdGU/image1_thumb.png?imgmax=800" width="982" height="87" /></a> </p> <p>When summing up values, usually the summation sequence doesn’t matter. (If you remember some mathematics from school that’s what the commutative law of addition is about). Therefore, reading values in multiple threads and adding up the values in any arbitrary order is perfect, as the order doesn’t have any influence on the result. Well, at least theoretically. When adding float values, there’s floating point arithmetic rounding errors with every addition. These added-up rounding errors are the reason for the non-zero values of the float totals in our example. So that’s ok, but why different results with almost every execution? The reason for this is parallel execution. Added-up rounding errors <em>depend</em> on the sequence, so the commutative law does not really apply to these errors. There’s a chance that the sequence of rows changes with every execution, if the query is executed in parallel. And that’s why the results change, dependent only on some butterfly wing movements at the other side of the world…</p> <p>If we add the MAXDOP 1 query hint, only one thread is utilized and the results are the same for every execution, although rounding errors still remain present. So this query:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">select</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal <br /><span style="mso-spacerun: yes">      </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">from</span> SumTest <span style="color: blue">option </span><span style="color: gray">(</span><span style="color: blue">maxdop</span> 1<span style="color: gray">)</span> </span></p> </td> </tr> </tbody></table> <p>will be executed by using the following (single thread) execution plan:</p> <p><a href="http://lh6.ggpht.com/_-C4uSahz1Gg/S31v040xHTI/AAAAAAAABcw/S3sP1BqTx8c/s1600-h/image7%5B1%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_-C4uSahz1Gg/S31v3V9wRDI/AAAAAAAABc4/nu24EdZdhyE/image7_thumb.png?imgmax=800" width="511" height="85" /></a> </p> <p>This time the result (and also the rounding error) is always the same.</p> <p>Pretty soon after delivering the explanation, the bug was closed. Reason: the observed behavior is “by design”.</p> <p>I can understand that the problem originates from computer resp. processor architecture and MSFT has no chance of control therefore.</p> <p>Although…</p> <p>When using SSAS’ write back functionality, SSAS will always create numeric columns of FLOAT data types. There’s no chance of manipulating the data type; it’s <em>always</em> float!</p> <p>Additionally, SSAS more often than not inserts rows into write back tables with vastly large resp. small values. When looking an these rows, it appeared that they are created solely with the intention of summing up to zero. We discovered plenty of these rows containing inverse values that usually should nullify in total, but apparently don’t. By the way that’s why closing the bug with the “By Design” explanation makes me somewhat sad.</p> <p>So, probably avoiding FLOATs is a good idea! Unfortunately, this is simply not possible in all cases and sometimes out of our control. </p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com0tag:blogger.com,1999:blog-213131476646021708.post-722617597272178392010-02-14T13:12:00.001+01:002010-02-18T17:51:51.174+01:00Did you know: MAXDOP 1 will not always limit CPU utilization to 1<p>Last week I came across a special behavior regarding the MAXDOP query hint. When trying to limit the number of CPUs for a particular query to 1, I discovered a peculiarity.</p> <p>See the following example for an illustration of the problem.</p> <p>In the first step, we create a test table:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">use</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> tempdb <br /><span style="color: blue">go <br /> <br />create</span> <span style="color: blue">table</span> t0 <br /><span style="color: blue"><span style="mso-spacerun: yes"> </span></span><span style="color: gray">( <br /></span><span style="mso-spacerun: yes">   </span>c1 <span style="color: blue">int <br /></span><span style="mso-spacerun: yes">  </span><span style="color: gray">,</span>c2 <span style="color: blue">nchar</span><span style="color: gray">(</span>200<span style="color: gray">)</span> <span style="color: gray">not</span> <span style="color: gray">null</span> <span style="color: blue">default</span> <span style="color: red">'#' <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">) <br /></span><span style="color: blue">go <br /> <br />insert</span> t0<span style="color: gray">(</span>c1<span style="color: gray">) <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">select</span> <span style="color: blue">top</span><span style="color: gray">(</span>500000<span style="color: gray">)</span> <br /><span style="mso-spacerun: yes">         </span><span style="color: fuchsia">row_number</span><span style="color: gray">()</span> <span style="color: blue">over</span><span style="color: gray">(</span><span style="color: blue">order</span> <span style="color: blue">by</span> <span style="color: fuchsia">current_timestamp</span><span style="color: gray">) <br /></span><span style="mso-spacerun: yes">    </span><span style="color: blue">from</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">trace_event_bindings</span> <span style="color: blue">as</span> b1 <br /><span style="mso-spacerun: yes">        </span><span style="color: gray">,</span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">trace_event_bindings</span> <span style="color: blue">as</span> b2 <br /></span><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">go</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> </span></p> </td> </tr> </tbody></table> <p>Our test table consists of two columns and contains 500000 rows.</p> <p>Now, let’s create a second table this way:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">create</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> <span style="color: blue">table</span> t1 <br /><span style="color: blue"><span style="mso-spacerun: yes"> </span></span><span style="color: gray">( <br /></span><span style="mso-spacerun: yes">  </span>c1 <span style="color: blue">int</span> <span style="color: gray">not</span> <span style="color: gray">null</span> <br /><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span>c2 <span style="color: blue">nchar</span><span style="color: gray">(</span>300<span style="color: gray">)</span> <span style="color: gray">not</span> <span style="color: gray">null</span> <span style="color: blue">default</span> <span style="color: red">'#' <br /></span><span style="mso-spacerun: yes"> </span></span><span style="font-family: "Lucida Console"; color: gray; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">) <br /></span><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">go</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> </span></p> </td> </tr> </tbody></table> <p>We’ll leave this table empty for the moment. Later on we’ll insert some rows. But first we also create an insert trigger for table t1:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: 115%; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="line-height: 115%; font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US">create</span><span style="line-height: 115%; font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> <span style="color: blue">trigger</span> ti_t1 <span style="color: blue">on</span> t1 <br /><span style="mso-spacerun: yes">  </span><span style="color: blue">for</span> <span style="color: blue">insert</span> <span style="color: blue">as <br /></span><span style="mso-spacerun: yes">  </span><span style="color: blue">declare</span> @p1 <span style="color: blue">int <br /></span><span style="mso-spacerun: yes"> </span><span style="color: blue">select</span> @p1 <span style="color: gray">=</span> t0<span style="color: gray">.</span>c1 <br /><span style="mso-spacerun: yes">    </span><span style="color: blue">from</span> t0<span style="color: gray">,</span>inserted <br /><span style="mso-spacerun: yes">    </span><span style="color: blue">where</span> t0<span style="color: gray">.</span>c1 <span style="color: gray">between</span> inserted<span style="color: gray">.</span>c1 <span style="color: gray">and</span> 30000 <br /><span style="mso-spacerun: yes">     </span></span><span style="line-height: 115%; font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">order</span><span style="line-height: 115%; font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> <span style="color: blue">by</span> t0<span style="color: gray">.</span>c1 <br /><span style="color: blue">go</span></span><span style="line-height: 115%; font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"> </span></p> </td> </tr> </tbody></table> <p>This trigger doesn’t do anything useful but we need it for the effect I’d like to demonstrate.</p> <p>We’re now ready to start the experiment. Let’s insert 1 row into table t1:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">insert</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> t1<span style="color: gray">(</span>c1<span style="color: gray">)</span> <span style="color: blue">values </span><span style="color: gray">(</span>100<span style="color: gray">)</span> </span></p> </td> </tr> </tbody></table> <p>As expected, the insert will also invoke our trigger and the execution plan looks like this:</p> <p><a href="http://lh6.ggpht.com/_-C4uSahz1Gg/S3f-gBOmTsI/AAAAAAAABb4/6fAvRXkVOoQ/s1600-h/image%5B23%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_-C4uSahz1Gg/S3f-gin_9lI/AAAAAAAABb8/64s6D2U2chU/image_thumb%5B13%5D.png?imgmax=800" width="670" height="135" /></a> </p> <p>Apparently the select statement inside the trigger is executed in parallel. If we’d like to avoid this, we may specify the MAXDOP query hint and limit the CPU utilization to 1:</p> <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody> <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"> <td style="border-bottom: #8eb4e3 1pt dashed; border-left: #8eb4e3 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; width: 678.75pt; padding-right: 5.4pt; border-top: #8eb4e3 1pt dashed; border-right: #8eb4e3 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905"> <p style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Lucida Console"; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">insert</span><span style="font-family: "Lucida Console"; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"> t1<span style="color: gray">(</span>c1<span style="color: gray">)</span> <span style="color: blue">values </span><span style="color: gray">(</span>100<span style="color: gray">)</span> <span style="color: blue">option </span><span style="color: gray">(</span><span style="color: blue">maxdop</span> 1<span style="color: gray">)</span> </span></p> </td> </tr> </tbody></table> <p>Surprisingly or not, the MAXDOP query hint does not affect the trigger code. The SQL inside our trigger is still executed in parallel. There’s no change in the execution plan.</p> Holger Schmelinghttp://www.blogger.com/profile/09685478805011670145noreply@blogger.com1