Challenge - 5 Problems
EXPLAIN Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Understanding EXPLAIN output for a simple SELECT
Given the table
employees with columns id (primary key), name, and department_id, what will the EXPLAIN output show for this query?SELECT name FROM employees WHERE id = 5;MySQL
EXPLAIN SELECT name FROM employees WHERE id = 5;
Attempts:
2 left
💡 Hint
Look for the use of the primary key in the WHERE clause.
✗ Incorrect
Since the query filters by the primary key 'id', MySQL uses a constant lookup (type: const) with the PRIMARY key index, scanning only one row.
❓ query_result
intermediate2:00remaining
Interpreting EXPLAIN for a JOIN query
Consider two tables:
orders with order_id (primary key) and customer_id, and customers with customer_id (primary key) and name. What does this EXPLAIN output indicate for the query?SELECT o.order_id, c.name FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_id = 10;MySQL
EXPLAIN SELECT o.order_id, c.name FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.customer_id = 10;
Attempts:
2 left
💡 Hint
Check which table is filtered by primary key and which uses an index for the join.
✗ Incorrect
The customers table is filtered by primary key (type const), and orders uses a ref type to find matching rows via the customer_id index.
📝 Syntax
advanced2:00remaining
Identify the syntax error in EXPLAIN usage
Which EXPLAIN statement is syntactically incorrect in MySQL?
Attempts:
2 left
💡 Hint
Check the correct placement of FORMAT keyword in EXPLAIN syntax.
✗ Incorrect
The FORMAT keyword must come immediately after EXPLAIN, not inside the SELECT clause.
❓ optimization
advanced2:00remaining
Optimizing a query based on EXPLAIN output
You run EXPLAIN on this query:
The output shows
SELECT * FROM products WHERE category = 'Books' AND price < 20;The output shows
type: ALL and rows: 10000. What is the best way to improve performance?Attempts:
2 left
💡 Hint
Think about how indexes can help filter multiple conditions efficiently.
✗ Incorrect
A composite index on (category, price) allows MySQL to quickly filter rows matching both conditions, avoiding a full table scan.
🧠 Conceptual
expert2:00remaining
Understanding EXPLAIN JSON output details
In MySQL's EXPLAIN FORMAT=JSON output, which field indicates the estimated number of rows MySQL expects to examine for a table access?
Attempts:
2 left
💡 Hint
Look for the field that quantifies rows scanned per index or table access.
✗ Incorrect
"rows_examined_per_scan" shows the estimated number of rows MySQL expects to scan for that table access in the JSON EXPLAIN output.