<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://communitytest.tessitura.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Measure and improve SQL query performance</title><link>https://communitytest.tessitura.com/topical_groups/developers/w/community-developer-documentation/804/measure-and-improve-sql-query-performance</link><description>Wiki for creating community documentation.</description><dc:language>en-US</dc:language><generator>Telligent Community 12 Non-Production</generator><item><title>Measure and improve SQL query performance</title><link>https://communitytest.tessitura.com/topical_groups/developers/w/community-developer-documentation/804/measure-and-improve-sql-query-performance</link><pubDate>Thu, 02 Feb 2023 04:06:50 GMT</pubDate><guid isPermaLink="false">fd08b0f2-65fa-4b2b-916a-cce3e88b61d0:9d41c095-a5e0-4485-b646-da895846d434</guid><dc:creator>James Murty</dc:creator><comments>https://communitytest.tessitura.com/topical_groups/developers/w/community-developer-documentation/804/measure-and-improve-sql-query-performance#comments</comments><description>Current Revision posted to Community Docs Wiki by James Murty on 2/2/2023 4:06:50 AM&lt;br /&gt;
&lt;p&gt;Some tips for writing custom database queries or stored procedures that perform well, or&amp;nbsp;improving the performance of existing&amp;nbsp;SQL.&lt;/p&gt;
&lt;p&gt;This page was inspired and informed by &lt;a href="https://tn-webshare.slack.com/archives/C02GE71RP/p1675270129492499"&gt;a thread&lt;/a&gt; in the Tessitura Network Slack. Thanks to all the contributors to that thread.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;It can be difficult to evaluate the&amp;nbsp;how quick (or slow) queries&amp;nbsp;are when you run them in SSMS because:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;there can be a significant difference between the time to run a query (as reported&amp;nbsp;as SQL Server Execution time) versus the &amp;quot;clock&amp;quot; time to return the results (as shown at the bottom right of the window)&lt;/li&gt;
&lt;li&gt;query caching can skew results of&amp;nbsp;re-run queries&lt;/li&gt;
&lt;li&gt;general database load can affect timings, if you&amp;#39;re&amp;nbsp;writing queries on a live or actively used database (don&amp;#39;t do this, if you can help it)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Use these directives to&amp;nbsp;improve the quality and consistency of query metrics, though&amp;nbsp;they may not work on RAMP deployments:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;DBCC DROPCLEANBUFFERS&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;SET STATISTICS IO ON&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Change the final statement to `&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;SELECT 1;&lt;/span&gt;` to measure just the query time without returning data. If&amp;nbsp;this shows a significant difference in performance you are likely experiencing key lookups, try&amp;nbsp;gradually adding back the real SELECT statements to find the one(s) that are&amp;nbsp;slow. In all cases avoid returning * from tables, only return what you really need.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: performance, database, SQL&lt;/div&gt;
</description></item><item><title>Measure and improve SQL query performance</title><link>https://communitytest.tessitura.com/topical_groups/developers/w/community-developer-documentation/804/measure-and-improve-sql-query-performance/revision/1</link><pubDate>Thu, 02 Feb 2023 04:05:13 GMT</pubDate><guid isPermaLink="false">fd08b0f2-65fa-4b2b-916a-cce3e88b61d0:9d41c095-a5e0-4485-b646-da895846d434</guid><dc:creator>James Murty</dc:creator><comments>https://communitytest.tessitura.com/topical_groups/developers/w/community-developer-documentation/804/measure-and-improve-sql-query-performance#comments</comments><description>Revision 1 posted to Community Docs Wiki by James Murty on 2/2/2023 4:05:13 AM&lt;br /&gt;
&lt;p&gt;Some tips for writing custom database queries or stored procedures that perform well, or&amp;nbsp;improving the performance of existing&amp;nbsp;SQL.&lt;/p&gt;
&lt;p&gt;This page was inspired and informed by &lt;a href="https://tn-webshare.slack.com/archives/C02GE71RP/p1675270129492499"&gt;a thread&lt;/a&gt; in the Tessitura Network Slack. Thanks to all the contributors to that thread.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;It can be difficult to evaluate the&amp;nbsp;how quick (or slow) queries&amp;nbsp;are when you run them in SSMS because:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;there can be a significant difference between the time to run a query (as reported&amp;nbsp;as SQL Server Execution time) versus the &amp;quot;clock&amp;quot; time to return the results (as shown at the bottom right of the window)&lt;/li&gt;
&lt;li&gt;query caching can skew results of&amp;nbsp;re-run queries&lt;/li&gt;
&lt;li&gt;general database load can affect timings, if you&amp;#39;re&amp;nbsp;writing queries on a live or actively used database (don&amp;#39;t do this, if you can help it)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Use these directives to&amp;nbsp;improve the quality and consistency of query metrics, though&amp;nbsp;they may not work on RAMP deployments:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;DBCC DROPCLEANBUFFERS&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;SET STATISTICS IO ON&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Change the final statement to `&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;SELECT 1;&lt;/span&gt;` to measure just the query time without returning data. If&amp;nbsp;this shows a significant difference in performance you are likely experiencing key lookups, try&amp;nbsp;gradually adding back the real SELECT statements to find the one(s) that are&amp;nbsp;slow. In all cases avoid returning * from tables, only return what you really need.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: performance, database, SQL&lt;/div&gt;
</description></item></channel></rss>