Search⌘ K
AI Features

Question: Partitioned Tables

Explore how to design a reporting table partitioned by PaymentMethod using MySQL's LIST COLUMNS partitioning. Learn to define primary keys compliant with partitioning rules, populate the table with existing data, and write queries that aggregate order counts per payment method. This lesson helps you improve query efficiency for filtered reports and master advanced partitioning techniques.

Question

Given the following structure of the Orders table:

Field

Type

OrderID

int

CustomerID

int

OrderDate

date

TotalAmount

decimal(10,2)

ShippedDate

date

DeliveryStatus

enum('Pending','Shipped','Delivered','Cancelled')

EmployeeID

int

CreatedAt

timestamp

ExpectedDeliveryDate

date

ActualDeliveryDate

date

LateDelivery

tinyint(1)

PaymentMethod

enum('Credit Card','PayPal','Cash on Delivery')

ReturnCount

int

FraudRisk

tinyint(1)

Where, OrderID is the primary key and CustomerID is the foreign key from the Customers table referring to the customer who placed the order.

The finance team frequently filters reports by PaymentMethod and wants these queries to run as efficiently as possible. Instead of querying the ...