public inbox for [email protected]
help / color / mirror / Atom feedFrom: Tom Lane <[email protected]>
To: Jelte Fennema-Nio <[email protected]>
Cc: PostgreSQL-development <[email protected]>
Subject: Re: psql: Greatly speed up "\d tablename" when not using regexes
Date: Wed, 10 Apr 2024 16:11:51 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAGECzQS7-564414-vV+XrPBj=4gHW6mPT8eObjq5=RrEseRcAw@mail.gmail.com>
References: <CAGECzQRqysy0eJMKR5he3gwtLrT87f9u5CQQua6B_XNwMnUtFA@mail.gmail.com>
<[email protected]>
<CAGECzQS7-564414-vV+XrPBj=4gHW6mPT8eObjq5=RrEseRcAw@mail.gmail.com>
Jelte Fennema-Nio <[email protected]> writes:
> On Wed, 10 Apr 2024 at 20:06, Tom Lane <[email protected]> wrote:
>> Really? ISTM this argument is ignoring an optimization the backend
>> has understood for a long time.
> Interesting. I didn't know about that optimization. I can't check
> right now, but probably the COLLATE breaks that optimization.
Not for me.
# explain select * from pg_class where relname ~ '^(foo)$' collate "en_US";
QUERY PLAN
---------------------------------------------------------------------------------------------
Index Scan using pg_class_relname_nsp_index on pg_class (cost=0.27..8.29 rows=1 width=263)
Index Cond: (relname = 'foo'::text)
Filter: (relname ~ '^(foo)$'::text COLLATE "en_US")
(3 rows)
Also, using -E:
# \d foo
/******** QUERY *********/
SELECT c.oid,
n.nspname,
c.relname
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname OPERATOR(pg_catalog.~) '^(foo)$' COLLATE pg_catalog.default
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 2, 3;
/************************/
# explain SELECT c.oid,
n.nspname,
c.relname
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname OPERATOR(pg_catalog.~) '^(foo)$' COLLATE pg_catalog.default
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 2, 3;
QUERY PLAN
----------------------------------------------------------------------------------------------------------
Sort (cost=9.42..9.42 rows=1 width=132)
Sort Key: n.nspname, c.relname
-> Nested Loop Left Join (cost=0.27..9.41 rows=1 width=132)
Join Filter: (n.oid = c.relnamespace)
-> Index Scan using pg_class_relname_nsp_index on pg_class c (cost=0.27..8.32 rows=1 width=72)
Index Cond: (relname = 'foo'::text)
Filter: ((relname ~ '^(foo)$'::text) AND pg_table_is_visible(oid))
-> Seq Scan on pg_namespace n (cost=0.00..1.04 rows=4 width=68)
(8 rows)
There may be an argument for psql to do what you suggest,
but so far it seems like duplicative complication.
If there's a case you can demonstrate where "\d foo" doesn't optimize
into an indexscan, we should look into exactly why that's happening,
because I think the cause must be more subtle than this.
regards, tom lane
view thread (3+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: psql: Greatly speed up "\d tablename" when not using regexes
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox