From 134d3e8d7e9de0443bc9e5094667cdb4275f71e7 Mon Sep 17 00:00:00 2001 From: Nick Jones Date: Tue, 25 Jun 2019 12:37:52 +1000 Subject: [PATCH] Read OIDs for composite types on connection init. This used to be done, but pulled in tables which slowed down connections on databases with a large number of tables; see https://github.com/jackc/pgx/issues/140. This change includes composite types but excludes tables by joining against [pg_class](https://www.postgresql.org/docs/11/catalog-pg-class.html) in which `relkind` is `'c'` for the former and `'r'` for the latter. Fixes https://github.com/jackc/pgx/issues/420. --- conn.go | 4 +++- pgmock/pgmock.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/conn.go b/conn.go index cb24748c..0cf6c167 100644 --- a/conn.go +++ b/conn.go @@ -404,9 +404,11 @@ func initPostgresql(c *Conn) (*pgtype.ConnInfo, error) { from pg_type t left join pg_type base_type on t.typelem=base_type.oid left join pg_namespace nsp on t.typnamespace=nsp.oid +left join pg_class cls on t.typrelid=cls.oid where ( - t.typtype in('b', 'p', 'r', 'e') + t.typtype in('b', 'p', 'r', 'e', 'c') and (base_type.oid is null or base_type.typtype in('b', 'p', 'r')) + and (cls.oid is null or cls.relkind='c') )` ) diff --git a/pgmock/pgmock.go b/pgmock/pgmock.go index 4d15f7b8..d4ab0d13 100644 --- a/pgmock/pgmock.go +++ b/pgmock/pgmock.go @@ -211,9 +211,11 @@ func PgxInitSteps() []Step { from pg_type t left join pg_type base_type on t.typelem=base_type.oid left join pg_namespace nsp on t.typnamespace=nsp.oid +left join pg_class cls on t.typrelid=cls.oid where ( - t.typtype in('b', 'p', 'r', 'e') + t.typtype in('b', 'p', 'r', 'e', 'c') and (base_type.oid is null or base_type.typtype in('b', 'p', 'r')) + and (cls.oid is null or cls.relkind='c') )`, }), ExpectMessage(&pgproto3.Describe{