Concept
Indexes are not merit badges. They should match the reads the API will perform, and EXPLAIN should tell the truth about whether the planner uses them at the current data size.
Task
- Add indexes for cinema bounding box, screens by cinema, and showtimes by screen/start.
- Seed enough showtime rows that planner behavior can be discussed.
- Capture EXPLAIN (ANALYZE, BUFFERS) for the cinema/day showtime query.
Run
docker compose up -d postgres./gradlew flywayMigratepsql postgresql://palabas:palabas@localhost:5432/palabas -f docs/transcripts/phase-2a-explain.sqlExpected Result
- The transcript explains the chosen plan instead of blindly celebrating an index.
Common Traps
- Adding indexes without naming the query they serve.
- Forcing an index hit on tiny data.
- Forgetting that showtimes by cinema travels through screens.
Hint Ladder
Hint 1
The query begins with cinema_id but showtimes only know screen_id.
Hint 2
A good transcript can say the planner chose a seq scan and why.
Hint 3
The artifact is the reasoning, not just the plan text.
Solution
See docs/transcripts/phase-2a-explain.sql and phase-2a-explain.txt.