Skip to content
Learn Netverks

Lesson

Step 15/36 42% through track

partial-indexes

Partial indexes

Last reviewed Jun 1, 2026 Content v20260601
Track mode
sql_sandbox
Means
SQL sandbox
Reading
~2 min
Level
intermediate

This lesson

This lesson teaches Partial indexes: the SQL patterns, schema habits, and query reasoning you need before advancing in PostgreSQL.

Teams query Partial indexes on every PostgreSQL codebase—skipping it leaves gaps in debugging and data reviews.

You will apply Partial indexes in contexts like: Modern startups, geospatial apps, and analytics-friendly OLTP systems.

Copy Postgres SQL into psql, local PostgreSQL, or DB Fiddle (PostgreSQL dialect)—use \d and EXPLAIN ANALYZE where lessons show them. The in-browser lab ships later; psql is the practice path now.

When you can explain the previous lesson's ideas without copying example queries verbatim.

A partial index indexes only rows matching a predicate—smaller and faster when queries always filter the same way (active users, open tickets).

Creating partial indexes

CREATE INDEX idx_users_active_email
  ON users (email)
  WHERE active = true;

CREATE UNIQUE INDEX idx_orders_open_number
  ON orders (order_number)
  WHERE status = 'open';

Practice: Apply DDL in a throwaway practice database. Use \d table in psql to verify constraints and indexes.

Matching queries

SELECT email FROM users
WHERE active = true AND email LIKE 'a%';

The planner can use the partial index when the query predicate implies the index WHERE clause.

Trade-offs

Partial indexes are invisible to generic ORMs unless migrations specify them—document predicates for the team.

Important interview questions and answers

  1. Q: Partial unique index?
    A: Enforces uniqueness only among rows matching the predicate—e.g. one open order number per customer segment.
  2. Q: When not to use?
    A: When application queries lack the matching filter—planner will ignore the index.

Self-check

  1. What clause defines which rows enter a partial index?
  2. Why are partial indexes smaller?

Tip: Document the partial index predicate—ORMs won't infer it automatically.

Interview prep

Partial index?

Indexes subset of rows matching a WHERE predicate.

When useful?

Queries always filter the same way (e.g. active = true).

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

  • Partial index use?
  • WHERE on index?

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