Partition pruning
- SQL course
- Advanced
- Lesson 76/81
- 4 min
Scan only the relevant partition.
Partition pruning
Partition pruning scans only relevant partitions. It speeds up the query.
SELECT * FROM sales WHERE sale_date >= '2026-01-01';
-- yalnız 2026 bölümleri taranırOnly relevant partition scanned.
All columns are selected from sales. WHERE keeps only the rows where sale_date >= '2026-01-01' holds.
Partition pruning — details
The WHERE condition prunes partitions. The query does not scan the whole table.
For this to work the WHERE condition must use the partition column (e.g. sale_date) directly; if the column is inside a function, pruning may not happen.
Practice Partition pruning
Trigger pruning with WHERE sale_date >= '2026-01-01'.
Starter code
-- pruning query
SELECT * FROM salesSample solution
SELECT * FROM sales WHERE sale_date >= '2026-01-01';Expected output
id sale_date amount 1 2026-01-05 100
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Add WHERE
SELECT * FROM sales ____ sale_date >= '2026-01-01'
SELECT * FROM sales WHERE sale_date >= '2026-01-01'
Explanation: Thanks to the WHERE on sale_date the database scans only the relevant partition (partition pruning).
2 Partition pruning: match the terms
| Term | Meaning |
|---|---|
pruning |
pruning |
relevant |
less scan |
WHERE |
condition |
fast |
less data |
3 What does partition pruning do?
- Adds an index
- Scans the whole table
- Scans only the relevant partition Correct answer
- Deletes data
Explanation: Pruning scans only the relevant partition.