AvailableIncluded in beta access

Micro-course · Intermediate

Speed up a query with indexes and EXPLAIN

Read a simple plan and add an index only when it solves a measured problem.

75 to 90 minPostgreSQL6 lessons · 9 activities available
Start the course

Free 30-day beta access · no payment · progress saved

The business problem

An email search slows down as the table grows.

What you will be able to do

Compare a plan before and after an index, and explain the index's cost.

  • Read EXPLAIN
  • Create a suitable index
  • Recognise a useless index
  • Measure before optimising

Scope of this micro-course

This micro-course targets one focused skill. It does not replace a complete path or server administration training.

Prerequisites

  • SELECT, filters and joins

Project and practice

9 verified exercises are available. Validation is based on the programme exercises.

Focused path

Your programme, in order.

Content remains centralised: completing an activity here also updates the path that contains it.

Micro-lessons

  1. 01
    WHERE keeps rows that meet a condition

    Without filter, the query returns all rows. `WHERE` is written after `FROM` and compares a column to a value.

    Open lesson
  2. 02
    ORDER BY organizes the result

    `ORDER BY` occurs after the filter. `ASC` sorts in ascending order and is usually the default. `DESC` applies descending order.

    Open lesson
  3. 03
    Make a filter explainable and reproducible

    A filter translates a business rule. Write this rule as a sentence before converting it to SQL: Paid orders, created during July, with an amount of at least €100. Each word influences the operator and the limits.

    Open lesson
  4. 04
    The problem to solve before syntax

    Adding indexes everywhere slows down writes and consumes space. The useful index depends on the filters, joins, sorts, volumes and selectivity of an actual query.

    Open lesson
  5. 05
    Build a controllable method

    Capture the slow query, use EXPLAIN then EXPLAIN ANALYZE on a safe environment, compare estimates and actual rows, and create the smallest index that serves the critical path.

    Open lesson
  6. 06
    Check before interpreting

    Measure before/after with representative data. Check the total time, readings, usage frequency and cost of the INSERT/UPDATE, not just the presence of an Index Scan.

    Open lesson

Practical exercises

  1. 01
    Choose an index and read EXPLAIN

    Compare a sequential scan and a scan indexed on 5,000 rows.

    Do exercise
  2. 02
    Indexing a billing search 2 · training scenario

    Create a targeted index and then verify its presence before interpreting a plan. You must produce the result, check it on the source data and explain what it allows you to decide in this billing system.

    Do exercise
  3. 03
    Indexing a logistics search 3 · training scenario

    Create a targeted index and then verify its presence before interpreting a plan. You must produce the result, check it on the source data and explain what it allows you to decide in this national expeditions.

    Do exercise
  4. 04
    Index an HR search 4 · training scenario

    Create a targeted index and then verify its presence before interpreting a plan. You must produce the result, control it on the source data and explain what it allows you to decide in this human resources management.

    Do exercise
  5. 05
    Indexing a search audit 5 · training scenario

    Create a targeted index and then verify its presence before interpreting a plan. You must produce the result, check it on the source data and explain what it allows you to decide in this audit log.

    Do exercise
  6. 06
    Filter then sort a threshold

    Keep the threshold inclusive and make the outcome controllable.

    Do exercise
  7. 07
    Filter and sort orders

    Find orders over €50, from highest to lowest.

    Do exercise
  8. 08
    Search for a prefix with LIKE

    Use a simple text pattern without confusing prefix and content.

    Do exercise
  9. 09
    Calculate revenue using three tables

    Follow the keys without adding a measure twice.

    Do exercise

Back to the full catalogue