Column changes such as an increase in varchar size, can cause extremely slow queries, and postgres should run analyze automatically.

From: Tyler <tyhou13(at)gmx(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Column changes such as an increase in varchar size, can cause extremely slow queries, and postgres should run analyze automatically.
Date: 2024-10-31 18:34:38
Message-ID: 263af164-52f5-4b9c-bac3-5309795fe802@gmx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

In our project lemmy, we recently had a production breaking bug causing extremely slow queries to one of our tables.

Finally after a lot of testing, we narrowed it down to a migration that increased the size of a varchar column meant to store URL data.

This increases the url column from 512 -> 2000 characters.

up.sql:

```sql
ALTER TABLE post
    ALTER COLUMN url TYPE varchar(2000);
```

This table currently has 1,186,895 rows, and joins are occasionally done to that column.

We finally realized that running this simple query manually, fixed the issue:

`ANALYZE post (url);`

I'm sure we're not the only ones to experience this potentially production-breaking bug, and postgres should probably automatically re-run analyze on columns for tables that have a large number of rows, that are changed.

For more context, see: https://github.com/LemmyNet/lemmy/pull/5148

Thanks everyone,

-- dessalines

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Bastien Roucariès 2024-10-31 20:12:12 Re: Detection of hadware feature => please do not use signal
Previous Message Tom Lane 2024-10-31 18:25:34 Re: Detection of hadware feature => please do not use signal