An index is like a shortcut or a map that helps the database find data quickly without looking at every row.
Click to reveal answer
beginner
How does an index speed up a query?
It reduces the amount of data the database scans by pointing directly to the rows that match the search, like using a book's index to find a topic fast.
Click to reveal answer
beginner
What happens if a table has no index and you search for a value?
The database checks every row one by one, which takes more time, especially if the table is large.
Click to reveal answer
intermediate
What is a common data structure used for indexes in MySQL?
MySQL often uses B-trees for indexes, which keep data sorted and allow fast searching, inserting, and deleting.
Click to reveal answer
intermediate
Can indexes slow down data insertion or updates? Why?
Yes, because the database must update the index every time data changes, which adds extra work.
Click to reveal answer
What does an index in a database help with?
AFinding data faster
BMaking data bigger
CDeleting data automatically
DBacking up data
✗ Incorrect
An index helps the database find data faster by avoiding scanning every row.
If a table has no index, how does the database find data?
AIt scans every row one by one
BIt uses a shortcut
CIt guesses the location
DIt uses a cache
✗ Incorrect
Without an index, the database must scan every row to find matching data.
Which data structure is commonly used for indexes in MySQL?
ALinked list
BB-tree
CStack
DHash table
✗ Incorrect
MySQL commonly uses B-trees for indexes to keep data sorted and searchable.
What is a downside of having many indexes on a table?
ADatabase crashes
BQueries become slower
CData gets lost
DData insertion and updates become slower
✗ Incorrect
Indexes must be updated on data changes, which slows down insertions and updates.
Why is using an index like using a book's index?
ABoth delete unnecessary pages
BBoth make the book heavier
CBoth help find information quickly without reading everything
DBoth print the whole content
✗ Incorrect
An index helps find data quickly just like a book's index helps find topics without reading all pages.
Explain in simple terms why indexes make database queries faster.
Think about how a book index helps you find a topic quickly.
You got /3 concepts.
Describe one tradeoff of using indexes in a database.
Indexes speed up reading but can slow down writing.
You got /2 concepts.
Practice
(1/5)
1. Why do indexes speed up queries in MySQL?
easy
A. They store all data in memory for faster access.
B. They create shortcuts to quickly find data without scanning the whole table.
C. They compress the data to reduce size.
D. They automatically backup the database.
Solution
Step 1: Understand what an index does
An index works like a shortcut or a map to find data quickly instead of checking every row.
Step 2: Compare with full table scan
Without an index, MySQL must look at every row, which is slow for big tables.
Final Answer:
They create shortcuts to quickly find data without scanning the whole table. -> Option B
Quick Check:
Indexes = shortcuts to data [OK]
Hint: Think of index as a book's index for fast lookup [OK]
Common Mistakes:
Confusing indexes with data compression
Thinking indexes store all data in memory
Believing indexes backup data automatically
2. Which of the following is the correct syntax to create an index on the column email in a table users?
easy
A. CREATE INDEX ON users email_index(email);
B. INDEX CREATE email_index ON users(email);
C. CREATE users INDEX email_index(email);
D. CREATE INDEX email_index ON users(email);
Solution
Step 1: Recall the correct CREATE INDEX syntax
The correct syntax is: CREATE INDEX index_name ON table_name(column_name);
Step 2: Match syntax with options
CREATE INDEX email_index ON users(email); matches the correct syntax exactly.
Final Answer:
CREATE INDEX email_index ON users(email); -> Option D
Quick Check:
CREATE INDEX index_name ON table(column) [OK]
Hint: Remember: CREATE INDEX name ON table(column) [OK]
Common Mistakes:
Swapping keywords order
Missing ON keyword
Placing index name after table name incorrectly
3. Given the table products(id INT, name VARCHAR(50), price DECIMAL) with an index on price, what will be the effect of this query? EXPLAIN SELECT * FROM products WHERE price = 100;
medium
A. The query will use the index on price to find matching rows quickly.
B. The query will scan the entire table ignoring the index.
C. The query will cause a syntax error due to missing index hint.
D. The query will lock the entire table during execution.
Solution
Step 1: Understand EXPLAIN output with index
When a column has an index and the query filters on that column, MySQL uses the index to speed up search.
Step 2: Analyze query behavior
The query filters by price = 100, so the index on price helps find rows without scanning all.
Final Answer:
The query will use the index on price to find matching rows quickly. -> Option A
Quick Check:
Index on filtered column = faster search [OK]
Hint: Filter on indexed column uses index automatically [OK]
Common Mistakes:
Assuming index is ignored without hints
Thinking syntax error occurs without hints
Believing table locks always happen on SELECT
4. You created an index on column username but your query SELECT * FROM users WHERE username = 'alice'; is still slow. What could be the problem?
medium
A. The column username is not used in the WHERE clause.
B. The query syntax is incorrect and causes slow execution.
C. The index was not created properly or is corrupted.
D. Indexes slow down all queries by default.
Solution
Step 1: Check if index exists and is valid
If the index was not created correctly or got corrupted, MySQL won't use it, causing slow queries.
Step 2: Verify query and column usage
The query syntax is correct and uses the indexed column, so syntax or column usage is not the issue.
Final Answer:
The index was not created properly or is corrupted. -> Option C
Quick Check:
Index missing or broken = slow query [OK]
Hint: Check index existence if query is slow on indexed column [OK]
Common Mistakes:
Blaming query syntax when it's correct
Thinking indexes always slow queries
Ignoring that column is used in WHERE clause
5. You have a large table orders with columns order_id, customer_id, and order_date. You often run this query: SELECT * FROM orders WHERE customer_id = 123 AND order_date > '2023-01-01'; Which indexing strategy will speed up this query best?
hard
A. Create a composite index on (customer_id, order_date).
B. Create separate indexes on customer_id and order_date.
C. Create an index only on order_date.
D. No index is needed; full table scan is faster.
Solution
Step 1: Understand composite index benefits
A composite index on (customer_id, order_date) helps MySQL filter rows by both columns efficiently in one index.
Step 2: Compare with separate indexes
Separate indexes may be used but are less efficient than a composite index for combined conditions.
Final Answer:
Create a composite index on (customer_id, order_date). -> Option A
Quick Check:
Composite index matches multi-column WHERE best [OK]
Hint: Use composite index for multi-column WHERE filters [OK]
Common Mistakes:
Creating only single-column indexes for multi-column queries
Assuming full table scan is faster on large tables
Ignoring order of columns in composite index
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.