Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
The ultimate performance benefit of table partitioning is Partition Pruning.
Partition pruning occurs when the MySQL Query Optimizer analyzes the query's WHERE clause and determines that only a specific subset of partitions could possibly contain matching rows. The optimizer skips (prunes) all other partitions entirely, reading only 10% or 5% of the total disk data!
To verify whether your query is pruning partitions, run EXPLAIN (or EXPLAIN PARTITIONS in older versions):
EXPLAIN Output:| id | select_type | table | partitions | type | rows |
|---|---|---|---|---|---|
| 1 | SIMPLE | orders_range | p2025 | range | 15000 |
Notice the partitions column: it displays p2025 only! Partitions p2023, p2024, and p_future were completely ignored! Disk I/O was reduced by 75%.
Just like index SARGability, poorly formed SQL queries can prevent the optimizer from pruning partitions, forcing it to scan every partition in the table:
If your table is partitioned by YEAR(order_date), and your query filters by:
If you query by customer ID without mentioning order_date:
Because MySQL has no way of knowing which year customer 101 placed their order in, it must scan every single partition!
Partitioning provides substantial benefits for massive data warehouses:
ALTER TABLE orders_range OPTIMIZE PARTITION p2025;
p2026) fit neatly into RAM buffer pool memory, while cold historical partitions stay on disk.Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Creating & Managing Partitioned Tables | InnoDB Architecture: Buffer Pool, Redo Log, Undo Log |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.