0
0
PostgreSQLquery~20 mins

B-tree index (default) behavior in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
B-tree Index Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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?
AReturns only one employee id with salary 50000
BReturns the ids of all three employees with salary 50000
CReturns no rows because B-tree indexes do not support equality searches
DReturns an error because salary is not unique
Attempts:
2 left
💡 Hint
Think about how B-tree indexes handle equality conditions.
query_result
intermediate
2: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?
AReturns the ids of all five products priced between 101 and 200
BReturns only products priced exactly 100 or 200
CReturns no rows because B-tree indexes do not support range queries
DReturns an error due to invalid range syntax
Attempts:
2 left
💡 Hint
Recall how B-tree indexes handle range conditions.
📝 Syntax
advanced
2: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?
ACREATE INDEX idx_email ON users WITH btree (email);
BCREATE BTREE INDEX idx_email ON users (email);
CCREATE INDEX idx_email ON users USING btree (email);
DCREATE INDEX idx_email ON users (email) USING BTREE;
Attempts:
2 left
💡 Hint
Check the correct syntax order for USING clause in CREATE INDEX.
optimization
advanced
2: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?
ACREATE INDEX idx_customer_order ON orders (customer_id, order_date);
BCREATE INDEX idx_customer ON orders (customer_id);
CCREATE INDEX idx_status ON orders (status);
DCREATE INDEX idx_order_date_customer ON orders (order_date, customer_id);
Attempts:
2 left
💡 Hint
Think about the order of columns in a multi-column B-tree index.
🧠 Conceptual
expert
2: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?
AB-tree indexes convert NULLs to zero before indexing
BB-tree indexes include NULL values and can be used to search for NULLs efficiently
CB-tree indexes exclude NULL values and cannot be used to search for NULLs
DB-tree indexes treat NULL as the highest possible value and sort accordingly
Attempts:
2 left
💡 Hint
Consider how NULLs are handled in B-tree indexes for search operations.