0
0
PostgreSQLquery~20 mins

Partitioning best practices in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Partitioning Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use partitioning in PostgreSQL?

Which of the following is the main reason to use table partitioning in PostgreSQL?

ATo automatically create indexes on all columns
BTo improve query performance by scanning only relevant partitions
CTo reduce the size of the database backups
DTo enforce foreign key constraints across partitions
Attempts:
2 left
💡 Hint

Think about how partitioning helps with large datasets and query speed.

query_result
intermediate
2:00remaining
Query result with range partitioning

Given a table sales partitioned by range on sale_date, which query will return sales only from 2023?

PostgreSQL
SELECT * FROM sales WHERE sale_date >= '2023-01-01' AND sale_date < '2024-01-01';
AReturns all sales from 2023 only
BReturns sales from all years
CReturns sales only from 2022
DReturns no rows due to syntax error
Attempts:
2 left
💡 Hint

Check the date range in the WHERE clause.

📝 Syntax
advanced
2:00remaining
Correct syntax for creating a list partition

Which of the following CREATE TABLE statements correctly creates a list partition for a table orders partitioned by region?

ACREATE TABLE orders_east PARTITION OF orders FOR VALUES IN ('East');
BCREATE TABLE orders_east PARTITION OF orders VALUES LIST ('East');
CCREATE TABLE orders_east PARTITION OF orders FOR VALUES ('East');
DCREATE TABLE orders_east PARTITION OF orders PARTITION BY LIST ('East');
Attempts:
2 left
💡 Hint

Look for the correct syntax to specify list partition values.

optimization
advanced
2:00remaining
Best practice for partition key choice

Which is the best practice when choosing a partition key for a large table?

AChoose a column that is not indexed
BChoose a column with very few distinct values to reduce partitions
CChoose a column that is rarely used in WHERE clauses
DChoose a column with high cardinality and frequent filtering in queries
Attempts:
2 left
💡 Hint

Think about how partition pruning works with query filters.

🔧 Debug
expert
3:00remaining
Why does this partitioned table query fail?

Consider a partitioned table events partitioned by LIST on event_type. The query SELECT * FROM events WHERE event_type = 'login'; returns no rows, but data exists. What is the most likely cause?

AThe event_type column is not part of the partition key
BThe query syntax is invalid for partitioned tables
CThe partition for 'login' was not created or attached properly
DPostgreSQL does not support filtering on partition keys
Attempts:
2 left
💡 Hint

Think about how partitions must be created and attached for data to be found.