Re: psql: Greatly speed up "\d tablename" when not using regexes - Mailing list pgsql-hackers

From Tom Lane
Subject Re: psql: Greatly speed up "\d tablename" when not using regexes
Date
Msg-id 4091190.1712772398@sss.pgh.pa.us
Whole thread Raw
In response to [MASSMAIL]psql: Greatly speed up "\d tablename" when not using regexes  (Jelte Fennema-Nio <postgres@jeltef.nl>)
Responses Re: psql: Greatly speed up "\d tablename" when not using regexes
List pgsql-hackers
Jelte Fennema-Nio <postgres@jeltef.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



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Issue with the PRNG used by Postgres
Next
From: Ranier Vilela
Date:
Subject: [MASSMAIL] Fix possible dereference null pointer (src/backend/replication/logical/reorderbuffer.c)