<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sort Operation &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/sort-operation/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Mon, 25 Dec 2017 11:46:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>SQL Server 2012: SORT_IN_TEMPDB used to Improve the Index Rebuild Performance</title>
		<link>https://www.dbrnd.com/2018/01/sql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb/</link>
					<comments>https://www.dbrnd.com/2018/01/sql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 09 Jan 2018 16:16:07 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Index Rebuild]]></category>
		<category><![CDATA[query performance]]></category>
		<category><![CDATA[Sort Operation]]></category>
		<category><![CDATA[SORT_IN_TEMPDB]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TempDB]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4209</guid>

					<description><![CDATA[<div><img width="679" height="382" src="https://www.dbrnd.com/wp-content/uploads/2017/12/Database-Perforamance-679x382.jpg" class="attachment-post-image size-post-image wp-post-image" alt="SQL Database Performance" decoding="async" fetchpriority="high" srcset="https://www.dbrnd.com/wp-content/uploads/2017/12/Database-Perforamance-679x382.jpg 679w, https://www.dbrnd.com/wp-content/uploads/2017/12/Database-Perforamance.jpg 800w" sizes="(max-width: 679px) 100vw, 679px" /></div>SQL Server 2012 enhanced the performance of INDEX REBUILD by introducing the SORT_IN_TEMPDB option. I observed that many SQL developers are not using this feature or maybe they don&#8217;t know about it. The INDEX REBUILD operation is removing the fragmentation of indexes which improves the query performance. It scans the data pages of base table [&#8230;]]]></description>
										<content:encoded><![CDATA[<div><img width="679" height="382" src="https://www.dbrnd.com/wp-content/uploads/2017/12/Database-Perforamance-679x382.jpg" class="attachment-post-image size-post-image wp-post-image" alt="SQL Database Performance" decoding="async" srcset="https://www.dbrnd.com/wp-content/uploads/2017/12/Database-Perforamance-679x382.jpg 679w, https://www.dbrnd.com/wp-content/uploads/2017/12/Database-Perforamance.jpg 800w" sizes="(max-width: 679px) 100vw, 679px" /></div><p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb%2F&amp;linkname=SQL%20Server%202012%3A%20SORT_IN_TEMPDB%20used%20to%20Improve%20the%20Index%20Rebuild%20Performance" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb%2F&amp;linkname=SQL%20Server%202012%3A%20SORT_IN_TEMPDB%20used%20to%20Improve%20the%20Index%20Rebuild%20Performance" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb%2F&amp;linkname=SQL%20Server%202012%3A%20SORT_IN_TEMPDB%20used%20to%20Improve%20the%20Index%20Rebuild%20Performance" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb%2F&amp;linkname=SQL%20Server%202012%3A%20SORT_IN_TEMPDB%20used%20to%20Improve%20the%20Index%20Rebuild%20Performance" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb%2F&amp;linkname=SQL%20Server%202012%3A%20SORT_IN_TEMPDB%20used%20to%20Improve%20the%20Index%20Rebuild%20Performance" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb%2F&amp;linkname=SQL%20Server%202012%3A%20SORT_IN_TEMPDB%20used%20to%20Improve%20the%20Index%20Rebuild%20Performance" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb%2F&#038;title=SQL%20Server%202012%3A%20SORT_IN_TEMPDB%20used%20to%20Improve%20the%20Index%20Rebuild%20Performance" data-a2a-url="https://www.dbrnd.com/2018/01/sql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb/" data-a2a-title="SQL Server 2012: SORT_IN_TEMPDB used to Improve the Index Rebuild Performance"></a></p><p>SQL Server 2012 enhanced the performance of INDEX REBUILD by introducing the SORT_IN_TEMPDB option.<br />
I observed that many SQL developers are not using this feature or maybe they don&#8217;t know about it. </p>
<blockquote><p>The INDEX REBUILD operation is removing the fragmentation of indexes which improves the query performance. It scans the data pages of base table to retrieve the key values and builds an index leaf row for each row.
</p></blockquote>
<blockquote><p>This process requires internal sorting which it stores in the buffer area.</p></blockquote>
<blockquote><p>Once the buffer filled with leaf index entries, it stores the sorted result into a disk as an intermediate sort run. Next, It again starts with the same process for further data pages.</p></blockquote>
<p>As per the MSDN,</p>
<blockquote><p>When you create or rebuild an index, by setting the SORT_IN_TEMPDB option to ON you can direct the SQL Server Database Engine to use tempdb to store the intermediate sort results that are used to build the index. </p>
<p>Although this option increases the amount of temporary disk space that is used to create an index, the option could reduce the time that is required to create or rebuild an index when tempdb is on a set of disks different from that of the user database.</p>
<p>If SORT_IN_TEMPDB is set to ON, there must be sufficient free space in tempdb to store the collection of sort runs for the largest index.</p></blockquote>
<p>When you are rebuilding the large size of Indexes, SORT_IN_TEMPDB helps you lot by reducing the operational execution time. </p>
<p><strong>Sample Script with option SORT_IN_TEMPDB:</strong></p>
<pre class="crayon-plain-tag">ALTER INDEX ALL ON MyTableName
REBUILD WITH 
(FILLFACTOR = 80, SORT_IN_TEMPDB = ON,
 STATISTICS_NORECOMPUTE = ON);
GO</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/01/sql-server-2012-sort_in_tempdb-used-to-improve-the-index-rebuild-performance-sort-operation-to-tempdb/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: Improve the performance of Query Sort operation by setting work_mem</title>
		<link>https://www.dbrnd.com/2017/02/postgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 03 Feb 2017 16:16:45 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[Sort Operation]]></category>
		<category><![CDATA[spilling disk]]></category>
		<category><![CDATA[work_mem]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4452</guid>

					<description><![CDATA[Yesterday, I was doing performance tuning for one our long running queries. I have checked the execution plan of the query and found that query sort operations are spilling to disk instead of fitting in memory. Every time, just tuning the Table Indexes should not be the ultimate solution to improve the query performance. There [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem%2F&amp;linkname=PostgreSQL%3A%20Improve%20the%20performance%20of%20Query%20Sort%20operation%20by%20setting%20work_mem" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem%2F&amp;linkname=PostgreSQL%3A%20Improve%20the%20performance%20of%20Query%20Sort%20operation%20by%20setting%20work_mem" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem%2F&amp;linkname=PostgreSQL%3A%20Improve%20the%20performance%20of%20Query%20Sort%20operation%20by%20setting%20work_mem" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem%2F&amp;linkname=PostgreSQL%3A%20Improve%20the%20performance%20of%20Query%20Sort%20operation%20by%20setting%20work_mem" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem%2F&amp;linkname=PostgreSQL%3A%20Improve%20the%20performance%20of%20Query%20Sort%20operation%20by%20setting%20work_mem" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem%2F&amp;linkname=PostgreSQL%3A%20Improve%20the%20performance%20of%20Query%20Sort%20operation%20by%20setting%20work_mem" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem%2F&#038;title=PostgreSQL%3A%20Improve%20the%20performance%20of%20Query%20Sort%20operation%20by%20setting%20work_mem" data-a2a-url="https://www.dbrnd.com/2017/02/postgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem/" data-a2a-title="PostgreSQL: Improve the performance of Query Sort operation by setting work_mem"></a></p><p>Yesterday, I was doing performance tuning for one our long running queries. I have checked the execution plan of the query and found that query sort operations are spilling to disk instead of fitting in memory. </p>
<p>Every time, just tuning the Table Indexes should not be the ultimate solution to improve the query performance. </p>
<p>There are always N factors behind the bad performance shape of your query. </p>
<p><strong>How can you know that your operations are spilling to disk?</strong></p>
<blockquote><p>When you execute EXPLAIN ANALYZE for your query and if you see a line like <code>Sort Method: external merge Disk: 88342kB</code>, your operations are spilling to disk.</p></blockquote>
<p><strong>Is spilling to disk a bad operation?</strong></p>
<blockquote><p>Yes: Because it requires more CPU/IO for the disk operation and it leads to biggest performance cause.</p></blockquote>
<p><strong>What is the solution?</strong></p>
<blockquote><p>The simple solution is, validate the configuration of a work_mem parameter.<br />
If you do a lot of complex sorts and have a lot of memory, then increasing the work_mem parameter allows PostgreSQL to do larger in-memory sorts which, unsurprisingly, will be faster than disk-based equivalents.</p></blockquote>
<p><strong>How can you configure work_mem?</strong></p>
<blockquote><p>A work_mem of at least 16MB would keep the intermediate data in memory and likely improve the query response time.<br />
You can set at the server level for the general use (in postgresql.conf). </p>
<p>You can also set at your session level using below sample query. Increase the setting until you see Memory instead of Disk in the EXPLAIN output.</p></blockquote>
<pre class="crayon-plain-tag">BEGIN;

SET LOCAL work_mem = '50MB';

SELECT *FROM Table_Name;

COMMIT;</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
