Partition Primary Index – Basics

Partitioned primary index or PPI is used for physically splitting the table into a series of subtables. With the proper use of Partition primary Index we can save queries from time consuming full table scan. Instead of scanning full table, only one particular partition is accessed.


Follow the example below to get the insight of PPI –

We have an order table (ORDER_TABLE) having two columns – Order_Date and Order_Number, in which PI is defined on Order_Date. The primary Index (Order_Date) was hashed and rows were distributed to the proper AMP based on Row Hash Value then sorted by the Row ID. The distribution of rows will take place as explained in the image below –

PPI_1

Now when we execute Query –

Select * from Order_Table where Order_Date between 1-1-2003 and 1-31-2003;

This query will result in a full table scan despite of Order_Date being PI.

PPI_2

Now we have defined PPI on the column Order_date. The primary Index (Order_Date) was hashed and rows were distributed to the proper AMP based on Row Hash Value then sorted by the Order_Date and not by Row ID. The distribution of rows will take place as explained in the image below –

PPI_3

Now when we execute Query –

Select * from Order_Table where Order_Date between 1-1-2003 and 1-31-2003;

This query will not result in a full table scan because all the January orders are kept together in their partition. 

PPI_4



Partitions are usually defined based on Range or Case as follows.

Partition by CASE

CREATE      TABLE ORDER_Table (

ORDER_ID  integer NOT NULL,

CUST_ID integer NOT NULL,

ORDER_DATE  date ,

ORDER_AMOUNT integer

)

PRIMARY INDEX (CUST_ID)

PARTITION BY case_n ( 

ORDER_AMOUNT  < 10000 ,

ORDER_AMOUNT  < 20000 ,

ORDER_AMOUNT  < 30000,

NO           CASE     OR        UNKNOWN ) ;


Partition by RANGE

CREATE      TABLE ORDER_Table

(

ORDER_ID  integer NOT NULL,

CUST_ID integer NOT NULL,

ORDER_DATE  date ,

ORDER_AMOUNT integer

)

PRIMARY INDEX (CUST_ID)

PARTITION BY range_n (

ORDER_DATE BETWEEN date ‘2012-01-01’ and ‘2012-12-31’ Each interval ‘1’ Month,

NO        range OR  UNKNOWN ) ;

If we use NO RANGE or NO CASE – then all values not in this range will be in a single partition.

If we specify UNKNOWN, then all null values will be placed in this partition


To know about the advantage and disadvantage of PPI please go to link below –

Partition Primary Index – Advantage and Disadvantage

34 comments

