- Lab
- Data

SQL Fundamentals: SQL Performance and Optimization
In this lab, you'll explore how to improve SQL query performance using indexing and query optimization techniques. You'll learn how to create and manage indexes, write efficient queries, and analyze execution plans to identify bottlenecks. By the end, you'll have a solid understanding of how to optimize SQL queries for better performance.

Path Info
Table of Contents
-
Challenge
Indexing
SQL Guide
For each task, replace or update the existing SQL code in the top pane (
main.sql
) with your answer to the task and run it to see the results in the bottom pane (SQL Viewer).
Step 1: Indexing
To review the concepts covered in this step, please refer to the course Additional Topics module of the Introduction to SQL Course.
In this step, you'll explore several types of indexes that improve database query performance, including
single-column
,composite
,UNIQUE
, andFULLTEXT
indexes. Indexes act like a roadmap for the database, allowing it to quickly locate data without scanning every row in a table. By indexing columns that are frequently searched or filtered inWHERE
clauses, you can optimize your queries and make the database more efficient.🫙Database Structure
Tables You Will Be Working With:
Employees:
| Column Name | Data Type | |-------------|-------------------| | EmployeeID | INT | | FirstName | VARCHAR(50) | | LastName | VARCHAR(50) | | Salary | DECIMAL(10, 2) | | Department | VARCHAR(100) | | TotalSales | DECIMAL(10, 2) |
Orders:
| Column Name | Data Type | |--------------|-------------------| | OrderID | INT | | CustomerID | INT | | OrderDate | DATE | | TotalAmount | DECIMAL(10, 2) |
Products:
| Column Name | Data Type | |----------------|-------------------| | ProductID | INT | | ProductName | VARCHAR(100) | | Category | VARCHAR(100) | | ListPrice | DECIMAL(10, 2) |
📚 Real-World Context
Indexes play a crucial role in optimizing queries in real-world systems. For instance, in an e-commerce application, using an index on product names can speed up product search operations. Similarly, a composite index on the order date and customer ID helps in efficiently retrieving customer orders by date.
-
Challenge
Query Optimization
Step 2: Query Optimization
Efficient queries are essential for optimal database performance. In this step, you'll learn techniques to optimize your SQL queries by limiting results, using proper indexing, and structuring queries effectively to reduce load and improve response times.
🫙Database Structure
Tables You Will Be Working With:
Employees:
| Column Name | Data Type | |-------------|------------------------------------| | EmployeeID | INT PRIMARY KEY AUTO_INCREMENT | | FirstName | VARCHAR(50) | | LastName | VARCHAR(50) | | Department | VARCHAR(100) | | Salary | DECIMAL(10, 2) | | TotalSales | DECIMAL(10, 2) DEFAULT 0 |
Products:
| Column Name | Data Type | |-------------|------------------------------------| | ProductID | INT PRIMARY KEY AUTO_INCREMENT | | ProductName | VARCHAR(100) | | Category | VARCHAR(100) | | ListPrice | DECIMAL(10, 2) |
Customers:
| Column Name | Data Type | |-------------|------------------------------------| | CustomerID | INT PRIMARY KEY AUTO_INCREMENT | | FirstName | VARCHAR(50) | | LastName | VARCHAR(50) | | TotalOrders | INT DEFAULT 0 |
📚 Real-World Context
Imagine a news website displaying the latest articles. Loading all articles ever published would be inefficient. Instead, the site shows the most recent ones. Similarly, optimizing queries to fetch only necessary data enhances performance and user experience.
-
Challenge
Analyzing Query Performance
Step 3: Analyzing Query Performance
Understanding how your queries are executed helps you identify and fix performance issues. In this step, you'll learn how to view execution plans and make adjustments to improve efficiency.
🫙Database Structure
Tables You Will Be Working With:
Orders:
| Column Name | Data Type | |-------------|------------------------------------| | OrderID | INT PRIMARY KEY AUTO_INCREMENT | | OrderDate | DATE | | CustomerID | INT | | Status | VARCHAR(50) | | TotalAmount | DECIMAL(10, 2) |
📚 Real-World Context
Just like a mechanic examines an engine to diagnose issues, a database professional analyzes query execution plans to identify and resolve performance bottlenecks. This ensures applications run smoothly and efficiently.
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.