You are on page 1of 7

Name: Praveen Yadav Practical 2 Roll no: 62

Practical No 2
Title: Implementation of Range Partition
Aim: To implement range partition.
Theory/Explanation:
What is a data partition?

 Range partitioning is a type of relational database partitioning wherein the partition is based on a
predefined range for a specific data field such as uniquely numbered IDs, dates or simple values
like currency. A partitioning key column is assigned with a specific range, and when a data entry fits
this range, it is assigned to this partition, otherwise it is placed in another partition where it fits.
 In a range partitioned table, rows are distributed based on a "partitioning key" where the only
requisite is whether or not the data falls within the range specification of the key. For example, if the
partition key is a date column, and January 2015 is a partition, then all data containing values from
January 1, 2015 to January 31, 2015 will be placed in this partition.
 Range partitioning is quite useful for applications requiring high performance for both decision-
support environments and online transaction processing (OLTP). This makes data segregation easy
and access to each smaller partition is fast, however extensive knowledge as to the data partitioning
is required in order to properly balance the load evenly across all partitions. In this scheme, many
partitions are ordered, with each succeeding partition having a higher bound than the previous
partition.
 Characteristics of range partitioning:
 Each partition has an exclusive upper bound.
 Each partition has a non-inclusive lower bound, except for the very first partition.

1] Create a table employee with attributes (eid, ename, address, salary):


2] Partition the table using range partitioning on salary (<10k, <20k, <50k)
Code:
create table employee(eid int, ename varchar(50), address varchar(200), salary int)
-> PARTITION BY RANGE(salary) (
-> PARTITION p0 VALUES LESS THAN (10000),
-> PARTITION p1 VALUES LESS THAN (20000),
-> PARTITION p2 VALUES LESS THAN (50000));

Output:
Name: Praveen Yadav Practical 2 Roll no: 62

3. Insert 10 records into the employee table


Code:
insert into employee values(1, 'Raju', 'Thane', 25000);
insert into employee values(2, 'Ram', 'Chembur', 35000),
-> (3, 'Shreyas', 'Mulund', 45000),
-> (4, 'Vinay', 'Dombivli', 45000),
-> (5, 'Harry', 'Thane', 40000),
-> (6, 'Shreya', 'Chembur', 15000),
-> (7, 'Rajesh', 'Vashi', 9000),
-> (8, 'Adi', 'Thane', 12000),
-> (9, 'Babu', 'Chembur', 30000),
-> (10, 'Shruti', 'Vashi', 45000);

Output:
Name: Praveen Yadav Practical 2 Roll no: 62

4. Display the data in the table and each partition


Code:
select * from employee;
Output:

5. Add 1 or more partitions to employee table


Code:
alter table employee ADD PARTITION (PARTITION p3 VALUES LESS THAN (60000));

Output:

6. Display the data from the new partition


Code:
select * from employee;
Output:
Name: Praveen Yadav Practical 2 Roll no: 62

7. Perform a few update operations on the partition table and main table and observe the difference.
Code:
UPDATE employee
-> SET salary=55000
-> WHERE eid=5;
Output:
Name: Praveen Yadav Practical 2 Roll no: 62

As you can see after updating the salary record of eid= 5, the record shifted from partition p2 to p3 partition.

8. Perform few aggregate operations and display the data (avg, min, max, sum, count)
Code:
select count(*) from employee;
select avg(salary) from employee;
select min(salary) from employee;
select max(salary) from employee;
select sum(salary) from employee;

Output:
Name: Praveen Yadav Practical 2 Roll no: 62

9. Drop any column or partition and observe the status of the main table.
Code:
alter table employee DROP PARTITION p0;
Output:
Name: Praveen Yadav Practical 2 Roll no: 62

Conclusion:
I have learned how to implement Range Partitioning in MySQL

You might also like