Challenge - 5 Problems
BRIN Index Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of BRIN index usage on sequential data scan
Given a table
Assuming the table is very large and data is inserted in timestamp order.
logs with a timestamp column storing sequential log entries, and a BRIN index created on timestamp, what will be the output of the following EXPLAIN query?EXPLAIN SELECT * FROM logs WHERE timestamp BETWEEN '2024-01-01' AND '2024-01-02';
Assuming the table is very large and data is inserted in timestamp order.
PostgreSQL
CREATE TABLE logs (id SERIAL PRIMARY KEY, timestamp TIMESTAMP NOT NULL, message TEXT); CREATE INDEX brin_timestamp_idx ON logs USING BRIN (timestamp); EXPLAIN SELECT * FROM logs WHERE timestamp BETWEEN '2024-01-01' AND '2024-01-02';
Attempts:
2 left
💡 Hint
BRIN indexes are used with Bitmap Index Scan and Bitmap Heap Scan for large sequential data.
✗ Incorrect
BRIN indexes in PostgreSQL are used to quickly filter large ranges by summarizing block ranges. The planner uses Bitmap Index Scan on the BRIN index followed by Bitmap Heap Scan on the table to fetch matching rows efficiently. Direct Index Scan is not used because BRIN indexes are block summaries, not exact pointers to rows.
🧠 Conceptual
intermediate1:30remaining
Why use BRIN indexes for large sequential data?
Which of the following best explains why BRIN indexes are suitable for very large tables with sequentially inserted data?
Attempts:
2 left
💡 Hint
Think about how BRIN indexes summarize data instead of storing exact row pointers.
✗ Incorrect
BRIN indexes store summaries (min/max values) for ranges of physical pages, which makes them very small and efficient for large tables where data is naturally ordered, like sequential timestamps. They do not store exact row locations.
📝 Syntax
advanced1:30remaining
Correct syntax to create a BRIN index with custom pages per range
Which option correctly creates a BRIN index on the
event_time column of the events table with a pages_per_range setting of 16?Attempts:
2 left
💡 Hint
The syntax for BRIN options uses WITH and parentheses with key = value pairs.
✗ Incorrect
The correct syntax to specify BRIN index options is WITH (option_name = value). The value can be numeric without quotes. Option C uses the correct syntax.
🔧 Debug
advanced2:00remaining
Identify the cause of slow queries despite BRIN index
A developer created a BRIN index on a large
sales table's sale_date column. However, queries filtering by sale_date are still slow and do not use the index. Which is the most likely cause?Attempts:
2 left
💡 Hint
Think about how BRIN indexes rely on physical ordering of data.
✗ Incorrect
BRIN indexes work best when the data is physically ordered or clustered by the indexed column. If the data is randomly ordered, the BRIN index summaries cover wide ranges and are less selective, causing the planner to ignore the index.
❓ optimization
expert3:00remaining
Optimizing BRIN index performance for a large log table
You have a large
logs table with a log_time timestamp column. Data is inserted sequentially by log_time. You want to optimize BRIN index performance for queries filtering recent logs. Which combination of actions is best?Attempts:
2 left
💡 Hint
Consider how physical ordering and pages per range affect BRIN index efficiency.
✗ Incorrect
A smaller pages_per_range makes BRIN index summaries more precise but larger. Regularly clustering the table by log_time physically orders data, improving BRIN index effectiveness for recent data queries.