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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql: Greatly speed up "\d tablename" when not using regexes
Date: 2024-04-10 18:06:38
Message-ID: 4091190.1712772398@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Jelte Fennema-Nio <postgres(at)jeltef(dot)nl> writes:
> 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.

Really? ISTM this argument is ignoring an optimization the backend
has understood for a long time.

regression=# explain select * from pg_class where relname ~ '^foo$';
QUERY PLAN

--------------------------------------------------------------------------------
-------------
Index Scan using pg_class_relname_nsp_index on pg_class (cost=0.28..8.30 rows=
1 width=739)
Index Cond: (relname = 'foo'::text)
Filter: (relname ~ '^foo$'::text)
(3 rows)

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ranier Vilela 2024-04-10 18:07:27 Fix possible dereference null pointer (src/backend/replication/logical/reorderbuffer.c)
Previous Message Tom Lane 2024-04-10 18:02:20 Re: Issue with the PRNG used by Postgres