0
0
MySQLquery~20 mins

EXPLAIN query analysis in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
EXPLAIN Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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;
Atype: const, key: PRIMARY, rows: 1
Btype: ref, key: department_id, rows: 10
Ctype: ALL, key: NULL, rows: 1000
Dtype: index, key: name, rows: 500
Attempts:
2 left
💡 Hint
Look for the use of the primary key in the WHERE clause.
query_result
intermediate
2: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;
Aorders: type ref using index on customer_id; customers: type const using PRIMARY key
Borders: type eq_ref using PRIMARY key; customers: type ref using customer_id
Corders: type ALL scanning all rows; customers: type ALL scanning all rows
Dorders: type index; customers: type index
Attempts:
2 left
💡 Hint
Check which table is filtered by primary key and which uses an index for the join.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in EXPLAIN usage
Which EXPLAIN statement is syntactically incorrect in MySQL?
AEXPLAIN SELECT * FROM users WHERE age > 30;
BEXPLAIN FORMAT=JSON SELECT * FROM users;
CEXPLAIN SELECT FORMAT JSON * FROM users;
DEXPLAIN EXTENDED SELECT * FROM users;
Attempts:
2 left
💡 Hint
Check the correct placement of FORMAT keyword in EXPLAIN syntax.
optimization
advanced
2:00remaining
Optimizing a query based on EXPLAIN output
You run EXPLAIN on this query:

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?
ARemove the WHERE clause to scan fewer rows
BAdd an index on price only
CRewrite the query using OR instead of AND
DAdd a composite index on (category, price)
Attempts:
2 left
💡 Hint
Think about how indexes can help filter multiple conditions efficiently.
🧠 Conceptual
expert
2: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?
A"filtered"
B"rows_examined_per_scan"
C"rows"
D"cost_info"
Attempts:
2 left
💡 Hint
Look for the field that quantifies rows scanned per index or table access.