SlideShare a Scribd company logo
1 of 5
Download to read offline
PL/SQL OPTIMIZATION – PARTITIONING
Creating a Partitioned Table
As the number of rows in your tables grows, the management and performance impacts will
increase. Backups will take longer, recoveries will take longer, and queries that span an entire table
will take longer. You can mitigate the administrative and performance issues for large tables by
separating the rows of a single table into multiple parts. Dividing a table’s data in this manner is
called partitioning the table; the table that is partitioned is called a partitioned table, and the parts
are called partitions.
Partitioning is useful for very large tables. By splitting a large table’s rows across multiple smaller
partitions, you accomplish several important goals:






The performance of queries against the tables may improve because Oracle may have to
search only one partition (one part of the table) instead of the entire table to resolve a
query.
Backup and recovery operations may perform better. Because the partitions are smaller than
the partitioned table, you may have more options for backing up and recovering the
partitions than you would have for a single large table.
The table may be easier to manage. Because the partitioned table’s data is stored in multiple
parts, it may be easier to load and delete data in the partitions than in the large table.

To create a partitioned table, you specify how to set up the partitions of the table’s data as part of
the create table command. Typically, tables are partitioned by ranges of values (known as range
partitioning).
CREATE TABLE tb_transactions_part
(
TRANS_ID

VARCHAR2(40 BYTE),

COUNTRY

VARCHAR2(10 BYTE),

YEAR

INT,

SHOP_ID

VARCHAR2(20 BYTE),

PRODUCT_ID

VARCHAR2(10 BYTE),

SALES_DATA

VARCHAR2(26 BYTE),

PRICE

NUMBER(28, 2),

PRODUCT_VERSION

VARCHAR2(15 BYTE),

CONSTRAINT trans_id_part_pk PRIMARY KEY (trans_id)
)
PARTITION BY RANGE (YEAR)

http://www.learn-with-video-tutorials.com/
(PARTITION part1 VALUES LESS THAN (2012)
TABLESPACE SYSTEM,
PARTITION part2 VALUES LESS THAN (MAXVALUE)
TABLESPACE example);

The tb_transactions_part table will be partitioned based on the values in the Year column. For any
Years less than '2012', the records will be stored in the partition named PART1. The PART1 partition
will be stored in the System tablespace. Any other years will be stored in the PART2 partition.
You do not need to specify a maximum value for the last partition; the maxvalue keyword tells Oracle
to use the partition to store any data that could not be stored in the earlier partitions.

Creating a hash partition
In addition to range partitions, Oracle supports hash partitions. A hash partition determines the
physical placement of data by performing a hash function on the values of the partition key. In range
partitioning, consecutive values of the partition key are usually stored in the same partition. In hash
partitioning, consecutive values of the partition key are not generally stored in the same partition.
Hash partitioning distributes a set of records over a greater set of partitions than range partitioning
does, potentially decreasing the likelihood for I/O contention.
To create a hash partition, use the partition by hash clause in place of the partition by range clause.
CREATE TABLE tb_transactions_part
(
trans_id

VARCHAR2(40 BYTE),

country

VARCHAR2(10 BYTE),

YEAR

INT,

shop_id

VARCHAR2(20 BYTE),

product_id

VARCHAR2(10 BYTE),

sales_data

VARCHAR2(26 BYTE),

price

NUMBER(28, 2),

product_version

VARCHAR2(15 BYTE),

CONSTRAINT trans_id_part_pk PRIMARY KEY (trans_id)
)
PARTITION BY HASH (YEAR)
PARTITIONS 2
STORE IN (system, example);

http://www.learn-with-video-tutorials.com/
The number of tablespaces specified in the store in clause does not have to equal the number of
partitions. If more partitions than tablespaces are specified, the partitions are assigned to the
tablespaces in a round-robin fashion.

You can specify named partitions. In this method, each partition is given a name and a tablespace,
with the option of using an additional lob or varray storage clause. This method gives you more
control over the location of the partitions, with the added benefit of letting you specify meaningful
names for the partitions.

List Partitioning
You can use list partitions in place of range and hash partitioning. In list partitioning, you tell Oracle
all the possible values and designate the partitions into which the corresponding rows should be
inserted.
CREATE TABLE tb_transactions_part
(
trans_id

VARCHAR2(40 BYTE),

country

VARCHAR2(10 BYTE),

YEAR

INT,

shop_id

VARCHAR2(20 BYTE),

product_id

VARCHAR2(10 BYTE),

sales_data

VARCHAR2(26 BYTE),

price

NUMBER(28, 2),

product_version

VARCHAR2(15 BYTE),

CONSTRAINT trans_id_part_pk PRIMARY KEY (trans_id)
)
PARTITION BY LIST (product_version)
(PARTITION part1 VALUES ('standard', 'simple')
TABLESPACE system,
PARTITION part2 VALUES ('full', 'vip')
TABLESPACE example);

Creating Subpartitions
You can create subpartitions—that is, partitions of partitions. You can use subpartitions to combine
all types of partitions: range partitions, list partitions, and hash partitions. For example, you can use
hash partitions in combination with range partitions, creating hash partitions of the range partitions.

http://www.learn-with-video-tutorials.com/
For very large tables, this composite partitioning may be an effective way of separating the data into
manageable and tunable divisions.
The following example range-partitions the tb_transactions_part table by the year column, and it
hash-partitions the year partitions by product version values.
CREATE TABLE tb_transactions_part
(
trans_id

VARCHAR2(40 BYTE),

country

VARCHAR2(10 BYTE),

YEAR

INT,

shop_id

VARCHAR2(20 BYTE),

product_id

VARCHAR2(10 BYTE),

sales_data

VARCHAR2(26 BYTE),

price

NUMBER(28, 2),

product_version

VARCHAR2(15 BYTE),

CONSTRAINT trans_id_part_pk PRIMARY KEY (trans_id)
)
PARTITION BY RANGE (YEAR)
SUBPARTITION BY HASH (product_version)
SUBPARTITIONS 4
(PARTITION part1 VALUES LESS THAN (2011)
TABLESPACE system,
PARTITION part2 VALUES LESS THAN (MAXVALUE)
TABLESPACE example);

The tb_transactions_part table will be range-partitioned into two partitions, using the year value
ranges specified for the named partitions. Each of those partitions will be hash-partitioned on the
product version column.

Indexing Partitions
When you create a partitioned table, you should create an index on the table. The index may be
partitioned according to the same range values used to partition the table.
CREATE INDEX ix_trans_year
ON tb_transactions_part(year)
LOCAL
(PARTITION part1

http://www.learn-with-video-tutorials.com/
TABLESPACE system,
PARTITION part2
TABLESPACE example);

In this create index command, no ranges are specified. Instead, the local keyword tells Oracle to
create a separate index for each partition of the tb_transactions_part table. Two partitions were
created on tb_transactions_part. This index will create two separate index partitions—one for each
table partition. Because there is one index per partition, the index partitions are “local” to the
partitions.
CREATE INDEX ix_trans_year_2
ON tb_transactions_part(year)
GLOBAL;

The global clause in this create index command allows you to create a nonpartitioned index or to
specify ranges for the index values that are different from the ranges for the table partitions. Local
indexes may be easier to manage than global indexes; however, global indexes may perform
uniqueness checks faster than local (partitioned) indexes perform them.
You cannot create global indexes for hash partitions or subpartitions.

More lessons: http://www.learn-with-video-tutorials.com/

http://www.learn-with-video-tutorials.com/

More Related Content

