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

From: "Jelte Fennema-Nio" <postgres(at)jeltef(dot)nl>
To: "Andres Freund" <andres(at)anarazel(dot)de>
Cc: "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org>, "Dilip Kumar" <dilipbalaut(at)gmail(dot)com>, "Thomas Munro" <thomas(dot)munro(at)gmail(dot)com>, "Noah Misch" <noah(at)leadboat(dot)com>, "Peter Eisentraut" <peter(at)eisentraut(dot)org>
Subject: Make \d tablename fast again, regression introduced by 85b7efa1cdd
Date: 2026-03-25 08:54:00
Message-ID: DHBQIZX8SZVI.ZX614ZMFL645@jeltef.nl
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

On Wed, 25 Mar 2026 at 04:15, Andres Freund <andres(at)anarazel(dot)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

Attachment Content-Type Size
v1-0001-Fix-LIKE-optimization-for-prefix-scan-with-determ.patch text/x-patch 4.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2026-03-25 08:57:31 Re: SQL Property Graph Queries (SQL/PGQ)
Previous Message Peter Smith 2026-03-25 08:48:32 Re: Initial COPY of Logical Replication is too slow