Lesson 62/100

Tutorials MySQL Tutorial

Secondary Indexes — Complete Guide

Secondary Indexes — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of MySQL Tutorial on Toolliyo Academy.

On this page

MySQL Tutorial · Lesson 62 of 100

Secondary Indexes

Basics ✓Advanced

Advanced · 2 — Production · ~10 min · MySQL — Indexing & Performance

What is this?

Secondary indexes are non-primary B-tree indexes on columns like email or customer_id. Leaves store indexed column + primary key for row lookup.

Why should you care?

Login by email needs idx_customers_email — without it MySQL scans entire customers table every auth.

See it live — copy this example

Run in MySQL Workbench or the mysql CLI.

CREATE INDEX idx_customers_email ON customers(email);
EXPLAIN SELECT customer_id, full_name
FROM customers
WHERE email = 'priya@dataflow.in';

What happened?

  • Index on email lets optimizer seek matching entries, then fetch rows by customer_id PK.
  • type=ref in EXPLAIN with key idx_customers_email shows index use.

Practice next

  1. ADD email column if missing; populate sample rows.
  2. EXPLAIN before index — type ALL.
  3. CREATE INDEX; EXPLAIN again.
  4. DROP INDEX and measure slow query log entry.
  5. Unique index on email prevents duplicate accounts.

Remember

Secondary indexes speed selective WHERE/JOIN. Each index costs write overhead. EXPLAIN confirms index pick.

DataFlow login path

Auth service queries by email 50k times/min — idx_customers_email required.

Outcome: Login P99 stays under 20ms.

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Junior Detailed
Explain SQL queries in the context of MySQL.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define SQL queri…
Mid Detailed
What are common mistakes teams make with Schema design when using MySQL?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Schema de…
Senior Detailed
How would you debug a production issue related to Transactions in a MySQL application?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Transacti…
Junior Detailed
Describe a real-world scenario where Normalization mattered in a MySQL project.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Normaliza…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

MySQL Tutorial
Course syllabus

MySQL Tutorial

MySQL — Foundations
MySQL — Queries & Clauses
MySQL — Joins & Relationships
MySQL — Functions & Window Functions
MySQL — Transactions & Concurrency
MySQL — Stored Procedures & Triggers
MySQL — Indexing & Performance
MySQL — Advanced MySQL
MySQL — Security & Cloud MySQL
MySQL — Real-World Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details