Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rucLM-006Uj0-MM for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Apr 2024 18:06:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rucLL-006DIC-MQ for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Apr 2024 18:06:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rucLL-006DI3-Cd for pgsql-hackers@lists.postgresql.org; Wed, 10 Apr 2024 18:06:43 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rucLI-000Etn-UM for pgsql-hackers@postgresql.org; Wed, 10 Apr 2024 18:06:42 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 43AI6co94091191; Wed, 10 Apr 2024 14:06:38 -0400 From: Tom Lane To: Jelte Fennema-Nio cc: PostgreSQL-development Subject: Re: psql: Greatly speed up "\d tablename" when not using regexes In-reply-to: References: Comments: In-reply-to Jelte Fennema-Nio message dated "Wed, 10 Apr 2024 17:50:42 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4091189.1712772398.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 10 Apr 2024 14:06:38 -0400 Message-ID: <4091190.1712772398@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jelte Fennema-Nio 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=3D# explain select * from pg_class where relname ~ '^foo$'; QUERY PLAN = = = --------------------------------------------------------------------------= ------ ------------- Index Scan using pg_class_relname_nsp_index on pg_class (cost=3D0.28..8.= 30 rows=3D 1 width=3D739) Index Cond: (relname =3D 'foo'::text) Filter: (relname ~ '^foo$'::text) (3 rows) regards, tom lane