<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Maria Zakourdaev : partitioning views, scaling out</title><link>http://sqlblog.com/blogs/maria_zakourdaev/archive/tags/partitioning+views/scaling+out/default.aspx</link><description>Tags: partitioning views, scaling out</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Unfairly forgotten partitioning views can help us make our partitioning tables design better</title><link>http://sqlblog.com/blogs/maria_zakourdaev/archive/2012/02/28/unfairly-forgotten-partitioning-views-can-help-us-make-our-partitioning-tables-design-better.aspx</link><pubDate>Tue, 28 Feb 2012 08:12:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:41977</guid><dc:creator>Maria Zakourdaev</dc:creator><slash:comments>5</slash:comments><comments>http://sqlblog.com/blogs/maria_zakourdaev/comments/41977.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/maria_zakourdaev/commentrss.aspx?PostID=41977</wfw:commentRss><description>&lt;p style="line-height:13pt;list-style-type:disc;margin-bottom:10pt;" class="MsoNormal" align="left"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size:11pt;"&gt;Partitioning is a very important feature for scalable applications, it allows breaking up huge monolithic tables in order to ensure their scalability &amp;amp; manageability within a single instance. For example, data deletion and loading can be very fast if done by partition. Reorganizing, optimizing and rebuilding indices also can be done by partition which is much less intrusive and faster.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="line-height:13pt;list-style-type:disc;margin-bottom:10pt;" class="MsoNormal" align="left"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size:11pt;"&gt;Also, when talking about performance, joins become faster when using tables that are partitioned. Smaller b-trees for each partition make partition access fast, especially when limiting rows by a partition key, accessing only a subset of data. Another performance benefit can be achieved when using partition level lock escalation.&lt;/font&gt;&lt;span style="mso-no-proof:yes;"&gt;&lt;font style="font-size:11pt;"&gt; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="line-height:13pt;list-style-type:disc;margin-bottom:10pt;" class="MsoNormal" align="left"&gt;&lt;font face="Calibri"&gt;&lt;span style="mso-no-proof:yes;"&gt;&lt;font style="font-size:11pt;"&gt;There are two partitioning designs in the SQL Server. In a partitioned view, the member tables are horizontally joined by a view, so from the user’s perspective, the data comes from one table. A natively partitioned table, a feature &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size:11pt;"&gt;introduced in SQL Server 2005, is treated as a single object by the relational engine, yet is handled as multiple objects by the storage engine.&lt;/font&gt;&lt;span style="mso-no-proof:yes;"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="line-height:13pt;list-style-type:disc;margin-bottom:10pt;" class="MsoNormal" align="left"&gt;&lt;span style="mso-no-proof:yes;"&gt;&lt;a href="http://sqlblog.com/blogs/maria_zakourdaev/clip_image002_3FB00494.jpg"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="clip_image002" border="0" alt="clip_image002" width="420" height="311" src="http://sqlblog.com/blogs/maria_zakourdaev/clip_image002_thumb_15EC89A1.jpg"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height:13pt;list-style-type:disc;margin-bottom:10pt;" class="MsoNormal" align="left"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size:11pt;"&gt;When comparing native partitioning to a partitioned view, one of the greatest improvements is that using a partitioned table results in relatively small query plans. PVs in general had enormous query plans because each table in the view was a separate object with separate statistics. Due to the fact that natively partitioned tables are treated by the relational engine as a single object, fewer permutations are considered during the optimization phase, meaning a faster optimization time. Also, auto-parameterization doesn’t work with PVs because the rules of auto-parameterization are quite strict.&lt;/font&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;font style="font-size:11pt;"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="line-height:13pt;list-style-type:disc;margin-bottom:10pt;" class="MsoNormal" align="left"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size:11pt;"&gt;Adhoc SQL that uses a single partitioned table has many more opportunities to get auto-parameterized and produce a re-usable adhoc query plan.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="line-height:13pt;list-style-type:disc;margin-bottom:10pt;" class="MsoNormal" align="left"&gt;&lt;font face="Calibri"&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;font style="font-size:11pt;"&gt;&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size:11pt;"&gt;In PVs, tables are accessed sequentially.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;When using native partitioning many operations can be done in parallel.&lt;/font&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;font style="font-size:11pt;"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="line-height:13pt;list-style-type:disc;margin-bottom:10pt;" class="MsoNormal" align="left"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size:11pt;"&gt;However, there are many challenges that we face when migrating from an environment that is using partitioned views to native partitioning. The usual way of upgrading such an environment is to create a new partitioned table and then to switch the data in, partition by partition. At some point in time, the old view and the new table flip flop names. During such an upgrade, from the user’s perspective, data is not available or even worse, partially available and the reports are not correct. &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="line-height:13pt;list-style-type:disc;margin-bottom:10pt;" class="MsoNormal" align="left"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size:11pt;"&gt;After upgrade, maintenance tasks are also more cumbersome when performed against a partitioned table. Adding new indices to a huge table with thousands of millions of rows takes about 4 hours and the table is locked during this time. Same story with data type changes on columns. Also consider primary key changes when you need to drop the PK, which also takes about 3 hours and then add a new one – another 4 hours (a PK change is usually a bad thing anyway since it indicates the database design is not correct but we all know that it happens and sometimes we need to add an additional column to the PK). Also, there is no scale out for partitioned tables, meaning all partitions must reside on the same server on the same database.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="line-height:13pt;list-style-type:disc;margin-bottom:10pt;" class="MsoNormal" align="left"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size:11pt;"&gt;Here, surprisingly, our good old, unfairly forgotten, partitioning views can help us make our partitioning design even better. &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="line-height:13pt;list-style-type:disc;margin-bottom:10pt;" class="MsoNormal" align="left"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size:11pt;"&gt;Consider the following scenario. You have a partitioned view with many big tables. Instead of switching the data partition by partition into a new table, you simply add the new partitioned table under the same partitioned view. No long Sch-M locks, no data partial availability and no downtime. All the new data is inserted into the new partitioned table. When the time comes, the old partitions get purged, leaving the partitioned view with only the native partitioned table underneath. If you need to support indices and other lengthy changes on metadata, you can simply add a new partition table to the view with the required metadata changes which means zero downtime to your environment. In case you need a distributed architecture across servers you also can do it using partitioned views.&lt;/font&gt;&lt;span style="mso-spacerun:yes;"&gt;&lt;font style="font-size:11pt;"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="line-height:13pt;list-style-type:disc;margin-bottom:10pt;" class="MsoNormal" align="left"&gt;&lt;span style="mso-no-proof:yes;"&gt;&lt;a href="http://sqlblog.com/blogs/maria_zakourdaev/clip_image004_0524DEF3.jpg"&gt;&lt;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="clip_image004" border="0" alt="clip_image004" width="576" height="426" src="http://sqlblog.com/blogs/maria_zakourdaev/clip_image004_thumb_18659592.jpg"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height:13pt;list-style-type:disc;margin-bottom:10pt;" class="MsoNormal" align="left"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size:11pt;"&gt;Native Partitioning is a great feature of SQL Server, but partitioned views can make it even better helping scaling out and performing maintenance tasks with zero downtime.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=41977" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/maria_zakourdaev/archive/tags/native+partitioning/default.aspx">native partitioning</category><category domain="http://sqlblog.com/blogs/maria_zakourdaev/archive/tags/partitioning+views/default.aspx">partitioning views</category><category domain="http://sqlblog.com/blogs/maria_zakourdaev/archive/tags/scaling+out/default.aspx">scaling out</category></item></channel></rss>