SQL
Optimization Questions
How to answer performance tuning questions
By TechCoder TeamLast updated: 2026-06-02
In a Nutshell
How to answer performance tuning questions This hands-on tutorial focuses on practical implementation of optimization questions concepts.
Scenario 1: "The query is slow. How do you debug it?"
Answer Approach:
- Check EXPLAIN Plan: Identify if indexes are being used.
- Scan Type: Look for "Full Table Scan" (bad) vs "Index Scan" (good).
- Indexes: Check if filtering columns (
WHERE,JOIN) are indexed. - Volume: Is the dataset too large? Can we partition it?
Scenario 2: "Improve this query with LIKE"
Query: SELECT * FROM Users WHERE Name LIKE '%John%';
Problem: Leading wildcard % prevents index usage.
Solution:
- If looking for 'John' at start:
LIKE 'John%'(uses index). - If full-text search needed: Use Full-Text Index (MySQL/PostgreSQL) output ElasticSearch.
Scenario 3: "UNION vs UNION ALL"
Question: Which is faster?
Answer: UNION ALL is faster because it does not check for duplicates. UNION removes duplicates, which is an expensive sorting operation.
Scenario 4: "Why is COUNT(*) fast or slow?"
- MyISAM (MySQL old): Fast (stores row count).
- InnoDB (MySQL new) / PostgreSQL: Slow (scans all rows due to MVCC).
- Optimization: Use an approximate count from system tables if exact number isn't critical.
sql-interview-union
UNION Performance
Problem Statement
Which operator should you use to combine results from two tables if you know there are no duplicates and want better performance?