What is the main purpose of an index in a database?
An index helps the database find data quickly, like a book's index helps you find a topic without reading every page.
Click to reveal answer
intermediate
Describe the structure of a B-tree used in database indexes.
A B-tree is a balanced tree with nodes containing keys and pointers. It keeps data sorted and allows fast searching by narrowing down where to look step-by-step.
Click to reveal answer
beginner
How does a B-tree index speed up searching for a value?
It starts at the top node, compares the value, and moves down the correct branch, skipping large parts of data, so it finds the value quickly without scanning everything.
Click to reveal answer
intermediate
Why is a B-tree called 'balanced'?
Because all leaf nodes are at the same depth, so the time to find any value is similar, preventing slow searches.
Click to reveal answer
advanced
What happens when a B-tree node becomes too full?
The node splits into two nodes and pushes a key up to the parent, keeping the tree balanced and efficient.
Click to reveal answer
What does a database index primarily do?
AStores all data in memory
BSpeeds up data retrieval
CDeletes duplicate data
DEncrypts the database
✗ Incorrect
An index speeds up data retrieval by allowing quick lookups.
In a B-tree index, what is stored in the nodes?
AKeys and pointers to child nodes
BOnly data rows
CUser passwords
DDatabase logs
✗ Incorrect
Nodes store keys and pointers to child nodes to guide the search.
Why is a B-tree index called balanced?
AIt has the same number of keys in every node
BIt uses equal memory for all nodes
CAll leaf nodes are at the same depth
DIt stores data in alphabetical order
✗ Incorrect
Balanced means all leaf nodes are at the same depth, ensuring consistent search times.
What happens when a B-tree node is full?
AIt deletes the oldest key
BIt stops accepting new data
CIt merges with another node
DIt splits and pushes a key up
✗ Incorrect
A full node splits and pushes a key up to keep the tree balanced.
How does a B-tree index improve search speed?
ABy narrowing search to branches step-by-step
BBy scanning every row quickly
CBy storing data in random order
DBy compressing data
✗ Incorrect
It narrows the search path step-by-step, skipping irrelevant data.
Explain how a B-tree index helps a database find data quickly.
Think about how a phone book helps you find a name without reading every page.
You got /4 concepts.
Describe what happens inside a B-tree when a node becomes too full.
Imagine a bookshelf that gets too full and you add a new shelf to keep things organized.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a B-tree index in a database?
easy
A. To speed up data retrieval by organizing data in a balanced tree structure
B. To store data in a random order for faster insertion
C. To compress data to save disk space
D. To backup the database automatically
Solution
Step 1: Understand what a B-tree index does
A B-tree index organizes data in a balanced tree structure to allow quick searching without scanning the entire table.
Step 2: Compare options with B-tree purpose
Only To speed up data retrieval by organizing data in a balanced tree structure describes speeding up data retrieval using a balanced tree, which matches the B-tree index function.
Final Answer:
To speed up data retrieval by organizing data in a balanced tree structure -> Option A
Quick Check:
B-tree index = fast data lookup [OK]
Hint: B-tree indexes speed up searches by organizing data hierarchically [OK]
Common Mistakes:
Thinking indexes store data randomly
Confusing index with data compression
Believing indexes backup data
2. Which SQL statement correctly creates a B-tree index on the column last_name of the table employees?
easy
A. CREATE INDEX idx_last_name ON employees USING HASH (last_name);
B. CREATE INDEX idx_last_name ON employees (last_name) USING BITMAP;
C. CREATE INDEX idx_last_name ON employees (last_name);
D. CREATE INDEX idx_last_name ON employees USING FULLTEXT (last_name);
Solution
Step 1: Identify default index type in SQL
By default, CREATE INDEX creates a B-tree index unless specified otherwise.
Step 2: Check syntax correctness
CREATE INDEX idx_last_name ON employees (last_name); uses correct syntax without specifying a different index type, so it creates a B-tree index on last_name.
Final Answer:
CREATE INDEX idx_last_name ON employees (last_name); -> Option C
Quick Check:
Default index type = B-tree [OK]
Hint: Default index type is B-tree unless stated otherwise [OK]
Common Mistakes:
Using HASH or FULLTEXT without need
Adding unsupported index types like BITMAP in standard SQL
Incorrect syntax for index creation
3. Given a table products with a B-tree index on product_id, what will the query optimizer most likely do when running: SELECT * FROM products WHERE product_id = 123;?
medium
A. Use the B-tree index to quickly locate the row with product_id 123
B. Perform a full table scan ignoring the index
C. Use a hash index lookup instead of the B-tree
D. Scan only the first 10 rows of the table
Solution
Step 1: Understand query condition and index
The query searches for a specific product_id value, which matches the indexed column.
Step 2: Predict optimizer behavior with B-tree index
The optimizer uses the B-tree index to quickly find the matching row without scanning the whole table.
Final Answer:
Use the B-tree index to quickly locate the row with product_id 123 -> Option A
Quick Check:
Indexed search = fast lookup [OK]
Hint: Queries on indexed columns use B-tree for fast lookup [OK]
Common Mistakes:
Assuming full table scan always happens
Confusing B-tree with hash index usage
Thinking partial scan happens without index
4. You created a B-tree index on the email column of the users table, but queries filtering by email are still slow. What is a likely cause?
medium
A. The index was created on the wrong column
B. The query uses a function on email preventing index use
C. B-tree indexes do not speed up queries on text columns
D. The table has too few rows for the index to help
Solution
Step 1: Analyze query and index interaction
If the query applies a function (like LOWER(email)) on the indexed column, the B-tree index cannot be used directly.
Step 2: Evaluate other options
The index was created on the wrong column is unlikely if index was created correctly; C is false because B-tree indexes work on text; D is possible but less likely than B.
Final Answer:
The query uses a function on email preventing index use -> Option B
Quick Check:
Functions on indexed columns block B-tree use [OK]
Hint: Functions on indexed columns disable B-tree index use [OK]
Common Mistakes:
Assuming B-tree indexes don't work on text
Ignoring query transformations on columns
Blaming index creation without checking query
5. You have a large table orders with columns order_id, customer_id, and order_date. You often query orders by customer_id and sort by order_date. How should you create an index to optimize these queries?
hard
A. Create a single-column B-tree index on order_date
B. Create separate B-tree indexes on customer_id and order_date
C. Create a hash index on customer_id
D. Create a composite B-tree index on (customer_id, order_date)
Solution
Step 1: Understand query pattern
Queries filter by customer_id and sort by order_date, so both columns matter together.
Step 2: Choose index type for filtering and sorting
A composite B-tree index on (customer_id, order_date) supports filtering by customer and sorting by date efficiently.
Final Answer:
Create a composite B-tree index on (customer_id, order_date) -> Option D
Quick Check:
Composite index matches filter + sort columns [OK]
Hint: Composite indexes speed up queries filtering and sorting on multiple columns [OK]
Common Mistakes:
Creating index only on sort column
Using separate indexes instead of composite
Choosing hash index which doesn't support sorting
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.