Make \d tablename fast again, regression introduced by 85b7efa1cdd

Jelte Fennema-Nio <postgres@jeltef.nl>

From: "Jelte Fennema-Nio" <postgres@jeltef.nl>
To: "Andres Freund" <andres@anarazel.de>
Cc: "PostgreSQL-development" <pgsql-hackers@postgresql.org>, "Dilip Kumar" <dilipbalaut@gmail.com>, "Thomas Munro" <thomas.munro@gmail.com>, "Noah Misch" <noah@leadboat.com>, "Peter Eisentraut" <peter@eisentraut.org>
Date: 2026-03-25T08:54:00Z
Lists: pgsql-hackers

Attachments

(forked from: Test timings are increasing too fast for cfbot)

On Wed, 25 Mar 2026 at 04:15, Andres Freund <andres@anarazel.de> wrote:
> It seems decidedly not optimal that "\d tablename", without any patterns, ends
> up doing a seqscan.  That's bad enough in the regression database, but there
> are many PG instances with many many entries in pg_class.
>
> I don't think this was always the case?
>
> If I remove the COLLATE pg_catalog.default, a sane plan is chosen. That's
> obviously not the right fix, but seemed interesting enough to mention.

Due to a very similar problem I faced in the past[1], I thought I had a
good sense of where roughly the problem was. And I indeed quickly found
it.

Attached is a patch that addresses this issue and starts using index
scans again for \d tablename.

This should be backpatched to PG18 where the regression was introduced
by 85b7efa1cdd

[1]: https://www.postgresql.org/message-id/flat/CAGECzQRqysy0eJMKR5he3gwtLrT87f9u5CQQua6B_XNwMnUtFA%40mail.gmail.com