> ## Content Index
> Fetch the complete content index at: https://logbuch-dev-blog.nichedthemes.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# One index took a lookup from 84 ms to 0.04 ms
- URL: https://logbuch-dev-blog.nichedthemes.com/one-index-84-ms-to-0-04/
- Published: 2026-09-14T17:30:00.000Z
- Updated: 2026-09-14T17:30:00.000Z
- Description: stummel looked up every code with a sequential scan over 1.2 million clicks’ worth of links. EXPLAIN ANALYZE showed it in one line.
- Author: Mira Okafor
- Tags: Postgres, Backend, #video-header, #Import 2026-11-19 07:37

0:00 

/0:06 

1× 

Before and after the index, in psql.

Every redirect looked up its code with a sequential scan. At 40,000 links that took 84 ms, longer than the rest of the request together. One unique index brought it to 0.04 ms.

![psql output: an index scan on links_code_key with an execution time of 0.042 ms.](https://logbuch-dev-blog.nichedthemes.com/content/images/logbuch/explain.jpg)

The plan after the index.

```sql
CREATE UNIQUE INDEX CONCURRENTLY links_code_key ON links (code);
```

`CONCURRENTLY` builds it without locking the table. It took 3 seconds and nobody noticed, which is the point.