Challenge - 5 Problems
Partition Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of range partition query
Given a table
Assume partitions are:
- sales_2022 for dates < '2023-01-01'
- sales_2023 for dates >= '2023-01-01'
sales partitioned by range on sale_date, what rows will be returned by this query?SELECT * FROM sales WHERE sale_date < '2023-01-01';Assume partitions are:
- sales_2022 for dates < '2023-01-01'
- sales_2023 for dates >= '2023-01-01'
PostgreSQL
CREATE TABLE sales ( id SERIAL PRIMARY KEY, sale_date DATE NOT NULL, amount NUMERIC ) PARTITION BY RANGE (sale_date); CREATE TABLE sales_2022 PARTITION OF sales FOR VALUES FROM ('2022-01-01') TO ('2023-01-01'); CREATE TABLE sales_2023 PARTITION OF sales FOR VALUES FROM ('2023-01-01') TO ('2024-01-01'); -- Sample data inserted in sales_2022 and sales_2023 partitions -- Query: SELECT * FROM sales WHERE sale_date < '2023-01-01';
Attempts:
2 left
💡 Hint
Think about how range partitions split data by date ranges.
✗ Incorrect
Range partitioning divides data into partitions based on continuous ranges. The query filters for sale_date before 2023-01-01, so only the partition covering 2022 dates is scanned.
🧠 Conceptual
intermediate1:30remaining
Identifying partition type by definition
Which partition type is described by this definition?
"Data is divided into partitions based on a list of discrete values for a column."
"Data is divided into partitions based on a list of discrete values for a column."
Attempts:
2 left
💡 Hint
Think about partitions defined by specific values, not ranges or hashes.
✗ Incorrect
List partitioning divides data by explicitly listing values for each partition, unlike range or hash partitioning.
📝 Syntax
advanced2:30remaining
Correct syntax for hash partition creation
Which option shows the correct syntax to create a hash partitioned table
users on column user_id with 4 partitions in PostgreSQL?Attempts:
2 left
💡 Hint
Hash partitions require one partition per remainder value from 0 to modulus-1.
✗ Incorrect
Hash partitioning requires defining each partition with a modulus and a unique remainder. Option A correctly defines all 4 partitions with remainders 0 to 3.
❓ optimization
advanced2:00remaining
Best partition type for querying by month
You have a large
orders table with a order_date column. Most queries filter by month. Which partition type will optimize query performance best?Attempts:
2 left
💡 Hint
Think about how to group continuous time periods efficiently.
✗ Incorrect
Range partitioning by month allows pruning partitions for queries filtering by month, improving performance. List partitioning by day is too granular and hash partitioning doesn't help with date ranges.
🔧 Debug
expert2:30remaining
Why does this partition insert fail?
Given this table creation:
And this partition:
Why does this INSERT fail?
CREATE TABLE logs (id SERIAL, log_level TEXT, message TEXT) PARTITION BY LIST (log_level);And this partition:
CREATE TABLE logs_info PARTITION OF logs FOR VALUES IN ('INFO', 'DEBUG');Why does this INSERT fail?
INSERT INTO logs (log_level, message) VALUES ('ERROR', 'test');Attempts:
2 left
💡 Hint
Consider what happens when a value is not assigned to any partition in list partitioning.
✗ Incorrect
In list partitioning, all possible values must be assigned to partitions. Inserting a value not assigned to any partition causes an error because no partition holds those rows.