pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Subject: Re: slow queries over information schema.tables
Date: Wed, 19 Dec 2018 23:29:35 -0500
Message-ID: <21662.1545280175@sss.pgh.pa.us> (raw)
In-Reply-To: <CAFj8pRDrfRR8MNxPTuPnN27FUcNeKwiPgiFttzt5K_XVWKOH7g@mail.gmail.com>
References: <CAFj8pRBUCX4LZ2rA2BbEkdD6NN59mgx+BLo1gO08Wod4RLtcTg@mail.gmail.com>
	<5978.1544030694@sss.pgh.pa.us>
	<9288.1545261277@sss.pgh.pa.us>
	<CAFj8pRDrfRR8MNxPTuPnN27FUcNeKwiPgiFttzt5K_XVWKOH7g@mail.gmail.com>

Pavel Stehule <pavel.stehule@gmail.com> writes:
> čt 20. 12. 2018 v 0:14 odesílatel Tom Lane <tgl@sss.pgh.pa.us> napsal:
>> After my last few commits, the only issue that's left here is the
>> cast-to-varchar implied by casting to sql_identifier.  Upthread
>> I showed a possible planner hack to get rid of that, and we could
>> still solve it that way so far as allowing indexscans on catalogs
>> is concerned.  However, I wonder what people would think of a
>> more aggressive approach, viz:
>> -CREATE DOMAIN sql_identifier AS character varying COLLATE "C";
>> +CREATE DOMAIN sql_identifier AS name;

> The very common will be compare with text type - some like
> SELECT * FROM information_schema.tables WHERE table_name =
> lower('somename');

Yeah, that's not really an issue.  After applying the above one-liner
to HEAD, I get plans like this:

regression=# explain SELECT * FROM information_schema.tables WHERE table_name =
lower('somename');
                                                                                                                                            QUERY PLAN                                                                                                                                            
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Nested Loop Left Join  (cost=8.76..18.60 rows=1 width=608)
   ->  Hash Join  (cost=8.34..10.07 rows=1 width=141)
         Hash Cond: (nc.oid = c.relnamespace)
         ->  Seq Scan on pg_namespace nc  (cost=0.00..1.62 rows=33 width=68)
               Filter: (NOT pg_is_other_temp_schema(oid))
         ->  Hash  (cost=8.33..8.33 rows=1 width=77)
               ->  Index Scan using pg_class_relname_nsp_index on pg_class c  (cost=0.28..8.33 rows=1 width=77)
                     Index Cond: ((relname)::name = 'somename'::text)
                     Filter: ((relkind = ANY ('{r,v,f,p}'::"char"[])) AND (pg_has_role(relowner, 'USAGE'::text) OR has_table_privilege(oid, 'SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER'::text) OR has_any_column_privilege(oid, 'SELECT, INSERT, UPDATE, REFERENCES'::text)))
   ->  Nested Loop  (cost=0.42..8.46 rows=1 width=132)
         ->  Index Scan using pg_type_oid_index on pg_type t  (cost=0.28..8.29 rows=1 width=72)
               Index Cond: (c.reloftype = oid)
         ->  Index Scan using pg_namespace_oid_index on pg_namespace nt  (cost=0.14..0.16 rows=1 width=68)
               Index Cond: (oid = t.typnamespace)
(14 rows)

You could surely argue about whether this is too complicated, but it's not
the planner's fault that we've got so many conditions here ...

			regards, tom lane




view thread (21+ messages)  latest in thread

Message-ID: <21662.1545280175@sss.pgh.pa.us>
Permalink:  ../21662.1545280175@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21662.1545280175@sss.pgh.pa.us

 · 

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: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pavel.stehule@gmail.com, peter.eisentraut@2ndquadrant.com
  Subject: Re: slow queries over information schema.tables
  In-Reply-To: <21662.1545280175@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox