SlideShare a Scribd company logo
1 of 13
Download to read offline
Storing and Accessing Data Rows
After completing this module, you will be able to:
• Explain the purpose of the Primary Index
• Distinguish between Primary Index and Primary Key
• State the reasons for selecting a UPI vs. a NUPI
Storing Rows
Table A rows
Table B rows
AMP AMP AMP AMP
• The rows of every table are distributed among all AMPs
• Each AMP is responsible for a subset of the rows of each table.
• Ideally, each table will be evenly distributed among all AMPs.
• Evenly distributed tables result in evenly distributed workloads.
• The uniformity of distribution of the rows of a table depends on the choice of
the Primary Index.
Note:
The acronym AMP is used to refer to both V1 AMPs and V2 AMP vprocs.
However, this course will assume AMPs are V2 vprocs.
Creating a Primary Index
• A Primary Index is defined at table creation.
• It may consist of a single column, or a combination of columns
– Limit of 16 columns with V2R4.1 and prior releases
– Limit of 64 columns with V2R5.
CREATE TABLE sample_1
(col_a INTEGER
,col_b INTEGER
,col_c INTEGER)
UNIQUE PRIMARY INDEX (col_b);
UPI If the index choice of column(s) is unique,
we call this a UPI (Unique Primary Index).
A UPI choice will result in even distribution
of the rows of the table across all AMPs.
CREATE TABLE sample_2
(col_x INTEGER
,col_y INTEGER
,col_z INTEGER)
PRIMARY INDEX (col_x);
NUPI If the index choice of column(s) isn’t
unique, we call this a NUPI (Non-Unique
Primary Index).
A NUPI choice will result in even
distribution of the rows of the table
proportional to the degree of uniqueness of
the index.
Note: Changing the choice of Primary Index
requires dropping and recreating the table.
Primary Index Values
• The value of the Primary Index for a specific row determines the AMP
assignment for that row.
• This is done using a hashing algorithm.
PE
Row assignment
Row access
Hashing
Algorithm
AMP AMP AMP
PI Value
• Accessing the row by its Primary Index value is:
– always a one-AMP operation
– the most efficient way to access a row
Other table access techniques:
• Secondary index access
• Full table scans
Accessing Via a Unique Primary Index
A UPI access is a one-AMP operation which may access at most a single row.
CREATE TABLE sample_1
(col_a INTEGER
,col_b INTEGER
,col_c INTEGER)
UNIQUE PRIMARY INDEX (col_b);
SELECT col_a
,col_b
,col_c
FROM sample_1
WHERE col_b = 345;
PE
Hashing
Algorithm
AMP
UPI = 345
AMP AMP
col_a col_b col_c
123
234
col_a col_b col_c
345
456
col_a col_b col_c
567
678
Accessing Via a Non-Unique Primary Index
A NUPI access is a one-AMP operation which may access multiple rows.
CREATE TABLE sample_2
(col_x INTEGER
,col_y INTEGER
,col_z INTEGER)
PRIMARY INDEX (col_x);
SELECT col_x
,col_y
,col_z
FROM sample_2
WHERE col_x = 25;
PE
Hashing
Algorithm
AMP
NUPI = 25
AMP AMP
col_x col_y col_z
10 30 A
10 30 B
35 40 B
col_x col_y col_z
20 50 A
25 55 A
25 60 B
col_x col_y col_z
5 70 B
30 80 B
30 80 A
Both UPI and NUPI
accesses are one
AMP operations.
Primary Keys and Primary Indexes
• Indexes are conceptually different from keys.
• A PK is a relational modeling convention which allows each row to be uniquely identified.
• A PI is a Teradata convention which determines how the row will be stored and accessed.
• A significant percentage of tables may use the same columns for both the PK and the PI.
• A well-designed database will use a PI that is different from the PK for some tables.
Primary Key Primary Index
Logical concept of data modeling Physical mechanism for access and storage
Teradata doesn’t need to recognize Each table must have exactly one primary index
No limit on number of columns 16 column limit (V2R4.1); 64 column limit (V2R5)
Documented in data model Defined in CREATE TABLE statement
(Optional in CREATE TABLE)
Must be unique May be unique or non-unique
Identifies each row May be unique or non-unique
Values should not change Values may be changed (Delete + Insert)
May not be NULL – requires a value May be NULL
Does not imply an access path Defines most efficient access path
Chosen for logical correctness Chosen for physical performance
Duplicate Rows
A duplicate row is a row of a table whose
column values are all identical to
another row in the same table.
col_a col_b col_c
20 50 A
25 50 A
25 50 A
Duplicate Rows
• Because a PK uniquely identifies each row, ideally a relational table should
not have duplicate rows!
• The ANSI standard, however, permits duplicate rows for specialized
situations, thus Teradata permits them as well.
• You may select whether your table will or will not allow them.
* Note: If a UPI is selected on a SET table, the duplicate row check is replaced by a
check for duplicate index values.
CREATE SET TABLE table_A
:
:
CREATE MULTISET TABLE table_B
:
:
Checks for * and disallows duplicate rows. Doesn’t check for and allows duplicate rows.
The Teradata default The ANSI default
Row Distribution Using a UPI – Case 1
Notes:
• Often, but not always, the PK column(s) will
be used as a UPI.
• PI values for Order_Number are known to be
unique (it’s a PK).
• Teradata will distribute different index
values evenly across all AMPs.
• Resulting row distribution among AMPs is
very uniform.
• Assures maximum efficiency for parallel
operations.
AMP AMP AMP AMP
o_# c_# o_dt o_st
7202 2 4/09 C
7415 1 4/13 C
o_# c_# o_dt o_st
7325 2 4/13 O
7103 1 4/10 O
7402 3 4/16 C
o_# c_# o_dt o_st
7188 1 4/13 C
7225 2 4/15 C
o_# c_# o_dt o_st
7324 3 4/13 O
7384 1 4/12 C
O rd er
N u m b er
C u sto m er
N u m b er
O rd er
D ate
O rd er
S tatu s
P K
U P I
7325
7324
7415
7103
7225
7384
7402
7188
7202
2
3
1
1
2
1
3
1
2
4/13
4/13
4/13
4/10
4/15
4/12
4/16
4/13
4/09
O
O
C
O
C
C
C
C
C
Order
Row Distribution Using a NUPI – Case 2
Notes:
• Customer_Number may be the preferred
access column for ORDER table, thus a good
index candidate.
• Values for Customer_Number are somewhat
non-unique.
• Choice of Customer_Number is therefore a
NUPI.
• Rows with the same PI value distribute to the
same AMP.
• Row distribution is less uniform or skewed.
o_# c_# o_dt o_st
7325 2 4/13 O
7202 2 4/09 C
7225 2 4/15 C
o_# c_# o_dt o_st
7384 1 4/12 C
7103 1 4/10 O
7415 1 4/13 C
7188 1 4/13 C
o_# c_# o_dt o_st
7402 3 4/16 C
7324 3 4/13 O
AMP AMP AMP AMP
O rd er
N u m b er
C u sto m er
N u m b er
O rd er
D ate
O rd er
S tatu s
P K
N U P I
7325
7324
7415
7103
7225
7384
7402
7188
7202
2
3
1
1
2
1
3
1
2
4/13
4/13
4/13
4/10
4/15
4/12
4/16
4/13
4/09
O
O
C
O
C
C
C
C
C
Order
Row Distribution Using a Highly Non-Unique Primary
Index (NUPI) – Case 3
O rd er
N u m b er
C u sto m er
N u m b er
O rd er
D ate
O rd er
S tatu s
P K
N U P I
7325
7324
7415
7103
7225
7384
7402
7188
7202
2
3
1
1
2
1
3
1
2
4/13
4/13
4/13
4/10
4/15
4/12
4/16
4/13
4/09
O
O
C
O
C
C
C
C
C
Order Notes:
• Values for Order_Status are “highly” non-
unique.
• Choice of Order_Status column is a NUPI.
• Only two values exist, so only two AMPs
will ever be used for this table.
• Table will not perform well in parallel
operations.
• Highly non-unique columns are poor PI
choices generally.
• The degree of uniqueness is critical to
efficiency.
AMP AMP AMP AMP
o_# c_# o_dt o_st
7402 3 4/16 C
7202 2 4/09 C
7225 2 4/15 C
7415 1 4/13 C
7188 1 4/13 C
7384 1 4/12 C
o_# c_# o_dt o_st
7103 1 4/10 O
7324 3 4/13 O
7325 2 4/13 O
Review Questions
For each statement, indicate whether it applies to:
UPI’s, NUPI’s, or Either
_______ 1. Specified in CREATE TABLE statement
_______ 2. Provides uniform distribution via the hashing algorithm
_______ 3. May be up to 64 columns in V2R5
_______ 4. Always a one-AMP operation
_______ 5. Access will return (at most) a single row
_______ 6. Used to assign a row to a specific AMP
_______ 7. Allows a null or nulls
_______ 8. Required on every table
_______ 9. Permits duplicate rows
_______ 10. Used as a Primary Key implementation
Review Question Answers
For each statement, indicate whether it applies to:
UPI’s, NUPI’s, or Either
Either 1. Specified in CREATE TABLE statement
UPI 2. Provides uniform distribution via the hashing algorithm
Either 3. May be up to 64 columns in V2R5
Either 4. Always a one-AMP operation
UPI 5. Access will return (at most) a single row
Either 6. Used to assign a row to a specific AMP
Either 7. Allows a null or nulls
Either 8. Required on every table
NUPI 9. Permits duplicate rows
UPI 10. Used as a Primary Key implementation

More Related Content

Similar to 1.5 PI Access.pdf

Enhancing Spark SQL Optimizer with Reliable Statistics
Enhancing Spark SQL Optimizer with Reliable StatisticsEnhancing Spark SQL Optimizer with Reliable Statistics
Enhancing Spark SQL Optimizer with Reliable StatisticsJen Aman
 
Sql scripting sorcerypaper
Sql scripting sorcerypaperSql scripting sorcerypaper
Sql scripting sorcerypaperoracle documents
 
Digital Electronics Lab
Digital Electronics LabDigital Electronics Lab
Digital Electronics LabCyber4Tech
 
IBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash JoinIBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash JoinAjay Gupte
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index TuningManikanda kumar
 
Programmable Logic Array
Programmable Logic Array Programmable Logic Array
Programmable Logic Array Sharun Rajeev
 
Bootcamp sql fundamentals bootcamp_part1
Bootcamp   sql fundamentals  bootcamp_part1Bootcamp   sql fundamentals  bootcamp_part1
Bootcamp sql fundamentals bootcamp_part1varunbhatt23
 
Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager Krishan Singh
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsNirav Shah
 
Algorithm and pseudocode conventions
Algorithm and pseudocode conventionsAlgorithm and pseudocode conventions
Algorithm and pseudocode conventionssaranyatdr
 
Sap abap
Sap abapSap abap
Sap abapnrj10
 
Dot matrix display design using fpga
Dot matrix display design using fpgaDot matrix display design using fpga
Dot matrix display design using fpgaHossam Hassan
 
Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Akhila Prabhakaran
 
New T-SQL Features in SQL Server 2012
New T-SQL Features in SQL Server 2012 New T-SQL Features in SQL Server 2012
New T-SQL Features in SQL Server 2012 Richie Rump
 

Similar to 1.5 PI Access.pdf (20)

Enhancing Spark SQL Optimizer with Reliable Statistics
Enhancing Spark SQL Optimizer with Reliable StatisticsEnhancing Spark SQL Optimizer with Reliable Statistics
Enhancing Spark SQL Optimizer with Reliable Statistics
 
Oracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guideOracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guide
 
Day 6.pptx
Day 6.pptxDay 6.pptx
Day 6.pptx
 
Sql scripting sorcerypaper
Sql scripting sorcerypaperSql scripting sorcerypaper
Sql scripting sorcerypaper
 
Digital Electronics Lab
Digital Electronics LabDigital Electronics Lab
Digital Electronics Lab
 
IBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash JoinIBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash Join
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
Programmable Logic Array
Programmable Logic Array Programmable Logic Array
Programmable Logic Array
 
Bootcamp sql fundamentals bootcamp_part1
Bootcamp   sql fundamentals  bootcamp_part1Bootcamp   sql fundamentals  bootcamp_part1
Bootcamp sql fundamentals bootcamp_part1
 
Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager
 
Oracle SQL Advanced
Oracle SQL AdvancedOracle SQL Advanced
Oracle SQL Advanced
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tips
 
Algorithm and pseudocode conventions
Algorithm and pseudocode conventionsAlgorithm and pseudocode conventions
Algorithm and pseudocode conventions
 
group 10 paper 10.pptx
group 10 paper 10.pptxgroup 10 paper 10.pptx
group 10 paper 10.pptx
 
Sap abap
Sap abapSap abap
Sap abap
 
Excel tips
Excel tipsExcel tips
Excel tips
 
Dot matrix display design using fpga
Dot matrix display design using fpgaDot matrix display design using fpga
Dot matrix display design using fpga
 
Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)
 
New T-SQL Features in SQL Server 2012
New T-SQL Features in SQL Server 2012 New T-SQL Features in SQL Server 2012
New T-SQL Features in SQL Server 2012
 
K map
K mapK map
K map
 

More from ssuser8b6c85

5.Analytical Function.pdf
5.Analytical Function.pdf5.Analytical Function.pdf
5.Analytical Function.pdfssuser8b6c85
 
5.Agg. Function.pdf
5.Agg. Function.pdf5.Agg. Function.pdf
5.Agg. Function.pdfssuser8b6c85
 
2.1 Data types.pdf
2.1 Data types.pdf2.1 Data types.pdf
2.1 Data types.pdfssuser8b6c85
 
1.8 Data Protection.pdf
1.8 Data Protection.pdf1.8 Data Protection.pdf
1.8 Data Protection.pdfssuser8b6c85
 
1.6 PI Mechanics.pdf
1.6  PI Mechanics.pdf1.6  PI Mechanics.pdf
1.6 PI Mechanics.pdfssuser8b6c85
 
1.4 System Arch.pdf
1.4 System Arch.pdf1.4 System Arch.pdf
1.4 System Arch.pdfssuser8b6c85
 
1.1 Intro to WinDDI.pdf
1.1 Intro to WinDDI.pdf1.1 Intro to WinDDI.pdf
1.1 Intro to WinDDI.pdfssuser8b6c85
 

More from ssuser8b6c85 (10)

5.Analytical Function.pdf
5.Analytical Function.pdf5.Analytical Function.pdf
5.Analytical Function.pdf
 
5.Agg. Function.pdf
5.Agg. Function.pdf5.Agg. Function.pdf
5.Agg. Function.pdf
 
2.1 Data types.pdf
2.1 Data types.pdf2.1 Data types.pdf
2.1 Data types.pdf
 
1.8 Data Protection.pdf
1.8 Data Protection.pdf1.8 Data Protection.pdf
1.8 Data Protection.pdf
 
1.6 PI Mechanics.pdf
1.6  PI Mechanics.pdf1.6  PI Mechanics.pdf
1.6 PI Mechanics.pdf
 
1.4 System Arch.pdf
1.4 System Arch.pdf1.4 System Arch.pdf
1.4 System Arch.pdf
 
Spark basic.pdf
Spark basic.pdfSpark basic.pdf
Spark basic.pdf
 
1.1 Overview.pdf
1.1 Overview.pdf1.1 Overview.pdf
1.1 Overview.pdf
 
1.1 Intro to WinDDI.pdf
1.1 Intro to WinDDI.pdf1.1 Intro to WinDDI.pdf
1.1 Intro to WinDDI.pdf
 
6.3 Mload.pdf
6.3 Mload.pdf6.3 Mload.pdf
6.3 Mload.pdf
 

Recently uploaded

MATERI MANAJEMEN OF PENYAKIT TETANUS.ppt
MATERI  MANAJEMEN OF PENYAKIT TETANUS.pptMATERI  MANAJEMEN OF PENYAKIT TETANUS.ppt
MATERI MANAJEMEN OF PENYAKIT TETANUS.pptRachmaGhifari
 
Sensing the Future: Anomaly Detection and Event Prediction in Sensor Networks
Sensing the Future: Anomaly Detection and Event Prediction in Sensor NetworksSensing the Future: Anomaly Detection and Event Prediction in Sensor Networks
Sensing the Future: Anomaly Detection and Event Prediction in Sensor NetworksBoston Institute of Analytics
 
Northern New England Tableau User Group (TUG) May 2024
Northern New England Tableau User Group (TUG) May 2024Northern New England Tableau User Group (TUG) May 2024
Northern New England Tableau User Group (TUG) May 2024patrickdtherriault
 
Formulas dax para power bI de microsoft.pdf
Formulas dax para power bI de microsoft.pdfFormulas dax para power bI de microsoft.pdf
Formulas dax para power bI de microsoft.pdfRobertoOcampo24
 
The Significance of Transliteration Enhancing
The Significance of Transliteration EnhancingThe Significance of Transliteration Enhancing
The Significance of Transliteration Enhancingmohamed Elzalabany
 
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...Amil baba
 
Seven tools of quality control.slideshare
Seven tools of quality control.slideshareSeven tools of quality control.slideshare
Seven tools of quality control.slideshareraiaryan448
 
社内勉強会資料  Mamba - A new era or ephemeral
社内勉強会資料   Mamba - A new era or ephemeral社内勉強会資料   Mamba - A new era or ephemeral
社内勉強会資料  Mamba - A new era or ephemeralNABLAS株式会社
 
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理pyhepag
 
Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...
Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...
Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...ThinkInnovation
 
一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理pyhepag
 
Digital Marketing Demystified: Expert Tips from Samantha Rae Coolbeth
Digital Marketing Demystified: Expert Tips from Samantha Rae CoolbethDigital Marketing Demystified: Expert Tips from Samantha Rae Coolbeth
Digital Marketing Demystified: Expert Tips from Samantha Rae CoolbethSamantha Rae Coolbeth
 
Credit Card Fraud Detection: Safeguarding Transactions in the Digital Age
Credit Card Fraud Detection: Safeguarding Transactions in the Digital AgeCredit Card Fraud Detection: Safeguarding Transactions in the Digital Age
Credit Card Fraud Detection: Safeguarding Transactions in the Digital AgeBoston Institute of Analytics
 
Bios of leading Astrologers & Researchers
Bios of leading Astrologers & ResearchersBios of leading Astrologers & Researchers
Bios of leading Astrologers & Researchersdarmandersingh4580
 
Audience Researchndfhcvnfgvgbhujhgfv.pptx
Audience Researchndfhcvnfgvgbhujhgfv.pptxAudience Researchndfhcvnfgvgbhujhgfv.pptx
Audience Researchndfhcvnfgvgbhujhgfv.pptxStephen266013
 
社内勉強会資料_Object Recognition as Next Token Prediction
社内勉強会資料_Object Recognition as Next Token Prediction社内勉強会資料_Object Recognition as Next Token Prediction
社内勉強会資料_Object Recognition as Next Token PredictionNABLAS株式会社
 
原件一样(UWO毕业证书)西安大略大学毕业证成绩单留信学历认证
原件一样(UWO毕业证书)西安大略大学毕业证成绩单留信学历认证原件一样(UWO毕业证书)西安大略大学毕业证成绩单留信学历认证
原件一样(UWO毕业证书)西安大略大学毕业证成绩单留信学历认证pwgnohujw
 
Predictive Precipitation: Advanced Rain Forecasting Techniques
Predictive Precipitation: Advanced Rain Forecasting TechniquesPredictive Precipitation: Advanced Rain Forecasting Techniques
Predictive Precipitation: Advanced Rain Forecasting TechniquesBoston Institute of Analytics
 
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证dq9vz1isj
 
Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...
Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...
Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...Klinik Aborsi
 

Recently uploaded (20)

MATERI MANAJEMEN OF PENYAKIT TETANUS.ppt
MATERI  MANAJEMEN OF PENYAKIT TETANUS.pptMATERI  MANAJEMEN OF PENYAKIT TETANUS.ppt
MATERI MANAJEMEN OF PENYAKIT TETANUS.ppt
 
Sensing the Future: Anomaly Detection and Event Prediction in Sensor Networks
Sensing the Future: Anomaly Detection and Event Prediction in Sensor NetworksSensing the Future: Anomaly Detection and Event Prediction in Sensor Networks
Sensing the Future: Anomaly Detection and Event Prediction in Sensor Networks
 
Northern New England Tableau User Group (TUG) May 2024
Northern New England Tableau User Group (TUG) May 2024Northern New England Tableau User Group (TUG) May 2024
Northern New England Tableau User Group (TUG) May 2024
 
Formulas dax para power bI de microsoft.pdf
Formulas dax para power bI de microsoft.pdfFormulas dax para power bI de microsoft.pdf
Formulas dax para power bI de microsoft.pdf
 
The Significance of Transliteration Enhancing
The Significance of Transliteration EnhancingThe Significance of Transliteration Enhancing
The Significance of Transliteration Enhancing
 
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
 
Seven tools of quality control.slideshare
Seven tools of quality control.slideshareSeven tools of quality control.slideshare
Seven tools of quality control.slideshare
 
社内勉強会資料  Mamba - A new era or ephemeral
社内勉強会資料   Mamba - A new era or ephemeral社内勉強会資料   Mamba - A new era or ephemeral
社内勉強会資料  Mamba - A new era or ephemeral
 
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
 
Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...
Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...
Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...
 
一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理
 
Digital Marketing Demystified: Expert Tips from Samantha Rae Coolbeth
Digital Marketing Demystified: Expert Tips from Samantha Rae CoolbethDigital Marketing Demystified: Expert Tips from Samantha Rae Coolbeth
Digital Marketing Demystified: Expert Tips from Samantha Rae Coolbeth
 
Credit Card Fraud Detection: Safeguarding Transactions in the Digital Age
Credit Card Fraud Detection: Safeguarding Transactions in the Digital AgeCredit Card Fraud Detection: Safeguarding Transactions in the Digital Age
Credit Card Fraud Detection: Safeguarding Transactions in the Digital Age
 
Bios of leading Astrologers & Researchers
Bios of leading Astrologers & ResearchersBios of leading Astrologers & Researchers
Bios of leading Astrologers & Researchers
 
Audience Researchndfhcvnfgvgbhujhgfv.pptx
Audience Researchndfhcvnfgvgbhujhgfv.pptxAudience Researchndfhcvnfgvgbhujhgfv.pptx
Audience Researchndfhcvnfgvgbhujhgfv.pptx
 
社内勉強会資料_Object Recognition as Next Token Prediction
社内勉強会資料_Object Recognition as Next Token Prediction社内勉強会資料_Object Recognition as Next Token Prediction
社内勉強会資料_Object Recognition as Next Token Prediction
 
原件一样(UWO毕业证书)西安大略大学毕业证成绩单留信学历认证
原件一样(UWO毕业证书)西安大略大学毕业证成绩单留信学历认证原件一样(UWO毕业证书)西安大略大学毕业证成绩单留信学历认证
原件一样(UWO毕业证书)西安大略大学毕业证成绩单留信学历认证
 
Predictive Precipitation: Advanced Rain Forecasting Techniques
Predictive Precipitation: Advanced Rain Forecasting TechniquesPredictive Precipitation: Advanced Rain Forecasting Techniques
Predictive Precipitation: Advanced Rain Forecasting Techniques
 
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
 
Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...
Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...
Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...
 

1.5 PI Access.pdf

  • 1. Storing and Accessing Data Rows After completing this module, you will be able to: • Explain the purpose of the Primary Index • Distinguish between Primary Index and Primary Key • State the reasons for selecting a UPI vs. a NUPI
  • 2. Storing Rows Table A rows Table B rows AMP AMP AMP AMP • The rows of every table are distributed among all AMPs • Each AMP is responsible for a subset of the rows of each table. • Ideally, each table will be evenly distributed among all AMPs. • Evenly distributed tables result in evenly distributed workloads. • The uniformity of distribution of the rows of a table depends on the choice of the Primary Index. Note: The acronym AMP is used to refer to both V1 AMPs and V2 AMP vprocs. However, this course will assume AMPs are V2 vprocs.
  • 3. Creating a Primary Index • A Primary Index is defined at table creation. • It may consist of a single column, or a combination of columns – Limit of 16 columns with V2R4.1 and prior releases – Limit of 64 columns with V2R5. CREATE TABLE sample_1 (col_a INTEGER ,col_b INTEGER ,col_c INTEGER) UNIQUE PRIMARY INDEX (col_b); UPI If the index choice of column(s) is unique, we call this a UPI (Unique Primary Index). A UPI choice will result in even distribution of the rows of the table across all AMPs. CREATE TABLE sample_2 (col_x INTEGER ,col_y INTEGER ,col_z INTEGER) PRIMARY INDEX (col_x); NUPI If the index choice of column(s) isn’t unique, we call this a NUPI (Non-Unique Primary Index). A NUPI choice will result in even distribution of the rows of the table proportional to the degree of uniqueness of the index. Note: Changing the choice of Primary Index requires dropping and recreating the table.
  • 4. Primary Index Values • The value of the Primary Index for a specific row determines the AMP assignment for that row. • This is done using a hashing algorithm. PE Row assignment Row access Hashing Algorithm AMP AMP AMP PI Value • Accessing the row by its Primary Index value is: – always a one-AMP operation – the most efficient way to access a row Other table access techniques: • Secondary index access • Full table scans
  • 5. Accessing Via a Unique Primary Index A UPI access is a one-AMP operation which may access at most a single row. CREATE TABLE sample_1 (col_a INTEGER ,col_b INTEGER ,col_c INTEGER) UNIQUE PRIMARY INDEX (col_b); SELECT col_a ,col_b ,col_c FROM sample_1 WHERE col_b = 345; PE Hashing Algorithm AMP UPI = 345 AMP AMP col_a col_b col_c 123 234 col_a col_b col_c 345 456 col_a col_b col_c 567 678
  • 6. Accessing Via a Non-Unique Primary Index A NUPI access is a one-AMP operation which may access multiple rows. CREATE TABLE sample_2 (col_x INTEGER ,col_y INTEGER ,col_z INTEGER) PRIMARY INDEX (col_x); SELECT col_x ,col_y ,col_z FROM sample_2 WHERE col_x = 25; PE Hashing Algorithm AMP NUPI = 25 AMP AMP col_x col_y col_z 10 30 A 10 30 B 35 40 B col_x col_y col_z 20 50 A 25 55 A 25 60 B col_x col_y col_z 5 70 B 30 80 B 30 80 A Both UPI and NUPI accesses are one AMP operations.
  • 7. Primary Keys and Primary Indexes • Indexes are conceptually different from keys. • A PK is a relational modeling convention which allows each row to be uniquely identified. • A PI is a Teradata convention which determines how the row will be stored and accessed. • A significant percentage of tables may use the same columns for both the PK and the PI. • A well-designed database will use a PI that is different from the PK for some tables. Primary Key Primary Index Logical concept of data modeling Physical mechanism for access and storage Teradata doesn’t need to recognize Each table must have exactly one primary index No limit on number of columns 16 column limit (V2R4.1); 64 column limit (V2R5) Documented in data model Defined in CREATE TABLE statement (Optional in CREATE TABLE) Must be unique May be unique or non-unique Identifies each row May be unique or non-unique Values should not change Values may be changed (Delete + Insert) May not be NULL – requires a value May be NULL Does not imply an access path Defines most efficient access path Chosen for logical correctness Chosen for physical performance
  • 8. Duplicate Rows A duplicate row is a row of a table whose column values are all identical to another row in the same table. col_a col_b col_c 20 50 A 25 50 A 25 50 A Duplicate Rows • Because a PK uniquely identifies each row, ideally a relational table should not have duplicate rows! • The ANSI standard, however, permits duplicate rows for specialized situations, thus Teradata permits them as well. • You may select whether your table will or will not allow them. * Note: If a UPI is selected on a SET table, the duplicate row check is replaced by a check for duplicate index values. CREATE SET TABLE table_A : : CREATE MULTISET TABLE table_B : : Checks for * and disallows duplicate rows. Doesn’t check for and allows duplicate rows. The Teradata default The ANSI default
  • 9. Row Distribution Using a UPI – Case 1 Notes: • Often, but not always, the PK column(s) will be used as a UPI. • PI values for Order_Number are known to be unique (it’s a PK). • Teradata will distribute different index values evenly across all AMPs. • Resulting row distribution among AMPs is very uniform. • Assures maximum efficiency for parallel operations. AMP AMP AMP AMP o_# c_# o_dt o_st 7202 2 4/09 C 7415 1 4/13 C o_# c_# o_dt o_st 7325 2 4/13 O 7103 1 4/10 O 7402 3 4/16 C o_# c_# o_dt o_st 7188 1 4/13 C 7225 2 4/15 C o_# c_# o_dt o_st 7324 3 4/13 O 7384 1 4/12 C O rd er N u m b er C u sto m er N u m b er O rd er D ate O rd er S tatu s P K U P I 7325 7324 7415 7103 7225 7384 7402 7188 7202 2 3 1 1 2 1 3 1 2 4/13 4/13 4/13 4/10 4/15 4/12 4/16 4/13 4/09 O O C O C C C C C Order
  • 10. Row Distribution Using a NUPI – Case 2 Notes: • Customer_Number may be the preferred access column for ORDER table, thus a good index candidate. • Values for Customer_Number are somewhat non-unique. • Choice of Customer_Number is therefore a NUPI. • Rows with the same PI value distribute to the same AMP. • Row distribution is less uniform or skewed. o_# c_# o_dt o_st 7325 2 4/13 O 7202 2 4/09 C 7225 2 4/15 C o_# c_# o_dt o_st 7384 1 4/12 C 7103 1 4/10 O 7415 1 4/13 C 7188 1 4/13 C o_# c_# o_dt o_st 7402 3 4/16 C 7324 3 4/13 O AMP AMP AMP AMP O rd er N u m b er C u sto m er N u m b er O rd er D ate O rd er S tatu s P K N U P I 7325 7324 7415 7103 7225 7384 7402 7188 7202 2 3 1 1 2 1 3 1 2 4/13 4/13 4/13 4/10 4/15 4/12 4/16 4/13 4/09 O O C O C C C C C Order
  • 11. Row Distribution Using a Highly Non-Unique Primary Index (NUPI) – Case 3 O rd er N u m b er C u sto m er N u m b er O rd er D ate O rd er S tatu s P K N U P I 7325 7324 7415 7103 7225 7384 7402 7188 7202 2 3 1 1 2 1 3 1 2 4/13 4/13 4/13 4/10 4/15 4/12 4/16 4/13 4/09 O O C O C C C C C Order Notes: • Values for Order_Status are “highly” non- unique. • Choice of Order_Status column is a NUPI. • Only two values exist, so only two AMPs will ever be used for this table. • Table will not perform well in parallel operations. • Highly non-unique columns are poor PI choices generally. • The degree of uniqueness is critical to efficiency. AMP AMP AMP AMP o_# c_# o_dt o_st 7402 3 4/16 C 7202 2 4/09 C 7225 2 4/15 C 7415 1 4/13 C 7188 1 4/13 C 7384 1 4/12 C o_# c_# o_dt o_st 7103 1 4/10 O 7324 3 4/13 O 7325 2 4/13 O
  • 12. Review Questions For each statement, indicate whether it applies to: UPI’s, NUPI’s, or Either _______ 1. Specified in CREATE TABLE statement _______ 2. Provides uniform distribution via the hashing algorithm _______ 3. May be up to 64 columns in V2R5 _______ 4. Always a one-AMP operation _______ 5. Access will return (at most) a single row _______ 6. Used to assign a row to a specific AMP _______ 7. Allows a null or nulls _______ 8. Required on every table _______ 9. Permits duplicate rows _______ 10. Used as a Primary Key implementation
  • 13. Review Question Answers For each statement, indicate whether it applies to: UPI’s, NUPI’s, or Either Either 1. Specified in CREATE TABLE statement UPI 2. Provides uniform distribution via the hashing algorithm Either 3. May be up to 64 columns in V2R5 Either 4. Always a one-AMP operation UPI 5. Access will return (at most) a single row Either 6. Used to assign a row to a specific AMP Either 7. Allows a null or nulls Either 8. Required on every table NUPI 9. Permits duplicate rows UPI 10. Used as a Primary Key implementation