A reproducible PostgreSQL index experiment on 200,000 rows
Doha I. · Published · Lire en français

In our local PostgreSQL 17.12 experiment, adding an index on customer_id changed a 200,000-row lookup from a sequential scan to an indexed plan. The median execution time over five warm-cache runs moved from 7.678 ms to 0.097 ms, with identical returned rows. These local results are not a LordBase hosting benchmark.
An index can reduce the work needed to find a small number of rows. Here is an experiment you can repeat, including the data generator, plans and observed results. It was executed on 2 December 2026 using a disposable local PostgreSQL 17.12 instance. It measures a SQL plan on one machine, not LordBase latency, throughput or reliability.
Dataset and question
The script creates 200,000 orders with an integer primary key, a customer ID distributed over 10,000 values and a deterministic text payload. The selected customer has 20 orders.
SELECT id, payload FROM orders WHERE customer_id = 4242;
First it measures the query without an index on customer_id. Then it adds that index, analyzes the table and repeats the same query. Both cases receive one warm-up and five measured EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) executions. ANALYZE actually executes the statement.
What happened
| Observation | Without customer index | With customer index |
|---|---|---|
| Table rows | 200,000 | 200,000 |
| Matching rows | 20 | 20 |
| Median execution time, five runs | 7.678 ms | 0.097 ms |
| Returned data | Identical to indexed case | Identical to original case |
The complete plans and individual timings are in the recorded result. The change illustrates selective access, not a universal speed multiplier. Different data distributions, cache states, machines and PostgreSQL settings will change the result. A local SQL execution time also excludes your application's network round trips.
Repeat it
Download and inspect the Python lab script. It requires Python 3 and the PostgreSQL command-line tools. Supply their installed directory:
python3 postgresql-recovery-lab.py --postgres-bin /path/to/postgresql/bin --output results.json
The script creates its own temporary cluster, uses a private Unix socket without TCP listening, then stops and removes that cluster. It accepts no connection URL and does not connect to an existing database. The run also performs the backup and restore experiment.
Apply the method to your application
Start with the queries that consume the most time. Confirm the filter, cardinality and plan before adding an index. Indexes use storage and add work to writes. Check the whole workload and keep the returned data unchanged.
LordBase exposes PostgreSQL query analytics. Verify that collection is available before interpreting its counters. If using an AI assistant, ask for diagnosis first and review any proposed schema change before executing it.