Recently uploaded

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Recently uploaded (20)

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Oracle Optimization Tutorial - Partitioning

  • 1. PL/SQL OPTIMIZATION – PARTITIONING Creating a Partitioned Table As the number of rows in your tables grows, the management and performance impacts will increase. Backups will take longer, recoveries will take longer, and queries that span an entire table will take longer. You can mitigate the administrative and performance issues for large tables by separating the rows of a single table into multiple parts. Dividing a table’s data in this manner is called partitioning the table; the table that is partitioned is called a partitioned table, and the parts are called partitions. Partitioning is useful for very large tables. By splitting a large table’s rows across multiple smaller partitions, you accomplish several important goals:    The performance of queries against the tables may improve because Oracle may have to search only one partition (one part of the table) instead of the entire table to resolve a query. Backup and recovery operations may perform better. Because the partitions are smaller than the partitioned table, you may have more options for backing up and recovering the partitions than you would have for a single large table. The table may be easier to manage. Because the partitioned table’s data is stored in multiple parts, it may be easier to load and delete data in the partitions than in the large table. To create a partitioned table, you specify how to set up the partitions of the table’s data as part of the create table command. Typically, tables are partitioned by ranges of values (known as range partitioning). CREATE TABLE tb_transactions_part ( TRANS_ID VARCHAR2(40 BYTE), COUNTRY VARCHAR2(10 BYTE), YEAR INT, SHOP_ID VARCHAR2(20 BYTE), PRODUCT_ID VARCHAR2(10 BYTE), SALES_DATA VARCHAR2(26 BYTE), PRICE NUMBER(28, 2), PRODUCT_VERSION VARCHAR2(15 BYTE), CONSTRAINT trans_id_part_pk PRIMARY KEY (trans_id) ) PARTITION BY RANGE (YEAR) http://www.learn-with-video-tutorials.com/
  • 2. (PARTITION part1 VALUES LESS THAN (2012) TABLESPACE SYSTEM, PARTITION part2 VALUES LESS THAN (MAXVALUE) TABLESPACE example); The tb_transactions_part table will be partitioned based on the values in the Year column. For any Years less than '2012', the records will be stored in the partition named PART1. The PART1 partition will be stored in the System tablespace. Any other years will be stored in the PART2 partition. You do not need to specify a maximum value for the last partition; the maxvalue keyword tells Oracle to use the partition to store any data that could not be stored in the earlier partitions. Creating a hash partition In addition to range partitions, Oracle supports hash partitions. A hash partition determines the physical placement of data by performing a hash function on the values of the partition key. In range partitioning, consecutive values of the partition key are usually stored in the same partition. In hash partitioning, consecutive values of the partition key are not generally stored in the same partition. Hash partitioning distributes a set of records over a greater set of partitions than range partitioning does, potentially decreasing the likelihood for I/O contention. To create a hash partition, use the partition by hash clause in place of the partition by range clause. CREATE TABLE tb_transactions_part ( trans_id VARCHAR2(40 BYTE), country VARCHAR2(10 BYTE), YEAR INT, shop_id VARCHAR2(20 BYTE), product_id VARCHAR2(10 BYTE), sales_data VARCHAR2(26 BYTE), price NUMBER(28, 2), product_version VARCHAR2(15 BYTE), CONSTRAINT trans_id_part_pk PRIMARY KEY (trans_id) ) PARTITION BY HASH (YEAR) PARTITIONS 2 STORE IN (system, example); http://www.learn-with-video-tutorials.com/
  • 3. The number of tablespaces specified in the store in clause does not have to equal the number of partitions. If more partitions than tablespaces are specified, the partitions are assigned to the tablespaces in a round-robin fashion. You can specify named partitions. In this method, each partition is given a name and a tablespace, with the option of using an additional lob or varray storage clause. This method gives you more control over the location of the partitions, with the added benefit of letting you specify meaningful names for the partitions. List Partitioning You can use list partitions in place of range and hash partitioning. In list partitioning, you tell Oracle all the possible values and designate the partitions into which the corresponding rows should be inserted. CREATE TABLE tb_transactions_part ( trans_id VARCHAR2(40 BYTE), country VARCHAR2(10 BYTE), YEAR INT, shop_id VARCHAR2(20 BYTE), product_id VARCHAR2(10 BYTE), sales_data VARCHAR2(26 BYTE), price NUMBER(28, 2), product_version VARCHAR2(15 BYTE), CONSTRAINT trans_id_part_pk PRIMARY KEY (trans_id) ) PARTITION BY LIST (product_version) (PARTITION part1 VALUES ('standard', 'simple') TABLESPACE system, PARTITION part2 VALUES ('full', 'vip') TABLESPACE example); Creating Subpartitions You can create subpartitions—that is, partitions of partitions. You can use subpartitions to combine all types of partitions: range partitions, list partitions, and hash partitions. For example, you can use hash partitions in combination with range partitions, creating hash partitions of the range partitions. http://www.learn-with-video-tutorials.com/
  • 4. For very large tables, this composite partitioning may be an effective way of separating the data into manageable and tunable divisions. The following example range-partitions the tb_transactions_part table by the year column, and it hash-partitions the year partitions by product version values. CREATE TABLE tb_transactions_part ( trans_id VARCHAR2(40 BYTE), country VARCHAR2(10 BYTE), YEAR INT, shop_id VARCHAR2(20 BYTE), product_id VARCHAR2(10 BYTE), sales_data VARCHAR2(26 BYTE), price NUMBER(28, 2), product_version VARCHAR2(15 BYTE), CONSTRAINT trans_id_part_pk PRIMARY KEY (trans_id) ) PARTITION BY RANGE (YEAR) SUBPARTITION BY HASH (product_version) SUBPARTITIONS 4 (PARTITION part1 VALUES LESS THAN (2011) TABLESPACE system, PARTITION part2 VALUES LESS THAN (MAXVALUE) TABLESPACE example); The tb_transactions_part table will be range-partitioned into two partitions, using the year value ranges specified for the named partitions. Each of those partitions will be hash-partitioned on the product version column. Indexing Partitions When you create a partitioned table, you should create an index on the table. The index may be partitioned according to the same range values used to partition the table. CREATE INDEX ix_trans_year ON tb_transactions_part(year) LOCAL (PARTITION part1 http://www.learn-with-video-tutorials.com/
  • 5. TABLESPACE system, PARTITION part2 TABLESPACE example); In this create index command, no ranges are specified. Instead, the local keyword tells Oracle to create a separate index for each partition of the tb_transactions_part table. Two partitions were created on tb_transactions_part. This index will create two separate index partitions—one for each table partition. Because there is one index per partition, the index partitions are “local” to the partitions. CREATE INDEX ix_trans_year_2 ON tb_transactions_part(year) GLOBAL; The global clause in this create index command allows you to create a nonpartitioned index or to specify ranges for the index values that are different from the ranges for the table partitions. Local indexes may be easier to manage than global indexes; however, global indexes may perform uniqueness checks faster than local (partitioned) indexes perform them. You cannot create global indexes for hash partitions or subpartitions. More lessons: http://www.learn-with-video-tutorials.com/ http://www.learn-with-video-tutorials.com/