0
0
PostgreSQLquery~20 mins

Why indexing strategy matters in PostgreSQL - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Indexing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Effect of Index on Query Speed

Consider a table employees with 1 million rows. It has a column department_id. Which query will run faster if there is an index on department_id?

Assume department_id has many repeated values.

PostgreSQL
SELECT * FROM employees WHERE department_id = 5;
AThe query will run faster because the index helps find rows with department_id = 5 quickly.
BThe query will run slower because the index adds overhead to the search.
CThe query speed will be the same because indexes do not affect SELECT queries.
DThe query will fail because indexes cannot be used on columns with repeated values.
Attempts:
2 left
💡 Hint

Think about how indexes help find data without scanning the whole table.

🧠 Conceptual
intermediate
2:00remaining
Choosing the Right Index Type

Which index type is best suited for a column that stores unique user IDs and is often used in equality searches?

AHash index because it supports range queries efficiently.
BBRIN index because it is best for columns with many unique values.
CB-tree index because it efficiently supports equality and range queries.
DGIN index because it is optimized for full-text search.
Attempts:
2 left
💡 Hint

Think about which index type supports equality searches well.

📝 Syntax
advanced
2:00remaining
Creating a Composite Index

Which SQL command correctly creates a composite index on columns last_name and first_name in the customers table?

ACREATE INDEX idx_name ON customers (last_name AND first_name);
BCREATE INDEX idx_name ON customers (first_name, last_name);
CCREATE INDEX idx_name ON customers (last_name); CREATE INDEX idx_name ON customers (first_name);
DCREATE INDEX idx_name ON customers (last_name, first_name);
Attempts:
2 left
💡 Hint

Composite indexes list columns separated by commas inside parentheses.

optimization
advanced
2:00remaining
Impact of Index on Insert Performance

What is a common downside of having many indexes on a table when performing frequent INSERT operations?

AINSERT operations become faster because indexes speed up data insertion.
BINSERT operations become slower because each index must be updated.
CINSERT operations are unaffected by indexes.
DINSERT operations fail if there are more than three indexes.
Attempts:
2 left
💡 Hint

Think about what happens to indexes when new data is added.

🔧 Debug
expert
3:00remaining
Why a Query Does Not Use an Index

You created an index on the email column of the users table. However, the query below does not use the index:

SELECT * FROM users WHERE LOWER(email) = 'test@example.com';

Why does this happen?

ABecause the query applies a function <code>LOWER()</code> on the column, the index on <code>email</code> is not used.
BBecause the index is corrupted and needs to be rebuilt.
CBecause the query is missing an explicit <code>USE INDEX</code> hint.
DBecause the <code>email</code> column is not indexed by default in PostgreSQL.
Attempts:
2 left
💡 Hint

Think about how functions on columns affect index usage.