# MNW 212: an index changes another query's plan

Requires Docker. From this directory, start an isolated Postgres container:

```sh
docker run -d --name mnw212-lab -e POSTGRES_PASSWORD=postgres postgres:18.6-alpine
docker exec mnw212-lab pg_isready -U postgres
docker cp lab.sql mnw212-lab:/tmp/lab.sql
docker exec mnw212-lab psql -X -U postgres -f /tmp/lab.sql
docker rm -f mnw212-lab
```

Wait until `pg_isready` reports accepting connections before running `psql`.
The script owns the `index_lab` schema and replaces it on every run.
It seeds one million comments with a fixed random seed and fixed date anchor.
User 42 owns exactly 10,000 comments, all older than a year.
It runs each plan twice; the article quotes the second run, with plan costs and buffer details trimmed.

`output.txt` is the complete local run. Timing and sampled planner estimates depend on the machine and may vary. The property to inspect is the date-only index scanning and filtering hundreds of thousands of rows, versus ten rows through the composite index.

References: [Postgres index ordering](https://www.postgresql.org/docs/18/indexes-ordering.html), [reading EXPLAIN](https://www.postgresql.org/docs/18/using-explain.html).
