{"id":28542,"date":"2022-08-09T10:11:50","date_gmt":"2022-08-09T10:11:50","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=28542"},"modified":"2022-12-23T05:47:49","modified_gmt":"2022-12-23T05:47:49","slug":"teradata-partitioned-primary-index-ppi","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/teradata-partitioned-primary-index-ppi\/","title":{"rendered":"Teradata Partitioned Primary Index (PPI)\u00a0"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is the&nbsp;Concept behind Partitioning a Table?<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Each Table in Teradata has a&nbsp;Primary Index&nbsp;unless it is a NoPI table.<\/li><li>The Primary Index is the mechanism that allows Teradata to physically&nbsp;distribute&nbsp;the rows of a table across the AMPs.<\/li><li>AMPs Sort their rows by the&nbsp;Row-ID,&nbsp;so the system can perform a lightning fast Binary Search since the rows are in Row-ID Order.<\/li><li>Partitioning merely tells the AMP to sort its tables\u2019 rows by the Partition first, but then sort the rows by Row-ID within the partition.<\/li><li>Partitioning queries will involve all AMPs, but partitioned tables are designed to prevent FULL Table Scans.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Advantages and Disadvantages of Partitioning<\/h2>\n\n\n\n<p><strong>Advantage<\/strong>s<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Increase query efficiency by avoiding full table scans<\/li><li>PPI\u2019s are defined on a table in order to increase query efficiency by avoiding full table scans without the overhead and maintenance costs of secondary indexes.<\/li><li>Deleting large volumes of rows in entire partitions can be extremely fast.<\/li><li>For range based queries we can effectively remove SI and use PPI, thus saving overhead of SI subtable.<\/li><li>It can access a subset of a large table quickly.<\/li><li>Maximum partitions allowed by Teradata \u2013&nbsp;<strong>65,535<\/strong><\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Disadvantages<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Partitioned rows are2 or 8 bytes longer. Table uses more PERM space.<\/li><li>A PI access may be degraded if the partitioning column is not part of the PI<\/li><li>Joins to non-partitioned tables with the same PI may be degraded.<\/li><li>The PI can\u2019t be defined as unique when the partitioning column is not part of the PI.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating&nbsp;a PPI Table with Simple Partitioning<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>A PPI table has the AMPs sort (order) the rows on the table by the Partition. <\/li><li>This allows for people to avoid Full Table Scans.<\/li><\/ul>\n\n\n\n<p><strong>A&nbsp;Visual Display of Simple Partitioning<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-33.png\" alt=\"\" class=\"wp-image-28543\" width=\"544\" height=\"380\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-33.png 803w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-33-300x210.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-33-768x537.png 768w\" sizes=\"auto, (max-width: 544px) 100vw, 544px\" \/><\/figure>\n\n\n\n<p><strong>An&nbsp;SQL Example that explains Simple Partitioning<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-34.png\" alt=\"\" class=\"wp-image-28544\" width=\"505\" height=\"370\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-34.png 787w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-34-300x220.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-34-768x563.png 768w\" sizes=\"auto, (max-width: 505px) 100vw, 505px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating&nbsp;a PPI Table with RANGE_N <\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>The expression is evaluated and is mapped into one of a list of specified ranges.<\/li><li>Ranges are listed in increasing order and must not overlap with each other.<\/li><li>Result is the data row being placed into a partition associated with that range.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Examples:<\/h3>\n\n\n\n<p><strong>Example 1 &#8211; Creating&nbsp;a PPI Table with RANGE_N Partitioning per Month<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-35.png\" alt=\"\" class=\"wp-image-28545\" width=\"362\" height=\"258\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-35.png 458w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-35-300x214.png 300w\" sizes=\"auto, (max-width: 362px) 100vw, 362px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-36.png\" alt=\"\" class=\"wp-image-28546\" width=\"52\" height=\"20\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-36.png 413w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-36-300x115.png 300w\" sizes=\"auto, (max-width: 52px) 100vw, 52px\" \/><figcaption>Above Example sort the rows on each AMP by order_date  and create a different partition every month<\/figcaption><\/figure>\n\n\n\n<p><strong>A&nbsp;Visual of One Year of Data with Range_N per Month<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-38.png\" alt=\"\" class=\"wp-image-28548\" width=\"494\" height=\"273\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-38.png 805w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-38-300x166.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-38-768x425.png 768w\" sizes=\"auto, (max-width: 494px) 100vw, 494px\" \/><\/figure>\n\n\n\n<p>Each AMP sorts their rows by Month (of Order_Date).<\/p>\n\n\n\n<p><strong>An&nbsp;SQL Example explaining Range_N Partitioning per Month<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-39.png\" alt=\"\" class=\"wp-image-28549\" width=\"521\" height=\"297\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-39.png 802w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-39-300x171.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-39-768x438.png 768w\" sizes=\"auto, (max-width: 521px) 100vw, 521px\" \/><figcaption>The above query wants to see orders in the first quarter, so each AMP reads 3 partitions.<\/figcaption><\/figure>\n\n\n\n<p><strong>Example 2<\/strong> &#8211; <strong>Creating&nbsp;a PPI Table with RANGE_N Partitioning per Day<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-40.png\" alt=\"\" class=\"wp-image-28550\" width=\"340\" height=\"194\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-40.png 529w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-40-300x171.png 300w\" sizes=\"auto, (max-width: 340px) 100vw, 340px\" \/><figcaption>Above Example sort the rows on each AMP by order_date  and create a different partition every Day<\/figcaption><\/figure>\n\n\n\n<p><strong>A&nbsp;Visual of Range_N Partitioning Per Day<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-41.png\" alt=\"\" class=\"wp-image-28551\" width=\"411\" height=\"226\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-41.png 781w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-41-300x165.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-41-768x422.png 768w\" sizes=\"auto, (max-width: 411px) 100vw, 411px\" \/><figcaption>There would be 365 partitions in total for an entire year of Partitioning per Day. Each AMP holds the orders assigned to them in daily partitions on the day of the order date.<\/figcaption><\/figure>\n\n\n\n<p><strong>An&nbsp;SQL Example that explains Range_N Partitioning per Day<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-42.png\" alt=\"\" class=\"wp-image-28552\" width=\"516\" height=\"317\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-42.png 793w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-42-300x184.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-42-768x472.png 768w\" sizes=\"auto, (max-width: 516px) 100vw, 516px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating&nbsp;a PPI Table with CASE_N<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-44.png\" alt=\"\" class=\"wp-image-28554\" width=\"459\" height=\"248\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-44.png 787w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-44-300x162.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-44-768x415.png 768w\" sizes=\"auto, (max-width: 459px) 100vw, 459px\" \/><figcaption>If an Order_Total is &lt; 1000, it will go into Partition 1. If an Order_Total is between 1000 and 4999.99, it will go in Partition 2. The NO Case partition is for anything falling through and the UNKNOWN partition is for NULL values in the Total.<\/figcaption><\/figure>\n\n\n\n<p><strong>A&nbsp;Visual of Case_N Partitioning<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-45.png\" alt=\"\" class=\"wp-image-28555\" width=\"631\" height=\"381\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-45.png 803w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-45-300x181.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-45-768x464.png 768w\" sizes=\"auto, (max-width: 631px) 100vw, 631px\" \/><figcaption>There are six partitions for this table. Orders go into partitions based on Order_Total.<\/figcaption><\/figure>\n\n\n\n<p>An&nbsp;SQL Example that explains CASE_N Partitioning<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-46.png\" alt=\"\" class=\"wp-image-28556\" width=\"482\" height=\"290\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-46.png 811w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-46-300x181.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-46-768x462.png 768w\" sizes=\"auto, (max-width: 482px) 100vw, 482px\" \/><figcaption>All AMPs retrieve, but each only reads partition 5&nbsp;<\/figcaption><\/figure>\n\n\n\n<p><strong>Note: <\/strong>NO CASE, NO RANGE, and UNKNOWN options are also available which we can use  in RANGE_N and CASE_N Partitioning<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is the&nbsp;Concept behind Partitioning a Table? Each Table in Teradata has a&nbsp;Primary Index&nbsp;unless it is a NoPI table. The Primary Index is the mechanism that allows Teradata to physically&nbsp;distribute&nbsp;the rows of a table across the AMPs. AMPs Sort their rows by the&nbsp;Row-ID,&nbsp;so the system can perform a lightning fast Binary Search since the rows&#8230;<\/p>\n","protected":false},"author":48,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-28542","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/28542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/48"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=28542"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/28542\/revisions"}],"predecessor-version":[{"id":30967,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/28542\/revisions\/30967"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=28542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=28542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=28542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}