Skip to comment form

    • Sagar on March 23, 2017 at 8:02 am

    Hi,

    The explanatin is good but need to understand how the data is been retrieved while quering on PPI?
    Will it exactly query only that partition in AMP instead of having so many number of partitins in AMP?

      • admin on March 23, 2017 at 3:34 pm
        Author

      Data retrieval process remains same with the exception of an additional check on partition number. If you are using PPI column in where clause then with the help of binary search Teradata will query exact partition, but in case no PPI column is being used in where clause then it needs to scan all the rows (in respective AMP) to find the matching row. This is trade off of using PPI because all queries without PPI column face all rows scan (in single AMP).

      Hope it helps !!!

        • Sagar on June 13, 2017 at 8:02 am

        Thanks..one more question what happens if i define PPI columns other than PI column in that table.How the data is being retrieved.will the performamce increase or decrease by the above method.??

    • Vijay Jadoun on August 21, 2016 at 5:11 pm

    Dear admin ,

    thanks for share Wonderfull blog

    Thanks regards
    Vijay Jadoun

    • Veeresh alkod on May 23, 2015 at 7:32 am

    Thank you Sir.

    • Rajesh Korlepara on March 2, 2015 at 5:34 am

    What is the process to change the existing table to PPI table and will there be any change in row distribution after conversion into Partioned primary index?

    • krishnendu hazra on January 26, 2015 at 5:55 pm

    Sir can you please kindly explain multiload , the way u have explained fastload?

    fastload explanation was really helpful..

    Regards

    • viraj raina on January 9, 2015 at 9:18 am

    How many amp operation is PPI?

      • admin on January 11, 2015 at 2:11 am
        Author

      can be any number of AMP depending on your query. but not full table scan if you are using PPI columns in where clause

    • Akanksha Gupta on November 12, 2014 at 9:16 am

    Range bases query on NUSI column ALWAYS do Full Table Scan OR it may utilize index?

    • Manoj on October 9, 2014 at 6:26 am

    simply superb explanation.

    • jeffry on August 28, 2014 at 11:19 am

    Information is very clear and simple…good work admin/..all the best for your future works

    • raj on August 7, 2014 at 1:44 pm

    will there be an impact while loading huge data into tables like performance increase/decrease

      • admin on September 26, 2014 at 12:44 pm
        Author

      yes definitely.
      if data is huge and your table is defined as SET table, then teradata needs to check uniqueness of each new row inserted. Similar check is required for Unique columns, UPI and USI as well.
      This is just one example where your performance can be degraded because of huge number of rows.

    • anji on July 15, 2014 at 12:05 pm

    its useful to me

    • anji on July 15, 2014 at 12:04 pm

    gud

    • Naveen on June 20, 2014 at 11:14 am

    Why it is called partition primary index ? if we can do PPI on any column no matter its PI or not .

    • dilip on April 30, 2014 at 12:15 pm

    I did not get this. So taking your last example. suppose cust_id is the primary index (NUPI) and you did the partitioning based on case (order_amount). Now i fire query like this:
    sel * from order table where order_amount between 5000 and 15000;

    what does it mean ? we are not quering on the PI (cust_id) at all ! this will result into FTS still..right.
    Also, why is it called PPI if the PI is cust_id and partitioning is done on ‘order_amount’ ? Thanks 🙂

      • admin on May 2, 2014 at 5:36 pm
        Author

      if order amount is defined as PPI, then optimizer will go for dynamic partition elimination step and pick only those partition which falls into the range specified in WHERE clause. Thus it will not be a FTS operation.

    • Sindhu on April 14, 2014 at 10:48 am

    Hi,
    Very nice explanation. Finally understood PPI.

    Thanks a lot!

    • CinderElla on March 11, 2014 at 4:29 pm

    How do I actually view infromation about the partitions? Info like amount of data in each partition, # of rows, date loaded, those kind of items?

      • admin on March 12, 2014 at 5:46 am
        Author

      you can write SQL queries to achieve this result. I don’t think there is any teradata tool available for this.

    • Agilan on February 14, 2014 at 9:44 am

    Hi Admin,

    if we didnt mention NO RANGE OR NO CASE or UNKNOWN, what will happen to the records not falling in the range/case?

    Thanks.

    • vignesh on October 14, 2013 at 7:19 am

    Hi,

    The article is really good.. 🙂
    One concern,
    In the example,since jan data is avilable in both the amp’s it would still require a full table scan right?

      • dblob on March 6, 2014 at 12:30 pm

      No, because each AMP processes only his own part of the table, especially only his part of the partition of the table..

    • Muniraj on October 8, 2013 at 8:53 am

    Good explanation

    • Prasanna on July 15, 2013 at 1:33 pm

    Really superb. Very Simple explanation

    Finally i undeerstood PPI.

    Thanks Admin.

    • Nagesh on July 9, 2013 at 9:16 am

    Good One.

    • manju on June 3, 2013 at 2:53 pm

    good explaination.. could have explained about Each interval ‘1’ Month,

    • Sarika on April 10, 2013 at 1:28 pm

    I never understood PPI but after reading ur article my doubt is clear.

    • veera on March 24, 2013 at 8:35 am

    I missed ur website all these days 🙁 .. Really helpful …keep posting .

      • admin on March 24, 2013 at 8:37 am
        Author

      Hi Veera,

      What do you mean by missed it ? … are you facing some server downtime for my website ?
      Next time please let me know in case you are facing this issue on my site 🙂

Comments have been disabled.