Вы находитесь на странице: 1из 14

Partitioned Primary Index

An indexing mechanism in the Teradata Database for use in physical database design

Available starting in V2R5 with enhancements in subsequent releases

An option to improve the performance of a certain class of queries

Only the rows of the qualified partitions in a query need to be accessed

Partitioned Primary Index

Rows are partitioned in up to 65535 partitions on each AMP


Partitions numbered 1 up to 65535 Includes range, conditional, modulo, and general expression partitioning

Partitioning columns do not have to be in the primary index

Does not support partitioning based on character or graphic comparison

Optimizer performs partition elimination for queries

CREATE TABLE

Option for the primary index of a table


CREATE TABLE ... (...) [UNIQUE] PRIMARY INDEX [index-name] (column-list)

PARTITION BY partitioning-expression

The value of the partitioning expression for a row determines the partition number of the row

Must be a value between 1 and 65535 Use RANGE_N function to define a mapping of ranges of values to an INTEGER Use CASE_N function to define a mapping between conditions to an INTEGER
5

CREATE TABLE

The partition expression definition is the only thing that needs to be done by the DBA

No separate partition layout No disk layout for partitions No definition of location in the system for partitions No need to define/manage separate tables per segment of the table that needs to be accessed Even data distribution and even processing of a logical partition is automatic

Due to the PI distribution of the rows

No modifications of queries required


6

PPI: How Does It Work?


Partitioning Fields Primary Index Fields Partition Teradata Hash Function RowHash (Hash Bucket) Data Fields

User-specified Partitioning Function

Hash Map BYNET

AMP

AMP

AMP

Table A

(Partitions ordered by P) Partition 1

RH

AMP

AMP

Partition 2

Denotes PPI feature


Partition 3
Rows ordered by RH

Partition 4

Row Placement by AMP with PPI


Row is inserted by AMP into table Partitioning expression produces internal partition number
Partition 1 Partition 2 Partition 3 Partition 1 Partition 2 Partition 3

Table

Partition 1 Partition 2 Partition 3

...

. . .
Partition N

. . .
Partition N

. . .
Partition N

...

AMP

AMP

AMP

Note: Rows in the same partition are distributed among the AMPs based on the hash

CREATE TABLE Examples


CREATE TABLE Orders (o_orderkey INTEGER NOT NULL, o_custkey INTEGER, o_orderstatus CHAR(1) CASESPECIFIC, o_totalprice DECIMAL(13,2) NOT NULL, o_orderdate DATE FORMAT 'yyyy-mm-dd' NOT NULL, o_orderpriority CHAR(21), o_shippriority INTEGER) PRIMARY INDEX (o_orderkey) PARTITION BY RANGE_N(o_orderdate BETWEEN DATE '1998-01-01' AND DATE '2004-12-31' EACH INTERVAL '1' MONTH) UNIQUE INDEX (o_orderkey);
Note: UPI is not allowed since partitioning column is not included in the PI. Unique secondary index is allowed on PI to enforce uniqueness.

CREATE TABLE Examples


CREATE TABLE Lineitem (l_orderkey INTEGER NOT NULL, l_partkey INTEGER NOT NULL, l_suppkey INTEGER, l_linenumber INTEGER, l_quantity INTEGER NOT NULL, l_discount DECIMAL(13,2), l_tax DECIMAL(13,2), l_linestatus CHAR(1), l_shipdate DATE FORMAT 'yyyy-mm-dd', l_shipinstruct VARCHAR(25), l_shipmode VARCHAR(10)) PRIMARY INDEX (l_orderkey) PARTITION BY RANGE_N(l_shipdate BETWEEN DATE '1998-01-01' AND DATE '2004-12-31' EACH INTERVAL '1' MONTH);
10

CREATE TABLE Examples


CREATE TABLE Sales (storeid INTEGER NOT NULL, productid INTEGER NOT NULL, salesdate DATE FORMAT 'yyyy-mm-dd' NOT NULL, totalrevenue DECIMAL(13,2), totalsold INTEGER, note VARCHAR(256)) UNIQUE PRIMARY INDEX (storeid, productid, salesdate) PARTITION BY RANGE_N(salesdate BETWEEN DATE '2003-11-01' AND DATE '2004-10-31' EACH INTERVAL '1' DAY);
Note: UPI is allowed because partitioning column is included in the PI. 11

CREATE TABLE Examples


CREATE TABLE SalesHistory (storeid INTEGER NOT NULL, productid INTEGER NOT NULL, salesdate DATE FORMAT 'yyyy-mm-dd' NOT NULL, totalrevenue DECIMAL(13,2), totalsold INTEGER, note VARCHAR(256)) UNIQUE PRIMARY INDEX (storeid, productid, salesdate) PARTITION BY RANGE_N(salesdate BETWEEN DATE '1997-01-01' AND DATE '2003-10-31' EACH INTERVAL '7' DAY);

12

CREATE TABLE Examples


CREATE TABLE SalesAndSalesHistory (storeid INTEGER NOT NULL, productid INTEGER NOT NULL, salesdate DATE FORMAT 'yyyy-mm-dd' NOT NULL, totalrevenue DECIMAL(13,2), totalsold INTEGER, note VARCHAR(256)) UNIQUE PRIMARY INDEX (storeid, productid, salesdate) PARTITION BY RANGE_N(salesdate BETWEEN DATE '1997-01-01' EACH INTERVAL '7' DAY, DATE '2003-11-01' AND DATE '2004-10-31' EACH INTERVAL '1' DAY);

13

CREATE TABLE Examples


-- This example constrains storeids -- to be between 1 and 65535. CREATE TABLE StoreSales (storeid INTEGER NOT NULL, productid INTEGER NOT NULL, salesdate DATE FORMAT 'yyyy-mm-dd' NOT NULL, totalrevenue DECIMAL(13,2), totalsold INTEGER, note VARCHAR(256)) UNIQUE PRIMARY INDEX (storeid, productid, salesdate) PARTITION BY storeid;

14

ALTER TABLE Examples


ALTER TABLE orders MODIFY PRIMARY INDEX DROP RANGE BETWEEN DATE '1998-01-01' AND DATE '1998-12-31' EACH INTERVAL '1' MONTH ADD RANGE BETWEEN DATE '2005-01-01' AND DATE '2005-12-31' EACH INTERVAL '1' MONTH WITH DELETE; -- dropped ranges may be non-empty

18

ALTER TABLE Examples


ALTER TABLE orders MODIFY PRIMARY INDEX DROP RANGE BETWEEN DATE '1998-01-01' AND DATE '1998-12-31' EACH INTERVAL '1' MONTH ADD RANGE BETWEEN DATE '2005-01-01' AND DATE '2005-12-31' EACH INTERVAL '1' MONTH WITH INSERT INTO Old_Orders; -- dropped ranges may be non-empty

19

Вам также может понравиться