Subject: psql: Greatly speed up "\d tablename" when not using regexes

From: Jelte Fennema-Nio <[email-masked]>
Date: Wed, 10 Apr 2024 17:50:42 +0200

Running "\d tablename" from psql could take multiple seconds when
running on a system with 100k+ tables. The reason for this was that
a sequence scan on pg_class takes place, due to regex matching being
used.

Regex matching is obviously unnecessary when we're looking for an exact
match. This checks for this (common) case and starts using plain
equality in that case.

---

From: Kirill Reshke <[email-masked]>
Date: Wed, 10 Apr 2024 23:20:48 +0500

Hi

> match. This checks for this (common) case and starts using plain

+1

> + appendPQExpBuffer(buf, "(%s OPERATOR(pg_catalog.=) ", namevar);
> + appendStringLiteralConn(buf, &namebuf.data[2], conn);
> + appendPQExpBuffer(buf, "\n        OR %s OPERATOR(pg_catalog.=) ",
> +  altnamevar);
> + appendStringLiteralConn(buf, &namebuf.data[2], conn);
> + appendPQExpBufferStr(buf, ")\n");

Do we need to force Collaction here like in other branches?
if (PQserverVersion(conn) >= 120000)
   appendPQExpBufferStr(buf, " COLLATE pg_catalog.default");