Challenge - 5 Problems
B-tree Index Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Effect of B-tree index on equality search
Given a table
employees(id INT PRIMARY KEY, name TEXT, salary INT) with a B-tree index on salary, what will be the output of the query SELECT id FROM employees WHERE salary = 50000; if there are three employees with salary 50000?Attempts:
2 left
💡 Hint
Think about how B-tree indexes handle equality conditions.
✗ Incorrect
B-tree indexes efficiently support equality searches and will return all matching rows. Since three employees have salary 50000, all their ids are returned.
❓ query_result
intermediate2:00remaining
Range query behavior with B-tree index
Consider a table
products(id SERIAL PRIMARY KEY, price NUMERIC) with a B-tree index on price. What will the query SELECT id FROM products WHERE price > 100 AND price <= 200; return if there are five products priced between 101 and 200?Attempts:
2 left
💡 Hint
Recall how B-tree indexes handle range conditions.
✗ Incorrect
B-tree indexes support range queries efficiently. The query returns all products with price greater than 100 and less than or equal to 200, which includes the five products.
📝 Syntax
advanced2:00remaining
Syntax for creating a B-tree index
Which of the following SQL statements correctly creates a B-tree index on the
email column of the users table in PostgreSQL?Attempts:
2 left
💡 Hint
Check the correct syntax order for USING clause in CREATE INDEX.
✗ Incorrect
The correct syntax is
CREATE INDEX index_name ON table_name USING btree (column_name);. Option D follows this syntax exactly.❓ optimization
advanced2:00remaining
Choosing columns for B-tree index to optimize queries
You have a table
orders(order_id INT, customer_id INT, order_date DATE, status TEXT). Which B-tree index will best optimize queries filtering by customer_id and sorting by order_date?Attempts:
2 left
💡 Hint
Think about the order of columns in a multi-column B-tree index.
✗ Incorrect
A B-tree index on (customer_id, order_date) supports filtering by customer_id and sorting by order_date efficiently. The order of columns matters for query optimization.
🧠 Conceptual
expert2:00remaining
Behavior of B-tree index with NULL values
In PostgreSQL, how does a B-tree index treat rows where the indexed column contains NULL values?
Attempts:
2 left
💡 Hint
Consider how NULLs are handled in B-tree indexes for search operations.
✗ Incorrect
In PostgreSQL, B-tree indexes do not index rows where the indexed column is NULL. Therefore, searching for NULL values cannot use the B-tree index efficiently.