Challenge - 5 Problems
Partition Pruning Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Partition pruning with static query filters
Given a partitioned table
sales partitioned by region, which query will prune partitions correctly and return only rows from the north region?PostgreSQL
SELECT * FROM sales WHERE region = 'north';
Attempts:
2 left
💡 Hint
Partition pruning works best with exact matches on the partition key.
✗ Incorrect
Only option C uses an exact equality condition on the partition key 'region', allowing PostgreSQL to prune partitions and scan only the 'north' partition. Other options use patterns or ranges that prevent pruning.
🧠 Conceptual
intermediate2:00remaining
Understanding partition pruning timing
When does PostgreSQL perform partition pruning during query execution?
Attempts:
2 left
💡 Hint
Think about how static values and parameters affect planning.
✗ Incorrect
PostgreSQL prunes partitions at planning time when filters are static constants. For parameterized queries, pruning happens at execution time when parameter values are known.
📝 Syntax
advanced2:00remaining
Which query syntax enables effective partition pruning with a parameter?
Given a partitioned table
orders partitioned by order_date, which query syntax will allow PostgreSQL to prune partitions when using a parameter for the date filter?PostgreSQL
Prepare a query to select orders for a specific date using a parameter.
Attempts:
2 left
💡 Hint
Partition pruning requires direct comparison on the partition key without transformations.
✗ Incorrect
Option A uses a direct equality comparison on the partition key with a parameter, enabling pruning. Options A, B, and C apply transformations or functions that prevent pruning.
🔧 Debug
advanced2:00remaining
Why does this query scan all partitions despite a filter?
A table
events is partitioned by event_type. The query SELECT * FROM events WHERE event_type = 'click' OR event_type = 'view'; scans all partitions. Why?Attempts:
2 left
💡 Hint
Consider how multiple conditions affect pruning.
✗ Incorrect
Partition pruning in PostgreSQL works best with simple equality conditions on the partition key. Using OR with multiple values disables pruning, causing all partitions to be scanned.
❓ optimization
expert2:00remaining
Optimizing partition pruning for range partitions
Given a table
logs partitioned by range on log_date, which query will maximize partition pruning efficiency for retrieving logs from January 2024?Attempts:
2 left
💡 Hint
Partition pruning works best with direct range comparisons on the partition key.
✗ Incorrect
Option D uses direct range conditions on the partition key, allowing PostgreSQL to prune partitions efficiently. Options A, B, and D use functions or inclusive ranges that may prevent pruning or scan extra partitions.