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

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationNeilDeclaro1
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answersdalebeck957
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 

Recently uploaded (20)

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 

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/