A database index is a data structure that helps speed up data retrieval by allowing the database to find rows faster without scanning the entire table.
Click to reveal answer
beginner
How does an index improve query performance?
An index works like a book's index: it points to the location of data, so the database can jump directly to the needed rows instead of checking every row.
Click to reveal answer
intermediate
What are the common types of database indexes?
Common types include B-tree indexes for range queries, hash indexes for exact matches, and bitmap indexes for columns with few unique values.
Click to reveal answer
intermediate
What is a trade-off when using indexes?
Indexes speed up reads but slow down writes because the index must be updated whenever data changes, and they also use extra storage space.
Click to reveal answer
intermediate
What is a composite index?
A composite index is an index on multiple columns, which helps queries that filter or sort by more than one column efficiently.
Click to reveal answer
Which data structure is commonly used for database indexes to support range queries?
AB-tree
BHash table
CLinked list
DStack
✗ Incorrect
B-tree indexes allow efficient range queries by keeping data sorted and balanced.
What is a downside of adding many indexes to a database table?
ALoss of data integrity
BSlower data retrieval
CReduced query flexibility
DIncreased storage and slower writes
✗ Incorrect
More indexes require extra storage and slow down insert, update, and delete operations.
Which type of index is best for exact match queries?
AHash index
BB-tree index
CBitmap index
DFull-text index
✗ Incorrect
Hash indexes provide fast lookups for exact matches but are not suitable for range queries.
What does a composite index index?
AA single column
BMultiple columns
COnly primary keys
DOnly foreign keys
✗ Incorrect
Composite indexes cover multiple columns to optimize queries filtering on those columns.
Why might a database choose not to use an index for a query?
AThe query is very complex
BThe index is corrupted
CThe table is very small
DThe database is offline
✗ Incorrect
For small tables, scanning all rows can be faster than using an index.
Explain how database indexes improve query speed and what trade-offs they introduce.
Think about how a book index helps find pages faster but takes space.
You got /4 concepts.
Describe different types of database indexes and when to use each.
Consider the kind of queries and data uniqueness.
You got /3 concepts.
Practice
(1/5)
1. What is the primary purpose of a database index?
easy
A. To increase the size of the database
B. To speed up data retrieval by allowing quick lookups
C. To store backup copies of data
D. To encrypt the database contents
Solution
Step 1: Understand what an index does
An index helps the database find data faster by creating a quick lookup structure.
Step 2: Identify the main benefit
This quick lookup reduces the time needed to search large tables.
Final Answer:
To speed up data retrieval by allowing quick lookups -> Option B
Quick Check:
Index = Faster data search [OK]
Hint: Indexes speed up searches by creating shortcuts [OK]
Common Mistakes:
Thinking indexes store extra data copies
Confusing indexes with backups
Assuming indexes encrypt data
2. Which of the following is the correct syntax to create an index on the column user_id in SQL?
easy
A. CREATE INDEX idx_user ON users (user_id);
B. INDEX CREATE user_id ON users;
C. CREATE users INDEX ON user_id;
D. MAKE INDEX user_id IN users;
Solution
Step 1: Recall SQL syntax for creating indexes
The standard syntax is CREATE INDEX index_name ON table_name (column_name);
Step 2: Match the syntax with options
CREATE INDEX idx_user ON users (user_id); matches the correct syntax exactly.
Final Answer:
CREATE INDEX idx_user ON users (user_id); -> Option A
Quick Check:
CREATE INDEX ... ON ... (column) [OK]
Hint: Remember: CREATE INDEX name ON table(column) [OK]
Common Mistakes:
Swapping table and column names
Using wrong keyword order
Missing parentheses around column
3. Given a table orders with an index on order_date, what will be the output of the query plan for SELECT * FROM orders WHERE order_date = '2023-01-01';?
medium
A. Full table scan without using the index
B. Ignoring the order_date column completely
C. Sorting all rows by order_date before filtering
D. Index seek on order_date to quickly find matching rows
Solution
Step 1: Understand how indexes affect query plans
An index on order_date allows the database to quickly locate rows matching the date.
Step 2: Identify the expected query plan
The database will perform an index seek to find matching rows efficiently, not scan the whole table.
Final Answer:
Index seek on order_date to quickly find matching rows -> Option D
Quick Check:
Indexed column = index seek [OK]
Hint: Indexed WHERE columns use index seek, not full scan [OK]
Common Mistakes:
Assuming full table scan despite index
Confusing sorting with filtering
Ignoring index usage in query plan
4. A developer created an index on a column but notices no improvement in query speed. What could be a likely reason?
medium
A. The database automatically disables all indexes
B. The index was created with the wrong SQL syntax
C. The queries do not filter or sort using the indexed column
D. Indexes always slow down queries
Solution
Step 1: Analyze index usage conditions
Indexes only help if queries use the indexed column in WHERE, JOIN, or ORDER BY clauses.
Step 2: Identify why no speed improvement occurs
If queries don't use the indexed column, the index is ignored, so no speed gain.
Final Answer:
The queries do not filter or sort using the indexed column -> Option C
Quick Check:
Index helps only if column used in query [OK]
Hint: Index unused if queries ignore indexed columns [OK]
Common Mistakes:
Assuming syntax error disables index
Believing all indexes slow queries
Thinking database disables indexes by default
5. You have a large table with frequent inserts and queries filtering by status and created_at. Which indexing strategy balances read speed and write overhead best?
hard
A. Create a composite index on (status, created_at)
B. Create separate indexes on status and created_at individually
C. Create no indexes to avoid write overhead
D. Create a full-text index on status and created_at
Solution
Step 1: Understand composite vs separate indexes
A composite index on (status, created_at) helps queries filtering on both columns efficiently.
Step 2: Consider write overhead and query patterns
Separate indexes increase write overhead more than one composite index and may be less efficient for combined filters.
Step 3: Exclude unsuitable options
No indexes hurt read speed; full-text index is for text search, not filtering by status/date.
Final Answer:
Create a composite index on (status, created_at) -> Option A
Quick Check:
Composite index = balanced read/write [OK]
Hint: Composite indexes optimize multi-column filters with less overhead [OK]
Common Mistakes:
Creating many separate indexes causing slow writes
Skipping indexes hurting read performance
Using full-text index for non-text filtering
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.