TOPIC 20/2816 MINNOT STARTED

Indexes and views: faster lookups and saved queries

Learn what an index does and costs, what a view is, and what a tester checks: that an index does not change answers, and that a view shows current data.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: the index of a book, and a reading list. The index at the back lets you jump to a topic. The publisher must update it when the book changes. A reading list names which pages to read. It is not a copy of the pages.

Daily List is a to-do list app. Looking up Lily's tasks by user id is slow on a large copy. Leo adds an index. A called open tasks is a view. Tom tests both. (SYNTHETIC / TRAINING ONLY: Daily List and the people here are invented.).

What it is: A is an extra structure that helps the database find rows by a column. (Structured Query Language) creates it with CREATE INDEX. A table is a grid. A row is one task. A column is one fact, such as user_id. The index is not a second copy of the answer. The neighbour is the table itself. The table still holds the rows. A stored query view is a saved SELECT that you read like a table. It is not a table, and a normal view stores no rows of its own.

Why it matters: An index that changes the rows is a bug, even if the screen is faster. A view that hides a new task is also a bug, if it was supposed to read current data. The is the extra work on every insert and update.

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.

THE REAL JOB A book index and a marked reading list.

  1. Compare
  2. Time
  3. View
Book index

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
The index at the back of the bookA lookup index
Updating the index for a new editionThe index write cost
A marked list of pagesA view
The pages themselvesThe table rows

WHERE THIS PICTURE STOPS

  • A book index is printed once, but a database index updates on every change.
  • A list is on paper, but a view runs when read.
  • A book has one index, but a table can have several.

HOOK

Index for speed, list for reuse.

TELL A FRIEND

A book: the index finds, the list points.

OFTEN MIXED UP WITH Looking at data with SQL SELECT. That topic reads data with SELECT. This one covers an index that speeds the read and a view that saves it.

PRACTISE AND KEEP

Sources for this topic — 4 sources
  1. Market practice

    Indexes: introduction (PostgreSQL documentation) ↗ — PostgreSQL · PostgreSQL introduction to indexes: an index lets the server find rows much faster than without one, but it adds overhead to the system as a whole, so it should be used with judgement (search excerpt, page not opened)

    The PostgreSQL introduction to indexes: an index lets the server find rows much faster, but it adds overhead to the system as a whole, so use indexes with judgement. Official project documentation. · Checked 2026-10-31

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  2. Market practice

    CREATE VIEW (PostgreSQL documentation) ↗ — PostgreSQL Global Development Group · Third-party tutorials on PostgreSQL views: a view is a named query stored in the database, and it stores no rows except a materialized view (search excerpt, page not opened)

    CREATE VIEW: ordinary query definition, not materialized result. PostgreSQL18 implementation, not a universal SQL mandate. · Checked 2026-11-06

    PostgreSQL18 publisher documentation opened on6November2026: CREATE VIEW: ordinary query definition, not materialized result. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.

  3. Implementation-specific

    PostgreSQL documentation ↗ — The PostgreSQL Global Development Group · PostgreSQL 18 official manual, opened 2026-11-06: indexes-intro §11.1, sql-createview, sql-explain and transaction-iso. Supports only PostgreSQL behavior; earlier execution evidence remains separately versioned.

    A free, precise, section-numbered description of the SQL a payments practitioner actually writes. Join types and what happens to unmatched rows, GROUP BY and HAVING against WHERE, window functions and the de-duplication and running-total idioms built on them. Transaction isolation levels and the anomalies each permits, index use, and null three-valued logic.

    Used here for the data-and-SQL questions a Payment Operations Analyst, a Production Support Analyst and a Sanctions Screening Analyst are asked. · Checked 2026-08-18

    An implementation, not the standard — which is the point. ISO/IEC 9075-2 is paywalled, and this documents the same constructs in text anybody can open. Its isolation-level chapter attributes to the standard explicitly, so it can carry a standard-level claim as long as the citation says which document it is quoting.

    Cited as market practice rather than an official standard by kind: an engine's manual is authoritative about that engine and is not the obligation. Where a question turns on behaviour PostgreSQL chose rather than behaviour SQL requires, the answer has to say so.

    One correction carried here because it circulates widely: the sentence "The fundamental difference between WHERE and HAVING…", quoted all over the internet as PostgreSQL documentation, is not in the current documentation. It was searched for in the source tree and is not there.

    Read through a mirror, because the publisher's own domain could not be fetched (a reachability gap, not a statement about the publisher). A 403 there is a policy refusal and says nothing about whether the document exists or is reachable elsewhere.

    Anyone on an unrestricted network should open the canonical URL above and confirm the section and page numbers cited against it. Every claim drawn from this entry is written so that it can be checked against a numbered page.

    Read from the postgres/postgres documentation source tree (doc/src/sgml), which the project itself maintains and which carries the section ids the published URLs are derived from — so a cited section id can be checked against the rendered page.

  4. Implementation-specific

    SQLite official documentation — constraints, types and transactions ↗ — SQLite · SQLite rolling official documentation, opened 2026-11-06: foreignkeys.html, datatype3.html, lang_createtable.html, lang_transaction.html, isolation.html, cli.html, series.html and lang_createtrigger.html as relevant. Historical SQLite 3.40.1 results remain distinct from in-memory audit witnesses on 3.53.1.

    Implementation-specific SQLite documentation, not a universal SQL standard. Includes foreign-key enforcement, type affinity, CREATE TABLE/TRIGGER, explicit/implicit transaction behavior, isolation, CLI and series extension references. · Checked 2026-11-06

    Relevant primary pages opened 6 November2026; rolling documentation and CLI examples (3.54.0) are distinct from historical lesson runs3.40.1 and audit witnesses3.53.1. No file/connected database audit execution.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.