Planlens
PostgreSQL query-plan analyser and index advisor.
- Status
- Implemented and documented; not yet run in a clean environment; no benchmarks
- PostgreSQL
- Query optimisation
- SQL
- Python
Status: the implementation and its test suite are included, but they have not yet been run in a clean environment, and benchmarks are not yet published. This page describes the design and scope; the repository README is the source of truth for the exact behaviour.
Problem
Query tuning is often done by trial and error: add an index, run the query again, hope. PostgreSQL already tells you what it does through EXPLAIN, but reading a large plan and turning it into a decision takes practice.
Planlens is a query-plan analyser and index advisor that tries to make that reading systematic.
Approach
- Read the
EXPLAIN (FORMAT JSON)plan PostgreSQL produces for a query. - Explain where the work happens, using a small set of detectors such as selective sequential scans, sorts that spill to disk and large gaps between estimated and actual rows.
- Suggest btree indexes that could change the plan, with the reasoning.
The goal is advice a person can check, not a black box: each suggestion points at the part of the plan that motivated it.
Design considerations
- Plans are evidence. Conclusions come from the plan, not from guesses about the schema.
- Suggestions are hypotheses. An index that looks helpful can be ignored by the planner, slow down writes or bloat storage. The tool presents candidates to be tested, not changes to apply blindly.
- Reproducible comparison. Plans and timings are only meaningful when the data and the settings are described, so the project favours scripted, repeatable comparisons over one-off screenshots.
Why it matters
Relational design, SQL and query optimisation are core skills for data engineering. This project is where I practise them deliberately.
Limitations
- Suggestions are advisory heuristics over a single plan and are not validated against every workload.
- The test plans are hand-written samples, not captured from a live server.
- No benchmark results are published yet. Any speed-up claim will appear only with the data, the settings and the commands needed to reproduce it.
Roadmap
- Capture real plans from several PostgreSQL versions as test fixtures.
- Publish a reproducible benchmark with its method and spread.
- Add partial and covering index suggestions, and read existing indexes directly from the catalogue.