Given a table sales partitioned by date ranges on the sale_date column, what will be the output of this query?
SELECT COUNT(*) FROM sales WHERE sale_date >= '2023-01-01' AND sale_date < '2023-04-01';
Assume the partitions are:
sales_2023_q1: 2023-01-01 to 2023-03-31sales_2023_q2: 2023-04-01 to 2023-06-30
The sales_2023_q1 partition contains 1500 rows, and sales_2023_q2 contains 2000 rows.
Think about which partitions the query will scan based on the date range.
The query filters for dates from 2023-01-01 up to but not including 2023-04-01. Only the sales_2023_q1 partition covers this range, so only its 1500 rows are counted.
Which statement correctly describes how PostgreSQL range partitions handle boundary values for date partitions?
Think about how ranges are usually defined in PostgreSQL partitions.
PostgreSQL range partitions include rows where the partition key is greater than or equal to the start boundary and less than the end boundary. This avoids overlap between partitions.
Which of the following SQL statements correctly creates a table events partitioned by range on the event_date column?
Check the syntax for partitioning by range in PostgreSQL.
The correct syntax uses PARTITION BY RANGE (column_name). Options A and B use wrong partition types, and D has incorrect syntax missing parentheses.
You created a range partition orders_2023_q1 for orders table with range from '2023-01-01' to '2023-04-01'. When inserting a row with order_date = '2023-04-01', you get a constraint violation error. Why?
Recall how PostgreSQL defines range partition boundaries.
PostgreSQL range partitions include the start boundary but exclude the end boundary. So '2023-04-01' belongs to the next partition, not this one.
You have a large logs table partitioned by month on log_date. You want to optimize a query that fetches logs for March 2024. Which approach will best improve query performance?
Think about how PostgreSQL uses partition pruning with WHERE clauses.
Adding a WHERE clause that matches the partition boundaries allows PostgreSQL to scan only the relevant partition, improving performance. Indexes on the parent table do not help partitions. Querying partitions directly is not recommended. Removing partitioning loses partition benefits.