Database Essentials - Partitioning Tables and Indexes - Exercise - Partitioned Tables

Automation of Writing Guidelines Response

Description
This is a response template for crafting an article based on specific guidelines. The response includes instructions on structuring the article, covering key concepts, providing hands-on tasks, and a call to action for engaging with the community.

Explanation for the video
The video linked in the article provides a visual guide to complement the text-based instructions. It offers a practical demonstration of the concepts discussed, making it easier for readers to understand and follow along with the content.

Put a placeholder for the video here with text so that I can replace as part of the automation

Key Concepts Explanation

In this section, we break down the key concepts discussed in the article to provide a clear understanding for the readers. Each concept is explained with inline code examples for better comprehension.

Key Concept 1

Description of the key concept 1 with inline code examples

# Sample Python code for key concept 1
print("This is an example of key concept 1")

Key Concept 2

Description of the key concept 2 with inline code examples

// Sample Java code for key concept 2
System.out.println("Example of key concept 2");

Hands-On Tasks

These hands-on tasks are designed to help readers apply the concepts learned in the article. By completing these tasks, readers can gain practical experience and a deeper understanding of the material.

  1. Task 1: Create a new table using SQL.
  2. Task 2: Partition the table based on a specific column.

Conclusion

In conclusion, this article has covered essential guidelines for writing an informative and engaging article on a technical topic. Readers are encouraged to practice the concepts discussed and engage with the community for further learning and support.

Exercises - Partitioning Tables

Here is the exercise to get comfortable with partitioning. We will be using range partitioning to partition a table in the retail database.

  • Use the retail database and ensure the orders table exists.
  • Reset the database by following the provided commands.
  • Connect to the retail database using the provided credentials.
psql -U itversity_retail_user \
  -h localhost \
  -p 5432 \
  -d itversity_retail_db \
  -W
  • Run the SQL commands to recreate the tables and load the data.
DROP TABLE IF EXISTS order_items;
DROP TABLE IF EXISTS orders;
DROP TABLE IF EXISTS customers;
DROP TABLE IF EXISTS products;
DROP TABLE IF EXISTS categories;
DROP TABLE IF EXISTS departments;

\i /data/retail_db/create_db_tables_pg.sql

\i /data/retail_db/load_db_tables_pg.sql

Exercise 1

Create a new table named orders_part with the same columns as the existing orders table.

  • Partition the table by month using range partitioning on the order_date column.
  • Add 14 partitions - 13 based on the data and 1 default partition.

Exercise 2

Load and validate data in the partitioned table orders_part.

  • Transfer data from the orders table into the orders_part table.
  • Get the count of records in orders_part and across all 14 partitions, ensuring correct distribution of data.

By completing these exercises, readers will gain practical experience in partitioning tables and handling data distribution effectively.

Watch the video tutorial here