Bird
0
0

Given a table 'orders' partitioned by RANGE on 'order_date' with partitions for 2023-01-01 to 2023-01-31 and 2023-02-01 to 2023-02-28, what partitions will be scanned by this query?

medium📝 query result Q4 of 15
PostgreSQL - Table Partitioning
Given a table 'orders' partitioned by RANGE on 'order_date' with partitions for 2023-01-01 to 2023-01-31 and 2023-02-01 to 2023-02-28, what partitions will be scanned by this query?
SELECT * FROM orders WHERE order_date >= '2023-01-15' AND order_date < '2023-02-10';
AOnly February partition
BOnly January partition
CBoth January and February partitions
DNo partitions scanned
Step-by-Step Solution
Solution:
  1. Step 1: Analyze query date range

    The query requests orders from 2023-01-15 up to but not including 2023-02-10.
  2. Step 2: Match partitions to date range

    January partition covers 2023-01-01 to 2023-01-31, February partition covers 2023-02-01 to 2023-02-28. The query range overlaps both partitions.
  3. Final Answer:

    Both January and February partitions -> Option C
  4. Quick Check:

    Overlapping partitions scanned = Both January and February partitions [OK]
Quick Trick: Query range overlapping partitions scans all those partitions [OK]
Common Mistakes:
  • Assuming only one partition scanned for range queries
  • Ignoring upper bound in range
  • Thinking partitions outside exact date are scanned

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes