Lab 04
Lab 04
Lab: 04
Topic: Data partitioning (Range Partitioning vs List Partitioning)
Using the same table created in TP 03, run the following queries:
Query 01:
EXPLAIN ANALYZE SELECT * FROM students WHERE enrollment_date BETWEEN
'2023-01-01' AND '2023-12-31';
Query 02:
EXPLAIN ANALYZE
SELECT * FROM students
WHERE major = 'Computer Science'
AND enrollment_date BETWEEN '2022-01-01' AND '2022-12-31';
Query 03:
EXPLAIN ANALYZE
SELECT * FROM students
WHERE enrollment_date >= '2024-01-01'
AND city IN ('New York', 'Los Angeles', 'Chicago');
Record the time for each query make sure that all indexes are deleted:
Query Time
Query 01
Query 02
Query 03
Part 02: Convert the student's table (TP 03) to a range partitioned table
Partitioning can be done using several strategies, such as range partitioning, list
partitioning, and hash partitioning. For our example, we will use range partitioning based
on the enrollment_date column.
1- Create a New Partitioned Table (with the same schema of students (TP 03)):
Create a new table with the same schema as the existing table, and partition it. This will
serve as the base partitioned table.
3- Insert Data from the Existing Table into the Partitioned Table:
Run the same queries (Part 01) on the partitioned table to see the differences in
performance (table name has changed: students_partitioned):
Query Time
Query 01
Query 02
Query 03
Run the following queries on student table, and save the result on this table:
Query Time
Query 01
Query 02
Query 03
Query 01:
EXPLAIN ANALYZE
SELECT * FROM students
WHERE city = 'New York';
Query 02:
EXPLAIN ANALYZE
SELECT * FROM students
WHERE city = 'Los Angeles'
AND major = 'Computer Science';
Query 03:
EXPLAIN ANALYZE
SELECT * FROM students
WHERE city NOT IN ('New York', 'Los Angeles', 'Chicago');
Questions:
1. Create a new partitioned version of the students table, partitioned by the city
column, name it “students_partitioned_by_city”.
2. Create Partitions for Specific Cities: 'New York', 'Los Angeles', 'Chicago',
3. Migrate Data into the Partitioned Table
4. Run the same 3 queries from part 4, and record the time:
Query Time
Query 01
Query 02
Query 03
Note: