#1 Data Analytics Program in India
₹2,499₹1,499Enroll Now
Step 16
4 min read

Query Analysis Techniques

Learn how to check if your query is fast or slow.

How to Check Query Speed

Performance Indicators
IndicatorGoodBad
Scan TypeIndex ScanSequential Scan
RowsFew (100)Many (100,000)
CostLow (< 100)High (> 1000)
3 rows

Use EXPLAIN to see how database runs your query.

EXPLAIN SELECT * FROM students WHERE age > 20;

What EXPLAIN Shows

Performance Indicators
IndicatorGoodBad
Scan TypeIndex ScanSequential Scan
RowsFew (100)Many (100,000)
CostLow (< 100)High (> 1000)
3 rows

Reading EXPLAIN Output

Performance Indicators
IndicatorGoodBad
Scan TypeIndex ScanSequential Scan
RowsFew (100)Many (100,000)
CostLow (< 100)High (> 1000)
3 rows

Good query:

Index Scan on students Rows: 50 Cost: 8.29

Bad query:

Seq Scan on students Rows: 100000 Cost: 1520.00

Fix Slow Queries

Performance Indicators
IndicatorGoodBad
Scan TypeIndex ScanSequential Scan
RowsFew (100)Many (100,000)
CostLow (< 100)High (> 1000)
3 rows
  1. Add index on columns in WHERE
  2. Reduce data with more filters
  3. Use selective projection

Summary

Performance Indicators
IndicatorGoodBad
Scan TypeIndex ScanSequential Scan
RowsFew (100)Many (100,000)
CostLow (< 100)High (> 1000)
3 rows
  • EXPLAIN shows query execution plan
  • Look for Index Scan (good) vs Seq Scan (bad)
  • Low rows and cost = fast query

Finished this topic?

Mark it complete to track your progress and maintain your streak!

SkillsetMaster - AI, Web Development & Data Analytics Courses