Skip to content
Learn Netverks

Lesson

Step 16/36 44% through track

indexes-intro

Indexes introduction

Last reviewed May 28, 2026 Content v20260528
Track mode
sql_sandbox
Means
SQL sandbox
Reading
~2 min
Level
intermediate

This lesson

An orientation to the SQL track—relational concepts, query patterns, and how to practice until the SQL sandbox lab ships.

You need a clear map of the SQL track so tables, keys, JOINs, and aggregates do not feel like magic.

You will apply Indexes introduction in contexts like: Slow API endpoints, batch ETL jobs, and DBA-led performance tuning.

Copy SQL from each lesson into SQLite (sqlite3), DB Fiddle, or local Postgres—read result grids and row counts. The in-browser SQL lab (sql_sandbox) will run queries when the runner ships; until then, local clients are the practice path. Also read the interview prep blocks.

After basic programming literacy—before ORM-heavy frameworks assume you can read the SQL they generate.

Indexes are auxiliary data structures that speed up lookups and sorting—like a book index. They trade extra storage and slower writes for faster reads on large tables.

Creating indexes

CREATE INDEX idx_orders_customer
  ON orders (customer_id);

CREATE UNIQUE INDEX idx_users_email
  ON users (email);

Practice: Run DDL in a fresh SQLite file or DB Fiddle schema pane. Drop test tables when experimenting.

When indexes help

  • WHERE on indexed columns (customer_id = 1)
  • JOIN keys matching indexed columns
  • ORDER BY on indexed columns (sometimes)

Leading wildcard LIKE patterns and functions on columns (WHERE LOWER(email) = ...) often defeat indexes.

Composite index

CREATE INDEX idx_orders_customer_date
  ON orders (customer_id, ordered_at);

Column order matters: index helps filters on leftmost prefix (customer_id alone, or both columns).

Important interview questions and answers

  1. Q: Index every column?
    A: No—each index slows INSERT/UPDATE/DELETE and uses disk; index high-selectivity query paths.
  2. Q: PRIMARY KEY indexed?
    A: Yes—primary keys create a unique index automatically.

Self-check

  1. Why index foreign key columns?
  2. What is a composite index leftmost prefix rule?

Tip: Index foreign keys and columns in frequent WHERE/JOIN predicates before micro-optimizing SELECT lists.

Interview prep

Index trade-off?

Faster reads, slower writes, extra storage.

Composite index order?

Leftmost prefix rule—leading columns must be filtered for index use.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Covering index?
  • Too many indexes?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump