0
0
SQLquery~20 mins

Why indexes matter in SQL - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Index Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Effect of Index on Query Speed

Consider a table Employees with 1 million rows. It has a column LastName without an index. You run this query:

SELECT * FROM Employees WHERE LastName = 'Smith';

Now, an index is added on LastName. What is the most likely effect on the query execution?

AThe query will run faster because the index allows quick lookup of 'Smith' rows.
BThe query result will change and return fewer rows.
CThe query will run slower because the index adds overhead to the search.
DThe query will fail because indexes prevent filtering on columns.
Attempts:
2 left
💡 Hint

Think about how indexes help find data quickly like a book's index helps find pages fast.

🧠 Conceptual
intermediate
2:00remaining
Why Indexes Can Slow Down Inserts

Why can adding indexes to a table slow down inserting new rows?

ABecause indexes cause the database to scan all rows before inserting.
BBecause the database must update the index data structure for each new row inserted.
CBecause indexes lock the entire table during inserts.
DBecause indexes prevent new rows from being added.
Attempts:
2 left
💡 Hint

Think about what happens behind the scenes when you add a new row and the index exists.

📝 Syntax
advanced
2:00remaining
Creating an Index Syntax

Which SQL statement correctly creates an index named idx_lastname on the LastName column of the Employees table?

AINDEX CREATE idx_lastname ON Employees LastName;
BCREATE Employees INDEX idx_lastname ON LastName;
CCREATE INDEX idx_lastname ON Employees (LastName);
DCREATE INDEX ON Employees (LastName) idx_lastname;
Attempts:
2 left
💡 Hint

Remember the order: CREATE INDEX <name> ON <table> (<column>);

query_result
advanced
2:00remaining
Index Usage in Query Plans

You have a table Orders with an index on OrderDate. You run this query:

EXPLAIN SELECT * FROM Orders WHERE OrderDate = '2023-01-01';

What is the expected behavior in the query plan?

AThe plan will show an index scan on OrderDate, using the index to find matching rows.
BThe plan will show a full table scan ignoring the index.
CThe plan will show a join operation instead of a scan.
DThe plan will show an error because EXPLAIN cannot be used with indexes.
Attempts:
2 left
💡 Hint

EXPLAIN shows how the database plans to execute the query, including index usage.

🔧 Debug
expert
3:00remaining
Diagnosing Slow Query Despite Index

You created an index on the Email column of the Users table. But this query is still slow:

SELECT * FROM Users WHERE Email LIKE '%@example.com';

Why is the index not helping?

ABecause indexes only work with numeric columns.
BBecause the index was created on the wrong column.
CBecause the query syntax is invalid and causes a full scan.
DBecause the LIKE pattern starts with a wildcard '%', the index cannot be used efficiently.
Attempts:
2 left
💡 Hint

Think about how indexes work with string patterns and wildcards.