0
0
PostgreSQLquery~20 mins

BRIN index for large sequential data in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
BRIN Index Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of BRIN index usage on sequential data scan
Given a table 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';
AIndex Scan using brin_timestamp_idx on logs (cost=0.00..50.00 rows=100 width=50) Index Cond: (timestamp >= '2024-01-01'::timestamp without time zone AND timestamp <= '2024-01-02'::timestamp without time zone)
BSeq Scan on logs (cost=0.00..1000.00 rows=100 width=50) Filter: (timestamp >= '2024-01-01'::timestamp without time zone AND timestamp <= '2024-01-02'::timestamp without time zone)
CSeq Scan on logs (cost=0.00..5000.00 rows=100000 width=50)
D
Bitmap Index Scan on brin_timestamp_idx  (cost=0.00..10.00 rows=100 width=50)
Bitmap Heap Scan on logs  (cost=10.00..100.00 rows=100 width=50)  Recheck Cond: (timestamp &gt;= '2024-01-01'::timestamp without time zone AND timestamp &lt;= '2024-01-02'::timestamp without time zone)
Attempts:
2 left
💡 Hint
BRIN indexes are used with Bitmap Index Scan and Bitmap Heap Scan for large sequential data.
🧠 Conceptual
intermediate
1: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?
ABRIN indexes summarize ranges of pages, reducing index size and improving performance on sequential data.
BBRIN indexes store exact row locations for every value, making lookups very fast.
CBRIN indexes require no maintenance and automatically sort data physically on disk.
DBRIN indexes duplicate the entire table data in compressed form for faster access.
Attempts:
2 left
💡 Hint
Think about how BRIN indexes summarize data instead of storing exact row pointers.
📝 Syntax
advanced
1: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?
ACREATE INDEX brin_event_time_idx ON events USING BRIN (event_time) WITH (pages_per_range := 16);
BCREATE INDEX brin_event_time_idx ON events USING BRIN (event_time) WITH PAGES_PER_RANGE = 16;
CCREATE INDEX brin_event_time_idx ON events USING BRIN (event_time) WITH (pages_per_range = 16);
DCREATE INDEX brin_event_time_idx ON events USING BRIN (event_time) WITH (pages_per_range = '16');
Attempts:
2 left
💡 Hint
The syntax for BRIN options uses WITH and parentheses with key = value pairs.
🔧 Debug
advanced
2: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?
AThe <code>sale_date</code> column has many NULL values, and BRIN indexes do not index NULLs.
BThe table data is not physically ordered by <code>sale_date</code>, so BRIN summaries are ineffective.
CThe BRIN index was created without specifying the <code>pages_per_range</code> option, causing it to be ignored.
DBRIN indexes cannot be used on date or timestamp columns.
Attempts:
2 left
💡 Hint
Think about how BRIN indexes rely on physical ordering of data.
optimization
expert
3: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?
ACreate a BRIN index on <code>log_time</code> with a small <code>pages_per_range</code> value and run <code>CLUSTER</code> on the table by <code>log_time</code> regularly.
BCreate a BRIN index on <code>log_time</code> with a small <code>pages_per_range</code> value and periodically run <code>VACUUM FULL</code> to reorder data physically.
CCreate a BRIN index on <code>log_time</code> with default <code>pages_per_range</code> and rely on autovacuum to maintain physical order.
DCreate a BRIN index on <code>log_time</code> with a large <code>pages_per_range</code> value and run <code>CLUSTER</code> on the table by <code>log_time</code> regularly.
Attempts:
2 left
💡 Hint
Consider how physical ordering and pages per range affect BRIN index efficiency.